Skip to content
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: 10 additions & 1 deletion nirc_ehr/resources/queries/study/clinical_observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
EHR.Server.Utils.addError(scriptErrors, 'remark', "You selected 'Other' for 'Daily Enrichment', please enter Remark", "WARN");
}

if (row.category === "Alopecia Score" && !row.observation) {
EHR.Server.Utils.addError(scriptErrors, 'observation', "Score required for 'Alopecia Score'.", "WARN");
}

if (row.category === "Alopecia Score" && !row.remark) {
EHR.Server.Utils.addError(scriptErrors, 'remark', "Remark required for 'Alopecia Score'.", "WARN");
}

var yesRemarkRequired = (row.category === "Self Biting Observed" || row.category === "New Injury Observed" || row.category === "Other Stereotopy" || row.category === "Environmental Change" || row.category === "Special Enrichment");
if (yesRemarkRequired && row.observation === "Yes" && !row.remark) {
EHR.Server.Utils.addError(scriptErrors, 'remark', "You selected 'Yes' for " + row.category + ", please explain in the Remark", "WARN");
Expand All @@ -55,9 +63,10 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
var orderData = triggerHelper.handleScheduledObservations(row, qc.RowId, orderTasks[0]);

if (orderData) {
row.caseid = orderData.caseId;
row.caseId = orderData.caseId;
row.orderid = orderData.orderId;
row.area = orderData.area;
row.type = orderData.type;
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions nirc_ehr/resources/queries/study/observationOrdersByDate.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SELECT
s.*,
co.qcstate.label AS obsStatus
FROM
(SELECT
s1.*,
timestampadd('SQL_TSI_MINUTE', ((s1.hours * 60) + s1.minutes), s1.origDate) AS date,
((s1.hours * 60) + s1.minutes) AS timeOffset

FROM (
SELECT
t1.lsid,
t1.dataset,
t1.id AS animalid,
coalesce(ft.hourofday, ((hour(t1.date) * 100) + minute(t1.date))) AS time,
(coalesce(ft.hourofday, (hour(t1.date) * 100)) / 100) AS hours,

CASE WHEN ft.hourofday IS NOT NULL
THEN (((ft.hourofday / 100.0) - floor(ft.hourofday / 100)) * 100)
ELSE minute(t1.date)
END AS minutes,

dr.date AS origDate,

t1.frequency.meaning AS frequency,
t1.date AS startDate,
timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly AS timestamp), dr.dateOnly) + 1 AS daysElapsed,
t1.enddate,
t1.category,
t1.area,
t1.performedby,
t1.remark,
t1.caseid.objectid AS caseid,
t1.taskid,
t1.type,
t1.objectid,

t1.qcstate
FROM nirc_ehr.dateRange dr
JOIN

-- order by category to replace string with Daily Obs
(SELECT * FROM study.observation_order ORDER BY category) t1
ON (dr.dateOnly >= t1.dateOnly AND (dr.dateOnly <= t1.enddate OR t1.enddate IS NULL) AND
--technically the first day of the treatment is day 1, not day 0
((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)))
LEFT JOIN ehr_lookups.treatment_frequency_times ft ON ft.frequency = t1.frequency.meaning
WHERE t1.date IS NOT NULL

) s1
) s
LEFT JOIN study.clinical_observations co ON co.scheduledDate IS NOT NULL AND s.date = co.scheduledDate AND co.orderId = s.objectid
98 changes: 18 additions & 80 deletions nirc_ehr/resources/queries/study/observationSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,31 @@ SELECT
g.id,
g.scheduledDate,
COUNT(g.caseid) cases,
GROUP_CONCAT(g.observations, ';') as observations,
SUM(obsCount) as obsCount,
GROUP_CONCAT(g.obsOrderIds, ';') as orderIds,
GROUP_CONCAT(g.status, ';') as status,
GROUP_CONCAT(g.taskids, ';') as taskids,
MAX(g.type) as type,
MAX(g.caseid) as caseid
GROUP_CONCAT(g.observations, ';') AS observations,
SUM(obsCount) AS obsCount,
GROUP_CONCAT(g.obsOrderIds, ';') AS orderIds,
GROUP_CONCAT(g.status, ';') AS status,
GROUP_CONCAT(g.taskids, ';') AS taskids,
MAX(g.type) AS type,
MAX(g.caseid) AS caseid
FROM
(
SELECT
sch.id,
sch.date as scheduledDate,
sch.animalId as id,
sch.date AS scheduledDate,
sch.caseid,
sch.type,
GROUP_CONCAT(sch.objectid, ';') as obsOrderIds,
GROUP_CONCAT(sch.category, ';') as observations,
GROUP_CONCAT(obsStatus, ';') as status,
GROUP_CONCAT(DISTINCT(sch.taskid), ';') as taskids,
COUNT(sch.category) as obsCount,
COUNT(sch.obsStatus) as statusCount
FROM
(
SELECT
d.id,
s.*,
co.qcstate.label as obsStatus
FROM study.demographics d JOIN
(SELECT
s1.*,
timestampadd('SQL_TSI_MINUTE', ((s1.hours * 60) + s1.minutes), s1.origDate) as date,
((s1.hours * 60) + s1.minutes) as timeOffset

FROM (

SELECT
t1.lsid,
t1.dataset,
t1.id as animalid,

coalesce(ft.hourofday, ((hour(t1.date) * 100) + minute(t1.date))) as time,
(coalesce(ft.hourofday, (hour(t1.date) * 100)) / 100) as hours,

CASE WHEN ft.hourofday IS NOT NULL
THEN (((ft.hourofday / 100.0) - floor(ft.hourofday / 100)) * 100)
ELSE minute(t1.date)
END as minutes,

dr.date as origDate,

t1.frequency.meaning as frequency,
t1.date as startDate,
timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly as timestamp), dr.dateOnly) + 1 as daysElapsed,
t1.enddate,
t1.category,
t1.area,
t1.performedby,
t1.remark,
t1.caseid,
t1.taskid,
t1.type,
t1.objectid,

t1.qcstate

FROM nirc_ehr.dateRange dr

JOIN

-- order by category to replace string with Daily Obs
(SELECT * FROM
study.observation_order
ORDER BY category) t1
ON (dr.dateOnly >= t1.dateOnly and dr.dateOnly <= t1.enddateCoalesced AND
--technically the first day of the treatment is day 1, not day 0
((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)))

LEFT JOIN ehr_lookups.treatment_frequency_times ft ON ft.frequency = t1.frequency.meaning

WHERE t1.date is not null

) s1

) s ON (s.animalid = d.id)
LEFT JOIN study.clinical_observations co ON co.scheduledDate IS NOT NULL AND s.date = co.scheduledDate AND co.orderId = s.objectid
GROUP_CONCAT(sch.objectid, ';') AS obsOrderIds,
GROUP_CONCAT(sch.category, ';') AS observations,
GROUP_CONCAT(obsStatus, ';') AS status,
GROUP_CONCAT(DISTINCT(sch.taskid), ';') AS taskids,
COUNT(sch.category) AS obsCount,
COUNT(sch.obsStatus) AS statusCount
FROM (
SELECT * FROM observationOrdersByDate
) sch
GROUP BY
sch.id,
sch.animalId,
sch.date,
sch.caseid,
sch.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<dataset name="housing" id="1018" category="Colony Management" type="Standard"/>
<dataset name="inbreeding" id="1021" category="Colony Management" type="Standard"/>
<dataset name="necropsy" id="1019" category="Pathology" type="Standard"/>
<dataset name="obs" id="1025" category="Clinical" type="Standard"/>
<dataset name="nhpTraining" id="1040" category="Behavior" type="Standard"/>
<dataset name="observation_order" id="1049" category="Clinical" type="Standard"/>
<dataset name="notes" id="1027" category="Colony Management" type="Standard"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
</columns>
</table>
<table tableName="clinical_observations" tableDbType="TABLE">
<tableTitle>Clinical Observations</tableTitle>
<tableTitle>Clinical/Behavior Observations</tableTitle>
<columns>
<column columnName="Id">
<datatype>varchar</datatype>
Expand Down Expand Up @@ -678,29 +678,6 @@
</columns>
<tableTitle>Inbreeding Coefficients</tableTitle>
</table>
<table tableName="obs" tableDbType="TABLE">
<tableTitle>Observations</tableTitle>
<columns>
<column columnName="Id">
<datatype>varchar</datatype>
<propertyURI>http://cpas.labkey.com/Study#ParticipantId</propertyURI>
<importAliases>
<importAlias>ptid</importAlias>
</importAliases>
</column>
<column columnName="date">
<datatype>timestamp</datatype>
<propertyURI>http://cpas.labkey.com/Study#VisitDate</propertyURI>
<conceptURI>http://cpas.labkey.com/Study#VisitDate</conceptURI>
</column>
<column columnName="category">
<datatype>varchar</datatype>
</column>
<column columnName="diagnosis">
<datatype>varchar</datatype>
</column>
</columns>
</table>
<table tableName="necropsy" tableDbType="TABLE">
<tableTitle>Necropsy</tableTitle>
<columns>
Expand Down
2 changes: 1 addition & 1 deletion nirc_ehr/src/org/labkey/nirc_ehr/NIRC_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext)
EHRService.get().registerHistoryDataSource(new NIRCCaseCloseDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCCaseOpenDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCClinicalObservationsDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCBehaviorObservationsDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCClinicalRemarksDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCEndTreatmentOrderDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCHousingDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCObservationOrdersDataSource(this));
EHRService.get().registerHistoryDataSource(new NIRCVitalsDataSource(this));
EHRService.get().registerHistoryDataSource(new ObservationsDataSource(this));
EHRService.get().registerHistoryDataSource(new PairingsDataSource(this));
EHRService.get().registerHistoryDataSource(new PhysicalExamDataSource(this));
EHRService.get().registerHistoryDataSource(new PregnancyDataSource(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.labkey.nirc_ehr.history;

import org.labkey.api.module.Module;

public class NIRCBehaviorObservationsDataSource extends NIRCObservationsDataSource
{
public NIRCBehaviorObservationsDataSource(Module module)
{
super("study", "behaviorObservations", "Behavior Observations", "Behavior Observations", module);
}
}

Loading