malawi_hiv_program_reports 1.0.9 → 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: a08c2c660947b3a6cef7293babf4b2fcb24c1e64dd8cd890f631d7afad67b638
4
- data.tar.gz: 70dcb9fc2ea37d029c1ebbb3b86fa569c843f689277deec5a017f00d9934e7ff
3
+ metadata.gz: 577d1f703cd4fa86123a4728cc6d88a373ad300a984cb44538713c8361f9149c
4
+ data.tar.gz: 411a5c315f87573ecd8450990774e6e1f3313da05a42817b79057b5320bf8f0a
5
5
  SHA512:
6
- metadata.gz: ec1e203183395cf35beb1b08f5fadd50b090888f61586712dc71ddf81316284ffa4d4aca5d32208942605f5cef05d0731a63a4d6d8420a30afcf4e22ecf6452b
7
- data.tar.gz: 67084f90cfe2d6e38d21abb1473161f45936f03b876addcd839044e1cf7aaec03ff10b5988138d6ed99a06b3865ad08c56d56a520d9f6459905d785cdf48a786
6
+ metadata.gz: 50c1ccfb88c9618276ef45af6150ffb1c8b60e26815b3f6cb5e2252e3d9a03a655bf22df23000d413644024de687f2630405ad3ca5c1c35d67a87dba764100f5
7
+ data.tar.gz: 7a359ad17a0b1cd0fe9fd048b18e5a96f395ff046098a70950b6d28b375ba884b83b53d201d4c0ac78762002c77c3f9dbaeafca6df9781b792c50e30107f210e
@@ -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.9'
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.9
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