malawi_hiv_program_reports 1.0.8 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b208d1cfb9b841533cb422c55be10119e1fbac4884b5ba86934c76080cff7053
4
- data.tar.gz: 8d03344e5ff345f9a183a84bcd303375234d3a7c2a39c3562f0d3b57ef28cd25
3
+ metadata.gz: 577d1f703cd4fa86123a4728cc6d88a373ad300a984cb44538713c8361f9149c
4
+ data.tar.gz: 411a5c315f87573ecd8450990774e6e1f3313da05a42817b79057b5320bf8f0a
5
5
  SHA512:
6
- metadata.gz: 20ff92a2f61133722d2815a84dd95320c9689696daf569d2007d3d4411e4ebc624d06f70bef48dab466f2dd3ed17618f3f0eb5f23a839090d03407dd84183d22
7
- data.tar.gz: ebd07c5962a6e3cd19d17eae483a32cecc4bbee991281632f7e3eeef200a3550e9ad88e6f2a618c2b13216a091a5403b383a67b8730619f24db4c6c8d802a9f7
6
+ metadata.gz: 50c1ccfb88c9618276ef45af6150ffb1c8b60e26815b3f6cb5e2252e3d9a03a655bf22df23000d413644024de687f2630405ad3ca5c1c35d67a87dba764100f5
7
+ data.tar.gz: 7a359ad17a0b1cd0fe9fd048b18e5a96f395ff046098a70950b6d28b375ba884b83b53d201d4c0ac78762002c77c3f9dbaeafca6df9781b792c50e30107f210e
@@ -745,10 +745,10 @@ module MalawiHivProgramReports
745
745
  AND prescription_encounter.program_id = patient_program.program_id
746
746
  AND prescription_encounter.encounter_datetime < DATE(#{end_date}) + INTERVAL 1 DAY
747
747
  AND prescription_encounter.encounter_type IN (SELECT encounter_type_id FROM encounter_type WHERE name LIKE 'Treatment')
748
- AND prescription_encounter.voided = 0 */
748
+ AND prescription_encounter.voided = 0
749
749
  LEFT JOIN temp_register_start_date AS patient_type_obs
750
750
  ON patient_type_obs.patient_id = patient_program.patient_id #{site_manager(operator: 'AND', column: 'patient_type_obs.site_id', location: @location)}
751
- /*INNER JOIN orders AS art_order
751
+ INNER JOIN orders AS art_order
752
752
  ON art_order.patient_id = patient_program.patient_id
753
753
  -- AND art_order.encounter_id = prescription_encounter.encounter_id
754
754
  AND art_order.concept_id IN (SELECT concept_id FROM concept_set WHERE concept_set = 1085)
@@ -1944,27 +1944,37 @@ module MalawiHivProgramReports
1944
1944
  SQL
1945
1945
  end
1946
1946
 
1947
+ def create_temp_pregnant_obs(start_date, end_date)
1948
+ ActiveRecord::Base.connection.execute 'DROP TABLE IF EXISTS temp_pregnant_obs;'
1949
+ ActiveRecord::Base.connection.execute <<~SQL
1950
+ CREATE TABLE temp_pregnant_obs
1951
+ SELECT o.person_id,o.value_coded, o.obs_datetime, o.site_id
1952
+ FROM obs o
1953
+ WHERE o.concept_id IN (6131,1755,7972,7563)
1954
+ AND o.value_coded IN (1065,1755)#{' '}
1955
+ AND o.voided = 0 #{site_manager(operator: 'AND', column: 'o.location_id', location: @location)}
1956
+ AND o.obs_datetime >= '#{start_date}' AND o.obs_datetime < '#{end_date}' + INTERVAL 1 DAY;
1957
+ SQL
1958
+ ActiveRecord::Base.connection.execute 'CREATE INDEX fre_person ON temp_pregnant_obs(person_id);'
1959
+ ActiveRecord::Base.connection.execute 'CREATE INDEX fre_obs_time ON temp_pregnant_obs(obs_datetime);'
1960
+ end
1961
+
1947
1962
  def pregnant_females_all_ages(start_date, end_date)
1948
- yes_concept_id = concept('Yes').concept_id
1949
- preg_concept_id = concept('IS PATIENT PREGNANT?').concept_id
1950
- patient_preg_concept_id = concept('PATIENT PREGNANT').concept_id
1951
- preg_at_initiation_concept_id = concept('PREGNANT AT INITIATION?').concept_id
1952
- reason_for_starting_concept_id = concept('Reason for ART eligibility').concept_id
1963
+ create_temp_pregnant_obs(start_date, end_date)
1964
+ concept('Yes').concept_id
1965
+ concept('IS PATIENT PREGNANT?').concept_id
1966
+ concept('PATIENT PREGNANT').concept_id
1967
+ concept('PREGNANT AT INITIATION?').concept_id
1968
+ concept('Reason for ART eligibility').concept_id
1953
1969
 
1954
1970
  # (patient_id_plus_date_enrolled || []).each do |patient_id, date_enrolled|
1955
1971
  registered = ActiveRecord::Base.connection.select_all <<~SQL
1956
- SELECT patients.*, obs.value_coded
1957
- FROM temp_earliest_start_date AS patients
1958
- INNER JOIN obs
1959
- ON obs.person_id = patients.patient_id
1960
- AND #{in_manager(column: 'obs.concept_id', values: [preg_concept_id, patient_preg_concept_id, preg_at_initiation_concept_id, reason_for_starting_concept_id])}
1961
- AND obs.obs_datetime >= patients.earliest_start_date
1962
- AND obs.obs_datetime < #{interval_manager(date: 'patients.earliest_start_date', value: 1, interval: 'DAY', operator: '+')}
1963
- AND #{in_manager(column: 'obs.value_coded', values: [yes_concept_id, patient_preg_concept_id])}
1964
- AND obs.voided = 0 #{site_manager(operator: 'AND', column: 'obs.site_id', location: @location)}
1965
- WHERE patients.gender IN ('F','Female')
1966
- AND patients.date_enrolled BETWEEN '#{start_date}' AND '#{end_date}' #{site_manager(operator: 'AND', column: 'patients.site_id', location: @location)}
1967
- GROUP BY patient_id #{@adapter == 'mysql2' ? '' : ',obs.value_coded'}
1972
+ SELECT tesd.*, ft.value_coded
1973
+ FROM temp_earliest_start_date tesd#{' '}
1974
+ INNER JOIN temp_pregnant_obs ft ON ft.person_id = tesd.patient_id AND DATE(ft.obs_datetime) = DATE(tesd.earliest_start_date)
1975
+ AND tesd.gender = 'F'
1976
+ WHERE tesd.gender = 'F' and tesd.date_enrolled >= DATE('#{start_date}') AND tesd.date_enrolled <= DATE('#{end_date}') #{site_manager(operator: 'AND', column: 'tesd.site_id', location: @location)}
1977
+ GROUP BY tesd.patient_id
1968
1978
  SQL
1969
1979
 
1970
1980
  pregnant_at_initiation = ActiveRecord::Base.connection.select_all <<~SQL
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.0.8'
4
+ VERSION = '1.0.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malawi_hiv_program_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Chanunkha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails