Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cnde 1844: Migrate Case Management SAS logic to RTR SQL #77

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,18 @@ databaseChangeLog:
changes:
- sqlFile:
path: 021-sp_nrt_case_count_postprocessing-001.sql
splitStatements: false
- changeSet:
id: 62
author: liquibase
changes:
- sqlFile:
path: 020-create_nrt_investigation_case_management-001.sql
splitStatements: false
- changeSet:
id: 63
author: liquibase
changes:
- sqlFile:
path: 021-create_nrt_case_management_key-001.sql
splitStatements: false
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ BEGIN
results.organization_participations,
results.investigation_confirmation_method,
results.investigation_case_answer,
results.investigation_case_management,
results.investigation_notifications,
results.notification_history,
results.case_count_info
Expand Down Expand Up @@ -279,6 +280,7 @@ BEGIN
nesteddata.organization_participations,
nesteddata.investigation_confirmation_method,
nesteddata.investigation_case_answer,
nesteddata.investigation_case_management,
nesteddata.investigation_notifications,
nesteddata.notification_history,
nesteddata.case_count_info
Expand Down Expand Up @@ -392,7 +394,7 @@ BEGIN
act_uid = phc.public_health_case_uid FOR json path,INCLUDE_NULL_VALUES
) AS act_ids
) AS act_ids,
-- get assocaited confirmation method
-- get associated confirmation method
(
SELECT
(
Expand Down Expand Up @@ -489,6 +491,82 @@ BEGIN
FOR json path,INCLUDE_NULL_VALUES
) AS investigation_case_answer
) AS investigation_case_answer,
-- get associated case management
(
SELECT
(
select cm.case_management_uid,
cm.public_health_case_uid,
phc.add_user_id,
phc.program_jurisdiction_oid as case_oid,
ooj_initg_agncy_outc_snt_date,
init_foll_up as init_fup_initial_foll_up_cd,
(select * from fn_get_value_by_cvg(init_foll_up, 'STD_CREATE_INV_LABMORB_NONSYPHILIS_PROC_DECISION')) as init_foll_up,
init_foll_up_closed_date as init_fup_closed_dt,
internet_foll_up as init_fup_internet_foll_up_cd,
(select * from fn_get_value_by_cvg(internet_foll_up, 'YN')) as internet_foll_up,
init_foll_up_notifiable as init_fup_notifiable_cd,
(select * from fn_get_value_by_cvg(init_foll_up_notifiable, 'NOTIFIABLE')) as init_foll_up_notifiable,
init_foll_up_clinic_code as init_fup_clinic_code,
surv_assigned_date as surv_investigator_assgn_dt,
surv_closed_date as surv_closed_dt,
surv_provider_contact as surv_provider_contact_cd,
(select * from fn_get_value_by_cvg(surv_provider_contact, 'PRVDR_CONTACT_OUTCOME')) as surv_provider_contact,
surv_prov_exm_reason,
(select * from fn_get_value_by_cvg(surv_prov_exm_reason, 'PRVDR_EXAM_REASON')) as surv_provider_exam_reason,
surv_prov_diagnosis as surv_provider_diagnosis,
surv_patient_foll_up,
(select * from fn_get_value_by_cvg(surv_patient_foll_up, 'SURVEILLANCE_PATIENT_FOLLOWUP')) as surv_patient_foll_up_cd,
status_900 as adi_900_status_cd,
(select * from fn_get_value_by_cvg(status_900, 'STATUS_900')) as status_900,
ehars_id as adi_ehars_id,
subj_height as adi_height,
subj_height as adi_height_legacy_case,
subj_size_build as adi_size_build,
subj_hair as adi_hair,
subj_complexion as adi_complexion,
subj_oth_idntfyng_info as adi_other_identifying_info,
field_record_number as fl_fup_field_record_num,
foll_up_assigned_date as fl_fup_investigator_assgn_dt,
init_foll_up_assigned_date as fl_fup_init_assgn_dt,
fld_foll_up_prov_exm_reason,
(select * from fn_get_value_by_cvg(fld_foll_up_prov_exm_reason, 'PRVDR_EXAM_REASON')) as fl_fup_prov_exm_reason,
fld_foll_up_prov_diagnosis,
LEFT(fld_foll_up_prov_diagnosis, 3) as fl_fup_prov_diagnosis,
fld_foll_up_notification_plan,
(select * from fn_get_value_by_cvg(fld_foll_up_notification_plan, 'NOTIFICATION_PLAN')) as fl_fup_notification_plan_cd,
fld_foll_up_expected_in,
(select * from fn_get_value_by_cvg(fld_foll_up_expected_in, 'YN')) as fl_fup_expected_in_ind,
fld_foll_up_expected_date as fl_fup_expected_dt,
fld_foll_up_exam_date as fl_fup_exam_dt,
fld_foll_up_dispo as fl_fup_disposition_cd,
(select * from fn_get_value_by_cvg(fld_foll_up_dispo, 'FIELD_FOLLOWUP_DISPOSITION_STDHIV')) as fl_fup_disposition_desc,
fld_foll_up_dispo_date as fl_fup_dispo_dt,
act_ref_type_cd,
(select * from fn_get_value_by_cvg(act_ref_type_cd, 'NOTIFICATION_ACTUAL_METHOD_STD')) as fl_fup_actual_ref_type,
case_review_status,
case_review_status_date,
fld_foll_up_internet_outcome as fl_fup_internet_outcome_cd,
(select * from fn_get_value_by_cvg(fld_foll_up_internet_outcome, 'INTERNET_FOLLOWUP_OUTCOME')) as fl_fup_internet_outcome,
(select * from fn_get_value_by_cvg(ooj_agency, 'OOJ_AGENCY_LOCAL')) as ooj_agency,
ooj_number,
ooj_due_date,
field_foll_up_ooj_outcome,
(select * from fn_get_value_by_cvg(field_foll_up_ooj_outcome, 'FIELD_FOLLOWUP_DISPOSITION_STDHIV')) as fl_fup_ooj_outcome,
interview_assigned_date as ca_interviewer_assign_dt,
init_interview_assigned_date as ca_init_intvwr_assgn_dt,
epi_link_id,
pat_intv_status_cd,
(select * from fn_get_value_by_cvg(pat_intv_status_cd, 'PAT_INTVW_STATUS')) as ca_patient_intv_status,
case_closed_date as cc_closed_dt,
(select * from fn_get_value_by_cvg(initiating_agncy, 'OOJ_AGENCY_LOCAL')) as initiating_agncy,
ooj_initg_agncy_recd_date,
ooj_initg_agncy_outc_due_date
from dbo.case_management cm
WHERE
cm.public_health_case_uid = phc.public_health_case_uid FOR json path,INCLUDE_NULL_VALUES
) AS investigation_case_management
) AS investigation_case_management,
-- investigation notification columns
(
SELECT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_investigation_case_management' and xtype = 'U')
CREATE TABLE dbo.nrt_investigation_case_management
(
public_health_case_uid bigint NULL,
case_management_uid bigint NULL,
act_ref_type_cd varchar(20) NULL,
adi_900_status_cd varchar(20) NULL,
adi_complexion varchar(20) NULL,
adi_ehars_id varchar(10) NULL,
adi_hair varchar(20) NULL,
adi_height varchar(20) NULL,
adi_height_legacy_case varchar(20) NULL,
adi_other_identifying_info varchar(2000) NULL,
adi_size_build varchar(20) NULL,
ca_init_intvwr_assgn_dt datetime NULL,
ca_interviewer_assign_dt datetime NULL,
ca_patient_intv_status varchar(29) NULL,
case_oid bigint NULL,
case_review_status varchar(20) NULL,
case_review_status_date datetime NULL,
cc_closed_dt datetime NULL,
epi_link_id varchar(20) NULL,
field_foll_up_ooj_outcome varchar(20) NULL,
fl_fup_actual_ref_type varchar(15) NULL,
fl_fup_dispo_dt datetime NULL,
fl_fup_disposition_cd varchar(20) NULL,
fl_fup_disposition_desc varchar(44) NULL,
fl_fup_exam_dt datetime NULL,
fl_fup_expected_dt datetime NULL,
fl_fup_expected_in_ind varchar(3) NULL,
fl_fup_field_record_num varchar(20) NULL,
fl_fup_init_assgn_dt datetime NULL,
fl_fup_internet_outcome varchar(41) NULL,
fl_fup_internet_outcome_cd varchar(10) NULL,
fl_fup_investigator_assgn_dt datetime NULL,
fl_fup_notification_plan_cd varchar(15) NULL,
fl_fup_ooj_outcome varchar(44) NULL,
fl_fup_prov_diagnosis varchar(3) NULL,
fl_fup_prov_exm_reason varchar(43) NULL,
fld_foll_up_expected_in varchar(20) NULL,
fld_foll_up_notification_plan varchar(20) NULL,
fld_foll_up_prov_diagnosis varchar(20) NULL,
fld_foll_up_prov_exm_reason varchar(20) NULL,
init_fup_clinic_code varchar(50) NULL,
init_fup_closed_dt datetime NULL,
init_fup_initial_foll_up varchar(22) NULL,
init_fup_initial_foll_up_cd varchar(20) NULL,
init_fup_internet_foll_up_cd varchar(20) NULL,
init_foll_up_notifiable varchar(36) NULL,
init_fup_notifiable_cd varchar(20) NULL,
initiating_agncy varchar(100) NULL,
internet_foll_up varchar(3) NULL,
ooj_agency varchar(100) NULL,
ooj_due_date datetime NULL,
ooj_initg_agncy_outc_due_date datetime NULL,
ooj_initg_agncy_outc_snt_date datetime NULL,
ooj_initg_agncy_recd_date datetime NULL,
ooj_number varchar(20) NULL,
pat_intv_status_cd varchar(20) NULL,
status_900 varchar(44) NULL,
surv_closed_dt datetime NULL,
surv_investigator_assgn_dt datetime NULL,
surv_patient_foll_up varchar(20) NULL,
surv_patient_foll_up_cd varchar(22) NULL,
surv_prov_exm_reason varchar(20) NULL,
surv_provider_contact varchar(27) NULL,
surv_provider_contact_cd varchar(20) NULL,
surv_provider_diagnosis varchar(20) NULL,
surv_provider_exam_reason varchar(43) NULL,
add_user_id bigint NULL,
refresh_datetime datetime2(7) GENERATED ALWAYS AS ROW START NOT NULL,
max_datetime datetime2(7) GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
PERIOD FOR SYSTEM_TIME (refresh_datetime, max_datetime)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DROP TABLE IF EXISTS dbo.nrt_case_management_key;

CREATE TABLE dbo.nrt_case_management_key (
d_case_management_key bigint IDENTITY(1,1) NOT NULL,
public_health_case_uid bigint NULL
);

declare @max bigint;
select @max=max(D_CASE_MANAGEMENT_KEY)+1 from dbo.D_CASE_MANAGEMENT;
select @max;
if @max IS NULL --check when max is returned as null
SET @max = 1
DBCC CHECKIDENT ('dbo.nrt_case_management_key', RESEED, @max);