Skip to content

Commit

Permalink
Merge pull request #465 from njorocs/appointment-dates
Browse files Browse the repository at this point in the history
Added patient appointment table etl for dwapi
  • Loading branch information
patryllus authored Jul 4, 2024
2 parents d53964b + 3e82d16 commit 63c848e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
20 changes: 20 additions & 0 deletions omod/src/main/resources/sql/dwapi/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ DROP TABLE IF EXISTS dwapi_etl.etl_preventive_services;
DROP TABLE IF EXISTS dwapi_etl.etl_overdose_reporting;
DROP TABLE IF EXISTS dwapi_etl.etl_art_fast_track;
DROP TABLE IF EXISTS dwapi_etl.etl_clinical_encounter;
DROP TABLE IF EXISTS dwapi_etl.etl_patient_appointment;

-- create table etl_patient_demographics
create table dwapi_etl.etl_patient_demographics (
Expand Down Expand Up @@ -3587,6 +3588,25 @@ CREATE TABLE dwapi_etl.etl_clinical_encounter (
);
SELECT "Successfully created etl_clinical_encounter table";

-- Create table dwapi_etl.etl_patient_appointment
CREATE TABLE dwapi_etl.etl_patient_appointment(
patient_appointment_id int NOT NULL PRIMARY KEY ,
provider_id int DEFAULT NULL,
patient_id int NOT NULL,
visit_date date NOT NULL,
start_date_time datetime DEFAULT NULL,
end_date_time datetime DEFAULT NULL,
appointment_service_id int DEFAULT NULL,
appointment_service_type_id int DEFAULT NULL,
status varchar(45) NOT NULL,
location_id int DEFAULT NULL,
date_created datetime NOT NULL,
INDEX(patient_id),
INDEX (location_id),
INDEX (visit_date),
INDEX (appointment_service_id)
);
SELECT "Successfully created dwapi_etl.etl_patient_appointment table";
UPDATE kenyaemr_etl.etl_script_status SET stop_time=NOW() where id= script_id;

END $$
77 changes: 77 additions & 0 deletions omod/src/main/resources/sql/dwapi/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7407,6 +7407,81 @@ BEGIN
SELECT "Completed processing overdose reporting";
END $$

-- Procedure sp_populate_dwapi_patient_appointment --
DROP PROCEDURE IF EXISTS sp_populate_dwapi_patient_appointment $$

CREATE PROCEDURE sp_populate_dwapi_patient_appointment()
BEGIN
SELECT "Processing Patient appointment";
INSERT INTO dwapi_etl.etl_patient_appointment(patient_appointment_id,
provider_id,
patient_id,
visit_date,
start_date_time,
end_date_time,
appointment_service_id,
status,
location_id,
date_created)
SELECT
patient_appointment_id,
provider_id,
patient_id,
DATE(date_appointment_scheduled) as visit_date,
start_date_time,
end_date_time,
appointment_service_id,
status,
location_id,
date_created
FROM patient_appointment;
SELECT "Completed processing Patient appointement";
END $$

-- Procedure sp_update_dwapi_next_appointment_date with appointment date from bahmni --
DROP PROCEDURE IF EXISTS sp_update_dwapi_next_appointment_date $$
CREATE PROCEDURE sp_update_dwapi_next_appointment_date()
BEGIN
SELECT "Processing Update next appointment date with appointment date from Bahmni";
update dwapi_etl.etl_patient_hiv_followup fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 1
set fup.next_appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_patient_hiv_followup fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 2
set fup.refill_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_prep_followup fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 8
set fup.appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_prep_monthly_refill fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 9
set fup.next_appointment = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_tb_follow_up_visit fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 6
set fup.next_appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_clinical_visit fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.client_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 3
set fup.appointment_date = date(pat.start_date_time) where fup.client_id > 0;

update dwapi_etl.etl_mch_antenatal_visit fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 4
set fup.next_appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_mch_postnatal_visit fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 5
set fup.appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

update dwapi_etl.etl_hei_follow_up_visit fup
inner join dwapi_etl.etl_patient_appointment pat on pat.patient_id = fup.patient_id and pat.visit_date = fup.visit_date and pat.appointment_service_id = 13
set fup.next_appointment_date = date(pat.start_date_time) where fup.patient_id > 0;

SELECT "Completed updating next appointment date";
END $$

-- Procedure sp_populate_dwapi_art_fast_track --
DROP PROCEDURE IF EXISTS sp_populate_dwapi_art_fast_track $$
CREATE PROCEDURE sp_populate_dwapi_art_fast_track()
Expand Down Expand Up @@ -7672,6 +7747,7 @@ CALL sp_populate_dwapi_hei_enrolment();
CALL sp_populate_dwapi_hei_immunization();
CALL sp_populate_dwapi_hei_follow_up();
CALL sp_populate_dwapi_mch_delivery();
CALL sp_populate_dwapi_patient_appointment();
CALL sp_populate_dwapi_mch_discharge();
CALL sp_populate_dwapi_drug_event();
CALL sp_populate_dwapi_hts_test();
Expand Down Expand Up @@ -7730,6 +7806,7 @@ CALL sp_populate_dwapi_overdose_reporting();
CALL sp_populate_dwapi_hts_patient_contact();
CALL sp_populate_dwapi_art_fast_track();
CALL sp_populate_dwapi_clinical_encounter();
CALL sp_update_dwapi_next_appointment_date();

UPDATE kenyaemr_etl.etl_script_status SET stop_time=NOW() where id= populate_script_id;

Expand Down

0 comments on commit 63c848e

Please sign in to comment.