From 3e894279239760152599d0a14590b77bef9bbe5b Mon Sep 17 00:00:00 2001 From: gabu90 Date: Wed, 27 Nov 2024 08:43:30 +0300 Subject: [PATCH 1/2] ETL for Orthopaedic form --- omod/src/main/resources/sql/DDL.sql | 63 +++++++ omod/src/main/resources/sql/DML.sql | 154 +++++++++++++++++ omod/src/main/resources/sql/DataTools.sql | 121 +++++++++++++ .../main/resources/sql/Scheduled_Updates.sql | 162 ++++++++++++++++++ omod/src/main/resources/sql/dwapi/DDL.sql | 61 +++++++ omod/src/main/resources/sql/dwapi/DML.sql | 154 +++++++++++++++++ 6 files changed, 715 insertions(+) diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index 0bcc44c9..8a231a80 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,68 @@ 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), + other_facility_name VARCHAR(255), + facility_name VARCHAR(255), + service_area INT(11), + other_unit_name VARCHAR(255), + orthopaedic_number INT (11), + select_symptoms VARCHAR(255), + symptoms_for_otc_other VARCHAR(255), + location VARCHAR(255), + otc_duration INT(11), + onset_otc VARCHAR(255), + hpi VARCHAR(255), + past_prescribed_drugs VARCHAR(255), +-- previous_physiotherapy INT(11), + 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 INT(11), + specify_condition_other VARCHAR(255), + family_history INT(11), + musculoskeletal_system_conditions INT(11), + musculoskeletal_system_conditions_other VARCHAR(255), + musculoskeletal_examination_findings VARCHAR(255), + musculoskeletal_findings INT(11), + musculoskeletal_findings_other 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), + procedure_done_other 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..da4f0861 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -3842,6 +3842,159 @@ 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, + other_facility_name, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + symptoms_for_otc_other, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, +-- previous_physiotherapy, + 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_examination_findings, + musculoskeletal_findings, + musculoskeletal_findings_other, + 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=160632,o.value_text,null)) as other_facility_name, + 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=160632,o.value_text,null)) as symptoms_for_otc_other, + 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=1628,o.value_coded,null)) as previous_physiotherapy, + 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, + max(if(o.concept_id=162747,o.value_coded,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, + max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, + max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_findings_other, + 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, + max(if(o.concept_id=165531,o.value_coded,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, + max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, + 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 form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 159368,164939,165531,166635,163104,120198,160632,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 +9218,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..65a2f27f 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -1254,6 +1254,127 @@ 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, + other_facility_name, + 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, + symptoms_for_otc_other, + 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, + (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as underlying_condition, + (case o.value_coded when 114698 then "Osteoarthritis" when 114662 then "Osteoporosis" when 127417 then "Rheumatoid arthritis" when 127706 then "Diabetes" when 115115 then "Obesity" when 117762 then "Gout" when 153690 then "Lupus" when 119955 then "Hip dysplasia" when 113125 then "Scoliosis" when 5622 then "Others" else "" end) as specify_condition, + specify_condition_other, + (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as family_history, + (case o.value_coded when 114698 then "Arthritis" when 114662 then "Osteoporosis" when 117585 then "Genetic disorders" + when 114931 then "Fractures" when 119955 then "Hip dysplasia" + when 113125 then "Scoliosis" when 5622 then "Others" else "" end) as musculoskeletal_system_conditions, + musculoskeletal_system_conditions_other, + musculoskeletal_examination_findings, + (case o.value_coded when 5313 then "Local Tenderness" when 80 then "Hot and Red joint" when 130917 then "Muscle Atrophy" + when 152183 then "Flexion Attitude(knee/neck/spine/ankle)" + when 134186 then "Homan's sign positive" + when 155871 then "Deformity(S-shaped)" + when 131113 then "Thickening of the bone" + when 152228 then "Local swelling" when 114362 then "Pseudo-paralysis" + when 126385 then "Adduction is restricted(Shoulder/hip/fingers)" + when 142671 then "Abduction is restricted" when 163894 then "Dugas test positive" + when 135412 then "Sulcus test positive" when 136421 + then "Crepitus" when 114431 then "Dimple Sign" when 131113 + then "Step sign positive" when 139740 then "Triangle disruption" + when 122904 then "Supination and pronation of the forarm" + when 135412 then "Anterior/posterior angulation" when 134186 then "Garden spade deformity" + when 116472 then "Kyphosis" when 5622 then "Other" + else "" end) as musculoskeletal_findings, + musculoskeletal_findings_other, + joint_assessed, + joint_movement, + angle_degrees, + clinician_findings_notes, + (case o.value_coded when 167004 then "Assessing" + when 2001239 then "Counselling Delivery" + when 162308 then "Measurement taking" + when 119758 then "Fabrication" + when 159630 then "Fitting" + when 5622 then "Assistive Technology Training" + when 2001627 then "Casting" + when 1000474 then "PWD assessment & Categorization" + when 160068 then "Referral" + when 142608 then "Delivery" + when 5622 then "Others" + else "" end) as intervention_given, + intervention_given_other, + management_plan, + (case o.value_coded when 1107 then "None" + when 1000133 then "Cryotherapy" + when 127642 then "Transverse friction massage" + when 162158 then "Compression bandaging" + when 527 then "Splinting" + when 165390 then "Pulsed electromagnetic field therapy(PEMF)" + when 5981 then "Thermotherapy" + when 160925 then "Limb Elevation" + when 166403 then "Plaster of Paris(POP) application" + when 108 then "Isometric exercises" + when 137971 then "ROM exercises" + when 5622 then "Joint Aspiration" + when 5108 then "Gait Training" + when 1933 then "TENS,SWD" + when 127642 then "Traction and counter traction" + when 162158 then "MClosed Reduction by traction(Gallow's/Dunlop's/Smith's traction)" + when 166939 then "Corrective osteotomy" + when 165390 then "Cuff and collar sling" + when 168650 then "Stripping" + when 160925 then "Intramedullary fixation with K-wires" + when 136117 then "Rigid plate and screw fixation" + when 108 then "Closed Reduction(Hippocrates's/Stimson's/Kocher's method)" + when 137971 then "Open reduction and internal fixation" + when 5622 then "DCP plating" + when 166737 then "Arm Sling" + when 1933 then "Cast fixed" + when 127642 then "Percutaneous fixation" + when 162158 then "Excision" + when 123498 then "External fixation" + when 165390 then "Anthroplasty" + when 166105 then "Arthrodesis" + when 160925 then "Buddy taping" + when 164009 then "Amputation" + when 163949 then "Debridement" + when 137971 then "Tenoctomy" + when 5622 then "Tenodes" + when 162926 then "Removal of Plaster" + else "" end) as procedure_done, + procedure_done_other, + (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..fd552821 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -3856,6 +3856,167 @@ 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, + other_facility_name, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + symptoms_for_otc_other, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, +-- previous_physiotherapy, + 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_examination_findings, + musculoskeletal_findings, + musculoskeletal_findings_other, + 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, + 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=160632,o.value_text,null)) as other_facility_name, + 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=160632,o.value_text,null)) as symptoms_for_otc_other, + 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=1628,o.value_coded,null)) as previous_physiotherapy, + 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, + max(if(o.concept_id=162747,o.value_coded,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, + max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, + max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_findings_other, + 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, + max(if(o.concept_id=165531,o.value_coded,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, + max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, + 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 form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 159368,164939,165531,166635,163104,120198,160632,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 +10402,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..28de865b 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,66 @@ 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), + other_facility_name VARCHAR(255), + facility_name VARCHAR(255), + service_area INT(11), + other_unit_name VARCHAR(255), + orthopaedic_number INT (11), + select_symptoms VARCHAR(255), + symptoms_for_otc_other VARCHAR(255), + location VARCHAR(255), + otc_duration INT(11), + onset_otc VARCHAR(255), + hpi VARCHAR(255), + past_prescribed_drugs VARCHAR(255), +-- previous_physiotherapy INT(11), + 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 INT(11), + specify_condition_other VARCHAR(255), + family_history INT(11), + musculoskeletal_system_conditions INT(11), + musculoskeletal_system_conditions_other VARCHAR(255), + musculoskeletal_examination_findings VARCHAR(255), + musculoskeletal_findings INT(11), + musculoskeletal_findings_other 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), + procedure_done_other 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..af678bd1 100644 --- a/omod/src/main/resources/sql/dwapi/DML.sql +++ b/omod/src/main/resources/sql/dwapi/DML.sql @@ -3675,6 +3675,159 @@ 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, + other_facility_name, + facility_name, + service_area, + other_unit_name, + orthopaedic_number, + select_symptoms, + symptoms_for_otc_other, + location, + otc_duration, + onset_otc, + hpi, + past_prescribed_drugs, +-- previous_physiotherapy, + 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_examination_findings, + musculoskeletal_findings, + musculoskeletal_findings_other, + 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=160632,o.value_text,null)) as other_facility_name, + 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=160632,o.value_text,null)) as symptoms_for_otc_other, + 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=1628,o.value_coded,null)) as previous_physiotherapy, + 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, + max(if(o.concept_id=162747,o.value_coded,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, + max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + max(if(o.concept_id=166635,o.value_text,null)) as musculoskeletal_system_conditions_other, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, + max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_findings_other, + 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, + max(if(o.concept_id=165531,o.value_coded,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, + max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, + 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 form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") + inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 159368,164939,165531,166635,163104,120198,160632,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 +8841,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(); From 81b721b86beab019a17754c531cd97379164756d Mon Sep 17 00:00:00 2001 From: gabu90 Date: Mon, 16 Dec 2024 11:51:18 +0300 Subject: [PATCH 2/2] Modification on the Checkbox --- omod/src/main/resources/sql/DDL.sql | 6 +- omod/src/main/resources/sql/DML.sql | 90 +++++++++++++++++-- omod/src/main/resources/sql/DataTools.sql | 76 ++-------------- .../main/resources/sql/Scheduled_Updates.sql | 90 +++++++++++++++++-- omod/src/main/resources/sql/dwapi/DDL.sql | 6 +- omod/src/main/resources/sql/dwapi/DML.sql | 90 +++++++++++++++++-- 6 files changed, 263 insertions(+), 95 deletions(-) diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index 8a231a80..8e830519 100644 --- a/omod/src/main/resources/sql/DDL.sql +++ b/omod/src/main/resources/sql/DDL.sql @@ -1826,13 +1826,13 @@ SELECT "Successfully created etl_ART_preparation table"; surgical_date DATE, surgery_indication VARCHAR(255), underlying_condition INT(11), - specify_condition INT(11), + specify_condition VARCHAR(255), specify_condition_other VARCHAR(255), family_history INT(11), - musculoskeletal_system_conditions INT(11), + musculoskeletal_system_conditions VARCHAR(255), musculoskeletal_system_conditions_other VARCHAR(255), musculoskeletal_examination_findings VARCHAR(255), - musculoskeletal_findings INT(11), + musculoskeletal_findings VARCHAR(255), musculoskeletal_findings_other VARCHAR(255), joint_assessed VARCHAR(255), joint_movement INT(11), diff --git a/omod/src/main/resources/sql/DML.sql b/omod/src/main/resources/sql/DML.sql index da4f0861..17532ce2 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -3939,13 +3939,48 @@ CREATE PROCEDURE sp_populate_etl_orthopaedic_clinic_visit() 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, - max(if(o.concept_id=162747,o.value_coded,null)) as specify_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, - max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + 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, max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, - max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + 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=160632,o.value_text,null)) as musculoskeletal_findings_other, 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)), @@ -3976,10 +4011,53 @@ CREATE PROCEDURE sp_populate_etl_orthopaedic_clinic_visit() 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, - max(if(o.concept_id=165531,o.value_coded,null)) as intervention_given, + 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, - max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + 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 = 127642, 'Traction and counter traction',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'MClosed Reduction by traction(Gallows/Dunlops/Smiths traction)',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 = 165390, 'Cuff and collar sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Intramedullary fixation with K-wires',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 = 108, 'Closed Reduction(Hippocratess/Stimsons/Kochers method)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Open reduction and internal fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'DCP plating',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 = 1933, 'Cast fixed',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Percutaneous fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Excision',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 = 165390, 'Anthroplasty',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Debridement',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Tenoctomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Tenodes',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, 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, @@ -3989,7 +4067,7 @@ CREATE PROCEDURE sp_populate_etl_orthopaedic_clinic_visit() inner join person p on p.person_id=e.patient_id and p.voided=0 inner join form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, - 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,1081,1128,166635,160632,164936,160632,165285,165139, 159368,164939,165531,166635,163104,120198,160632,1788,162724) and o.voided=0 where e.voided=0 group by e.encounter_id; diff --git a/omod/src/main/resources/sql/DataTools.sql b/omod/src/main/resources/sql/DataTools.sql index 65a2f27f..8a2eddc2 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -1284,87 +1284,21 @@ SELECT "Successfully created enhanced adherence table"; type_of_surgery, surgical_date, surgery_indication, - (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as underlying_condition, - (case o.value_coded when 114698 then "Osteoarthritis" when 114662 then "Osteoporosis" when 127417 then "Rheumatoid arthritis" when 127706 then "Diabetes" when 115115 then "Obesity" when 117762 then "Gout" when 153690 then "Lupus" when 119955 then "Hip dysplasia" when 113125 then "Scoliosis" when 5622 then "Others" else "" end) as specify_condition, + specify_condition, specify_condition_other, - (case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end) as family_history, - (case o.value_coded when 114698 then "Arthritis" when 114662 then "Osteoporosis" when 117585 then "Genetic disorders" - when 114931 then "Fractures" when 119955 then "Hip dysplasia" - when 113125 then "Scoliosis" when 5622 then "Others" else "" end) as musculoskeletal_system_conditions, + musculoskeletal_system_conditions, musculoskeletal_system_conditions_other, musculoskeletal_examination_findings, - (case o.value_coded when 5313 then "Local Tenderness" when 80 then "Hot and Red joint" when 130917 then "Muscle Atrophy" - when 152183 then "Flexion Attitude(knee/neck/spine/ankle)" - when 134186 then "Homan's sign positive" - when 155871 then "Deformity(S-shaped)" - when 131113 then "Thickening of the bone" - when 152228 then "Local swelling" when 114362 then "Pseudo-paralysis" - when 126385 then "Adduction is restricted(Shoulder/hip/fingers)" - when 142671 then "Abduction is restricted" when 163894 then "Dugas test positive" - when 135412 then "Sulcus test positive" when 136421 - then "Crepitus" when 114431 then "Dimple Sign" when 131113 - then "Step sign positive" when 139740 then "Triangle disruption" - when 122904 then "Supination and pronation of the forarm" - when 135412 then "Anterior/posterior angulation" when 134186 then "Garden spade deformity" - when 116472 then "Kyphosis" when 5622 then "Other" - else "" end) as musculoskeletal_findings, + musculoskeletal_findings, musculoskeletal_findings_other, joint_assessed, joint_movement, angle_degrees, clinician_findings_notes, - (case o.value_coded when 167004 then "Assessing" - when 2001239 then "Counselling Delivery" - when 162308 then "Measurement taking" - when 119758 then "Fabrication" - when 159630 then "Fitting" - when 5622 then "Assistive Technology Training" - when 2001627 then "Casting" - when 1000474 then "PWD assessment & Categorization" - when 160068 then "Referral" - when 142608 then "Delivery" - when 5622 then "Others" - else "" end) as intervention_given, + intervention_given, intervention_given_other, management_plan, - (case o.value_coded when 1107 then "None" - when 1000133 then "Cryotherapy" - when 127642 then "Transverse friction massage" - when 162158 then "Compression bandaging" - when 527 then "Splinting" - when 165390 then "Pulsed electromagnetic field therapy(PEMF)" - when 5981 then "Thermotherapy" - when 160925 then "Limb Elevation" - when 166403 then "Plaster of Paris(POP) application" - when 108 then "Isometric exercises" - when 137971 then "ROM exercises" - when 5622 then "Joint Aspiration" - when 5108 then "Gait Training" - when 1933 then "TENS,SWD" - when 127642 then "Traction and counter traction" - when 162158 then "MClosed Reduction by traction(Gallow's/Dunlop's/Smith's traction)" - when 166939 then "Corrective osteotomy" - when 165390 then "Cuff and collar sling" - when 168650 then "Stripping" - when 160925 then "Intramedullary fixation with K-wires" - when 136117 then "Rigid plate and screw fixation" - when 108 then "Closed Reduction(Hippocrates's/Stimson's/Kocher's method)" - when 137971 then "Open reduction and internal fixation" - when 5622 then "DCP plating" - when 166737 then "Arm Sling" - when 1933 then "Cast fixed" - when 127642 then "Percutaneous fixation" - when 162158 then "Excision" - when 123498 then "External fixation" - when 165390 then "Anthroplasty" - when 166105 then "Arthrodesis" - when 160925 then "Buddy taping" - when 164009 then "Amputation" - when 163949 then "Debridement" - when 137971 then "Tenoctomy" - when 5622 then "Tenodes" - when 162926 then "Removal of Plaster" - else "" end) as procedure_done, + procedure_done, procedure_done_other, (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, diff --git a/omod/src/main/resources/sql/Scheduled_Updates.sql b/omod/src/main/resources/sql/Scheduled_Updates.sql index fd552821..c1f7704d 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -3945,22 +3945,100 @@ CREATE PROCEDURE sp_update_etl_orthopaedic_clinic_visit(IN last_update_time DATE 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, - max(if(o.concept_id=162747,o.value_coded,null)) as specify_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, - max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + 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, max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, - max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + 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=160632,o.value_text,null)) as musculoskeletal_findings_other, 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, - max(if(o.concept_id=165531,o.value_coded,null)) as intervention_given, + 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, - max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + 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 = 127642, 'Traction and counter traction',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'MClosed Reduction by traction(Gallows/Dunlops/Smiths traction)',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 = 165390, 'Cuff and collar sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Intramedullary fixation with K-wires',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 = 108, 'Closed Reduction(Hippocratess/Stimsons/Kochers method)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Open reduction and internal fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'DCP plating',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 = 1933, 'Cast fixed',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Percutaneous fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Excision',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 = 165390, 'Anthroplasty',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Debridement',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Tenoctomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Tenodes',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, 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, @@ -3969,7 +4047,7 @@ CREATE PROCEDURE sp_update_etl_orthopaedic_clinic_visit(IN last_update_time DATE inner join person p on p.person_id=e.patient_id and p.voided=0 inner join form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, - 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,1128,166635,160632,164936,160632,165285,165139, 159368,164939,165531,166635,163104,120198,160632,1788,162724) and o.voided=0 where e.voided=0 and e.date_created >= last_update_time or e.date_changed >= last_update_time diff --git a/omod/src/main/resources/sql/dwapi/DDL.sql b/omod/src/main/resources/sql/dwapi/DDL.sql index 28de865b..a42a2969 100644 --- a/omod/src/main/resources/sql/dwapi/DDL.sql +++ b/omod/src/main/resources/sql/dwapi/DDL.sql @@ -1797,13 +1797,13 @@ SELECT "Successfully created etl_generalized_anxiety_disorder table"; surgical_date DATE, surgery_indication VARCHAR(255), underlying_condition INT(11), - specify_condition INT(11), + specify_condition VARCHAR(255), specify_condition_other VARCHAR(255), family_history INT(11), - musculoskeletal_system_conditions INT(11), + musculoskeletal_system_conditions VARCHAR(255), musculoskeletal_system_conditions_other VARCHAR(255), musculoskeletal_examination_findings VARCHAR(255), - musculoskeletal_findings INT(11), + musculoskeletal_findings VARCHAR(255), musculoskeletal_findings_other VARCHAR(255), joint_assessed VARCHAR(255), joint_movement INT(11), diff --git a/omod/src/main/resources/sql/dwapi/DML.sql b/omod/src/main/resources/sql/dwapi/DML.sql index af678bd1..78e27782 100644 --- a/omod/src/main/resources/sql/dwapi/DML.sql +++ b/omod/src/main/resources/sql/dwapi/DML.sql @@ -3772,13 +3772,48 @@ CREATE PROCEDURE sp_populate_dwapi_orthopaedic_clinic_visit() 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, - max(if(o.concept_id=162747,o.value_coded,null)) as specify_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, - max(if(o.concept_id=162747,o.value_coded,null)) as musculoskeletal_system_conditions, + 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, max(if(o.concept_id=160632,o.value_text,null)) as musculoskeletal_examination_findings, - max(if(o.concept_id=164936,o.value_coded,null)) as musculoskeletal_findings, + 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=160632,o.value_text,null)) as musculoskeletal_findings_other, 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)), @@ -3808,10 +3843,53 @@ CREATE PROCEDURE sp_populate_dwapi_orthopaedic_clinic_visit() 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, - max(if(o.concept_id=165531,o.value_coded,null)) as intervention_given, + 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, - max(if(o.concept_id=120198,o.value_coded,null)) as procedure_done, + 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 = 127642, 'Traction and counter traction',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'MClosed Reduction by traction(Gallows/Dunlops/Smiths traction)',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 = 165390, 'Cuff and collar sling',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 168650, 'Stripping',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Intramedullary fixation with K-wires',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 = 108, 'Closed Reduction(Hippocratess/Stimsons/Kochers method)',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Open reduction and internal fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'DCP plating',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 = 1933, 'Cast fixed',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 127642, 'Percutaneous fixation',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162158, 'Excision',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 = 165390, 'Anthroplasty',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 160925, 'Debridement',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 137971, 'Tenoctomy',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 5622, 'Tenodes',NULL)), + max(if(o.concept_id = 120198 and o.value_coded = 162926, 'Removal of Plaster',NULL))) as procedure_done, max(if(o.concept_id=160632,o.value_text,null)) as procedure_done_other, 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, @@ -3821,7 +3899,7 @@ CREATE PROCEDURE sp_populate_dwapi_orthopaedic_clinic_visit() inner join person p on p.person_id=e.patient_id and p.voided=0 inner join form f on f.form_id=e.form_id and f.uuid in ("beec83df-6606-4019-8223-05a54a52f2b0") inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,161643,160632,162724,168146,166635,159893,5219,160632,167992,1731, - 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,162747,166635,160632,164936,160632,165285,165139, + 162642,160430,1628,159520,168148,166635,160715,163393,165034,162747,166635,162747,1081,1128,166635,160632,164936,160632,165285,165139, 159368,164939,165531,166635,163104,120198,160632,1788,162724) and o.voided=0 where e.voided=0 group by e.encounter_id;