Skip to content

Commit 3830019

Browse files
authored
22.3 fb hl7 demographics (#422)
* New queries and ETLs for Orchard demographics ETL * Additional HL7 changes * 1. Changed .sql file encoding to UTF-8 2. Removed un-needed files * reformatted and changed line endings * reformatted and changed line endings
1 parent b8014c9 commit 3830019

7 files changed

Lines changed: 587 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<etl xmlns="http://labkey.org/etl/xml">
2+
<name>DemographicsHL7</name>
3+
<description>Export Demographics Data to Orchard Harvest</description>
4+
<transforms>
5+
<transform id="step1" type="org.labkey.di.pipeline.TransformTask">
6+
<description>Copy to target</description>
7+
<source schemaName="study" queryName="DemographicsHL7" />
8+
<destination schemaName="LISExport" queryName="DemographicsHL7Staging" bulkLoad="true" targetOption="append">
9+
<alternateKeys>
10+
<column name="objectid"/>
11+
</alternateKeys>
12+
</destination>
13+
</transform>
14+
<transform id="step2" type="StoredProcedure">
15+
<description>Kick off HL7 processing</description>
16+
<source schemaName="study" queryName="DemographicsHL7" />
17+
<procedure schemaName="LISExport" procedureName="p_load_demographics">
18+
</procedure>
19+
</transform>
20+
</transforms>
21+
<incrementalFilter className="ModifiedSinceFilterStrategy" timestampColumnName="modified" />
22+
<schedule>
23+
<poll interval="60m" />
24+
</schedule>
25+
</etl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SELECT
2+
d.Id,
3+
d.gender,
4+
d.species.arc_species_code.Common_name as species,
5+
d.species.arc_species_code as breed,
6+
d.birth as birthDate,
7+
d.death as deathDate,
8+
case when d.calculated_status.code = 'Alive' then 'Y' when d.calculated_status.code = 'Dead' then 'N' else Null end as isAlive,
9+
d.dam,
10+
d.sire,
11+
d.objectId,
12+
d.modifiedBy.DisplayName as modifiedBy,
13+
d.modified
14+
FROM demographics as d
15+
where len(d.id) <= 6
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
USE animal
2+
GO
3+
4+
-- Create TAC schema if not exists
5+
IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'LIS')
6+
BEGIN
7+
-- The schema must be run in its own batch!
8+
EXEC( 'CREATE SCHEMA LIS' );
9+
END
10+
11+
DROP TABLE IF EXISTS LIS.DemographicsHL7Staging;
12+
13+
CREATE TABLE LIS.DemographicsHL7Staging
14+
(
15+
RowId INT IDENTITY,
16+
Id VARCHAR(6) NOT NULL,
17+
Gender CHAR(1) NULL,
18+
BirthDate DATETIME NULL,
19+
DeathDate DATETIME NULL,
20+
Breed VARCHAR(2) NULL, -- arc_species_code
21+
Species VARCHAR(MAX) NULL, -- common name
22+
isAlive Varchar(1) NULL, -- Y/N/NULL
23+
Sire VARCHAR(6) NULL,
24+
Dam VARCHAR(6) NULL,
25+
Modified DATETIME NULL,
26+
ModifiedBy VARCHAR(MAX) NULL,
27+
Processed INT DEFAULT 0 NOT NULL, -- will be 0 when data is exported, and stored procedure will update it to 1 when processed
28+
ObjectId UNIQUEIDENTIFIER DEFAULT NEWID() NOT NULL,
29+
CONSTRAINT PK_TAC_DemographicsHL7Staging
30+
PRIMARY KEY CLUSTERED (RowId ASC)
31+
)
32+
33+
GO
34+
35+
-- Table permissions
36+
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE ON LIS.DemographicsHL7Staging TO z_labkey;
37+
GRANT VIEW DEFINITION ON LIS.DemographicsHL7Staging TO z_labkey;
38+
39+
GO
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
USE animal
2+
GO
3+
/*
4+
Error log for demographics export errors
5+
*/
6+
-- Create TAC schema if not exists
7+
IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'LIS')
8+
BEGIN
9+
-- The schema must be run in its own batch!
10+
EXEC( 'CREATE SCHEMA LIS' );
11+
END
12+
13+
DROP TABLE IF EXISTS LIS.HL7ExportErrorLog;
14+
15+
CREATE TABLE LIS.HL7ExportErrorLog
16+
(
17+
[RowId] [NUMERIC](18, 0) IDENTITY(1,1) NOT NULL,
18+
[ObjectId] [VARCHAR](50) NOT NULL,
19+
[ProcessedDateTm] [DATETIME] NULL,
20+
[MessageControlId] [VARCHAR](50) NULL,
21+
[PatientId] [VARCHAR](20) NULL,
22+
[ErrorMsg] [VARCHAR](MAX) NULL,
23+
[UserName] [VARCHAR](128) NOT NULL,
24+
[EntryDateTm] [DATETIME] NOT NULL,
25+
CONSTRAINT PK_TAC_HL7ExportErrorLog
26+
PRIMARY KEY CLUSTERED (RowId ASC)
27+
)
28+
29+
GO
30+
31+
-- Table permissions
32+
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE ON LIS.HL7ExportErrorLog TO z_labkey;
33+
GRANT VIEW DEFINITION ON LIS.HL7ExportErrorLog TO z_labkey;
34+
35+
GO
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
USE animal
2+
GO
3+
/*
4+
Import log for results from Orchard Harvest
5+
*/
6+
-- Create TAC schema if not exists
7+
IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'LIS')
8+
BEGIN
9+
-- The schema must be run in its own batch!
10+
EXEC( 'CREATE SCHEMA LIS' );
11+
END
12+
13+
DROP TABLE IF EXISTS LIS.HL7ImportLog;
14+
15+
CREATE TABLE LIS.HL7ImportLog
16+
(
17+
[RowId] [NUMERIC](18, 0) IDENTITY(1,1) NOT NULL,
18+
[MessageId] [VARCHAR](50) NOT NULL,
19+
[ObservationDateTm] [DATETIME] NULL,
20+
[MessageControlId] [VARCHAR](50) NULL,
21+
[ImportStatus] [INT] NOT NULL,
22+
[ResultStatis] [VARCHAR](10) NULL,
23+
[PatientId] [VARCHAR](20) NULL,
24+
[Species] [VARCHAR](50) NULL,
25+
[HL7MessageText] [VARCHAR](MAX) NULL,
26+
[ImportText] [VARCHAR](MAX) NULL,
27+
[UserName] [VARCHAR](128) NOT NULL,
28+
[EntryDateTm] [DATETIME] NOT NULL,
29+
[TIMESTAMP] [TIMESTAMP] NULL,
30+
CONSTRAINT PK_TAC_HL7ImportLog
31+
PRIMARY KEY CLUSTERED (RowId ASC)
32+
)
33+
34+
GO
35+
36+
-- Table permissions
37+
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE ON LIS.HL7ImportLog TO z_labkey;
38+
GRANT VIEW DEFINITION ON LIS.HL7ImportLog TO z_labkey;
39+
40+
GO
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
USE
2+
[TAC_HL7_staging]
3+
GO
4+
/****** Object: UserDefinedFunction [dbo].[f_format_hl7_date] Script Date: 3/23/2022 11:14:18 AM ******/
5+
SET ANSI_NULLS ON
6+
GO
7+
SET QUOTED_IDENTIFIER ON
8+
GO
9+
-- =============================================
10+
-- Author: Terry Hawkins
11+
-- Create date: 1/30/2014
12+
-- Description: Converts a date and time string into MSSQL datetime format
13+
-- =============================================
14+
CREATE FUNCTION [dbo].[f_format_hl7_date]
15+
(
16+
-- Add the parameters for the function here
17+
@date_str VARCHAR(50)
18+
)
19+
RETURNS DATETIME
20+
21+
AS
22+
BEGIN
23+
DECLARE
24+
@ret_date DATETIME
25+
IF LEN(@date_str) = 8
26+
BEGIN
27+
--20140117
28+
SET
29+
@ret_date = CAST(SUBSTRING(@date_str, 1,4)+ '-' + SUBSTRING(@date_str, 5,2) + '-' + SUBSTRING(@date_str,7,2) AS DATETIME)
30+
END
31+
ELSE
32+
BEGIN
33+
--201401171008
34+
SET
35+
@ret_date = CAST(SUBSTRING(@date_str, 1,4)+ '-' + SUBSTRING(@date_str, 5,2) + '-' + SUBSTRING(@date_str,7,2) +
36+
' ' + SUBSTRING(@date_str, 9,2) + ':' + SUBSTRING(@date_str, 11,2) AS DATETIME)
37+
END
38+
39+
RETURN @ret_date
40+
41+
END

0 commit comments

Comments
 (0)