Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions config/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ aco_measures_hqmf_set_ids:
'ABDC37CC-BAC6-4156-9B91-D1BE2C8B7268',
'9A031E24-3D9B-11E1-8634-00237D5BF174']

# CMS1017
shift_encounter_ends_measure_ids:
[ 'E7B2323F-934A-4E2F-ABB1-3391011DC5B0']

# These measures do not
telehealth_ineligible_measures:
# CMS22v9, CMS69v9, CMS142v9, CMS143v9, CMS771v2
Expand Down
21 changes: 21 additions & 0 deletions lib/cypress/population_clone_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def randomize_ids(patients, prng)
end
end

# rubocop:disable Metrics/MethodLength
# if provider argument is nil, this function will assign a new provider based on the @option['providers'] and @option['generate_provider'] options
def clone_and_save_patient(patient, prng, provider = nil, allow_dups: false)
# This operates on the assumption that we are always cloning a patient for a product test.
Expand All @@ -105,12 +106,17 @@ def clone_and_save_patient(patient, prng, provider = nil, allow_dups: false)
DemographicsRandomizer.randomize_race(cloned_patient, Random.new(0)) if cloned_patient.race == '2131-1'
DemographicsRandomizer.update_demographic_codes(cloned_patient)
randomize_entry_ids(cloned_patient) unless options['disable_randomization']

# Some measures report the length of stay. There is an edge case around day light savings when the length can change due to timezone.
shift_measure_ids = Measure.where(hqmf_set_id: { '$in': APP_CONSTANTS['shift_encounter_ends_measure_ids'] }).distinct(:hqmf_id)
shift_encounter_ends(cloned_patient) if options['randomize_demographics'] && shift_measure_ids.include?(@test.measure_ids.first)
# if the test is a multi measure test, restrict to a single code
restrict_entry_codes(cloned_patient) if @test.is_a? MultiMeasureTest
provider ? assign_existing_provider(cloned_patient, provider) : assign_provider(cloned_patient)
cloned_patient.save!
cloned_patient
end
# rubocop:enable Metrics/MethodLength

def unnumerify(patient)
[%w[0 ZERO], %w[1 ONE], %w[2 TWO], %w[3 THREE], %w[4 FOUR], %w[5 FIVE], %w[6 SIX], %w[7 SEVEN], %w[8 EIGHT], %w[9 NINE]].each do |replacement|
Expand All @@ -119,6 +125,21 @@ def unnumerify(patient)
end
end

def shift_encounter_ends(cloned_patient)
cloned_patient.qdmPatient.get_data_elements('encounter', 'performed').each do |encounter|
encounter_length = (encounter.relevantPeriod.high.to_f - encounter.relevantPeriod.low.to_f) / (60 * 60)
encounter_mod = encounter_length.modulo(24)
# Skip if encounter is less than 1 day or if the encounter end hour of day is not within an hour of the start hour of day
next if (encounter_length < 23) || (encounter_mod < 23 && encounter_mod > 1)

# Shift towards the middle of the day. 26 hours will shift a morning time 2 hours later. 22 will shift an afternoon time earlier.
hour_shift = encounter.relevantPeriod.high.hour < 12 ? 26 : 22

shifted_rp = QDM::Interval.new(encounter.relevantPeriod.low, encounter.relevantPeriod.high.to_time + (60 * 60 * hour_shift))
encounter.relevantPeriod = shifted_rp
end
end

def restrict_entry_codes(cloned_patient)
# Loop through every data element
cloned_patient.qdmPatient.dataElements.each do |entry|
Expand Down