Skip to content

Commit 1b406cb

Browse files
Behavior Obs Refinements (#565)
* Ticket 53574: Multiple obs orders of same category in same form but different dates getting duplicates when marking complete from schedule * Ticket 53576: Relabel Clinical Obs with Behavior Obs in Forms and Clin History * Ticket 53575: Alopecia Score observation requires a remark * Fix future obs schedule * Cleanup obs dataset
1 parent 2bf2c3d commit 1b406cb

12 files changed

+317
-368
lines changed

nirc_ehr/resources/queries/study/clinical_observations.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
3131
EHR.Server.Utils.addError(scriptErrors, 'remark', "You selected 'Other' for 'Daily Enrichment', please enter Remark", "WARN");
3232
}
3333

34+
if (row.category === "Alopecia Score" && !row.observation) {
35+
EHR.Server.Utils.addError(scriptErrors, 'observation', "Score required for 'Alopecia Score'.", "WARN");
36+
}
37+
38+
if (row.category === "Alopecia Score" && !row.remark) {
39+
EHR.Server.Utils.addError(scriptErrors, 'remark', "Remark required for 'Alopecia Score'.", "WARN");
40+
}
41+
3442
var yesRemarkRequired = (row.category === "Self Biting Observed" || row.category === "New Injury Observed" || row.category === "Other Stereotopy" || row.category === "Environmental Change" || row.category === "Special Enrichment");
3543
if (yesRemarkRequired && row.observation === "Yes" && !row.remark) {
3644
EHR.Server.Utils.addError(scriptErrors, 'remark', "You selected 'Yes' for " + row.category + ", please explain in the Remark", "WARN");
@@ -55,9 +63,10 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
5563
var orderData = triggerHelper.handleScheduledObservations(row, qc.RowId, orderTasks[0]);
5664

5765
if (orderData) {
58-
row.caseid = orderData.caseId;
66+
row.caseId = orderData.caseId;
5967
row.orderid = orderData.orderId;
6068
row.area = orderData.area;
69+
row.type = orderData.type;
6170
}
6271
}
6372
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
SELECT
2+
s.*,
3+
co.qcstate.label AS obsStatus
4+
FROM
5+
(SELECT
6+
s1.*,
7+
timestampadd('SQL_TSI_MINUTE', ((s1.hours * 60) + s1.minutes), s1.origDate) AS date,
8+
((s1.hours * 60) + s1.minutes) AS timeOffset
9+
10+
FROM (
11+
SELECT
12+
t1.lsid,
13+
t1.dataset,
14+
t1.id AS animalid,
15+
coalesce(ft.hourofday, ((hour(t1.date) * 100) + minute(t1.date))) AS time,
16+
(coalesce(ft.hourofday, (hour(t1.date) * 100)) / 100) AS hours,
17+
18+
CASE WHEN ft.hourofday IS NOT NULL
19+
THEN (((ft.hourofday / 100.0) - floor(ft.hourofday / 100)) * 100)
20+
ELSE minute(t1.date)
21+
END AS minutes,
22+
23+
dr.date AS origDate,
24+
25+
t1.frequency.meaning AS frequency,
26+
t1.date AS startDate,
27+
timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly AS timestamp), dr.dateOnly) + 1 AS daysElapsed,
28+
t1.enddate,
29+
t1.category,
30+
t1.area,
31+
t1.performedby,
32+
t1.remark,
33+
t1.caseid.objectid AS caseid,
34+
t1.taskid,
35+
t1.type,
36+
t1.objectid,
37+
38+
t1.qcstate
39+
FROM nirc_ehr.dateRange dr
40+
JOIN
41+
42+
-- order by category to replace string with Daily Obs
43+
(SELECT * FROM study.observation_order ORDER BY category) t1
44+
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
45+
--technically the first day of the treatment is day 1, not day 0
46+
((mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly AS timestamp), dr.dateOnly) AS integer), t1.frequency.intervalindays) = 0 AND t1.frequency.intervalindays IS NOT NULL AND t1.frequency.dayofweek IS NULL)))
47+
LEFT JOIN ehr_lookups.treatment_frequency_times ft ON ft.frequency = t1.frequency.meaning
48+
WHERE t1.date IS NOT NULL
49+
50+
) s1
51+
) s
52+
LEFT JOIN study.clinical_observations co ON co.scheduledDate IS NOT NULL AND s.date = co.scheduledDate AND co.orderId = s.objectid

