diff --git a/snprc_ehr/resources/queries/study/BrowseDataSets.sql b/snprc_ehr/resources/queries/study/BrowseDataSets.sql index aab30e6f..9b2b44a5 100644 --- a/snprc_ehr/resources/queries/study/BrowseDataSets.sql +++ b/snprc_ehr/resources/queries/study/BrowseDataSets.sql @@ -68,3 +68,5 @@ UNION select 'ehr' as schema, 'Colony Management' as CategoryId,'Kinship' as Label, 'kinship' as Name, true as ShowByDefault, true as isAnimal UNION select 'ehr' as schema, 'Colony Management' as CategoryId,'Project' as Label, 'project' as Name, true as ShowByDefault, false as isAnimal +UNION +select 'study' as schema, 'Colony Management' as CategoryId,'Offspring' as Label, 'demographicsOffspring' as Name, true as ShowByDefault, true as isAnimal diff --git a/snprc_ehr/resources/queries/study/demographicsEarliestHousing.sql b/snprc_ehr/resources/queries/study/demographicsEarliestHousing.sql new file mode 100644 index 00000000..3480516d --- /dev/null +++ b/snprc_ehr/resources/queries/study/demographicsEarliestHousing.sql @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017-2018 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 + */ +SELECT + d.Id AS Id, + h.date as FirstHousingDate, + h.room as FirstHousingRoom, + h.room.area.description as FirstHousingRoomDescription +FROM study.demographics d + + +--date of first housing +LEFT JOIN study.housing as h on h.id = d.id and h.qcstate.publicdata = true + and h.date = (select min(c1.date) from study.housing as c1 + where h.id = c1.id) diff --git a/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java b/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java index 821b2d6a..7f3f448f 100644 --- a/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java +++ b/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java @@ -65,6 +65,7 @@ import org.labkey.snprc_ehr.demographics.CurrentDietDemographicsProvider; import org.labkey.snprc_ehr.demographics.CurrentPedigreeDemographicsProvider; import org.labkey.snprc_ehr.demographics.DeathsDemographicsProvider; +import org.labkey.snprc_ehr.demographics.EarliestHousingDemographicsProvider; import org.labkey.snprc_ehr.demographics.IdHistoryDemographicsProvider; import org.labkey.snprc_ehr.demographics.LastBcsDemographicsProvider; import org.labkey.snprc_ehr.demographics.LastHousingDemographicsProvider; @@ -195,6 +196,9 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext) EHRService.get().registerDemographicsProvider(new LastHousingDemographicsProvider(this)); EHRService.get().registerDemographicsProvider(new LastBcsDemographicsProvider(this)); + // Commented out until we need to add the EarliestHousing to the snapshot view. tjh + //EHRService.get().registerDemographicsProvider(new EarliestHousingDemographicsProvider(this)); + EHRService.get().registerReportLink(EHRService.REPORT_LINK_TYPE.housing, "Find Animals Housed In A Given Room/Cage At A Specific Time", this, DetailsURL.fromString("/ehr-housingOverlaps.view?groupById=1"), "Commonly Used Queries"); EHRService.get().registerReportLink(EHRService.REPORT_LINK_TYPE.animalSearch, "Population Summary By Species, Gender and Age", this, DetailsURL.fromString("/query-executeQuery.view?schemaName=study&query.queryName=colonyPopulationByAge"), "Other Searches"); EHRService.get().registerReportLink(EHRService.REPORT_LINK_TYPE.animalSearch, "Find Animals Housed At The Center Over A Date Range", this, DetailsURL.fromString("/ehr-housingOverlaps.view?groupById=1"), "Other Searches"); diff --git a/snprc_ehr/src/org/labkey/snprc_ehr/demographics/EarliestHousingDemographicsProvider.java b/snprc_ehr/src/org/labkey/snprc_ehr/demographics/EarliestHousingDemographicsProvider.java new file mode 100644 index 00000000..ca3dd6e0 --- /dev/null +++ b/snprc_ehr/src/org/labkey/snprc_ehr/demographics/EarliestHousingDemographicsProvider.java @@ -0,0 +1,43 @@ +package org.labkey.snprc_ehr.demographics; + +import org.labkey.api.ehr.demographics.AbstractListDemographicsProvider; +import org.labkey.api.module.Module; +import org.labkey.api.query.FieldKey; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public class EarliestHousingDemographicsProvider extends AbstractListDemographicsProvider + +{ + + public EarliestHousingDemographicsProvider(Module owner) + { + super(owner, "study", "demographicsEarliestHousing", "earliestHousing"); + _supportsQCState = false; + } + + @Override + public String getName() + { + return "Earliest Housing"; + } + + @Override + protected Collection getFieldKeys() + { + Set keys = new HashSet<>(); + keys.add(FieldKey.fromString("FirstHousingDate")); + keys.add(FieldKey.fromString("FirstHousingRoom")); + keys.add(FieldKey.fromString("FirstHousingRoomDescription")); + + return keys; + } + + @Override + public boolean requiresRecalc(String schema, String query) + { + return ("study".equalsIgnoreCase(schema) && "Housing".equalsIgnoreCase(query)); + } +} diff --git a/snprc_ehr/src/org/labkey/snprc_ehr/table/SNPRC_EHRCustomizer.java b/snprc_ehr/src/org/labkey/snprc_ehr/table/SNPRC_EHRCustomizer.java index 8da6ec56..717039f9 100644 --- a/snprc_ehr/src/org/labkey/snprc_ehr/table/SNPRC_EHRCustomizer.java +++ b/snprc_ehr/src/org/labkey/snprc_ehr/table/SNPRC_EHRCustomizer.java @@ -45,7 +45,6 @@ import org.labkey.snprc_ehr.SNPRC_EHRSchema; import org.labkey.snprc_ehr.helpers.CustomizerQueryProvider; import org.labkey.snprc_ehr.model.CalculatedColumn; - import static org.labkey.snprc_ehr.constants.QueryConstants.*; import java.util.Calendar; @@ -62,6 +61,7 @@ public class SNPRC_EHRCustomizer extends AbstractTableCustomizer private Set calculatedColumns; + public SNPRC_EHRCustomizer() { _provider = new CustomizerQueryProvider(); @@ -161,8 +161,14 @@ public void doTableSpecificCustomizations(AbstractTableInfo ti) */ if (matches(ti, "study", "Animal")) { + UserSchema us = getEHRUserSchema(ti, STUDY_SCHEMA); customizeAnimalTable(ti); + var col = getWrappedCol(us, ti, "earliestHousing", "demographicsEarliestHousing", ID_COLUMN, ID_COLUMN); + col.setLabel("Housing - Earliest"); + col.setDescription("The calculates the earliest housing location for each living animal."); + ti.addColumn(col); } + if (matches(ti, "study", "Animal Events") || matches(ti, "study", "encounters")) { customizeEncounterTable(ti); @@ -444,27 +450,27 @@ private void customizeAnimalTable(AbstractTableInfo ds) } if (ds.getColumn("flags") == null) { - var col = getWrappedCol(us, ds, "Flags", "demographicsActiveFlags", "Id", "Id"); + var col = getWrappedCol(us, ds, "Flags", "demographicsActiveFlags", ID_COLUMN, ID_COLUMN); col.setLabel("ActiveFlags"); col.setURL(DetailsURL.fromString("/query/executeQuery.view?schemaName=ehr_lookups&queryName=flag_values&query.Id~eq=${Id}", ds.getContainerContext())); ds.addColumn(col); } if (ds.getColumn("parents") == null) { - var col = getWrappedCol(us, ds, "parents", "demographicsParents", "Id", "Id"); + var col = getWrappedCol(us, ds, "parents", "demographicsParents", ID_COLUMN, ID_COLUMN); col.setLabel("Parents"); ds.addColumn(col); } if (ds.getColumn("mhcSummary") == null) { - var col = getWrappedCol(us, ds, "mhcSummary", "mhcSummary", "Id", "Id"); + var col = getWrappedCol(us, ds, "mhcSummary", "mhcSummary", ID_COLUMN, ID_COLUMN); col.setLabel("mhcSummary"); ds.addColumn(col); } if (ds.getColumn("totalOffspring") == null) { - var col15 = getWrappedCol(us, ds, "totalOffspring", "demographicsTotalOffspring", "Id", "Id"); + var col15 = getWrappedCol(us, ds, "totalOffspring", "demographicsTotalOffspring", ID_COLUMN, ID_COLUMN); col15.setLabel("Number of Offspring"); col15.setDescription("Shows the total offspring of each animal"); ds.addColumn(col15); @@ -472,7 +478,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("labworkHistory") == null) { - var col = getWrappedCol(us, ds, "labworkHistory", "demographicsLabwork", "Id", "Id"); + var col = getWrappedCol(us, ds, "labworkHistory", "demographicsLabwork", ID_COLUMN, ID_COLUMN); col.setLabel("Labwork History"); col.setDescription("Shows the date of last labwork for a subsets of tests"); ds.addColumn(col); @@ -481,7 +487,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) //do we have freezer samples? if (ds.getColumn("freezerSamples") == null) { - var col = getWrappedCol(us, ds, "freezerSamples", "demographicsFreezers", "Id", "Id"); + var col = getWrappedCol(us, ds, "freezerSamples", "demographicsFreezers", ID_COLUMN, ID_COLUMN); col.setLabel("Freezer Samples"); col.setDescription("Shows the number of archived freezer samples"); col.setURL(DetailsURL.fromString("/query/executeQuery.view?schemaName=study&queryName=freezerWorks&query.Id~eq=${Id}", ds.getContainerContext())); @@ -489,7 +495,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) } if (ds.getColumn("idHistoryList") == null) { - var col = getWrappedCol(us, ds, "idHistoryList", "demographicsIdHistory", "Id", "Id"); + var col = getWrappedCol(us, ds, "idHistoryList", "demographicsIdHistory", ID_COLUMN, ID_COLUMN); col.setLabel("Id Hx List"); col.setDescription("List of Ids assigned to animal"); col.setURL(DetailsURL.fromString("/query/executeQuery.view?schemaName=study&queryName=idHistory&query.Id~eq=${Id}", ds.getContainerContext())); @@ -498,7 +504,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("activeAccounts") == null) { - var col = getWrappedCol(us, ds, "activeAccounts", "demographicsActiveAccount", "Id", "Id"); + var col = getWrappedCol(us, ds, "activeAccounts", "demographicsActiveAccount", ID_COLUMN, ID_COLUMN); col.setLabel("Accounts - Active"); col.setDescription("Shows all accounts to which the animal is actively assigned on the current date"); ds.addColumn(col); @@ -506,7 +512,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("packageCategory") == null) { - var col = getWrappedCol(us, ds, "packageCategory", "demographicsPackageCategories", "Id", "Id"); + var col = getWrappedCol(us, ds, "packageCategory", "demographicsPackageCategories", ID_COLUMN, ID_COLUMN); col.setLabel("Package Category"); col.setDescription("Shows the package category for procedures"); ds.addColumn(col); @@ -514,7 +520,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("activeAssignments") == null) { - var col = getWrappedCol(us, ds, "activeAssignments", "demographicsActiveAssignment", "Id", "Id"); + var col = getWrappedCol(us, ds, "activeAssignments", "demographicsActiveAssignment", ID_COLUMN, ID_COLUMN); col.setLabel("IACUC Assignments - Active"); col.setDescription("Shows all protocols to which the animal is actively assigned on the current date"); ds.addColumn(col); @@ -522,7 +528,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("activeGroups") == null) { - var col = getWrappedCol(us, ds, "activeGroups", "demographicsAnimalGroups", "Id", "Id"); + var col = getWrappedCol(us, ds, "activeGroups", "demographicsAnimalGroups", ID_COLUMN, ID_COLUMN); col.setLabel("Animal Groups - Active"); col.setDescription("Shows all groups to which the animal is actively assigned on the current date"); ds.addColumn(col); @@ -530,14 +536,14 @@ private void customizeAnimalTable(AbstractTableInfo ds) if (ds.getColumn("MostRecentTBDate") == null) { - var col = getWrappedCol(us, ds, "MostRecentTBDate", "demographicsMostRecentTBDate", "Id", "Id"); + var col = getWrappedCol(us, ds, "MostRecentTBDate", "demographicsMostRecentTBDate", ID_COLUMN, ID_COLUMN); col.setLabel("Most Recent TB"); col.setDescription("Queries the most recent TB date for the animal."); ds.addColumn(col); } if (ds.getColumn("LastBCS") == null) { - var col = getWrappedCol(us, ds, "LastBCS", "demographicsLastBCS", "Id", "Id"); + var col = getWrappedCol(us, ds, "LastBCS", "demographicsLastBCS", ID_COLUMN, ID_COLUMN); col.setLabel("Most Recent BCS"); col.setDescription("Queries the most recent BCS value for the animal."); ds.addColumn(col); @@ -546,7 +552,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) // Change label and description 8/31/2017 tjh if (ds.getColumn("MostRecentArrival") != null) { - var col = getWrappedCol(us, ds, "MostRecentArrival", "demographicsArrival", "Id", "Id"); + var col = getWrappedCol(us, ds, "MostRecentArrival", "demographicsArrival", ID_COLUMN, ID_COLUMN); ds.removeColumn(col); col.setLabel("Acquisition"); col.setDescription("Calculates the earliest and most recent acquisition per animal."); @@ -556,7 +562,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) // Change label and description 8/31/2017 tjh if (ds.getColumn("MostRecentDeparture") != null) { - var col = getWrappedCol(us, ds, "MostRecentDeparture", "demographicsMostRecentDeparture", "Id", "Id"); + var col = getWrappedCol(us, ds, "MostRecentDeparture", "demographicsMostRecentDeparture", ID_COLUMN, ID_COLUMN); ds.removeColumn(col); col.setLabel("Disposition"); col.setDescription("Calculates the earliest and most recent departure per animal, if applicable, and most recent acquisition."); @@ -568,7 +574,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) { if (ds.getColumn("GenDemoCustomizer") == null) { - var col = getWrappedCol(us, ds, "GenDemoCustomizer", "GenDemoCustomizer", "Id", "Id"); + var col = getWrappedCol(us, ds, "GenDemoCustomizer", "GenDemoCustomizer", ID_COLUMN, ID_COLUMN); col.setLabel("Genetic Assays"); col.setDescription("Show if genetic assays exist for ID"); ds.addColumn(col);