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

// The Observations form leaves the type blank; derive it from the observation type's category.
// Every other form sets it explicitly, so those rows pass through untouched.
if (!row.type) {
row.type = triggerHelper.getObservationTypeCategory(row.category) === 'Behavior' ? 'Behavior' : 'Clinical';
}

// Handle scheduled observations
if (!helper.isValidateOnly() && row.scheduledDate) {
var qc;
Expand Down
7 changes: 7 additions & 0 deletions nirc_ehr/resources/web/nirc_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 NIRCBehaviorRoundsFormType(DataEntryFormContext ctx, Module owner)
new NIRCAnimalDetailsFormSection(),
new NIRCCaseTemplateFormSection("Case Template", "Case Template", "nirc_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nirc_ehr/panel/CaseTemplatePanel.js"))),
new NIRCCasesFormPanelSection("Behavior Case", ctx, true),
new NIRCClinicalObservationsFormSection(true, "cases"),
new NIRCClinicalObservationsFormSection(null, true, "cases"),
new NIRCTreatmentGivenFormSection(true, "cases")
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NIRCBehavioralCasesFormType(DataEntryFormContext ctx, Module owner)
new NIRCCaseTemplateFormSection("Case Template", "Case Template", "nirc_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nirc_ehr/panel/CaseTemplatePanel.js"))),
new NIRCCasesFormPanelSection("Behavior Case", ctx, true),
new NIRCClinicalRemarksFormPanelSection(true, "cases", "Behavior Assessment", ctx, true),
new NIRCClinicalObservationsFormSection(true, "cases"),
new NIRCClinicalObservationsFormSection(null, true, "cases"),
new NIRCObservationOrdersFormSection(null, true, "cases"),
new NIRCTreatmentGivenFormSection(true, "cases"),
new NIRCTreatmentOrderFormSection(true, "cases")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public NIRCBulkBehaviorFormType(DataEntryFormContext ctx, Module owner)
new NIRCClinicalRemarksFormSection("Behavior Assessment", ctx.getContainer().hasPermission(ctx.getUser(), NIRCEHRVetTechPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), EHRVeterinarianPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), AdminPermission.class)),
new NIRCClinicalObservationsFormSection(false, null),
new NIRCObservationOrdersFormSection("NIRC_DAILY_CLINICAL_OBS_ORDERS", false, null),
new NIRCClinicalObservationsFormSection(null, false, null),
new NIRCObservationOrdersFormSection(null, false, null),
new NIRCTreatmentGivenFormSection(),
new NIRCTreatmentOrderFormSection()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public NIRCBulkClinicalFormType(DataEntryFormContext ctx, Module owner)
ctx.getContainer().hasPermission(ctx.getUser(), EHRVeterinarianPermission.class),
ctx.getContainer().hasPermission(ctx.getUser(), AdminPermission.class)),
new NIRCWeightFormSection(true, true),
new NIRCClinicalObservationsFormSection(false, null),
new NIRCClinicalObservationsFormSection("NIRC_DAILY_CLINICAL_OBS", false, null),
new NIRCObservationOrdersFormSection("NIRC_DAILY_CLINICAL_OBS_ORDERS", false, null),
new NIRCProcedureFormSection(),
new NIRCProcedureOrderFormSection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public NIRCCasesFormType(DataEntryFormContext ctx, Module owner)
new NIRCCasesFormPanelSection("Clinical Case", ctx, false),
new NIRCClinicalRemarksFormPanelSection(true, "cases", "Clinical Remarks", ctx, false),
new NIRCWeightFormSection(true, false, true, "cases"),
new NIRCClinicalObservationsFormSection(true, "cases"),
new NIRCClinicalObservationsFormSection("NIRC_DAILY_CLINICAL_OBS", true, "cases"),
new NIRCObservationOrdersFormSection(null, true, "cases"),
new NIRCProcedureFormSection(true, "cases"),
new NIRCProcedureOrderFormSection(true, "cases"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public NIRCClinicalObservationsFormType(DataEntryFormContext ctx, Module owner)
super(ctx, owner, NAME, NAME, "Clinical", Arrays.asList(
new NIRCTaskFormSection(),
new NIRCAnimalDetailsFormSection(),
new NIRCClinicalObservationsFormSection(false, false),
new NIRCClinicalObservationsFormSection("NIRC_DAILY_CLINICAL_OBS", false),
new NIRCWeightFormSection(true, true)
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NIRCClinicalRoundsFormType(DataEntryFormContext ctx, Module owner)
new NIRCCaseTemplateFormSection("Case Template", "Case Template", "nirc_ehr-casetemplatepanel", Arrays.asList(ClientDependency.supplierFromPath("nirc_ehr/panel/CaseTemplatePanel.js"))),
new NIRCCasesFormPanelSection("Clinical Case", ctx, false),
new NIRCWeightFormSection(true, false, true, "cases"),
new NIRCClinicalObservationsFormSection(true, "cases"),
new NIRCClinicalObservationsFormSection("NIRC_DAILY_CLINICAL_OBS", true, "cases"),
new NIRCProcedureFormSection(true, "cases"),
new NIRCTreatmentGivenFormSection(true, "cases"),
new NIRCVitalsFormSection(true, "cases"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
public class NIRCClinicalObservationsFormSection extends BaseFormSection
{
public static final String LABEL = "Observations";
private boolean _autoPopulateDailyObs;
private final String _dailyObsOption;

public NIRCClinicalObservationsFormSection(boolean autoPopulateDailyObs, boolean initCollapsed)
public NIRCClinicalObservationsFormSection(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("nirc_ehr/data/ClinicalObservationClientStore.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/grid/ClinicalObservationGridPanel.js"));
Expand All @@ -37,9 +37,9 @@ public NIRCClinicalObservationsFormSection(boolean autoPopulateDailyObs, boolean
setClientStoreClass("NIRC_EHR.data.ClinicalObservationsClientStore");
}

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

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

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

return defaults;
Expand Down
21 changes: 21 additions & 0 deletions nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class NIRC_EHRTriggerHelper
private User _user;
private static final Logger _log = LogManager.getLogger(NIRC_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 @@ -810,6 +811,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