nirc_ehr/resources/queries/study/observationSchedule.sql

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,31 @@ SELECT
22
g.id,
33
g.scheduledDate,
44
COUNT(g.caseid) cases,
5-
GROUP_CONCAT(g.observations, ';') as observations,
6-
SUM(obsCount) as obsCount,
7-
GROUP_CONCAT(g.obsOrderIds, ';') as orderIds,
8-
GROUP_CONCAT(g.status, ';') as status,
9-
GROUP_CONCAT(g.taskids, ';') as taskids,
10-
MAX(g.type) as type,
11-
MAX(g.caseid) as caseid
5+
GROUP_CONCAT(g.observations, ';') AS observations,
6+
SUM(obsCount) AS obsCount,
7+
GROUP_CONCAT(g.obsOrderIds, ';') AS orderIds,
8+
GROUP_CONCAT(g.status, ';') AS status,
9+
GROUP_CONCAT(g.taskids, ';') AS taskids,
10+
MAX(g.type) AS type,
11+
MAX(g.caseid) AS caseid
1212
FROM
1313
(
1414
SELECT
15-
sch.id,
16-
sch.date as scheduledDate,
15+
sch.animalId as id,
16+
sch.date AS scheduledDate,
1717
sch.caseid,
1818
sch.type,
19-
GROUP_CONCAT(sch.objectid, ';') as obsOrderIds,
20-
GROUP_CONCAT(sch.category, ';') as observations,
21-
GROUP_CONCAT(obsStatus, ';') as status,
22-
GROUP_CONCAT(DISTINCT(sch.taskid), ';') as taskids,
23-
COUNT(sch.category) as obsCount,
24-
COUNT(sch.obsStatus) as statusCount
25-
FROM
26-
(
27-
SELECT
28-
d.id,
29-
s.*,
30-
co.qcstate.label as obsStatus
31-
FROM study.demographics d JOIN
32-
(SELECT
33-
s1.*,
34-
timestampadd('SQL_TSI_MINUTE', ((s1.hours * 60) + s1.minutes), s1.origDate) as date,
35-
((s1.hours * 60) + s1.minutes) as timeOffset
36-
37-
FROM (
38-
39-
SELECT
40-
t1.lsid,
41-
t1.dataset,
42-
t1.id as animalid,
43-
44-
coalesce(ft.hourofday, ((hour(t1.date) * 100) + minute(t1.date))) as time,
45-
(coalesce(ft.hourofday, (hour(t1.date) * 100)) / 100) as hours,
46-
47-
CASE WHEN ft.hourofday IS NOT NULL
48-
THEN (((ft.hourofday / 100.0) - floor(ft.hourofday / 100)) * 100)
49-
ELSE minute(t1.date)
50-
END as minutes,
51-
52-
dr.date as origDate,
53-
54-
t1.frequency.meaning as frequency,
55-
t1.date as startDate,
56-
timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly as timestamp), dr.dateOnly) + 1 as daysElapsed,
57-
t1.enddate,
58-
t1.category,
59-
t1.area,
60-
t1.performedby,
61-
t1.remark,
62-
t1.caseid,
63-
t1.taskid,
64-
t1.type,
65-
t1.objectid,
66-
67-
t1.qcstate
68-
69-
FROM nirc_ehr.dateRange dr
70-
71-
JOIN
72-
73-
-- order by category to replace string with Daily Obs
74-
(SELECT * FROM
75-
study.observation_order
76-
ORDER BY category) t1
77-
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
78-
--technically the first day of the treatment is day 1, not day 0
79-
((mod(CAST(timestampdiff('SQL_TSI_DAY', CAST(t1.dateOnly as timestamp), dr.dateOnly) as integer), t1.frequency.intervalindays) = 0 And t1.frequency.intervalindays is not null And t1.frequency.dayofweek is null)))
80-
81-
LEFT JOIN ehr_lookups.treatment_frequency_times ft ON ft.frequency = t1.frequency.meaning
82-
83-
WHERE t1.date is not null
84-
85-
) s1
86-
87-
) s ON (s.animalid = d.id)
88-
LEFT JOIN study.clinical_observations co ON co.scheduledDate IS NOT NULL AND s.date = co.scheduledDate AND co.orderId = s.objectid
19+
GROUP_CONCAT(sch.objectid, ';') AS obsOrderIds,
20+
GROUP_CONCAT(sch.category, ';') AS observations,
21+
GROUP_CONCAT(obsStatus, ';') AS status,
22+
GROUP_CONCAT(DISTINCT(sch.taskid), ';') AS taskids,
23+
COUNT(sch.category) AS obsCount,
24+
COUNT(sch.obsStatus) AS statusCount
25+
FROM (
26+
SELECT * FROM observationOrdersByDate
8927
) sch
9028
GROUP BY
91-
sch.id,
29+
sch.animalId,
9230
sch.date,
9331
sch.caseid,
9432
sch.type

