diff --git a/snprc_ehr/resources/data/reports.tsv b/snprc_ehr/resources/data/reports.tsv index 6ce6563cc..c7b4acf40 100644 --- a/snprc_ehr/resources/data/reports.tsv +++ b/snprc_ehr/resources/data/reports.tsv @@ -69,4 +69,5 @@ Exposure History Exposures query Exposure History true study ExpExposureHistory Procedure History Exposures query Procedure History true study ExpProcedureHistory Date false false qcstate/publicdata Exposure procedures data Research Treatments Exposures query Research Treatments true study ExpResearchTreatments Date false false qcstate/publicdata Research Treatments data Abnormal Behavior Behavior query Abnormal Behavior true study BehaviorAbnormalSummary Date false false qcstate/publicdata Abnormal behavoir detail data -Vaccines Exposures query Vaccines true study ExpVaccines Date false false qcstate/publicdata Exposure vaccines data \ No newline at end of file +Vaccines Exposures query Vaccines true study ExpVaccines Date false false qcstate/publicdata Exposure vaccines data +Body Condition Score Clinical query Body Condition Score true study BodyConditionScores \ No newline at end of file diff --git a/snprc_ehr/resources/queries/study/BodyConditionScores.query.xml b/snprc_ehr/resources/queries/study/BodyConditionScores.query.xml new file mode 100644 index 000000000..25f789429 --- /dev/null +++ b/snprc_ehr/resources/queries/study/BodyConditionScores.query.xml @@ -0,0 +1,50 @@ + + + + + Body Condition Scores + + + true + + study + animal + Id + + + + BCS Date + + + Body Condition Score + + + Numeric BCS Value + + + true + + + true + + UserId + Users + core + + + + true + + + true + + UserId + Users + core + + + +
+
+
+
diff --git a/snprc_ehr/resources/queries/study/BodyConditionScores.sql b/snprc_ehr/resources/queries/study/BodyConditionScores.sql new file mode 100644 index 000000000..d83466358 --- /dev/null +++ b/snprc_ehr/resources/queries/study/BodyConditionScores.sql @@ -0,0 +1,17 @@ + +SELECT + p.id as Id, + p.date as BcsDate, + p.procNarrative as BCS, + case when substring(p.procNarrative, 7, 1) = ' ' then cast(substring (p.procNarrative, 6,1) as float) + else cast( substring (p.procNarrative, 6,3) as float ) + end as BCSValue, + p.Created, + p.CreatedBy, + p.Modified, + p.ModifiedBy + +FROM study.procedure AS p +WHERE p.qcstate.publicdata = true + AND p.pkgId.categories like '%BCS%' + AND p.procNarrative <> 'BCS: error' diff --git a/snprc_ehr/resources/queries/study/BrowseDataSets.sql b/snprc_ehr/resources/queries/study/BrowseDataSets.sql index d01a81557..3504b5bef 100644 --- a/snprc_ehr/resources/queries/study/BrowseDataSets.sql +++ b/snprc_ehr/resources/queries/study/BrowseDataSets.sql @@ -60,3 +60,5 @@ UNION select 'study' as schema, 'Misc' as CategoryId,'Animals with Genetic data' as Label, 'GenDemohasData' as Name, true as ShowByDefault, true as isAnimal UNION select 'study' as schema, 'Behavior' as CategoryId,'Abnormal Behavior' as Label, 'BehaviorAbnormalAll' as Name, true as ShowByDefault, true as isAnimal +UNION +select 'study' as schema, 'Clinical' as CategoryId,'Body Condition Scores' as Label, 'BodyConditionScores' as Name, true as ShowByDefault, true as isAnimal diff --git a/snprc_ehr/resources/queries/study/demographicsLastBCS.sql b/snprc_ehr/resources/queries/study/demographicsLastBCS.sql new file mode 100644 index 000000000..5e2e25cc4 --- /dev/null +++ b/snprc_ehr/resources/queries/study/demographicsLastBCS.sql @@ -0,0 +1,12 @@ + +SELECT + p.id as Id, + p.date as BcsDate, + p.procNarrative as LastBCS, + p.QCState + +FROM study.procedure AS p +WHERE p.qcstate.publicdata = true +AND p.pkgId.categories like '%BCS%' +and p.date = (select max(p2.date) from study.procedure as p2 + where p2.id = p.id and p2.pkgId.categories like '%BCS%') diff --git a/snprc_ehr/resources/web/snprc_ehr/DemographicsRecord.js b/snprc_ehr/resources/web/snprc_ehr/DemographicsRecord.js index b450448f2..04251b8b1 100644 --- a/snprc_ehr/resources/web/snprc_ehr/DemographicsRecord.js +++ b/snprc_ehr/resources/web/snprc_ehr/DemographicsRecord.js @@ -201,6 +201,10 @@ EHR.DemographicsRecord = function(data){ getSourceRecord: function(){ return data.source; - } + }, + + getLastBcs: function() { + return data['LastBCS']; + }, } -} \ No newline at end of file +} diff --git a/snprc_ehr/resources/web/snprc_ehr/snprcOverrides.js b/snprc_ehr/resources/web/snprc_ehr/snprcOverrides.js index 1036e8b3b..bf3d7de58 100644 --- a/snprc_ehr/resources/web/snprc_ehr/snprcOverrides.js +++ b/snprc_ehr/resources/web/snprc_ehr/snprcOverrides.js @@ -110,6 +110,27 @@ Ext4.override(EHR.panel.SnapshotPanel, { toSet['idHistories'] = text.length ? '' + text.join('') + '
' : null; }, + appendLastBcs: function (toSet, results) { + var text = []; + if (results) { + var rows = []; + Ext4.each(results, function (row) { + var d = LDK.ConvertUtils.parseDate(row['BcsDate'], LABKEY.extDefaultDateFormat); + var newRow = { + BcsDate: d.format(LABKEY.extDefaultDateFormat), + LastBCS: row['LastBCS'] + }; + rows.push(newRow); + }, this); + + Ext4.each(rows, function (r) { + text.push('' + r.BcsDate + ':' + '' + r.LastBCS + ''); + }, this); + } + + toSet['LastBCS'] = text.length ? '' + text.join('') + '
' : null; + }, + appendCurrentAccountsResults: function (toSet, results) { var text = []; @@ -337,7 +358,11 @@ Ext4.override(EHR.panel.SnapshotPanel, { xtype: 'displayfield', fieldLabel: 'Id History', name: 'idHistories' - }] + },{ + xtype: 'displayfield', + fieldLabel: 'Last BCS', + name: 'LastBCS' + },] }] }] }]; @@ -499,6 +524,7 @@ Ext4.override(EHR.panel.SnapshotPanel, { this.appendFlags(toSet, results.getActiveFlags()); this.appendTBResults(toSet, results.getTBRecord()); + this.appendLastBcs(toSet, results.getLastBcs()); if (this.showExtendedInformation) { this.appendBirthResults(toSet, results.getBirthInfo(), results.getBirth()); @@ -533,4 +559,4 @@ Ext4.override(EHR.panel.SnapshotPanel, { // }] // }] // } -// }); \ No newline at end of file +// }); 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 d2484d784..5048f9035 100644 --- a/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java +++ b/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java @@ -64,6 +64,7 @@ import org.labkey.snprc_ehr.demographics.ActiveFlagsDemographicsProvider; import org.labkey.snprc_ehr.demographics.BirthDemographicsProvider; import org.labkey.snprc_ehr.demographics.CurrentAccountsDemographicsProvider; +import org.labkey.snprc_ehr.demographics.LastBcsDemographicsProvider; import org.labkey.snprc_ehr.demographics.CurrentDietDemographicsProvider; import org.labkey.snprc_ehr.demographics.CurrentPedigreeDemographicsProvider; import org.labkey.snprc_ehr.demographics.DeathsDemographicsProvider; @@ -199,6 +200,7 @@ protected void doStartupAfterSpringConfig(ModuleContext moduleContext) EHRService.get().registerDemographicsProvider(new ActiveFlagsDemographicsProvider(this)); EHRService.get().registerDemographicsProvider(new MhcSummaryDemographicsProvider(this)); EHRService.get().registerDemographicsProvider(new LastHousingDemographicsProvider(this)); + EHRService.get().registerDemographicsProvider(new LastBcsDemographicsProvider(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"); @@ -370,4 +372,4 @@ public WebPartView getWebPartView(@NotNull ViewContext portalCtx, @NotNull Porta return webPartFactories; } -} \ No newline at end of file +} diff --git a/snprc_ehr/src/org/labkey/snprc_ehr/demographics/LastBcsDemographicsProvider.java b/snprc_ehr/src/org/labkey/snprc_ehr/demographics/LastBcsDemographicsProvider.java new file mode 100644 index 000000000..5498610d1 --- /dev/null +++ b/snprc_ehr/src/org/labkey/snprc_ehr/demographics/LastBcsDemographicsProvider.java @@ -0,0 +1,53 @@ +package org.labkey.snprc_ehr.demographics; + + +import org.labkey.api.data.CompareType; +import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; +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; + +/** + * Created by thawkins on 7/6/2020. + */ + +public class LastBcsDemographicsProvider extends AbstractListDemographicsProvider +{ + + public LastBcsDemographicsProvider(Module owner) + { + super(owner, "study", "demographicsLastBCS", "LastBCS"); + _supportsQCState = false; + } + + @Override + protected Set getFieldKeys() + { + Set keys = new HashSet<>(); + keys.add(FieldKey.fromString("Id")); + keys.add(FieldKey.fromString("BcsDate")); + keys.add(FieldKey.fromString("LastBCS")); + + return keys; + } + + @Override + protected Sort getSort() + { + return new Sort("-Id"); + } + + @Override + protected SimpleFilter getFilter(Collection ids) + { + SimpleFilter filter = super.getFilter(ids); + filter.addCondition(FieldKey.fromString("qcstate/publicData"), true, CompareType.EQUAL); + + return filter; + } +} 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 f7c34734e..f519f6b52 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 @@ -460,6 +460,13 @@ private void customizeAnimalTable(AbstractTableInfo ds) 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"); + col.setLabel("Most Recent BCS"); + col.setDescription("Queries the most recent BCS value for the animal."); + ds.addColumn(col); + } // Change label and description 8/31/2017 tjh if (ds.getColumn("MostRecentArrival") != null) @@ -480,6 +487,7 @@ private void customizeAnimalTable(AbstractTableInfo ds) col.setDescription("Calculates the earliest and most recent departure per animal, if applicable, and most recent acquisition."); ds.addColumn(col); } + // Because of performance, changed to study based dataset ETLed from genetics folder 10/14/19 srr if (genetics != null) { @@ -533,4 +541,4 @@ else if (targetTable.getSchema() != null) } return realTable; } -} \ No newline at end of file +}