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
45 changes: 13 additions & 32 deletions ehr/resources/queries/study/HousingOverlaps.sql
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
/*
* Copyright (c) 2011-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/

/**
* This query is designed to find housing records that overlap. In this query, the overlap to calculated based on both date and time
* A record that ends at the same time that a second record begins is not considered an overlap.
*/
PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP, Room CHAR DEFAULT NULL, Cage CHAR DEFAULT NULL)

Modified by Kollil on 7/23/25 - Added Area field to the query and the rooms are filtered by area(s) selected, refer to tkt # 12894
*/
SELECT
h.lsid,
h.id,
h.room,
h.cage,
h.date,
h.enddate,
h.reason,
h.remark,
h.qcstate

h.lsid,
h.id,
h.room.area as area, -- Added by Kollil
h.room,
h.cage,
h.date,
h.enddate,
h.reason,
h.remark,
h.qcstate
FROM study.housing h

WHERE
h.qcstate = 18

(h.room = ROOM OR ROOM IS NULL or ROOM = '') AND
(h.cage = CAGE OR CAGE IS NULL OR CAGE = '') AND

/* entered startdate must be <= entered enddate */
coalesce( STARTDATE , cast('1900-01-01 00:00:00.0' as timestamp)) <= coalesce(ENDDATE, now())
and

/* entered startdate must be less than record's enddate */
coalesce( STARTDATE , cast('1900-01-01 00:00:00.0' as timestamp)) < coalesce(h.enddate, now())
and

/* entered enddate must be greater than record's startdate */
coalesce(ENDDATE, now()) >= coalesce(h.date, now())
31 changes: 0 additions & 31 deletions ehr/resources/queries/study/HousingOverlapsById.sql

This file was deleted.

64 changes: 0 additions & 64 deletions ehr/resources/queries/study/HousingOverlapsById/.qview.xml

This file was deleted.

31 changes: 0 additions & 31 deletions ehr/resources/queries/study/HousingOverlapsByIdDateOnly.sql

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="HousingOverlapsById" tableDbType="TABLE">
<table tableName="HousingOverlapsReport" tableDbType="TABLE">
<javaCustomizer class="org.labkey.ehr.table.DefaultEHRCustomizer" />
<tableTitle>Housing Overlaps</tableTitle>
<description>This query identifies distinct animal IDs that overlapped with given housing records, accounting for date and time</description>
<description>This query identifies distinct housing records that overlapped with the given housing records, accounting for date and time</description>
<tableUrl />
<columns>
<column columnName="Id">
<column columnName="lsid">
<isKeyField>true</isKeyField>
</column>
<column columnName="date">
<columnTitle>Start Date</columnTitle>
<isHidden>true</isHidden>
</column>
</columns>
<buttonBarOptions position="both" includeStandardButtons="false">
Expand Down
27 changes: 27 additions & 0 deletions ehr/resources/queries/study/HousingOverlapsReport.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP)

SELECT
h.lsid,
h.id,
h.room,
h.cage,
h.date,
h.enddate,
h.reason,
h.remark,
h.qcstate

FROM study.housing h

WHERE

/* entered startdate must be <= entered enddate */
coalesce( STARTDATE , cast('1900-01-01 00:00:00.0' as timestamp)) <= coalesce(ENDDATE, now())
and

/* entered startdate must be less than record's enddate */
coalesce( STARTDATE , cast('1900-01-01 00:00:00.0' as timestamp)) < coalesce(h.enddate, now())
and

/* entered enddate must be greater than record's startdate */
coalesce(ENDDATE, now()) >= coalesce(h.date, now())
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<sorts>
<sort column="room"/>
<sort column="cage"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="HousingOverlapsByIdDateOnly" tableDbType="TABLE">
<table tableName="HousingOverlapsReportDateOnly" tableDbType="TABLE">
<javaCustomizer class="org.labkey.ehr.table.DefaultEHRCustomizer" />
<tableTitle>Housing Overlaps</tableTitle>
<description>This query identifies all distinct animal IDs that overlapped with housing records, accounting for date only, not date/time</description>
<tableTitle>Housing Overlaps (Date Only)</tableTitle>
<description>This query identifies overlapping housing records, accounting for date only, not date/time</description>
<tableUrl />
<columns>
<column columnName="Id">
<column columnName="lsid">
<isKeyField>true</isKeyField>
</column>
<column columnName="date">
<columnTitle>Start Date</columnTitle>
<isHidden>true</isHidden>
</column>
</columns>
<buttonBarOptions position="both" includeStandardButtons="false">
Expand Down
24 changes: 24 additions & 0 deletions ehr/resources/queries/study/HousingOverlapsReportDateOnly.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP)

SELECT
h.lsid,
h.id,
h.room,
h.cage,
h.date,
h.enddate,
h.reason,
h.remark,
h.qcstate

FROM study.housing h

WHERE

(
(cast(COALESCE(STARTDATE, '1900-01-01') AS DATE) >= cast(h.date AS DATE) AND cast(COALESCE(STARTDATE, '1900-01-01') AS DATE) < cast(COALESCE(h.enddate, now()) AS DATE))
OR
(cast(COALESCE(ENDDATE, now()) AS DATE) > cast(h.date AS DATE) AND cast(COALESCE(ENDDATE, now()) AS DATE) <= cast(COALESCE(h.enddate, now()) AS DATE))
OR
(cast(COALESCE(STARTDATE, '1900-01-01') AS DATE) <= cast(h.date AS DATE) AND cast(COALESCE(ENDDATE, now()) AS DATE) >= cast(COALESCE(h.enddate, now()) AS DATE))
)
Loading