Skip to content
Open
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
7 changes: 7 additions & 0 deletions nbri_ehr/resources/queries/study/clinical_observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
EHR.Server.Utils.addError(scriptErrors, 'remark', "You selected 'Yes' for " + row.category + ", please explain in the Remark", "WARN");
}

// Always derive the type from the observation type's category rather than trusting the incoming value.
// The Observations form leaves it blank because it offers every type; the other forms set it explicitly,
// but their type pickers are filtered to the categories that agree with the value they set, so deriving
// here gives them the same answer. Deriving unconditionally also re-derives when a re-opened draft or a
// saved template carries a type left over from a different category.
row.type = triggerHelper.getObservationTypeCategory(row.category) === 'Behavior' ? 'Behavior' : 'Clinical';

// Handle scheduled observations
if (!helper.isValidateOnly() && row.scheduledDate) {
var qc;
Expand Down
6 changes: 4 additions & 2 deletions nbri_ehr/resources/queries/study/demographicsCagemates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ JOIN study.housing h2
-- cagemates. Room is not consulted, since it is derived from this same id and so can never distinguish two rows.
ON (h.cage = h2.cage
AND h2.Id.demographics.calculated_status = 'Alive'
AND h2.enddateTimeCoalesced >= now()
AND h2.isActive = true
AND h2.qcstate.publicdata = true)

WHERE h.enddateTimeCoalesced >= now()
-- a null location never resolved, so the row gets no cagemates rather than grouping with every other unresolved row
WHERE h.cage IS NOT NULL
AND h.isActive = true
AND h.qcstate.publicdata = true
GROUP BY h.id, h.cage

Expand Down
59 changes: 0 additions & 59 deletions nbri_ehr/resources/web/nbri_ehr/buttons/clinicalObsGridButton.js

This file was deleted.

7 changes: 7 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/ObsDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
EHR.model.DataModelManager.registerMetadata('ObsDefaults', {
byQuery: {
'study.clinical_observations': {
// This form offers every observation type, so it can't know the observation's type up front.
// Clearing the default inherited from ClinicalDefaults lets the trigger script derive it
// from the selected type's category.
type: {
hidden: true,
defaultValue: null
},
category: {
lookup: {
columns: 'value,description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public NBRIBehaviorRoundsFormType(DataEntryFormContext ctx, Module owner)
new NBRIAnimalDetailsFormSection(),
new NBRICaseTemplateFormSection("Case Template", "Case Template", "nbri_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nbri_ehr/panel/CaseTemplatePanel.js"))),
new NBRICasesFormPanelSection("Behavior Case", ctx, true),
new NBRIClinicalObservationsFormSection(true, "cases"),
new NBRIClinicalObservationsFormSection(null, true, "cases"),
new NBRITreatmentGivenFormSection(true, "cases")
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NBRIBehavioralCasesFormType(DataEntryFormContext ctx, Module owner)
new NBRICaseTemplateFormSection("Case Template", "Case Template", "nbri_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nbri_ehr/panel/CaseTemplatePanel.js"))),
new NBRICasesFormPanelSection("Behavior Case", ctx, true),
new NBRIClinicalRemarksFormPanelSection(true, "cases", "Behavior Assessment", ctx, true),
new NBRIClinicalObservationsFormSection(true, "cases"),
new NBRIClinicalObservationsFormSection(null, true, "cases"),
new NBRIObservationOrdersFormSection(null, true, "cases"),
new NBRITreatmentGivenFormSection(true, "cases"),
new NBRITreatmentOrderFormSection(true, "cases")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public NBRIBulkBehaviorFormType(DataEntryFormContext ctx, Module owner)
new NBRIClinicalRemarksFormSection("Behavior Assessment", ctx.getContainer().hasPermission(ctx.getUser(), NBRIEHRVetTechPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), EHRVeterinarianPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), AdminPermission.class)),
new NBRIClinicalObservationsFormSection(false, null),
new NBRIObservationOrdersFormSection("NBRI_DAILY_CLINICAL_OBS_ORDERS", false, null),
new NBRIClinicalObservationsFormSection(null, false, null),
new NBRIObservationOrdersFormSection(null, false, null),
new NBRITreatmentGivenFormSection(),
new NBRITreatmentOrderFormSection()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public NBRIBulkClinicalFormType(DataEntryFormContext ctx, Module owner)
ctx.getContainer().hasPermission(ctx.getUser(), EHRVeterinarianPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), AdminPermission.class)),
new NBRIWeightFormSection(true, true),
new NBRIClinicalObservationsFormSection(false, null),
new NBRIClinicalObservationsFormSection("NBRI_DAILY_CLINICAL_OBS", false, null),
new NBRIObservationOrdersFormSection("NBRI_DAILY_CLINICAL_OBS_ORDERS", false, null),
new NBRIProcedureFormSection(),
new NBRIProcedureOrderFormSection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public NBRICasesFormType(DataEntryFormContext ctx, Module owner)
new NBRICasesFormPanelSection("Clinical Case", ctx, false),
new NBRIClinicalRemarksFormPanelSection(true, "cases", "Clinical Remarks", ctx, false),
new NBRIWeightFormSection(true, false, true, "cases"),
new NBRIClinicalObservationsFormSection(true, "cases"),
new NBRIClinicalObservationsFormSection("NBRI_DAILY_CLINICAL_OBS", true, "cases"),
new NBRIObservationOrdersFormSection(null, true, "cases"),
new NBRIProcedureFormSection(true, "cases"),
new NBRIProcedureOrderFormSection(true, "cases"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public NBRIClinicalObservationsFormType(DataEntryFormContext ctx, Module owner)
super(ctx, owner, NAME, NAME, "Clinical", Arrays.asList(
new NBRITaskFormSection(),
new NBRIAnimalDetailsFormSection(),
new NBRIClinicalObservationsFormSection(false, false),
new NBRIClinicalObservationsFormSection("NBRI_DAILY_CLINICAL_OBS", false),
new NBRIWeightFormSection(true, true)
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NBRIClinicalRoundsFormType(DataEntryFormContext ctx, Module owner)
new NBRICaseTemplateFormSection("Case Template", "Case Template", "nbri_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nbri_ehr/panel/CaseTemplatePanel.js"))),
new NBRICasesFormPanelSection("Clinical Case", ctx, false),
new NBRIWeightFormSection(true, false, true, "cases"),
new NBRIClinicalObservationsFormSection(true, "cases"),
new NBRIClinicalObservationsFormSection("NBRI_DAILY_CLINICAL_OBS", true, "cases"),
new NBRIProcedureFormSection(true, "cases"),
new NBRITreatmentGivenFormSection(true, "cases"),
new NBRIVitalsFormSection(true, "cases"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@
public class NBRIClinicalObservationsFormSection extends BaseFormSection
{
public static final String LABEL = "Observations";
private boolean _autoPopulateDailyObs;
private final String _dailyObsOption;

public NBRIClinicalObservationsFormSection(boolean autoPopulateDailyObs, boolean initCollapsed)
public NBRIClinicalObservationsFormSection(String dailyObsOption, boolean initCollapsed)
{
super("study", "clinical_observations", LABEL, "ehr-clinicalobservationgridpanel", true, initCollapsed, true);

_autoPopulateDailyObs = autoPopulateDailyObs;
_dailyObsOption = dailyObsOption;
addClientDependency(ClientDependency.supplierFromPath("ehr/plugin/ClinicalObservationsCellEditing.js"));
addClientDependency(ClientDependency.supplierFromPath("nbri_ehr/data/ClinicalObservationClientStore.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/grid/ClinicalObservationGridPanel.js"));
addClientDependency(ClientDependency.supplierFromPath("nbri_ehr/buttons/clinicalObsGridButton.js"));
addClientDependency(ClientDependency.supplierFromPath("nbri_ehr/buttons/addClinicalObsButton.js"));
setClientStoreClass("NBRI_EHR.data.ClinicalObservationsClientStore");
}

public NBRIClinicalObservationsFormSection(boolean isChild, String parentQueryName)
public NBRIClinicalObservationsFormSection(String dailyObsOption, boolean isChild, String parentQueryName)
{
this(false, true);
this(dailyObsOption, true);

if (isChild && null != parentQueryName)
{
Expand All @@ -57,12 +56,9 @@ public List<String> getTbarButtons()
{
List<String> defaults = super.getTbarButtons();

if (_autoPopulateDailyObs)
if (_dailyObsOption != null)
{
defaults.add("NBRI_AUTO_POPULATE_DAILY_OBS");
}
else {
defaults.add("NBRI_DAILY_CLINICAL_OBS");
defaults.add(_dailyObsOption);
}

return defaults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public NBRIObservationOrdersFormSection(String dailyObsOption, boolean initColla
_dailyObsOption = dailyObsOption;
addClientDependency(ClientDependency.supplierFromPath("ehr/plugin/ClinicalObservationsCellEditing.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/grid/ClinicalObservationGridPanel.js"));
addClientDependency(ClientDependency.supplierFromPath("nbri_ehr/buttons/clinicalObsGridButton.js"));
addClientDependency(ClientDependency.supplierFromPath("nbri_ehr/buttons/addClinicalObsButton.js"));

setClientStoreClass("NBRI_EHR.data.ObsOrdersClientStore");
Expand Down
21 changes: 21 additions & 0 deletions nbri_ehr/src/org/labkey/nbri_ehr/query/NBRI_EHRTriggerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class NBRI_EHRTriggerHelper
private User _user;
private static final Logger _log = LogManager.getLogger(NBRI_EHRTriggerHelper.class);
private final Map<String,Object> _cachedDrugFormulary = new HashMap<>();
private final Map<String,String> _cachedObservationTypeCategories = new HashMap<>();

// Maps an originating observation order's taskid to the task its scheduled observations are grouped under,
// for the duration of a single save batch (the same helper instance is reused across rows in the batch).
Expand Down Expand Up @@ -924,6 +925,26 @@ public void ensureDailyClinicalObservationOrders(String id, String caseid, final
}
}

/**
* Returns the category of an observation type from ehr.observation_types, or null when the type has no
* category or is not found. Cached for the life of the save batch.
*/
public String getObservationTypeCategory(String observationType)
{
if (observationType == null)
return null;

if (!_cachedObservationTypeCategories.containsKey(observationType))
{
TableInfo ti = getTableInfo("ehr", "observation_types");
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("value"), observationType);
List<String> categories = new TableSelector(ti, Collections.singleton("category"), filter, null).getArrayList(String.class);
_cachedObservationTypeCategories.put(observationType, categories.isEmpty() ? null : categories.get(0));
}

return _cachedObservationTypeCategories.get(observationType);
}

// This helper function propagates clinical observations through clinical cases
public Map<String, Object> handleScheduledObservations(Map<String, Object> row, String qcstate, String orderTasks) throws SQLException, BatchValidationException, QueryUpdateServiceException, DuplicateKeyException
{
Expand Down
Loading