From 39c11331936b6ebe8de43a62b760ca7172104406 Mon Sep 17 00:00:00 2001 From: srouseTxbiomed Date: Mon, 5 Apr 2021 12:01:44 -0500 Subject: [PATCH 1/2] Updated NewAnimalData for SourceInstitutionLocation 04.05.2021 srr --- .../queries/snprc_ehr/ExportNewAnimalData.sql | 7 ++- .../sqlserver/snprc_ehr-21.000-21.001.sql | 57 +++++++++++++++++++ .../create_CAMP_NewAnimalData.sql | 8 +++ .../org/labkey/snprc_ehr/SNPRC_EHRModule.java | 2 +- 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 snprc_ehr/resources/schemas/dbscripts/sqlserver/snprc_ehr-21.000-21.001.sql diff --git a/snprc_ehr/resources/queries/snprc_ehr/ExportNewAnimalData.sql b/snprc_ehr/resources/queries/snprc_ehr/ExportNewAnimalData.sql index 580a584f8..3f1ac6e10 100644 --- a/snprc_ehr/resources/queries/snprc_ehr/ExportNewAnimalData.sql +++ b/snprc_ehr/resources/queries/snprc_ehr/ExportNewAnimalData.sql @@ -6,7 +6,11 @@ srr 07.07.2020 - Syncing with current table structure 02.02.21 + Syncing with current table structure + srr 02.02.2021 + Adding SourceInstitution column to hold source institution for + non-birth acquisitions. + srr 03.31.2021 ********************************************************/ SELECT @@ -15,6 +19,7 @@ SELECT n.BirthCode as Bd_Status, n.AcquisitionType, n.AcqDate AS AcquisitionDate, + n.SourceInstitutionLocation, n.species, n.Gender, n.sire, diff --git a/snprc_ehr/resources/schemas/dbscripts/sqlserver/snprc_ehr-21.000-21.001.sql b/snprc_ehr/resources/schemas/dbscripts/sqlserver/snprc_ehr-21.000-21.001.sql new file mode 100644 index 000000000..94437a526 --- /dev/null +++ b/snprc_ehr/resources/schemas/dbscripts/sqlserver/snprc_ehr-21.000-21.001.sql @@ -0,0 +1,57 @@ +/******************************************************* +New table to load data from new animal wizard. + Data will be ETLed back down to animal database + +srr 01.28.2020 + + May not use all columns. + I defaulted to nvarchar(400) if unsure of datatype. + May need to change datatypes to match those in lookup tables. + +srr 03.09.2020 version 20.003 + Changed to ints for values that have a dropdown. + No Real data, therefore dropping table and re-recreating. +srr 06.08.2020 version 20.007 + Added column for BirthCode. + 1 DOB accurate + 2 Month-Year accurate + 3 Year accurate + No Real data, therefore dropping table and re-recreating. + + srr 06.24.2020 + Changed Diet, AnimalAccount and IACUC to strings + srr 04012021 version 21.000 +*******************************************************/ + +EXEC core.fn_dropifexists 'NewAnimalData','snprc_ehr', 'TABLE'; + + +CREATE TABLE snprc_ehr.NewAnimalData +( + Id nvarchar(32) NOT NULL, + BirthDate datetime NULL, + BirthCode int NULL, + AcquisitionType int NULL, + AcqDate datetime NULL, + SourceInstitutionLocation nvarchar(10) NULL, + Gender nvarchar(10) NULL, + Sire nvarchar(32) NULL, + Dam nvarchar(32) NULL, + Species nvarchar(3) NULL, + Colony int NULL, + AnimalAccount nvarchar(16) NULL, + OwnerInstitution int NULL, + ResponsibleInstitution int NULL, + Room int NULL, + Cage int NULL, + Diet nvarchar(20) NULL, + Pedigree int NULL, + IACUC nvarchar(200) NULL, + Created datetime NULL, + CreatedBy dbo.USERID NULL, + Modified datetime NULL, + ModifiedBy dbo.USERID NULL, + Container dbo.ENTITYID NOT NULL, + objectid uniqueidentifier NOT NULL, + CONSTRAINT PK_snprc_NEWANIMALDATA PRIMARY KEY (Id) +); \ No newline at end of file diff --git a/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql b/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql index 2b86de125..57527b216 100644 --- a/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql +++ b/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql @@ -31,6 +31,13 @@ EXEC('CREATE SCHEMA [TAC_src] AUTHORIZATION [DBO]'); -- new schema DROP TABLE IF EXISTS TAC_src.NewAnimalData; +/***************************************************** + Added SourceInstitutionLocation to hold + source location for non-birth acquisitions +04.01.2021 srr + ******************************************************/ + + CREATE TABLE TAC_src.NewAnimalData ( tid INT IDENTITY, @@ -39,6 +46,7 @@ CREATE TABLE TAC_src.NewAnimalData Bd_Status INT NULL, AcquisitionType INT NULL, AcquisitionDate DATETIME NULL, -- Start date for Data Tables + SourceInstitutionLocation VARCHAR(10) NULL, -- handle as room Gender CHAR(1) NULL, Sire VARCHAR(6) NULL, Dam VARCHAR(6) NULL, 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 2d7c916fa..b67bf4e3a 100644 --- a/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java +++ b/snprc_ehr/src/org/labkey/snprc_ehr/SNPRC_EHRModule.java @@ -119,7 +119,7 @@ public String getName() @Override public @Nullable Double getSchemaVersion() { - return 21.000; + return 21.001; } @Override From af99fa6597e2be2b324a1a70606c6141fe509e13 Mon Sep 17 00:00:00 2001 From: srouseTxbiomed Date: Tue, 6 Apr 2021 17:26:50 -0500 Subject: [PATCH 2/2] Updated NewAnimalData for SourceInstitutionLocation Added logic for adding actual location 1 minute later to accommodate the source location move. 04.06.2021 srr --- .../create_CAMP_NewAnimalData.sql | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql b/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql index 57527b216..acd98b8f3 100644 --- a/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql +++ b/snprc_ehr/resources/source_queries/create_CAMP_NewAnimalData.sql @@ -274,8 +274,34 @@ FROM inserted i ON i.tid = t.tid; - -- move to SNPRC loc +-- move to SNPRC loc +-- Move to source location for non TxBiomed births +/******************************** +To allow for a move to a source location, actual +onCampus move will be 1 minute after the AcquisitionDate +srr 04.05.2021 +********************************/ +-- move to ori source location +IF UPDATE(SourceInstitutionLocation) +BEGIN +INSERT INTO dbo.location +( id , + move_date_tm , + location, + user_name, + entry_date_tm +) +SELECT t.id, + i.AcquisitionDate, + CAST(i.SourceInstitutionLocation AS NUMERIC(7,2)), + t.CreatedBy, @insertDateTime +FROM inserted i + INNER JOIN @TxIds t +ON i.tid = t.tid +WHERE i.SourceInstitutionLocation IS NOT NULL; +END +-- Current Location INSERT INTO dbo.location ( id , move_date_tm , @@ -284,12 +310,18 @@ INSERT INTO dbo.location entry_date_tm ) -- insert shim -SELECT t.id, i.AcquisitionDate, CAST(i.Room AS NUMERIC(7,2)), +SELECT t.id, + CASE WHEN i.SourceInstitutionLocation IS NOT NULL THEN DATEADD(MINUTE,1, i.AcquisitionDate) + ELSE i.AcquisitionDate + END AcquisitionDate, + CAST(i.Room AS NUMERIC(7,2)), t.CreatedBy, @insertDateTime FROM inserted i INNER JOIN @TxIds t ON i.tid = t.tid; + + -- add Primary ID to id_history INSERT INTO dbo.id_history ( sfbr_id ,