nirc_ehr/resources/referenceStudy/study/datasets/datasets_manifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<dataset name="housing" id="1018" category="Colony Management" type="Standard"/>
2525
<dataset name="inbreeding" id="1021" category="Colony Management" type="Standard"/>
2626
<dataset name="necropsy" id="1019" category="Pathology" type="Standard"/>
27-
<dataset name="obs" id="1025" category="Clinical" type="Standard"/>
2827
<dataset name="nhpTraining" id="1040" category="Behavior" type="Standard"/>
2928
<dataset name="observation_order" id="1049" category="Clinical" type="Standard"/>
3029
<dataset name="notes" id="1027" category="Colony Management" type="Standard"/>

nirc_ehr/resources/referenceStudy/study/datasets/datasets_metadata.xml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
</columns>
292292
</table>
293293
<table tableName="clinical_observations" tableDbType="TABLE">
294-
<tableTitle>Clinical Observations</tableTitle>
294+
<tableTitle>Clinical/Behavior Observations</tableTitle>
295295
<columns>
296296
<column columnName="Id">
297297
<datatype>varchar</datatype>
@@ -678,29 +678,6 @@
678678
</columns>
679679
<tableTitle>Inbreeding Coefficients</tableTitle>
680680
</table>
681-
<table tableName="obs" tableDbType="TABLE">
682-
<tableTitle>Observations</tableTitle>
683-
<columns>
684-
<column columnName="Id">
685-
<datatype>varchar</datatype>
686-
<propertyURI>http://cpas.labkey.com/Study#ParticipantId</propertyURI>
687-
<importAliases>
688-
<importAlias>ptid</importAlias>
689-
</importAliases>
690-
</column>
691-
<column columnName="date">
692-
<datatype>timestamp</datatype>
693-
<propertyURI>http://cpas.labkey.com/Study#VisitDate</propertyURI>
694-
<conceptURI>http://cpas.labkey.com/Study#VisitDate</conceptURI>
695-
</column>
696-
<column columnName="category">
697-
<datatype>varchar</datatype>
698-
</column>
699-
<column columnName="diagnosis">
700-
<datatype>varchar</datatype>
701-
</column>
702-
</columns>
703-
</table>
704681
<table tableName="necropsy" tableDbType="TABLE">
705682
<tableTitle>Necropsy</tableTitle>
706683
<columns>

nirc_ehr/src/org/labkey/nirc_ehr/NIRC_EHRModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext)
152152
EHRService.get().registerHistoryDataSource(new NIRCCaseCloseDataSource(this));
153153
EHRService.get().registerHistoryDataSource(new NIRCCaseOpenDataSource(this));
154154
EHRService.get().registerHistoryDataSource(new NIRCClinicalObservationsDataSource(this));
155+
EHRService.get().registerHistoryDataSource(new NIRCBehaviorObservationsDataSource(this));
155156
EHRService.get().registerHistoryDataSource(new NIRCClinicalRemarksDataSource(this));
156157
EHRService.get().registerHistoryDataSource(new NIRCEndTreatmentOrderDataSource(this));
157158
EHRService.get().registerHistoryDataSource(new NIRCHousingDataSource(this));
158159
EHRService.get().registerHistoryDataSource(new NIRCObservationOrdersDataSource(this));
159160
EHRService.get().registerHistoryDataSource(new NIRCVitalsDataSource(this));
160-
EHRService.get().registerHistoryDataSource(new ObservationsDataSource(this));
161161
EHRService.get().registerHistoryDataSource(new PairingsDataSource(this));
162162
EHRService.get().registerHistoryDataSource(new PhysicalExamDataSource(this));
163163
EHRService.get().registerHistoryDataSource(new PregnancyDataSource(this));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.labkey.nirc_ehr.history;
2+
3+
import org.labkey.api.module.Module;
4+
5+
public class NIRCBehaviorObservationsDataSource extends NIRCObservationsDataSource
6+
{
7+
public NIRCBehaviorObservationsDataSource(Module module)
8+
{
9+
super("study", "behaviorObservations", "Behavior Observations", "Behavior Observations", module);
10+
}
11+
}
12+

0 commit comments

Comments
 (0)