Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ETL for Orthopaedic form #488

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't handle multi-select. Check data type.

Expand Down
90 changes: 84 additions & 6 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use "=" instead of in for single value comparison

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;
Expand Down
76 changes: 5 additions & 71 deletions omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading