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
2 changes: 2 additions & 0 deletions snprc_ehr/resources/queries/study/BrowseDataSets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions snprc_ehr/resources/queries/study/demographicsEarliestHousing.sql
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FieldKey> getFieldKeys()
{
Set<FieldKey> 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));
}
}
40 changes: 23 additions & 17 deletions snprc_ehr/src/org/labkey/snprc_ehr/table/SNPRC_EHRCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,6 +61,7 @@ public class SNPRC_EHRCustomizer extends AbstractTableCustomizer

private Set<CalculatedColumn> calculatedColumns;


public SNPRC_EHRCustomizer()
{
_provider = new CustomizerQueryProvider();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -444,35 +450,35 @@ 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);
}

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);
Expand All @@ -481,15 +487,15 @@ 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()));
ds.addColumn(col);
}
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()));
Expand All @@ -498,46 +504,46 @@ 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);
}

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);
}

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);
}

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);
}

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);
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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);
Expand Down