diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index 0bcc44c9..40639aee 100644 --- a/omod/src/main/resources/sql/DDL.sql +++ b/omod/src/main/resources/sql/DDL.sql @@ -66,6 +66,7 @@ DROP TABLE IF EXISTS kenyaemr_etl.etl_hts_referral; DROP TABLE IF EXISTS kenyaemr_etl.etl_prep_behaviour_risk_assessment; DROP TABLE IF EXISTS kenyaemr_etl.etl_prep_monthly_refill; DROP TABLE IF EXISTS kenyaemr_etl.etl_prep_discontinuation; +DROP TABLE IF EXISTS kenyaemr_etl.etl_orthopaedic_clinic_visit; DROP TABLE IF EXISTS kenyaemr_etl.etl_prep_enrollment; DROP TABLE IF EXISTS kenyaemr_etl.etl_prep_followup; DROP TABLE IF EXISTS kenyaemr_etl.etl_progress_note; @@ -1793,6 +1794,62 @@ SELECT "Successfully created etl_ART_preparation table"; ); SELECT "Successfully created etl_prep_discontinuation table"; +------------------- create table etl_orthopaedic_clinic_visit ----------------------- + CREATE TABLE kenyaemr_etl.etl_orthopaedic_clinic_visit ( + uuid CHAR(38), + encounter_id INT(11) NOT NULL PRIMARY KEY, + patient_id INT(11) NOT NULL , + location_id INT(11) DEFAULT NULL, + visit_date DATE, + visit_id INT(11), + encounter_provider INT(11), + date_created DATETIME NOT NULL, + date_last_modified DATETIME, + visit_type INT(11), + referral_form INT(11), + facility_name VARCHAR(255), + service_area INT(11), + other_unit_name VARCHAR(255), + orthopaedic_number INT (11), + select_symptoms VARCHAR(255), + location VARCHAR(255), + otc_duration INT(11), + onset_otc VARCHAR(255), + hpi VARCHAR(255), + past_prescribed_drugs VARCHAR(255), + trauma_history INT(11), + surgical_history INT(11), + type_of_surgery VARCHAR(255), + surgical_date DATE, + surgery_indication VARCHAR(255), + underlying_condition INT(11), + specify_condition VARCHAR(255), + specify_condition_other VARCHAR(255), + family_history INT(11), + musculoskeletal_system_conditions VARCHAR(255), + musculoskeletal_system_conditions_other VARCHAR(255), + musculoskeletal_findings VARCHAR(255), + joint_assessed VARCHAR(255), + joint_movement INT(11), + angle_degrees INT(11), + clinician_findings_notes VARCHAR(255), + intervention_given VARCHAR(255), + intervention_given_other VARCHAR(255), + management_plan VARCHAR(255), + procedure_done VARCHAR(255), + patient_referral VARCHAR(255), + name_of_the_facility VARCHAR(255), + voided INT(11), + CONSTRAINT FOREIGN KEY (patient_id) REFERENCES kenyaemr_etl.etl_patient_demographics(patient_id), + CONSTRAINT unique_uuid UNIQUE(uuid), + INDEX(visit_date), + INDEX(encounter_id), + INDEX(patient_id, visit_date) + ); + + SELECT "Successfully created etl_orthopaedic_clinic_visit table"; + + -- ------------ create table etl_prep_enrollment----------------------- CREATE TABLE kenyaemr_etl.etl_prep_enrolment ( uuid char(38), diff --git a/omod/src/main/resources/sql/DML.sql b/omod/src/main/resources/sql/DML.sql index 3bede29c..1a88f31a 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -3842,6 +3842,216 @@ CREATE PROCEDURE sp_populate_etl_prep_discontinuation() SELECT "Completed processing PrEP discontinuation", CONCAT("Time: ", NOW()); END $$ +-- ------------- populate etl_orthopaedic_clinic_visit------------------------- + +DROP PROCEDURE IF EXISTS sp_populate_etl_orthopaedic_clinic_visit $$ +CREATE PROCEDURE sp_populate_etl_orthopaedic_clinic_visit() + BEGIN + SELECT "Processing Orthopaedic Clinic Visit form", CONCAT("Time: ", NOW()); + insert into kenyaemr_etl.etl_orthopaedic_clinic_visit( + uuid, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + encounter_provider, + date_created, + visit_type, + referral_form, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, + trauma_history, + surgical_history, + type_of_surgery, + surgical_date, + surgery_indication, + underlying_condition, + specify_condition, + specify_condition_other, + family_history, + musculoskeletal_system_conditions, + musculoskeletal_system_conditions_other, + musculoskeletal_findings, + joint_assessed, + joint_movement, + angle_degrees, + clinician_findings_notes, + intervention_given, + intervention_given_other, + management_plan, + procedure_done, + procedure_done_other, + patient_referral, + name_of_the_facility, + date_last_modified, + voided + ) + select + e.uuid, + e.patient_id, + e.visit_id, + date(e.encounter_datetime) as visit_date, + e.location_id, + e.encounter_id as encounter_id, + e.creator, + e.date_created as date_created, + max(if(o.concept_id=164181,trim(o.value_coded),null)) as visit_type, + max(if(o.concept_id=161643,trim(o.value_coded),null)) as referral_form, + max(if(o.concept_id=162724,o.value_text,null)) as facility_name, + max(if(o.concept_id=168146,o.value_coded,null)) as service_area, + max(if(o.concept_id=166635,o.value_text,null)) as other_unit_name, + max(if(o.concept_id=159893,o.value_numeric,null)) as orthopaedic_number, + concat_ws(',', max(if(o.concept_id = 5219 and o.value_coded = 114403, 'Pain', null)), + max(if(o.concept_id = 5219 and o.value_coded = 130842, 'Immobility', null)), + max(if(o.concept_id = 5219 and o.value_coded = 140468, 'Muscle tenseness', null)), + max(if(o.concept_id = 5219 and o.value_coded = 119775, 'Muscle spasms', null)), + max(if(o.concept_id = 5219 and o.value_coded = 163894, 'Swelling', null)), + max(if(o.concept_id = 5219 and o.value_coded = 111525, 'Loss of function', null)), + max(if(o.concept_id = 5219 and o.value_coded = 116554, 'Joint stiffness', null)), + max(if(o.concept_id = 5219 and o.value_coded = 5622, 'Other', null))) as select_symptoms, + max(if(o.concept_id=167992,o.value_text,null)) as location, + max(if(o.concept_id=1731,o.value_numeric,null)) as otc_duration, + max(if(o.concept_id=162642,o.value_coded,null)) as onset_otc, + max(if(o.concept_id=160430,o.value_text,null)) as hpi, + concat_ws(',', max(if(o.concept_id = 1628 and o.value_text = 162725, 'Drug Name', null)), + max(if(o.concept_id = 1628 and o.value_numeric = 1731, 'Duration', null)), + max(if(o.concept_id = 1628 and o.value_numeric = 1443, 'Dosage', null))) as past_prescribed_drugs, + max(if(o.concept_id=159520,o.value_coded,null)) as trauma_history, + max(if(o.concept_id=168148,o.value_coded,null)) as surgical_history, + max(if(o.concept_id=166635,o.value_text,null)) as type_of_surgery, + max(if(o.concept_id=160715,o.value_datetime,null)) as surgical_date, + max(if(o.concept_id=163393,o.value_text,null)) as surgery_indication, + max(if(o.concept_id=165034,o.value_coded,null)) as underlying_condition, + CONCAT_WS(',',max(if(o.concept_id = 162747 and o.value_coded = 114698, 'Osteoarthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127417, 'Rheumatoid arthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127706, 'Diabetes',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 115115, 'Obesity',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 117762, 'Gout',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 153690, 'Lupus',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 5622, 'Others',NULL))) as specify_condition, + max(if(o.concept_id=166635,o.value_text,null)) as specify_condition_other, + max(if(o.concept_id=1081,o.value_coded,null)) as family_history, + CONCAT_WS(',',max(if(o.concept_id = 1128 and o.value_coded = 114698, 'Arthritis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 117585, 'Genetic disorders',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114931, 'Fractures',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + CONCAT_WS(',',max(if(o.concept_id = 164936 and o.value_coded = 5313, 'Local Tenderness',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 80, 'Hot and Red joint',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 130917, 'Muscle Atrophy',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152183, 'Flexion Attitude(knee/neck/spine/ankle)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Homans sign positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 155871, 'Deformity(S-shaped)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 131113, 'Thickening of the bone',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152228, 'Local swelling',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114362, 'Pseudo-paralysis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 126385, 'Adduction is restricted(Shoulder/hip/fingers)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 142671, 'Abduction is restricted',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 163894, 'Dugas test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Sulcus test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 136421, 'Crepitus',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114431, 'Dimple Sign',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 139740, 'Triangle disruption',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 122904, 'Supination and pronation of the forarm',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Anterior/posterior angulation',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Garden spade deformity',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 116472, 'Kyphosis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_findings, + concat_ws(',', max(if(o.concept_id = 165285 and o.value_coded = 166161, 'Ankle', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166204, 'Cervical spine', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166231, 'Elbow', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166241, 'Forearm', null)), + max(if(o.concept_id = 165285 and o.value_coded = 164387, 'Foot', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166245, 'Hip', null)), + max(if(o.concept_id = 165285 and o.value_coded = 112764, 'Sacroiliac', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166306, 'Shoulder', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166293, 'Thumb', null))) as joint_assessed, + concat_ws(',', max(if(o.concept_id = 165139 and o.value_coded = 125286, 'Abduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 125284, 'Adduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 154488, 'Dorsiflexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 142492, 'Deviation', null)), + max(if(o.concept_id = 165139 and o.value_coded = 125974, 'Elevation', null)), + max(if(o.concept_id = 165139 and o.value_coded = 145939, 'Eversion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 124199, 'Extension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 127691, 'Hyperextension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 166344, 'Lateral bending', null)), + max(if(o.concept_id = 165139 and o.value_coded = 152183, 'Flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 159279, 'Inversion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 124179, 'Plantar flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 166746, 'Rotation in abduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 140714, 'Rotation in extension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 161572, 'Rotation in neutral position', null)), + max(if(o.concept_id = 165139 and o.value_coded = 152183, 'Rotation in flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 157783, 'Rotation', null))) as joint_movement, + + max(if(o.concept_id=159368,o.value_numeric,null)) as angle_degrees, + max(if(o.concept_id=164939,o.value_text,null)) as clinician_findings_notes, + CONCAT_WS(',',max(if(o.concept_id = 165531 and o.value_coded = 167004, 'Assessing',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001239, 'Counselling Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 162308, 'Measurement taking',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 119758, 'Fabrication',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 159630, 'Fitting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001627, 'Casting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 1000474, 'PWD assessment & Categorization',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 160068, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 5622, 'Others',NULL))) as intervention_given, + max(if(o.concept_id=166635,o.value_text,null)) as intervention_given_other, + max(if(o.concept_id=163104,o.value_text,null)) as management_plan, + CONCAT_WS(',',max(if(o.concept_id = 120198 and o.value_coded = 1107, 'None',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1000133, 'Cryotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Transverse friction massage',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Compression bandaging',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 527, 'Splinting',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 165390, 'Pulsed electromagnetic field therapy(PEMF)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5981, 'Thermotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Limb Elevation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166403, 'Plaster of Paris(POP) application',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 108, 'Isometric exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'ROM exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Joint Aspiration',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5108, 'Gait Training',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1933, 'TENS,SWD',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166939, 'Corrective osteotomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 136117, 'Rigid plate and screw fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166737, 'Arm Sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 123498, 'External fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, + max(if(o.concept_id=1788,o.value_text,null)) as patient_referral, + max(if(o.concept_id=162724,o.value_text,null)) as name_of_the_facility, + if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified, + e.voided as voided + from encounter e + inner join person p on p.person_id=e.patient_id and p.voided=0 + inner join + ( + select form_id, uuid,name from form where + uuid in('beec83df-6606-4019-8223-05a54a52f2b0') + ) f on f.form_id=e.form_id + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,162724,168146,166635,159893,5219,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,1081,1128,166635,164936,165285,165139, + 159368,164939,165531,166635,163104,120198,1788,162724) and o.voided=0 + where e.voided=0 + group by e.encounter_id; + SELECT "Completed processing Orthopaedic Clinic Visit", CONCAT("Time: ", NOW()); + END $$ -- ------------- populate etl_prep_enrollment------------------------- DROP PROCEDURE IF EXISTS sp_populate_etl_prep_enrolment $$ @@ -9065,6 +9275,7 @@ CALL sp_populate_etl_prep_behaviour_risk_assessment(); CALL sp_populate_etl_prep_monthly_refill(); CALL sp_populate_etl_progress_note(); CALL sp_populate_etl_prep_discontinuation(); +CALL sp_populate_etl_orthopaedic_clinic_visit(); CALL sp_populate_etl_hts_linkage_tracing(); CALL sp_populate_etl_patient_program(); CALL sp_create_default_facility_table(); diff --git a/omod/src/main/resources/sql/DataTools.sql b/omod/src/main/resources/sql/DataTools.sql index 35a14946..a16f16c3 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -1254,6 +1254,56 @@ SELECT "Successfully created enhanced adherence table"; SELECT "Successfully created generalized anxiety disorder table"; + -- create table datatools_orthopaedic_clinic_visit + create table kenyaemr_datatools.orthopaedic_clinic_visit as + select + uuid, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + encounter_provider, + date_created, + (case o.value_coded when 164180 then "New visit" when 160530 then "Re-visit" when 160551 then "Referral" else "" end) as visit_type, + (case o.value_coded when 160542 then "Community unit(CU)" when 164407 then "Other health facility" when 163266 then "This health facility" else "" end) as referral_form, + facility_name, + (case o.value_coded when 160542 then "CBR(Community-based rehabilitation)" when 159937 then "MCH" when 159927 then "Outreach/Mobile Clinic" when 164103 then "Diabetic clinic" when 167396 then "NBU(newborn unit)" when 5622 then "Others" else "" end) as service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + location, + otc_duration, + (case o.value_coded when 1839 then "Sudden" when 1499 then "Gradual" else "" end) as onset_otc, + hpi, + past_prescribed_drugs, + (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as trauma_history, + (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as surgical_history, + type_of_surgery, + surgical_date, + surgery_indication, + specify_condition, + specify_condition_other, + musculoskeletal_system_conditions, + musculoskeletal_system_conditions_other, + musculoskeletal_findings, + joint_assessed, + joint_movement, + angle_degrees, + clinician_findings_notes, + intervention_given, + intervention_given_other, + management_plan, + procedure_done, + (case o.value_coded when 163266 then "This Facility" when 164407 then "Other Facility" when 1000478 then "Community Unit" else "" end) as patient_referral, + name_of_the_facility, + voided + from kenyaemr_etl.etl_orthopaedic_clinic_visit; + + ALTER TABLE kenyaemr_datatools.orthopaedic_clinic_visit ADD FOREIGN KEY (patient_id) REFERENCES kenyaemr_datatools.patient_demographics(patient_id); + ALTER TABLE kenyaemr_datatools.orthopaedic_clinic_visit ADD INDEX(visit_date); + SELECT "Successfully created orthopaedic clinic visit table"; + -- create table datatools_patient_contact create table kenyaemr_datatools.patient_contact as select diff --git a/omod/src/main/resources/sql/Scheduled_Updates.sql b/omod/src/main/resources/sql/Scheduled_Updates.sql index a4c4c1f8..6d55990d 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -3856,6 +3856,223 @@ CREATE PROCEDURE sp_update_etl_prep_discontinuation(IN last_update_time DATETIME voided=VALUES(voided); END $$ +-- ------------- populate etl_orthopaedic_clinic_visit------------------------- + +DROP PROCEDURE IF EXISTS sp_update_etl_orthopaedic_clinic_visit $$ +CREATE PROCEDURE sp_update_etl_orthopaedic_clinic_visit(IN last_update_time DATETIME) + BEGIN + SELECT "Processing Orthopaedic clinic visit", CONCAT("Time: ", NOW()); + insert into kenyaemr_etl.etl_orthopaedic_clinic_visit( + uuid, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + encounter_provider, + date_created, + visit_type, + referral_form, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, + trauma_history, + surgical_history, + type_of_surgery, + surgical_date, + surgery_indication, + underlying_condition, + specify_condition, + specify_condition_other, + family_history, + musculoskeletal_system_conditions, + musculoskeletal_system_conditions_other, + musculoskeletal_findings, + joint_assessed, + joint_movement, + angle_degrees, + clinician_findings_notes, + intervention_given, + intervention_given_other, + management_plan, + procedure_done, + patient_referral, + name_of_the_facility, + date_last_modified, + voided + ) + select + e.uuid, + e.patient_id, + e.visit_id, + date(e.encounter_datetime) as visit_date, + e.location_id, + e.encounter_id as encounter_id, + e.creator, + e.date_created as date_created, + if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified, + max(if(o.concept_id=164181,trim(o.value_coded),null)) as visit_type, + max(if(o.concept_id=161643,trim(o.value_coded),null)) as referral_form, + max(if(o.concept_id=162724,o.value_text,null)) as facility_name, + max(if(o.concept_id=168146,o.value_coded,null)) as service_area, + max(if(o.concept_id=166635,o.value_text,null)) as other_unit_name, + max(if(o.concept_id=159893,o.value_numeric,null)) as orthopaedic_number, + max(if(o.concept_id=5219,o.value_coded,null)) as select_symptoms, + max(if(o.concept_id=167992,o.value_text,null)) as location, + max(if(o.concept_id=1731,o.value_numeric,null)) as otc_duration, + max(if(o.concept_id=162642,o.value_coded,null)) as onset_otc, + max(if(o.concept_id=160430,o.value_text,null)) as hpi, + max(if(o.concept_id=1628,o.value_coded,null)) as past_prescribed_drugs, + max(if(o.concept_id=159520,o.value_coded,null)) as trauma_history, + max(if(o.concept_id=168148,o.value_coded,null)) as surgical_history, + max(if(o.concept_id=166635,o.value_text,null)) as type_of_surgery, + max(if(o.concept_id=160715,o.value_datetime,null)) as surgical_date, + max(if(o.concept_id=163393,o.value_text,null)) as surgery_indication, + max(if(o.concept_id=165034,o.value_coded,null)) as underlying_condition, + CONCAT_WS(',',max(if(o.concept_id = 162747 and o.value_coded = 114698, 'Osteoarthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127417, 'Rheumatoid arthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127706, 'Diabetes',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 115115, 'Obesity',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 117762, 'Gout',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 153690, 'Lupus',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 5622, 'Others',NULL))) as specify_condition, + max(if(o.concept_id=166635,o.value_text,null)) as specify_condition_other, + max(if(o.concept_id=1081,o.value_coded,null)) as family_history, + CONCAT_WS(',',max(if(o.concept_id = 1128 and o.value_coded = 114698, 'Arthritis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 117585, 'Genetic disorders',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114931, 'Fractures',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + CONCAT_WS(',',max(if(o.concept_id = 164936 and o.value_coded = 5313, 'Local Tenderness',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 80, 'Hot and Red joint',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 130917, 'Muscle Atrophy',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152183, 'Flexion Attitude(knee/neck/spine/ankle)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Homans sign positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 155871, 'Deformity(S-shaped)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 131113, 'Thickening of the bone',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152228, 'Local swelling',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114362, 'Pseudo-paralysis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 126385, 'Adduction is restricted(Shoulder/hip/fingers)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 142671, 'Abduction is restricted',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 163894, 'Dugas test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Sulcus test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 136421, 'Crepitus',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114431, 'Dimple Sign',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 139740, 'Triangle disruption',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 122904, 'Supination and pronation of the forarm',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Anterior/posterior angulation',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Garden spade deformity',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 116472, 'Kyphosis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_findings, + max(if(o.concept_id=165285,o.value_coded,null)) as joint_assessed, + max(if(o.concept_id=165139,o.value_coded,null)) as joint_movement, + max(if(o.concept_id=159368,o.value_numeric,null)) as angle_degrees, + max(if(o.concept_id=164939,o.value_text,null)) as clinician_findings_notes, + CONCAT_WS(',',max(if(o.concept_id = 165531 and o.value_coded = 167004, 'Assessing',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001239, 'Counselling Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 162308, 'Measurement taking',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 119758, 'Fabrication',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 159630, 'Fitting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001627, 'Casting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 1000474, 'PWD assessment & Categorization',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 160068, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 5622, 'Others',NULL))) as intervention_given, + max(if(o.concept_id=166635,o.value_text,null)) as intervention_given_other, + max(if(o.concept_id=163104,o.value_text,null)) as management_plan, + CONCAT_WS(',',max(if(o.concept_id = 120198 and o.value_coded = 1107, 'None',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1000133, 'Cryotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Transverse friction massage',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Compression bandaging',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 527, 'Splinting',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 165390, 'Pulsed electromagnetic field therapy(PEMF)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5981, 'Thermotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Limb Elevation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166403, 'Plaster of Paris(POP) application',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 108, 'Isometric exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'ROM exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Joint Aspiration',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5108, 'Gait Training',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1933, 'TENS,SWD',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166939, 'Corrective osteotomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 136117, 'Rigid plate and screw fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166737, 'Arm Sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 123498, 'External fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, + max(if(o.concept_id=1788,o.value_text,null)) as patient_referral, + max(if(o.concept_id=162724,o.value_text,null)) as name_of_the_facility, + e.voided as voided + from encounter e + inner join person p on p.person_id=e.patient_id and p.voided=0 + inner join + ( + select form_id, uuid,name from form where + uuid in('beec83df-6606-4019-8223-05a54a52f2b0') + ) f on f.form_id=e.form_id + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,162724,168146,166635,159893,5219,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,1128,166635,164936,165285,165139, + 159368,164939,165531,166635,163104,120198,1788,162724) and o.voided=0 + where e.voided=0 and e.date_created >= last_update_time + or e.date_changed >= last_update_time + or e.date_voided >= last_update_time + or o.date_created >= last_update_time + or o.date_voided >= last_update_time + group by e.encounter_id + ON DUPLICATE KEY UPDATE + visit_date=VALUES(visit_date), + encounter_provider=VALUES(encounter_provider), + visit_type=VALUES(visit_type), + referral_form=VALUES(referral_form), + other_facility_name=VALUES(other_facility_name), + facility_name=VALUES(facility_name), + service_area=VALUES(service_area), + other_unit_name=VALUES(other_unit_name), + orthopaedic_number=VALUES(orthopaedic_number), + select_symptoms=VALUES(select_symptoms), + symptoms_for_otc_other=VALUES(symptoms_for_otc_other),location=VALUES(location), + otc_duration=VALUES(otc_duration),onset_otc=VALUES(onset_otc),hpi=VALUES(hpi), + past_prescribed_drugs=VALUES(past_prescribed_drugs), +-- previous_physiotherapy=VALUES(previous_physiotherapy), + trauma_history=VALUES(trauma_history),surgical_history=VALUES(surgical_history),type_of_surgery=VALUES(type_of_surgery), + surgical_date=VALUES(surgical_date),surgery_indication=VALUES(surgery_indication), + underlying_condition=VALUES(underlying_condition), + specify_condition=VALUES(specify_condition), + specify_condition_other=VALUES(specify_condition_other), + family_history=VALUES(family_history), + musculoskeletal_system_conditions=VALUES(musculoskeletal_system_conditions), + musculoskeletal_system_conditions_other=VALUES(musculoskeletal_system_conditions_other), + musculoskeletal_examination_findings=VALUES(musculoskeletal_examination_findings), + musculoskeletal_findings=VALUES(musculoskeletal_findings), + musculoskeletal_findings_other=VALUES(musculoskeletal_findings_other), + joint_assessed=VALUES(joint_assessed), + joint_movement=VALUES(joint_movement), + angle_degrees=VALUES(angle_degrees), + clinician_findings_notes=VALUES(clinician_findings_notes), + intervention_given=VALUES(intervention_given), + intervention_given_other=VALUES(intervention_given_other), + management_plan=VALUES(management_plan), + procedure_done=VALUES(procedure_done), + procedure_done_other=VALUES(procedure_done_other), + patient_referral=VALUES(patient_referral), + name_of_the_facility=VALUES(name_of_the_facility), + date_last_modified=VALUES(date_last_modified), + voided=VALUES(voided); + END $$ -- ------------- populate etl_prep_enrollment------------------------- DROP PROCEDURE IF EXISTS sp_update_etl_prep_enrolment $$ @@ -10241,6 +10458,7 @@ CREATE PROCEDURE sp_scheduled_updates() CALL sp_update_etl_prep_followup(last_update_time); CALL sp_update_etl_progress_note(last_update_time); CALL sp_update_etl_prep_discontinuation(last_update_time); + CALL sp_update_etl_orthopaedic_clinic_visit(last_update_time); CALL sp_update_etl_hts_linkage_tracing(last_update_time); CALL sp_update_etl_patient_program(last_update_time); CALL sp_update_etl_person_address(last_update_time); diff --git a/omod/src/main/resources/sql/dwapi/DDL.sql b/omod/src/main/resources/sql/dwapi/DDL.sql index 14b61326..49c01a1d 100644 --- a/omod/src/main/resources/sql/dwapi/DDL.sql +++ b/omod/src/main/resources/sql/dwapi/DDL.sql @@ -53,6 +53,7 @@ DROP TABLE IF EXISTS dwapi_etl.etl_hts_referral; DROP TABLE IF EXISTS dwapi_etl.etl_prep_behaviour_risk_assessment; DROP TABLE IF EXISTS dwapi_etl.etl_prep_monthly_refill; DROP TABLE IF EXISTS dwapi_etl.etl_prep_discontinuation; +DROP TABLE IF EXISTS dwapi_etl.etl_orthopaedic_clinic_visit; DROP TABLE IF EXISTS dwapi_etl.etl_prep_enrollment; DROP TABLE IF EXISTS dwapi_etl.etl_prep_followup; DROP TABLE IF EXISTS dwapi_etl.etl_progress_note; @@ -1763,6 +1764,60 @@ SELECT "Successfully created etl_generalized_anxiety_disorder table"; ); SELECT "Successfully created etl_prep_discontinuation table"; + -- ------------ create table etl_orthopaedic_clinic_visit----------------------- + + CREATE TABLE dwapi_etl.etl_orthopaedic_clinic_visit ( + uuid CHAR(38), + encounter_id INT(11) NOT NULL PRIMARY KEY, + patient_id INT(11) NOT NULL , + location_id INT(11) DEFAULT NULL, + visit_date DATE, + visit_id INT(11), + encounter_provider INT(11), + date_created DATETIME NOT NULL, + date_last_modified DATETIME, + visit_type INT(11), + referral_form INT(11), + facility_name VARCHAR(255), + service_area INT(11), + other_unit_name VARCHAR(255), + orthopaedic_number INT (11), + select_symptoms VARCHAR(255), + location VARCHAR(255), + otc_duration INT(11), + onset_otc VARCHAR(255), + hpi VARCHAR(255), + past_prescribed_drugs VARCHAR(255), + trauma_history INT(11), + surgical_history INT(11), + type_of_surgery VARCHAR(255), + surgical_date DATE, + surgery_indication VARCHAR(255), + underlying_condition INT(11), + specify_condition VARCHAR(255), + specify_condition_other VARCHAR(255), + family_history INT(11), + musculoskeletal_system_conditions VARCHAR(255), + musculoskeletal_system_conditions_other VARCHAR(255), + musculoskeletal_findings VARCHAR(255), + joint_assessed VARCHAR(255), + joint_movement INT(11), + angle_degrees INT(11), + clinician_findings_notes VARCHAR(255), + intervention_given VARCHAR(255), + intervention_given_other VARCHAR(255), + management_plan VARCHAR(255), + procedure_done VARCHAR(255), + patient_referral VARCHAR(255), + name_of_the_facility VARCHAR(255), + voided INT(11), + CONSTRAINT FOREIGN KEY (patient_id) REFERENCES dwapi_etl.etl_patient_demographics(patient_id), + CONSTRAINT unique_uuid UNIQUE(uuid), + INDEX(visit_date), + INDEX(encounter_id), + INDEX(patient_id, visit_date) + ); + SELECT "Successfully created etl_orthopaedic_clinic_visit table"; -- ------------ create table etl_prep_enrollment----------------------- CREATE TABLE dwapi_etl.etl_prep_enrolment ( uuid char(38), diff --git a/omod/src/main/resources/sql/dwapi/DML.sql b/omod/src/main/resources/sql/dwapi/DML.sql index 9fddb2bc..dabfde9d 100644 --- a/omod/src/main/resources/sql/dwapi/DML.sql +++ b/omod/src/main/resources/sql/dwapi/DML.sql @@ -3675,6 +3675,215 @@ CREATE PROCEDURE sp_populate_dwapi_prep_discontinuation() SELECT "Completed processing PrEP discontinuation", CONCAT("Time: ", NOW()); END $$ +-- ------------- populate etl_orthopaedic_clinic_visit------------------------- + +DROP PROCEDURE IF EXISTS sp_populate_dwapi_orthopaedic_clinic_visit $$ +CREATE PROCEDURE sp_populate_dwapi_orthopaedic_clinic_visit() + BEGIN + SELECT "Processing Orthopaedic Clinic Visit form", CONCAT("Time: ", NOW()); + insert into dwapi_etl.etl_orthopaedic_clinic_visit( + uuid, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + encounter_provider, + date_created, + visit_type, + referral_form, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, + trauma_history, + surgical_history, + type_of_surgery, + surgical_date, + surgery_indication, + underlying_condition, + specify_condition, + specify_condition_other, + family_history, + musculoskeletal_system_conditions, + musculoskeletal_system_conditions_other, + musculoskeletal_findings, + joint_assessed, + joint_movement, + angle_degrees, + clinician_findings_notes, + intervention_given, + intervention_given_other, + management_plan, + procedure_done, + patient_referral, + name_of_the_facility, + date_last_modified, + voided + ) + select + e.uuid, + e.patient_id, + e.visit_id, + date(e.encounter_datetime) as visit_date, + e.location_id, + e.encounter_id as encounter_id, + e.creator, + e.date_created as date_created, + max(if(o.concept_id=164181,trim(o.value_coded),null)) as visit_type, + max(if(o.concept_id=161643,trim(o.value_coded),null)) as referral_form, + max(if(o.concept_id=162724,o.value_text,null)) as facility_name, + max(if(o.concept_id=168146,o.value_coded,null)) as service_area, + max(if(o.concept_id=166635,o.value_text,null)) as other_unit_name, + max(if(o.concept_id=159893,o.value_numeric,null)) as orthopaedic_number, + concat_ws(',', max(if(o.concept_id = 5219 and o.value_coded = 114403, 'Pain', null)), + max(if(o.concept_id = 5219 and o.value_coded = 130842, 'Immobility', null)), + max(if(o.concept_id = 5219 and o.value_coded = 140468, 'Muscle tenseness', null)), + max(if(o.concept_id = 5219 and o.value_coded = 119775, 'Muscle spasms', null)), + max(if(o.concept_id = 5219 and o.value_coded = 163894, 'Swelling', null)), + max(if(o.concept_id = 5219 and o.value_coded = 111525, 'Loss of function', null)), + max(if(o.concept_id = 5219 and o.value_coded = 116554, 'Joint stiffness', null)), + max(if(o.concept_id = 5219 and o.value_coded = 5622, 'Other', null))) as select_symptoms, + max(if(o.concept_id=167992,o.value_text,null)) as location, + max(if(o.concept_id=1731,o.value_numeric,null)) as otc_duration, + max(if(o.concept_id=162642,o.value_coded,null)) as onset_otc, + max(if(o.concept_id=160430,o.value_text,null)) as hpi, + concat_ws(',', max(if(o.concept_id = 1628 and o.value_text = 162725, 'Drug Name', null)), + max(if(o.concept_id = 1628 and o.value_numeric = 1731, 'Duration', null)), + max(if(o.concept_id = 1628 and o.value_numeric = 1443, 'Dosage', null))) as past_prescribed_drugs, + max(if(o.concept_id=159520,o.value_coded,null)) as trauma_history, + max(if(o.concept_id=168148,o.value_coded,null)) as surgical_history, + max(if(o.concept_id=166635,o.value_text,null)) as type_of_surgery, + max(if(o.concept_id=160715,o.value_datetime,null)) as surgical_date, + max(if(o.concept_id=163393,o.value_text,null)) as surgery_indication, + max(if(o.concept_id=165034,o.value_coded,null)) as underlying_condition, + CONCAT_WS(',',max(if(o.concept_id = 162747 and o.value_coded = 114698, 'Osteoarthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127417, 'Rheumatoid arthritis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 127706, 'Diabetes',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 115115, 'Obesity',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 117762, 'Gout',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 153690, 'Lupus',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 162747 and o.value_coded = 5622, 'Others',NULL))) as specify_condition, + max(if(o.concept_id=166635,o.value_text,null)) as specify_condition_other, + max(if(o.concept_id=1081,o.value_coded,null)) as family_history, + CONCAT_WS(',',max(if(o.concept_id = 1128 and o.value_coded = 114698, 'Arthritis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114662, 'Osteoporosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 117585, 'Genetic disorders',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 114931, 'Fractures',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 119955, 'Hip dysplasia',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 113125, 'Scoliosis',NULL)), + max(if(o.concept_id = 1128 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + CONCAT_WS(',',max(if(o.concept_id = 164936 and o.value_coded = 5313, 'Local Tenderness',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 80, 'Hot and Red joint',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 130917, 'Muscle Atrophy',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152183, 'Flexion Attitude(knee/neck/spine/ankle)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Homans sign positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 155871, 'Deformity(S-shaped)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 131113, 'Thickening of the bone',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 152228, 'Local swelling',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114362, 'Pseudo-paralysis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 126385, 'Adduction is restricted(Shoulder/hip/fingers)',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 142671, 'Abduction is restricted',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 163894, 'Dugas test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Sulcus test positive',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 136421, 'Crepitus',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 114431, 'Dimple Sign',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 139740, 'Triangle disruption',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 122904, 'Supination and pronation of the forarm',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 135412, 'Anterior/posterior angulation',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 134186, 'Garden spade deformity',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 116472, 'Kyphosis',NULL)), + max(if(o.concept_id = 164936 and o.value_coded = 5622, 'Others',NULL))) as musculoskeletal_findings, + concat_ws(',', max(if(o.concept_id = 165285 and o.value_coded = 166161, 'Ankle', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166204, 'Cervical spine', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166231, 'Elbow', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166241, 'Forearm', null)), + max(if(o.concept_id = 165285 and o.value_coded = 164387, 'Foot', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166245, 'Hip', null)), + max(if(o.concept_id = 165285 and o.value_coded = 112764, 'Sacroiliac', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166306, 'Shoulder', null)), + max(if(o.concept_id = 165285 and o.value_coded = 166293, 'Thumb', null))) as joint_assessed, + concat_ws(',', max(if(o.concept_id = 165139 and o.value_coded = 125286, 'Abduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 125284, 'Adduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 154488, 'Dorsiflexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 142492, 'Deviation', null)), + max(if(o.concept_id = 165139 and o.value_coded = 125974, 'Elevation', null)), + max(if(o.concept_id = 165139 and o.value_coded = 145939, 'Eversion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 124199, 'Extension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 127691, 'Hyperextension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 166344, 'Lateral bending', null)), + max(if(o.concept_id = 165139 and o.value_coded = 152183, 'Flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 159279, 'Inversion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 124179, 'Plantar flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 166746, 'Rotation in abduction', null)), + max(if(o.concept_id = 165139 and o.value_coded = 140714, 'Rotation in extension', null)), + max(if(o.concept_id = 165139 and o.value_coded = 161572, 'Rotation in neutral position', null)), + max(if(o.concept_id = 165139 and o.value_coded = 152183, 'Rotation in flexion', null)), + max(if(o.concept_id = 165139 and o.value_coded = 157783, 'Rotation', null))) as joint_movement, + max(if(o.concept_id=159368,o.value_numeric,null)) as angle_degrees, + max(if(o.concept_id=164939,o.value_text,null)) as clinician_findings_notes, + CONCAT_WS(',',max(if(o.concept_id = 165531 and o.value_coded = 167004, 'Assessing',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001239, 'Counselling Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 162308, 'Measurement taking',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 119758, 'Fabrication',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 159630, 'Fitting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 2001627, 'Casting',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 1000474, 'PWD assessment & Categorization',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 160068, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Referral',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 142608, 'Delivery',NULL)), + max(if(o.concept_id = 165531 and o.value_coded = 5622, 'Others',NULL))) as intervention_given, + max(if(o.concept_id=166635,o.value_text,null)) as intervention_given_other, + max(if(o.concept_id=163104,o.value_text,null)) as management_plan, + CONCAT_WS(',',max(if(o.concept_id = 120198 and o.value_coded = 1107, 'None',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1000133, 'Cryotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Transverse friction massage',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Compression bandaging',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 527, 'Splinting',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 165390, 'Pulsed electromagnetic field therapy(PEMF)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5981, 'Thermotherapy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Limb Elevation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166403, 'Plaster of Paris(POP) application',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 108, 'Isometric exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'ROM exercises',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Joint Aspiration',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5108, 'Gait Training',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 1933, 'TENS,SWD',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166939, 'Corrective osteotomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 136117, 'Rigid plate and screw fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 166737, 'Arm Sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 123498, 'External fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, + max(if(o.concept_id=1788,o.value_text,null)) as patient_referral, + max(if(o.concept_id=162724,o.value_text,null)) as name_of_the_facility, + if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified, + e.voided as voided + from encounter e + inner join person p on p.person_id=e.patient_id and p.voided=0 + inner join + ( + select form_id, uuid,name from form where + uuid in('beec83df-6606-4019-8223-05a54a52f2b0') + ) f on f.form_id=e.form_id + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,162724,168146,166635,159893,5219,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,1128,166635,164936,165285,165139, + 159368,164939,165531,166635,163104,120198,1788,162724) and o.voided=0 + where e.voided=0 + group by e.encounter_id; + SELECT "Completed processing Orthopaedic Clinic Visit", CONCAT("Time: ", NOW()); + END $$ + -- ------------- populate etl_prep_enrollment------------------------- DROP PROCEDURE IF EXISTS sp_populate_dwapi_prep_enrolment $$ @@ -8688,6 +8897,7 @@ CALL sp_populate_dwapi_prep_followup(); CALL sp_populate_dwapi_prep_behaviour_risk_assessment(); CALL sp_populate_dwapi_prep_monthly_refill(); CALL sp_populate_dwapi_prep_discontinuation(); +CALL sp_populate_dwapi_orthopaedic_clinic_visit(); CALL sp_populate_dwapi_hts_linkage_tracing(); CALL sp_populate_dwapi_patient_program(); CALL sp_populate_dwapi_person_address();