1+ -- ============================================================
2+ -- COVID_LAB_DATAMART Post-Processing Stored Procedure
3+ -- Happy path unit test for sp_covid_lab_datamart_postprocessing
4+ -- - assumes all entities are present in nrt tables
5+ -- - skips code branch to populate AOE columns
6+ -- ============================================================
7+
8+ USE [RDB_Modern];
9+
10+ -- ------------------------------------------------------------
11+ -- UIDs
12+ -- ------------------------------------------------------------
13+ DECLARE @patient_uid BIGINT = 90001001 ;
14+ DECLARE @org_uid_perform BIGINT = 90002001 ; -- Testing lab
15+ DECLARE @org_uid_author BIGINT = 90002002 ; -- Reporting facility
16+ DECLARE @org_uid_order BIGINT = 90002003 ; -- Ordering facility
17+ DECLARE @provider_uid BIGINT = 90003001 ;
18+ DECLARE @material_id BIGINT = 90004001 ;
19+ DECLARE @phc_uid BIGINT = 90005001 ;
20+ DECLARE @obs_uid_order BIGINT = 90006001 ;
21+ DECLARE @obs_uid_result BIGINT = 90006002 ;
22+
23+ -- ------------------------------------------------------------
24+ -- Reference / SRTE tables
25+ -- ------------------------------------------------------------
26+
27+ -- Add condition mapping for Covid LOINCs
28+ INSERT INTO dbo .nrt_srte_Loinc_condition (loinc_cd, condition_cd)
29+ SELECT ' 94500-6' , ' 11065'
30+ WHERE NOT EXISTS (SELECT 1 FROM dbo .nrt_srte_Loinc_condition WHERE loinc_cd = ' 94500-6' AND condition_cd = ' 11065' );
31+
32+ INSERT INTO dbo .nrt_srte_Loinc_condition (loinc_cd, condition_cd)
33+ SELECT ' 94309-2' , ' 11065'
34+ WHERE NOT EXISTS (SELECT 1 FROM dbo .nrt_srte_Loinc_condition WHERE loinc_cd = ' 94309-2' AND condition_cd = ' 11065' );
35+
36+ -- Ensure our LOINC values don't have invalid details
37+ DELETE FROM dbo .nrt_srte_Loinc_code
38+ WHERE loinc_cd IN (' 94500-6' , ' 94309-2' ) AND time_aspect = ' Pt' AND system_cd = ' ^Patient' ;
39+
40+ -- ------------------------------------------------------------
41+ -- Patient
42+ -- ------------------------------------------------------------
43+ INSERT INTO dbo .nrt_patient
44+ (patient_uid, local_id, last_name, middle_name, first_name, curr_sex_cd,
45+ age_reported, age_reported_unit_cd, dob, phone_home,
46+ street_address_1, city, state_code, zip, county_code, county,
47+ race_calculated, ethnic_group_ind)
48+ VALUES
49+ (@patient_uid, ' PSN-TEST-' + CAST (@patient_uid AS VARCHAR ), ' Smith' , ' A' , ' John' , ' M' ,
50+ ' 45' , ' a' , ' 1979-03-15' , ' 4045550100' ,
51+ ' 123 Main St' , ' Atlanta' , ' 13' , ' 30301' , ' 063' , ' Fulton' ,
52+ ' White' , ' N' );
53+
54+ INSERT INTO dbo .nrt_patient_key (patient_uid)
55+ VALUES (@patient_uid);
56+
57+ -- ------------------------------------------------------------
58+ -- Organizations
59+ -- ------------------------------------------------------------
60+ INSERT INTO dbo .nrt_organization
61+ (organization_uid, organization_name, street_address_1, city, state_code, state , zip, county_code, county, country_code, facility_id, phone_work, phone_ext_work)
62+ VALUES
63+ (@org_uid_perform, ' State Reference Lab' , ' 456 Lab Blvd' , ' Atlanta' , ' 13' , ' Georgia' , ' 30302' , ' 063' , ' Fulton' , ' US' , ' 10D2289533' , ' 4045550200' , ' ' ),
64+ (@org_uid_author, ' Emory University Hospital' , ' 789 Clifton Rd' , ' Atlanta' , ' 13' , ' Georgia' , ' 30322' , ' 063' , ' Fulton' , ' US' , ' 10D0123456' , ' 4045550300' , ' ' ),
65+ (@org_uid_order, ' Peachtree Urgent Care' , ' 321 Peachtree St' , ' Atlanta' , ' 13' , ' Georgia' , ' 30303' , ' 063' , ' Fulton' , ' US' , ' 10D9876543' , ' 4045550400' , ' ' );
66+
67+ -- ------------------------------------------------------------
68+ -- Provider
69+ -- ------------------------------------------------------------
70+ INSERT INTO dbo .nrt_provider
71+ (provider_uid, first_name, last_name, street_address_1, city, state_code, zip, county_code, county, country_code, phone_work_phone, phone_ext_work_phone, provider_npi)
72+ VALUES
73+ (@provider_uid, ' Jane' , ' Doe' , ' 555 Provider Ave' , ' Atlanta' , ' 13' , ' 30308' , ' 063' , ' Fulton' , ' US' , ' 4045550500' , ' ' , ' 1234567890' );
74+
75+ -- ------------------------------------------------------------
76+ -- Observation material (specimen)
77+ -- ------------------------------------------------------------
78+ INSERT INTO dbo .nrt_observation_material (act_uid, material_id, material_cd, material_desc, material_details)
79+ VALUES (@obs_uid_order, @material_id, ' NP' , ' Nasopharyngeal Swab' , ' Combined Naso/Oropharyngeal Swab' );
80+
81+ -- ------------------------------------------------------------
82+ -- Investigation
83+ -- ------------------------------------------------------------
84+ INSERT INTO dbo .nrt_investigation (public_health_case_uid, local_id)
85+ VALUES (@phc_uid, ' CAS-TEST-' + CAST (@phc_uid AS VARCHAR ));
86+
87+ -- ------------------------------------------------------------
88+ -- Observations (order and result)
89+ -- ------------------------------------------------------------
90+ INSERT INTO dbo .nrt_observation
91+ (observation_uid, local_id, record_status_cd, cd, cd_desc_txt, cd_system_cd,
92+ electronic_ind, version_ctrl_nbr, prog_area_cd, jurisdiction_cd,
93+ activity_to_time, rpt_to_state_time, activity_from_time, effective_from_time,
94+ target_site_cd, target_site_desc_txt, status_cd,
95+ accession_number, add_time, last_chg_time,
96+ result_observation_uid, obs_domain_cd_st_1,
97+ material_id, patient_id,
98+ performing_organization_id, author_organization_id, ordering_organization_id,
99+ ordering_person_id, associated_phc_uids, batch_id,
100+ method_cd, method_desc_txt, device_instance_id_1, device_instance_id_2,
101+ interpretation_cd, interpretation_desc_txt)
102+ VALUES
103+ -- ORDER row
104+ (@obs_uid_order, ' LAB-TEST-' + CAST (@obs_uid_order AS VARCHAR ), ' ACTIVE' , ' 94500-6' , ' SARS-CoV-2 RNA panel' , ' LN' ,
105+ ' Y' , 1 , ' STD' , ' 130001' ,
106+ ' 2021-01-10 12:00:00' , ' 2021-01-10 14:00:00' , ' 2021-01-09 09:00:00' , ' 2021-01-09 09:00:00' ,
107+ ' NP' , ' Nasopharynx' , ' D' ,
108+ ' ACC-2021-001' , ' 2021-01-10 08:00:00' , ' 2021-01-10 15:00:00' ,
109+ CAST (@obs_uid_result AS NVARCHAR (MAX )), ' Order' ,
110+ @material_id, @patient_uid,
111+ @org_uid_perform, @org_uid_author, @org_uid_order,
112+ CAST (@provider_uid AS NVARCHAR (MAX )), CAST (@phc_uid AS NVARCHAR (MAX )), 1 ,
113+ NULL , NULL , NULL , NULL , NULL , NULL ),
114+
115+ -- RESULT row
116+ (@obs_uid_result, ' LAB-TEST-' + CAST (@obs_uid_result AS VARCHAR ), ' ACTIVE' , ' 94309-2' , ' SARS-CoV-2 RNA Ql NAA+probe' , ' LN' ,
117+ ' Y' , 1 , ' STD' , ' GA' ,
118+ ' 2021-01-10 12:00:00' , NULL , NULL , NULL ,
119+ NULL , NULL , ' D' ,
120+ NULL , ' 2021-01-10 08:00:00' , ' 2021-01-10 15:00:00' ,
121+ NULL , ' Result' ,
122+ NULL , @patient_uid,
123+ @org_uid_perform, @org_uid_author, @org_uid_order,
124+ CAST (@provider_uid AS NVARCHAR (MAX )), CAST (@phc_uid AS NVARCHAR (MAX )), 1 ,
125+ ' EUA001' , ' RT-PCR' , ' DEVICE-SERIAL-001' , NULL ,
126+ ' POS' , ' Positive' );
127+
128+ -- ------------------------------------------------------------
129+ -- Observation results
130+ -- ------------------------------------------------------------
131+
132+ -- Coded result — "Detected"
133+ INSERT INTO dbo .nrt_observation_coded (observation_uid, ovc_code, ovc_code_system_cd, ovc_display_name)
134+ VALUES (@obs_uid_result, ' 260373001' , ' SCT' , ' Detected' );
135+
136+ -- Text result (type 'O') and comment (type 'N')
137+ INSERT INTO dbo .nrt_observation_txt (observation_uid, ovt_seq, ovt_txt_type_cd, ovt_value_txt)
138+ VALUES
139+ (@obs_uid_result, 1 , ' O' , ' SARS-CoV-2 RNA Detected' ),
140+ (@obs_uid_result, 2 , ' N' , ' Specimen received in good condition.' );
141+
142+ -- ------------------------------------------------------------
143+ -- Execute the stored procedure
144+ -- ------------------------------------------------------------
145+ DECLARE @obs_id_list NVARCHAR (MAX ) = CAST (@obs_uid_order AS NVARCHAR (MAX ));
146+
147+ EXEC dbo .sp_covid_lab_datamart_postprocessing
148+ @observation_id_list = @obs_id_list,
149+ @debug = ' false' ;
0 commit comments