diff --git a/ehr/resources/queries/study/HousingOverlaps.sql b/ehr/resources/queries/study/HousingOverlaps.sql
index a4efd7d90..2889b8eca 100644
--- a/ehr/resources/queries/study/HousingOverlaps.sql
+++ b/ehr/resources/queries/study/HousingOverlaps.sql
@@ -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())
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsById.sql b/ehr/resources/queries/study/HousingOverlapsById.sql
deleted file mode 100644
index 6296f7ef7..000000000
--- a/ehr/resources/queries/study/HousingOverlapsById.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2011-2019 LabKey Corporation
- *
- * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
- */
-
-PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP, Room CHAR DEFAULT NULL, Cage CHAR DEFAULT NULL)
-
-SELECT
-h.Id,
-cast(StartDate as timestamp) as date
-
-FROM study.housing h
-
-WHERE
-
-(h.room = ROOM OR ROOM IS NULL or ROOM = '') AND
-(h.cage = CAGE OR CAGE IS NULL OR CAGE = '') AND
-
-/* entered startdate must be <= 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())
-
-GROUP BY h.Id
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsById/.qview.xml b/ehr/resources/queries/study/HousingOverlapsById/.qview.xml
deleted file mode 100644
index 603b1f172..000000000
--- a/ehr/resources/queries/study/HousingOverlapsById/.qview.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly.sql b/ehr/resources/queries/study/HousingOverlapsByIdDateOnly.sql
deleted file mode 100644
index a6fa7185e..000000000
--- a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2012-2019 LabKey Corporation
- *
- * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
- */
-
-PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP, Room CHAR DEFAULT NULL, Cage CHAR DEFAULT NULL)
-
-SELECT
-h.Id,
-cast(StartDate as timestamp) as date
-
-FROM study.housing h
-
-WHERE
-
-(h.room = ROOM OR ROOM IS NULL or ROOM = '') AND
-(h.cage = CAGE OR CAGE IS NULL OR CAGE = '') AND
-
-/* entered startdate must be <= enddate */
-cast(coalesce(STARTDATE , cast('1900-01-01' as DATE)) as DATE) <= cast(coalesce(ENDDATE, now()) as DATE)
-and
-
-/* entered startdate must be less than record's enddate */
-cast(coalesce(STARTDATE , cast('1900-01-01' as DATE)) as DATE) < cast(coalesce(h.enddate, now()) as DATE)
-and
-
-/* entered enddate must be greater than record's startdate */
-cast(coalesce(ENDDATE, now()) as DATE) >= cast(coalesce(h.date, now()) as DATE)
-
-GROUP BY h.Id
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly/.qview.xml b/ehr/resources/queries/study/HousingOverlapsByIdDateOnly/.qview.xml
deleted file mode 100644
index 32b8acce5..000000000
--- a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly/.qview.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsById.query.xml b/ehr/resources/queries/study/HousingOverlapsReport.query.xml
similarity index 82%
rename from ehr/resources/queries/study/HousingOverlapsById.query.xml
rename to ehr/resources/queries/study/HousingOverlapsReport.query.xml
index 1f1321218..1256b36ac 100644
--- a/ehr/resources/queries/study/HousingOverlapsById.query.xml
+++ b/ehr/resources/queries/study/HousingOverlapsReport.query.xml
@@ -1,17 +1,15 @@
-
+
Housing Overlaps
- This query identifies distinct animal IDs that overlapped with given housing records, accounting for date and time
+ This query identifies distinct housing records that overlapped with the given housing records, accounting for date and time
-
+
true
-
-
- Start Date
+ true
diff --git a/ehr/resources/queries/study/HousingOverlapsReport.sql b/ehr/resources/queries/study/HousingOverlapsReport.sql
new file mode 100644
index 000000000..f2cb68596
--- /dev/null
+++ b/ehr/resources/queries/study/HousingOverlapsReport.sql
@@ -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())
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsReport/.qview.xml b/ehr/resources/queries/study/HousingOverlapsReport/.qview.xml
new file mode 100644
index 000000000..7edf3755c
--- /dev/null
+++ b/ehr/resources/queries/study/HousingOverlapsReport/.qview.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly.query.xml b/ehr/resources/queries/study/HousingOverlapsReportDateOnly.query.xml
similarity index 79%
rename from ehr/resources/queries/study/HousingOverlapsByIdDateOnly.query.xml
rename to ehr/resources/queries/study/HousingOverlapsReportDateOnly.query.xml
index 967758d1c..ae23c19fe 100644
--- a/ehr/resources/queries/study/HousingOverlapsByIdDateOnly.query.xml
+++ b/ehr/resources/queries/study/HousingOverlapsReportDateOnly.query.xml
@@ -1,17 +1,15 @@
-
+
- Housing Overlaps
- This query identifies all distinct animal IDs that overlapped with housing records, accounting for date only, not date/time
+ Housing Overlaps (Date Only)
+ This query identifies overlapping housing records, accounting for date only, not date/time
-
+
true
-
-
- Start Date
+ true
diff --git a/ehr/resources/queries/study/HousingOverlapsReportDateOnly.sql b/ehr/resources/queries/study/HousingOverlapsReportDateOnly.sql
new file mode 100644
index 000000000..65847cacd
--- /dev/null
+++ b/ehr/resources/queries/study/HousingOverlapsReportDateOnly.sql
@@ -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))
+ )
\ No newline at end of file
diff --git a/ehr/resources/views/housingOverlaps.html b/ehr/resources/views/housingOverlaps.html
index 9736656cc..48f211317 100644
--- a/ehr/resources/views/housingOverlaps.html
+++ b/ehr/resources/views/housingOverlaps.html
@@ -1,210 +1,278 @@
+
+
\ No newline at end of file
diff --git a/ehr/resources/web/ehr/ehr_api.lib.xml b/ehr/resources/web/ehr/ehr_api.lib.xml
index 59f74effe..ead5f3356 100644
--- a/ehr/resources/web/ehr/ehr_api.lib.xml
+++ b/ehr/resources/web/ehr/ehr_api.lib.xml
@@ -63,6 +63,7 @@
+
diff --git a/ehr/resources/web/ehr/form/field/BuildingField.js b/ehr/resources/web/ehr/form/field/BuildingField.js
new file mode 100644
index 000000000..ea9f75cb9
--- /dev/null
+++ b/ehr/resources/web/ehr/form/field/BuildingField.js
@@ -0,0 +1,59 @@
+Ext4.define('EHR.form.field.BuildingField', {
+ extend: 'Ext.ux.CheckCombo',
+ alias: 'widget.ehr-buildingfield',
+
+ fieldLabel: 'Building',
+ nullCaption: '[Blank]',
+ editable: false,
+ expandToFitContent: true,
+ addAllSelector: true,
+ typeAhead: true,
+
+ initComponent: function(){
+ Ext4.apply(this, {
+ displayField:'name',
+ valueField: 'name',
+ queryMode: 'local',
+ store: Ext4.create('LABKEY.ext4.data.Store', {
+ schemaName: 'ehr_lookups',
+ queryName: 'buildings',
+ sort: 'name',
+ filterArray: [LABKEY.Filter.create('dateDisabled', true, LABKEY.Filter.Types.ISBLANK)],
+ autoLoad: true
+ })
+ });
+
+ this.callParent(arguments);
+
+ if (this.pairedWithRoomField)
+ this.addRoomListeners();
+ },
+
+
+ addRoomListeners: function(){
+ this.on('select', function(field, records){
+ if (!records.length)
+ return;
+
+ var buildings = [];
+ Ext4.Array.forEach(records, function(r){
+ buildings.push(r.get('name'));
+ }, this);
+
+ var roomField = this.getRoomField();
+ roomField.suspendEvents();
+ roomField.selectByBuildings(buildings);
+ roomField.resumeEvents();
+ }, this);
+
+ this.on('render', function(field){
+ var val = field.getValue();
+ val = Ext4.isArray(val) || !val ? val : [val];
+
+ var roomField = this.getRoomField();
+ roomField.suspendEvents();
+ roomField.selectByBuildings(val);
+ roomField.resumeEvents();
+ }, this);
+ }
+});
\ No newline at end of file
diff --git a/ehr/resources/web/ehr/form/field/RoomField.js b/ehr/resources/web/ehr/form/field/RoomField.js
index 28bf62cf2..8c14a8bc7 100644
--- a/ehr/resources/web/ehr/form/field/RoomField.js
+++ b/ehr/resources/web/ehr/form/field/RoomField.js
@@ -19,7 +19,7 @@ Ext4.define('EHR.form.field.RoomField', {
type: 'labkey-store',
schemaName: 'ehr_lookups',
queryName: 'rooms',
- columns: 'room,room_sortValue,area',
+ columns: 'room,room_sortValue,area,building',
sort: 'room_sortValue',
filterArray: this.getStoreFilterArray(),
autoLoad: true
@@ -76,6 +76,35 @@ Ext4.define('EHR.form.field.RoomField', {
}
},
+ selectByBuildings: function(buildings){
+ if (!this.rendered || !this.store){
+ this.on('afterrender', function(field){
+ field.selectByBuildings(buildings);
+ }, this, {single: true});
+
+ return;
+ }
+
+ this.store.clearFilter();
+ if (!this.store.getCount()){
+ this.store.on('load', function(store){
+ this.selectByBuildings(buildings);
+ }, this, {single: true});
+ }
+ else {
+ if (buildings && buildings.length){
+ var values = [];
+ this.store.each(function(rec){
+ if (buildings.indexOf(rec.get('building')) != -1){
+ values.push(rec.get('room'));
+ }
+ }, this);
+
+ this.setValue(values);
+ }
+ }
+ },
+
filterByAreas: function(areas){
this.store.clearFilter();
if (!this.rendered){