malawi_hiv_program_reports 1.0.9 → 1.0.11

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: 6b0b18ac14704b02389c59bca8c5e49c80fa48b381ec37faf25a26dbe9995c90
4
+ data.tar.gz: 8ad3b0382ec582c6e8289f599e65591011e15969b7f0ddba40f71e87bd626bad
5
5
  SHA512:
6
- metadata.gz: ec1e203183395cf35beb1b08f5fadd50b090888f61586712dc71ddf81316284ffa4d4aca5d32208942605f5cef05d0731a63a4d6d8420a30afcf4e22ecf6452b
7
- data.tar.gz: 67084f90cfe2d6e38d21abb1473161f45936f03b876addcd839044e1cf7aaec03ff10b5988138d6ed99a06b3865ad08c56d56a520d9f6459905d785cdf48a786
6
+ metadata.gz: bcbbb974329cd00cfe4b57d3d6bb154c669952cf91a1996b89aee8df63086cd35b7cdf5435173f42d329ac7e00eb4d966f57e13e440aa5aa494c26584e8f2c89
7
+ data.tar.gz: 3dfd717d6d6364097edaf7397c5b3380542d74f4eba5bbfd89911c562da8def22584d0adc574e7c45b358f7247bcf7925db8832aebf83b7cb0e1078f03eadbc7
@@ -92,6 +92,7 @@ module MalawiHivProgramReports
92
92
  cohort_struct.quarterly_all_males = males(quarter_start_date, end_date)
93
93
 
94
94
  # Pregnant females (all ages)
95
+ create_temp_pregnant_obs(start_date, end_date)
95
96
  cohort_struct.pregnant_females_all_ages = pregnant_females_all_ages(start_date, end_date)
96
97
  cohort_struct.cum_pregnant_females_all_ages = pregnant_females_all_ages(cum_start_date, end_date)
97
98
  cohort_struct.quarterly_pregnant_females_all_ages = pregnant_females_all_ages(quarter_start_date, end_date)
@@ -1944,27 +1945,36 @@ module MalawiHivProgramReports
1944
1945
  SQL
1945
1946
  end
1946
1947
 
1948
+ def create_temp_pregnant_obs(start_date, end_date)
1949
+ ActiveRecord::Base.connection.execute 'DROP TABLE IF EXISTS temp_pregnant_obs;'
1950
+ ActiveRecord::Base.connection.execute <<~SQL
1951
+ CREATE TABLE temp_pregnant_obs
1952
+ SELECT o.person_id,o.value_coded, o.obs_datetime, o.site_id
1953
+ FROM obs o
1954
+ WHERE o.concept_id IN (6131,1755,7972,7563)
1955
+ AND o.value_coded IN (1065,1755)#{' '}
1956
+ AND o.voided = 0 #{site_manager(operator: 'AND', column: 'o.location_id', location: @location)}
1957
+ AND o.obs_datetime >= '#{start_date}' AND o.obs_datetime < '#{end_date}' + INTERVAL 1 DAY;
1958
+ SQL
1959
+ ActiveRecord::Base.connection.execute 'CREATE INDEX fre_person ON temp_pregnant_obs(person_id);'
1960
+ ActiveRecord::Base.connection.execute 'CREATE INDEX fre_obs_time ON temp_pregnant_obs(obs_datetime);'
1961
+ end
1962
+
1947
1963
  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
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.11'
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.11
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