Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NOEL/LOEL form and display #907

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions frontend/animal/EditEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ class EditEndpoint {

// set NOEL, LOEL, FEL
const {endpoint} = this;
var fields = $("#id_NOEL, #id_LOEL, #id_FEL").html(
"<option value=-999>&lt;None&gt;</option>"
const options = firstDoses.values.map(
(v, i) => `<option value="${i}">${v} ${firstDoses.name}</option>`
);

$(".doses").each(function(i, v) {
fields.append(`<option value="${i}">${v.textContent}</option>`);
});

options.unshift("<option value=-999>&lt;None&gt;</option>");
$("#id_NOEL, #id_LOEL, #id_FEL").html(options);
$(`#id_NOEL option[value="${endpoint.data.NOEL}"]`).prop("selected", true);
$(`#id_LOEL option[value="${endpoint.data.LOEL}"]`).prop("selected", true);
$(`#id_FEL option[value="${endpoint.data.FEL}"]`).prop("selected", true);
Expand Down
4 changes: 2 additions & 2 deletions frontend/animal/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ class Endpoint extends Observee {
critical_dose = function(type) {
if (self.data[type] < 0) return;
var span = $("<span>");
new EndpointCriticalDose(self, span, type, true);
new EndpointCriticalDose(self, span, type);
return span;
},
bmd_response = function(type, showURL) {
if (self.data.bmds.length === 0) {
return;
}
var el = $("<div>");
new BMDResult(self, el, type, true, showURL);
new BMDResult(self, el, type, showURL);
return el;
},
getTaglist = function(tags, assessment_id) {
Expand Down
34 changes: 11 additions & 23 deletions frontend/animal/EndpointCriticalDose.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
import PropTypes from "prop-types";
import React from "react";
import ReactDOM from "react-dom";
import _ from "lodash";
import h from "shared/utils/helpers";

const Renderer = function(props) {
return (
<p>
{props.dose} {props.units}
</p>
);
};

class EndpointCriticalDose {
constructor(endpoint, span, type, show_units) {
constructor(endpoint, span, type) {
// custom field to observe dose changes and respond based on selected dose
endpoint.addObserver(this);
this.endpoint = endpoint;
this.span = span;
this.type = type;
this.critical_effect_idx = endpoint.data[type];
this.show_units = show_units;
this.update();
}

update() {
const ep = this.endpoint,
dose = h.ff(ep.data.groups[this.critical_effect_idx].dose),
units = this.show_units ? ep.doseUnits.activeUnit.name : "";

ReactDOM.render(<Renderer dose={dose} units={units} />, this.span[0]);
const dose_group_id = this.critical_effect_idx,
dose_units_id = this.endpoint.doseUnits.activeUnit.id,
group = _.find(this.endpoint.data.animal_group.dosing_regime.doses, el => {
return el.dose_group_id === dose_group_id && el.dose_units.id === dose_units_id;
}),
dose = group ? h.ff(group.dose) : "",
units = group ? group.dose_units.name : "",
text = `${dose} ${units}`;
this.span.text(text);
}
}

Renderer.propTypes = {
dose: PropTypes.string,
units: PropTypes.string,
};

export default EndpointCriticalDose;