Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
MAT-5993: Ratio observation data migration and Excel export issues (#…
Browse files Browse the repository at this point in the history
…2161)

* MAT-5993 ratio observation migration script

* MAT-5860 added couple more test cases for ratio measures actual vs expected values

* MAT-5860 removed unwanted code

* MAT-5993 Ratio patient excel Export issues

* MAT-5993 ratio patient delete OBSERV

* more test cases

* MAT-5859 remove unit switch
  • Loading branch information
adongare authored Jul 27, 2023
1 parent 7a7cbc0 commit f651498
Show file tree
Hide file tree
Showing 10 changed files with 3,852 additions and 23 deletions.
5 changes: 0 additions & 5 deletions app/assets/javascripts/models/expected_value.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ class Thorax.Models.ExpectedValue extends Thorax.Model
if @get('OBSERV').length - result.get('observation_values').length < 0
@get('OBSERV').push(undefined) for n in [(@get('OBSERV').length + 1)..result.get('observation_values').length]

for popCrit in @populationCriteria()
if popCrit.indexOf('OBSERV') != -1 then return false unless @compareObservs(@get('OBSERV')?[@observIndex(popCrit)], result.get('observation_values')?[@observIndex(popCrit)])
else return false unless @get(popCrit) == result.get(popCrit)
return true

comparison: (result) ->
results = []
for popCrit in @populationCriteria()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
{{else}}
<div class="form-group">
<label for="{{key}}_{{@cid}}" class="checkbox-inline">{{displayName}}</label>
<div class="btn-group">
{{#button "togglePerc" class="btn btn-xs btn-observ-unit-perc"}} % {{/button}}
{{#button "toggleMins" class="btn btn-xs btn-observ-unit-mins"}} mins {{/button}}
</div>
{{#each ../../../OBSERV}}
<input type="number" id="{{../key}}_{{@index}}" name="{{../key}}" min="0" value="{{this}}">
{{/each}}
Expand Down
48 changes: 47 additions & 1 deletion app/assets/javascripts/views/measure_view.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,23 @@ class Thorax.Views.Measure extends Thorax.Views.BonnieView
result_criteria = {}
for pop_crit of result.get('population_relevance')
result_criteria[pop_crit] = result.get(pop_crit)
expectedValues = patient.getExpectedValues(@model);
camMeasure = this.model.get('cqmMeasure')
# update observations for ratio scoring
if (camMeasure.measure_scoring == 'RATIO')
expectedValues = @correctExpectedRatioObservations(expectedValues.models)
if (camMeasure.calculation_method == 'EPISODE_OF_CARE')
result_criteria['observation_values'] = @getEpisodeBasedObservations(result)
else
result_criteria['observation_values'] = @getPatientBsedObservations(result, pop.get('index'))

calc_results[pop.cid][patient.cid] = {statement_results: @removeExtra(result.get("statement_results")), criteria: result_criteria}
# Populates the patient details
if (patient_details[patient.cid] == undefined)
patient_details[patient.cid] = {
first: patient.getFirstName()
last: patient.getLastName()
expected_values: patient.getExpectedValues(@model)
expected_values: expectedValues
birthdate: patient.getBirthDate()
expired: patient.get("expired")
deathdate: patient.getDeathDate()
Expand Down Expand Up @@ -195,6 +205,42 @@ class Thorax.Views.Measure extends Thorax.Views.BonnieView
measure_hqmf_set_id: @model.get('cqmMeasure').hqmf_set_id
}

correctExpectedRatioObservations: (expectedValues) ->
return expectedValues.map((expectedValue) =>
copy = $.extend({}, expectedValue);
denomObs = expectedValue.get('DENOM_OBSERV') || []
numerObs = expectedValue.get('NUMER_OBSERV') || []
copy.set('OBSERV', [denomObs..., numerObs...])
copy
)

getEpisodeBasedObservations: (result) ->
if (result)
denomObs = []
numerObs = []
for episodeId of result.get('episode_results')
episodeResult = result.get('episode_results')[episodeId]
if episodeResult['DENOM'] && !episodeResult['DENEX']
denomObs.push(episodeResult.observation_values[0]) # denom obs is at 0 index always
if episodeResult['NUMER'] && !episodeResult['NUMEX']
numerObs.push(episodeResult.observation_values[1]) # numer obs is at 1 index always
return [denomObs..., numerObs...]
else
return []

getPatientBsedObservations: (result, groupIndex) ->
observations = result.get('observation_values')
if observations
obsByGroups = ArrayHelpers.chunk([observations...], 2)
currentGroupObs = obsByGroups[groupIndex]
if currentGroupObs
if (!result.get('DENOM') || result.get('DENEX'))
currentGroupObs.shift() # remove first element because denom obs is first in the list
if !result.get('NUMER') || result.get('NUMEX')
currentGroupObs.pop() # remove last element because numer obs is last in the list
return currentGroupObs
return []

# Iterates through the results to remove extraneous fields.
removeExtra: (results) ->
ret = {}
Expand Down
23 changes: 12 additions & 11 deletions mongodb/ratio_patients_observation_updates.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// this script removes OBSERV array from ratio measure patients
print("Observation data removal started...");
const patientsUpdated = {}
db.getCollection('cqm_patients').find().forEach((patient) => {
print(`-------Updating patient : ${patient._id} ------------` );
print(`Patient id : ${patient._id}` );
const expectedValues = patient.expectedValues;
// empty patient, not possible but if in case
if (!expectedValues) {
print('No expected values present' );
return;
}
expectedValues.forEach((expectedValue) => {
if (expectedValue.hasOwnProperty('OBSERV') && !expectedValue.hasOwnProperty('MSRPOPL')) {
delete expectedValue.OBSERV
print(`Deleting OBSERV for patient : ${patient._id}` );
db.getCollection('cqm_patients').updateOne(
{ _id: patient._id},
{
$unset: {'expectedValues.$[].OBSERV': ""}
}
);
patientsUpdated[`${patient._id}`] =`${patient.familyName} ${patient.givenNames[0]}`
} else {
print(`Does not have OBSERV or not a ratio patient: ${patient._id}`);
}
})
// update patient
if (patientsUpdated[`${patient._id}`]) {
db.getCollection('cqm_patients').update(
{ _id: patient._id},
patient,
{ multi: false }
);
}
});
print(JSON.stringify(patientsUpdated));
print("Number of patients updated: ", Object.keys(patientsUpdated).length);
Expand Down
Loading

0 comments on commit f651498

Please sign in to comment.