Skip to content

Commit 23591f6

Browse files
committed
add happy path unit test for case_lab_datamart sp
1 parent 11f2580 commit 23591f6

3 files changed

Lines changed: 378 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"0": [
3+
{
4+
"Observation_UID": 90006001,
5+
"Lab_Local_ID": "LAB-TEST-90006001",
6+
"Ordered_Test_Cd": "94500-6",
7+
"Ordered_Test_Desc": "SARS-CoV-2 RNA panel",
8+
"Ordered_Test_Code_System": "LN",
9+
"Electronic_Ind": "Y",
10+
"Program_Area_Cd": "STD",
11+
"Jurisdiction_Cd": "130001",
12+
"Jurisdiction_Nm": "Fulton County",
13+
"Specimen_Cd": "NP",
14+
"Specimen_Desc": "Nasopharyngeal Swab",
15+
"Specimen_type_free_text": "Combined Naso/Oropharyngeal Swab",
16+
"Specimen_Id": "ACC-2021-001",
17+
"Testing_Lab_Accession_Number": "ACC-2021-001",
18+
"SPECIMEN_SOURCE_SITE_CD": "NP",
19+
"SPECIMEN_SOURCE_SITE_DESC": "Nasopharynx",
20+
"Lab_Report_Dt": "2021-01-10 12:00:00",
21+
"Lab_Rpt_Received_By_PH_Dt": "2021-01-10 14:00:00",
22+
"ORDER_TEST_DATE": "2021-01-09 09:00:00",
23+
"Specimen_Coll_Dt": "2021-01-09 09:00:00",
24+
"Lab_Added_Dt": "2021-01-10 08:00:00",
25+
"Lab_Update_Dt": "2021-01-10 15:00:00",
26+
"Order_result_status": "Final",
27+
"Test_result_status": "Final",
28+
"COVID_LAB_DATAMART_KEY": 90006002,
29+
"Resulted_Test_Cd": "94309-2",
30+
"Resulted_Test_Desc": "SARS-CoV-2 RNA Ql NAA+probe",
31+
"Resulted_Test_Code_System": "LN",
32+
"DEVICE_INSTANCE_ID_1": "DEVICE-SERIAL-001",
33+
"DEVICE_INSTANCE_ID_2": null,
34+
"Device_Type_Id_1": "EUA001",
35+
"Device_Type_Id_2": null,
36+
"Test_Method_Desc": "RT-PCR",
37+
"Result_Cd": "260373001",
38+
"Result_Cd_Sys": "SCT",
39+
"Result_Desc": "Detected",
40+
"Text_Result_Desc": "SARS-CoV-2 RNA Detected",
41+
"Result_Comments": "Specimen received in good condition.",
42+
"Result": "Detected SARS-CoV-2 RNA Detected Specimen received in good condition.",
43+
"Result_Category": "Positive",
44+
"Numeric_Comparator_Cd": null,
45+
"Numeric_Value_1": null,
46+
"Numeric_Value_2": null,
47+
"Numeric_Unit_Cd": null,
48+
"Numeric_Low_Range": null,
49+
"Numeric_High_Range": null,
50+
"Numeric_Separator_Cd": null,
51+
"Interpretation_Cd": "POS",
52+
"Interpretation_Desc": "Positive",
53+
"Last_Name": "Smith",
54+
"Middle_Name": "A",
55+
"First_Name": "John",
56+
"Patient_Local_ID": "PSN-TEST-90001001",
57+
"Current_Sex_Cd": "M",
58+
"Age_Reported": "45",
59+
"Age_Unit_Cd": "a",
60+
"Birth_Dt": "1979-03-15 00:00:00",
61+
"Phone_Number": "4045550100",
62+
"Address_One": "123 Main St",
63+
"City": "Atlanta",
64+
"State_Cd": "13",
65+
"State": "GA",
66+
"Zip_Code": "30301",
67+
"County_Cd": "063",
68+
"County_Desc": "Fulton",
69+
"PATIENT_RACE_CALC": "White",
70+
"PATIENT_ETHNICITY": "N",
71+
"Perform_Facility_Name": "State Reference Lab",
72+
"Testing_lab_Address_One": "456 Lab Blvd",
73+
"Testing_lab_City": "Atlanta",
74+
"Testing_lab_State_Cd": "13",
75+
"Testing_lab_State": "GA",
76+
"Testing_lab_Zip_Cd": "30302",
77+
"Testing_lab_county": "063",
78+
"Testing_lab_county_Desc": "Fulton",
79+
"Testing_lab_Country": "US",
80+
"Reporting_Facility_Name": "Emory University Hospital",
81+
"Reporting_Facility_Address_One": "789 Clifton Rd",
82+
"Reporting_Facility_City": "Atlanta",
83+
"Reporting_Facility_State_Cd": "13",
84+
"Reporting_Facility_State": "GA",
85+
"Reporting_Facility_Zip_Cd": "30322",
86+
"Reporting_Facility_Clia": "10D0123456",
87+
"Reporting_Facility_Phone_Nbr": "4045550300",
88+
"Reporting_Facility_Phone_Ext": "",
89+
"Ordering_Facility_Name": "Peachtree Urgent Care",
90+
"Ordering_Facility_Address_One": "321 Peachtree St",
91+
"Ordering_Facility_City": "Atlanta",
92+
"Ordering_Facility_State_Cd": "13",
93+
"Ordering_Facility_State": "GA",
94+
"Ordering_Facility_Zip_Cd": "30303",
95+
"Ordering_Facility_Phone_Nbr": "4045550400",
96+
"Ordering_Facility_Phone_Ext": "",
97+
"Ordering_Provider_First_Name": "Jane",
98+
"Ordering_Provider_Last_Name": "Doe",
99+
"Ordering_Provider_Address_One": "555 Provider Ave",
100+
"Ordering_Provider_City": "Atlanta",
101+
"Ordering_Provider_State_Cd": "13",
102+
"Ordering_Provider_State": "GA",
103+
"Ordering_Provider_Zip_Cd": "30308",
104+
"Ordering_Provider_Phone_Nbr": "4045550500",
105+
"ORDERING_PROVIDER_ID": "1234567890",
106+
"Associated_Case_ID": "CAS-TEST-90005001"
107+
}
108+
]
109+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
SELECT
2+
-- Core lab identifiers
3+
Observation_UID,
4+
Lab_Local_ID,
5+
Ordered_Test_Cd,
6+
Ordered_Test_Desc,
7+
Ordered_Test_Code_System,
8+
Electronic_Ind,
9+
Program_Area_Cd,
10+
Jurisdiction_Cd,
11+
Jurisdiction_Nm,
12+
-- Specimen
13+
Specimen_Cd,
14+
Specimen_Desc,
15+
Specimen_type_free_text,
16+
Specimen_Id,
17+
Testing_Lab_Accession_Number,
18+
SPECIMEN_SOURCE_SITE_CD,
19+
SPECIMEN_SOURCE_SITE_DESC,
20+
-- Dates
21+
Lab_Report_Dt,
22+
Lab_Rpt_Received_By_PH_Dt,
23+
ORDER_TEST_DATE,
24+
Specimen_Coll_Dt,
25+
Lab_Added_Dt,
26+
Lab_Update_Dt,
27+
-- Status
28+
Order_result_status,
29+
Test_result_status,
30+
-- Result observation
31+
COVID_LAB_DATAMART_KEY,
32+
Resulted_Test_Cd,
33+
Resulted_Test_Desc,
34+
Resulted_Test_Code_System,
35+
DEVICE_INSTANCE_ID_1,
36+
DEVICE_INSTANCE_ID_2,
37+
Device_Type_Id_1,
38+
Device_Type_Id_2,
39+
Test_Method_Desc,
40+
-- Coded result
41+
Result_Cd,
42+
Result_Cd_Sys,
43+
Result_Desc,
44+
Text_Result_Desc,
45+
Result_Comments,
46+
Result,
47+
Result_Category,
48+
-- Numeric result
49+
Numeric_Comparator_Cd,
50+
Numeric_Value_1,
51+
Numeric_Value_2,
52+
Numeric_Unit_Cd,
53+
Numeric_Low_Range,
54+
Numeric_High_Range,
55+
Numeric_Separator_Cd,
56+
Interpretation_Cd,
57+
Interpretation_Desc,
58+
-- Patient
59+
Last_Name,
60+
Middle_Name,
61+
First_Name,
62+
Patient_Local_ID,
63+
Current_Sex_Cd,
64+
Age_Reported,
65+
Age_Unit_Cd,
66+
Birth_Dt,
67+
Phone_Number,
68+
Address_One,
69+
City,
70+
State_Cd,
71+
State,
72+
Zip_Code,
73+
County_Cd,
74+
County_Desc,
75+
PATIENT_RACE_CALC,
76+
PATIENT_ETHNICITY,
77+
-- Testing lab
78+
Perform_Facility_Name,
79+
Testing_lab_Address_One,
80+
Testing_lab_City,
81+
Testing_lab_State_Cd,
82+
Testing_lab_State,
83+
Testing_lab_Zip_Cd,
84+
Testing_lab_county,
85+
Testing_lab_county_Desc,
86+
Testing_lab_Country,
87+
-- Reporting facility
88+
Reporting_Facility_Name,
89+
Reporting_Facility_Address_One,
90+
Reporting_Facility_City,
91+
Reporting_Facility_State_Cd,
92+
Reporting_Facility_State,
93+
Reporting_Facility_Zip_Cd,
94+
Reporting_Facility_Clia,
95+
Reporting_Facility_Phone_Nbr,
96+
Reporting_Facility_Phone_Ext,
97+
-- Ordering facility
98+
Ordering_Facility_Name,
99+
Ordering_Facility_Address_One,
100+
Ordering_Facility_City,
101+
Ordering_Facility_State_Cd,
102+
Ordering_Facility_State,
103+
Ordering_Facility_Zip_Cd,
104+
Ordering_Facility_Phone_Nbr,
105+
Ordering_Facility_Phone_Ext,
106+
-- Ordering provider
107+
Ordering_Provider_First_Name,
108+
Ordering_Provider_Last_Name,
109+
Ordering_Provider_Address_One,
110+
Ordering_Provider_City,
111+
Ordering_Provider_State_Cd,
112+
Ordering_Provider_State,
113+
Ordering_Provider_Zip_Cd,
114+
Ordering_Provider_Phone_Nbr,
115+
ORDERING_PROVIDER_ID,
116+
-- Associated investigation
117+
Associated_Case_ID
118+
FROM dbo.COVID_LAB_DATAMART
119+
WHERE Observation_UID = 90006001
120+
ORDER BY Observation_UID;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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

Comments
 (0)