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
4 changes: 4 additions & 0 deletions nirc_ehr/resources/queries/dbo/q_clinremarks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ SELECT anmEvt.ANIMAL_EVENT_ID
anmEvt.EVENT_ID.EVENT_ID AS category,
anmEvt.DIAGNOSIS AS vetreview,
anmCmt.TEXT AS remark,
CASE WHEN anmEvt.ATTACHMENT_PATH IS NOT NULL THEN
('C:\Program Files\Labkey\labkey\files\NIRC\EHR\@files\attachments'
|| substring(anmEvt.ATTACHMENT_PATH, LENGTH('N:\'), LENGTH(anmEvt.ATTACHMENT_PATH)))
ELSE NULL END AS attachmentFile,
CAST(COALESCE(adt.modified, anmEvt.CREATED_DATETIME) AS TIMESTAMP) AS modified
FROM ANIMAL_EVENT anmEvt
LEFT JOIN ANIMAL_EVENT_COMMENT anmCmt ON anmEvt.ANIMAL_EVENT_ID = anmCmt.ANIMAL_EVENT_ID
Expand Down
11 changes: 11 additions & 0 deletions nirc_ehr/resources/queries/nirc_ehr/necropsyTasks/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
<column name="viewNecropsy"/>
<column name="enterNecropsyData"/>
<column name="animalId"/>
<column name="animalId/curLocation/cage">
<properties>
<property name="columnTitle" value="Location"/>
</properties>
</column>
<column name="animalId/activeProjectAssignments/project"/>
<column name="animalId/activeProtocolAssignments/protocolDisplayName">
<properties>
<property name="columnTitle" value="Protocol"/>
</properties>
</column>
<column name="assignedTo"/>
<column name="created"/>
<column name="createdBy"/>
Expand Down
2 changes: 1 addition & 1 deletion nirc_ehr/resources/queries/study/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
if (!qc) {
console.error('Unable to find QCState: ' + row.QCState + '/' + row.QCStateLabel);
}
else if (qc.Label == 'Completed' && row.caseid && row.Id && row.performedby && row.taskid && qc) {
else if ((qc.Label == 'Completed' || qc.Label == 'Review Required') && row.caseid && row.Id && row.performedby && row.taskid && qc) {
var ordersInTransaction = helper.getProperty('ordersInTransaction');
var oit = [];
if (ordersInTransaction && ordersInTransaction.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<column name="openRemark"/>
<column name="plan"/>
<column name="closeRemark"/>
<column name="openDiagnosis"/>
<column name="closeDiagnosis"/>
</columns>
<filters>
<filter column="category" operator="eq" value="Clinical"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<columns>
<column name="Id"/>
<column name="date"/>
<column name="category"/>
<column name="area"/>
<column name="observation"/>
<column name="remark"/>
<column name="performedBy"/>
<column name="QCState"/>
</columns>
<filters>
<filter column="category" operator="eq" value="Clinical"/>
<filter column="type" operator="eq" value="Clinical"/>
</filters>
</customView>
8 changes: 8 additions & 0 deletions nirc_ehr/resources/queries/study/deathNotification.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

SELECT
Id,
date,
taskid,
performedBy.DisplayName AS performedBy,
reason.title AS reason
FROM study.deaths
3 changes: 1 addition & 2 deletions nirc_ehr/resources/queries/study/demographicsCagemates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ FROM study.housing h

JOIN study.housing h2
ON (h2.Id.demographics.calculated_status = 'Alive'
-- AND h.room = h2.room
AND (h.cage = h2.cage OR (h.cage IS NULL and h2.cage IS NULL)))
AND (h.cage = h2.cage))

WHERE h.enddateTimeCoalesced >= now()
GROUP BY h.id, h.room, h.cage
Expand Down
4 changes: 3 additions & 1 deletion nirc_ehr/resources/queries/study/demographicsCurLocation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ coalesce(d2.room, '') as room_order,
d2.room_sortValue @hidden,

coalesce(d2.cage, '') as cage_order,
d2.cage_sortValue @hidden
d2.cage_sortValue @hidden,

d2.performedBy.displayName AS performedBy

FROM study.housing d2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Add more here to make a single query for animal details in notifications
SELECT
Id,
date,
project.name AS project,
enddate
FROM study.assignment
WHERE enddate IS NULL
2 changes: 1 addition & 1 deletion nirc_ehr/resources/queries/study/observationSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ FROM

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

WHERE t1.date is not null AND t1.qcstate.publicdata = true
WHERE t1.date is not null

) s1

Expand Down
158 changes: 62 additions & 96 deletions nirc_ehr/resources/queries/study/treatmentSchedule.sql
Original file line number Diff line number Diff line change
@@ -1,102 +1,68 @@
/*
* Copyright (c) 2010-2014 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/

SELECT
d.id,
d.calculated_status,
s.*,
s.objectid as treatmentid,
drug.qcstate.label as treatmentStatus,
s.objectid || '-pkSeparator-' || s.date as primaryKey -- -pkSeparator- is used to separate the two parts of the primary key in RecordTreatmentButton.js
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.objectid,
t1.dataset,
t1.id as animalid,

coalesce(tt.time, ft.hourofday, ((hour(t1.date) * 100) + minute(t1.date))) as time,
(coalesce(tt.time, ft.hourofday, (hour(t1.date) * 100)) / 100) as hours,
CASE
WHEN (tt.time IS NOT NULL OR ft.hourofday IS NOT NULL) THEN (((coalesce(tt.time, ft.hourofday) / 100.0) - floor(coalesce(tt.time, ft.hourofday) / 100)) * 100)
ELSE minute(t1.date)
END as minutes,
dr.date as origDate,
CASE
WHEN (tt.time IS NULL) THEN 'Default'
ELSE 'Custom'
END as timeType,

CASE
WHEN snomed.code IS NOT NULL THEN 'Diet'
ELSE IFDEFINED(t1.category)
END as category,
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.code,
t1.treatmentRecord,
t1.volume,
t1.vol_units,
t1.concentration,
t1.conc_units,
t1.amount,
t1.amount_units,
t1.amountWithUnits,
t1.amountAndVolume,
t1.dosage,
t1.dosage_units,
t1.route,
IFDEFINED(t1.reason) AS reason,
t1.performedby,
t1.remark,
t1.caseid,
t1.orderedby,

t1.qcstate

FROM nirc_ehr.dateRange dr

JOIN study."Treatment Orders" 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.treatment_times tt ON (tt.treatmentid = t1.objectid)
LEFT JOIN ehr_lookups.treatment_frequency_times ft ON (ft.frequency = t1.frequency.meaning AND tt.rowid IS NULL)

LEFT JOIN (
s.objectid AS treatmentid,
drug.qcstate.label AS treatmentStatus,
s.objectid || '-pkSeparator-' || s.date AS primaryKey -- -pkSeparator- is used to separate the two parts of the primary key in RecordTreatmentButton.js
FROM study.demographics d
JOIN(
SELECT
sc.code
from ehr_lookups.snomed_subset_codes sc
WHERE sc.primaryCategory = 'Diet'
GROUP BY sc.code
) snomed ON snomed.code = t1.code

--NOTE: if we run this report on a future interval, we want to include those treatments
WHERE t1.date is not null

) s1

) s ON (s.animalid = d.id) LEFT JOIN
study.drug drug ON s.objectid = drug.treatmentid AND s.date = IFDEFINED(drug.scheduledDate)

WHERE (d.lastDayatCenter Is Null or d.lastDayAtCenter > s.enddate OR s.enddate IS NULL)


--account for date/time in schedule
and s.date >= s.startDate and (s.enddate IS NULL OR s.date <= s.enddate)
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.objectid,
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.category,
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.code,
t1.treatmentRecord,
t1.volume,
t1.vol_units,
t1.concentration,
t1.conc_units,
t1.amount,
t1.amount_units,
t1.amountWithUnits,
t1.amountAndVolume,
t1.dosage,
t1.dosage_units,
t1.route,
IFDEFINED(t1.reason) AS reason,
t1.performedby,
t1.remark,
t1.caseid,
t1.orderedby,
t1.qcstate
FROM nirc_ehr.dateRange dr
JOIN study."Treatment Orders" t1 ON (dr.dateOnly >= t1.dateOnly 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
--NOTE: if we run this report on a future interval, we want to include those treatments
WHERE t1.date IS NOT NULL

) s1

) s ON (s.animalid = d.id)
LEFT JOIN study.drug drug ON s.objectid = drug.treatmentid AND s.date = IFDEFINED(drug.scheduledDate)

WHERE (d.lastDayatCenter IS NULL OR d.lastDayAtCenter > s.enddate OR s.enddate IS NULL)
AND s.date >= s.startDate AND (s.enddate IS NULL OR s.date <= s.enddate)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<column name="Id/curLocation/cage"/>

<column name="date"/>
<column name="timeOfDay"/>
<column name="daysElapsed"/>

<column name="frequency"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@
<datatype>varchar</datatype>
<propertyURI>urn:ehr.labkey.org/#CaseId</propertyURI>
</column>
<column columnName="attachmentFile">
<columnTitle>Attachment File</columnTitle>
<datatype>varchar</datatype>
<rangeURI>http://cpas.fhcrc.org/exp/xml#fileLink</rangeURI>
</column>
</columns>
</table>
<table tableName="demographics" tableDbType="TABLE">
Expand Down Expand Up @@ -643,6 +648,11 @@
<propertyURI>urn:ehr.labkey.org/#CaseId</propertyURI>
</column>
</columns>
<indices>
<index type="non-unique">
<column>cage</column>
</index>
</indices>
</table>
<table tableName="inbreeding" tableDbType="TABLE">
<columns>
Expand Down
12 changes: 12 additions & 0 deletions nirc_ehr/src/org/labkey/nirc_ehr/NIRCOrchardFileGenerator.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.labkey.nirc_ehr;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.exp.OntologyManager;
import org.labkey.api.module.Module;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.module.ModuleProperty;
Expand All @@ -16,6 +19,7 @@
import org.labkey.api.study.StudyService;
import org.labkey.api.util.JobRunner;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.logging.LogHelper;
import org.labkey.api.writer.PrintWriters;

import java.io.File;
Expand All @@ -33,6 +37,7 @@
public class NIRCOrchardFileGenerator
{
public static final String NIRCOrchardFileLocation = "NIRCOrchardFileLocation";
private static final Logger _log = LogHelper.getLogger(NIRCOrchardFileGenerator.class, "Orchard update on trigger.");

public void generateOrchardFile(Container c, User u, String taskid)
{
Expand Down Expand Up @@ -80,6 +85,13 @@ public FileWriteTask(Container c, User u, String taskid, String orchardFileLocat
@Override
public void run()
{
if (orchardFileLocation == null)
{
// Don't run if we don't have a location to write the file
_log.warn("Orchard file location is null, cannot generate Orchard file for taskid: " + taskid);
return;
}

JobRunner.getDefault().execute(() ->
{
TableInfo ti = getTableInfo(c, u, "study", "orchardData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected Collection<FieldKey> getFieldKeys()
keys.add(FieldKey.fromString("reason"));
keys.add(FieldKey.fromString("remark"));
keys.add(FieldKey.fromString("location"));
keys.add(FieldKey.fromString("performedBy"));

return keys;
}
Expand Down
Loading