diff --git a/app/assets/javascripts/patient_api_extension.js.coffee b/app/assets/javascripts/patient_api_extension.js.coffee index e343d50..5e6737e 100644 --- a/app/assets/javascripts/patient_api_extension.js.coffee +++ b/app/assets/javascripts/patient_api_extension.js.coffee @@ -7,6 +7,9 @@ hQuery.Patient::allDevices = -> this.conditions().concat(this.procedures()).conc hQuery.Patient::activeDiagnoses = -> this.conditions().concat(this.socialHistories()).withStatuses(['active']) hQuery.Patient::inactiveDiagnoses = -> this.conditions().concat(this.socialHistories()).withStatuses(['inactive']) hQuery.Patient::resolvedDiagnoses = -> this.conditions().concat(this.socialHistories()).withStatuses(['resolved']) +hQuery.Patient::deathdate = -> + hQuery.dateFromUtcSeconds this.json["deathdate"] + hQuery.CodedEntry::asIVL_TS = -> tsLow = new TS() tsLow.date = this.startDate() || this.date() || null diff --git a/lib/generator/characteristic.js.erb b/lib/generator/characteristic.js.erb index ed972c6..4bd35df 100644 --- a/lib/generator/characteristic.js.erb +++ b/lib/generator/characteristic.js.erb @@ -8,7 +8,18 @@ events = <%= temporal_reference.type %>(events, hqmfjs.<%= temporal_reference.re <%- end -%> events.specificContext=hqmf.SpecificsManager.identity(); return events; - <%- elsif criteria.property == :expired or criteria.property == :clinicalTrialParticipant -%> + <%- elsif criteria.property == :expired %> + var return_value = matchingValue(value, 'true'); + + <%- if criteria.temporal_references -%> + var events = [patient.deathdate()]; + <%- criteria.temporal_references.each do |temporal_reference| -%> + return_value = <%= temporal_reference.type %>(events, hqmfjs.<%= temporal_reference.reference.id %>(patient)<%= ", #{js_for_bounds(temporal_reference.range)}" if temporal_reference.range %>); + <%- end -%> + <%- end -%> +return_value.specificContext=hqmf.SpecificsManager.identity(); +return return_value + <%- elsif criteria.property == :clinicalTrialParticipant -%> matching = matchingValue(value, 'true'); matching.specificContext=hqmf.SpecificsManager.identity(); return matching diff --git a/test/fixtures/json/59New.json b/test/fixtures/json/59New.json index 47de4b3..d15bdfc 100644 --- a/test/fixtures/json/59New.json +++ b/test/fixtures/json/59New.json @@ -552,6 +552,154 @@ ] } }, + "dead4MonthsBeforeMeasurePeriod": { + "title": "Deceased", + "description": "Patient Characteristic Expired: Deceased", + "standard_category": "individual_characteristic", + "qds_data_type": "individual_characteristic", + "code_list_id": "2.16.840.1.113883.3.67.1.101.11.721", + "property": "expired", + "type": "characteristic", + "definition": "patient_characteristic_expired", + "hard_status": false, + "negation": false, + "source_data_criteria": "PatientCharacteristicExpiredDeceased", + "inline_code_list": { + "SNOMED-CT": [ + "18632008", + "371828006" + ] + }, + "temporal_references": [ + { + "type": "SBS", + "reference": "MeasurePeriod", + "range": { + "type": "IVL_PQ", + "low": { + "type": "PQ", + "unit": "mo", + "value": "4", + "inclusive?": true, + "derived?": false + } + } + } + ] + }, + "dead3MonthsBeforeMeasurePeriod": { + "title": "Deceased", + "description": "Patient Characteristic Expired: Deceased", + "standard_category": "individual_characteristic", + "qds_data_type": "individual_characteristic", + "code_list_id": "2.16.840.1.113883.3.67.1.101.11.721", + "property": "expired", + "type": "characteristic", + "definition": "patient_characteristic_expired", + "hard_status": false, + "negation": false, + "source_data_criteria": "PatientCharacteristicExpiredDeceased", + "inline_code_list": { + "SNOMED-CT": [ + "18632008", + "371828006" + ] + }, + "temporal_references": [ + { + "type": "SBS", + "reference": "MeasurePeriod", + "range": { + "type": "IVL_PQ", + "low": { + "type": "PQ", + "unit": "mo", + "value": "3", + "inclusive?": true, + "derived?": false + } + } + } + ] + }, + + "dead3MonthsAfterMeasurePeriod": { + "title": "Deceased", + "description": "Patient Characteristic Expired: Deceased", + "standard_category": "individual_characteristic", + "qds_data_type": "individual_characteristic", + "code_list_id": "2.16.840.1.113883.3.67.1.101.11.721", + "property": "expired", + "type": "characteristic", + "definition": "patient_characteristic_expired", + "hard_status": false, + "negation": false, + "source_data_criteria": "PatientCharacteristicExpiredDeceased", + "inline_code_list": { + "SNOMED-CT": [ + "18632008", + "371828006" + ] + }, + "temporal_references": [ + { + "type": "SAS", + "reference": "MeasurePeriod", + "range": { + "type": "IVL_PQ", + "low": { + "type": "PQ", + "unit": "mo", + "value": "3", + "inclusive?": true, + "derived?": false + } + } + } + ] + }, + "deadBetween5and6MonthsDuringMeasurePeriod": { + "title": "Deceased", + "description": "Patient Characteristic Expired: Deceased", + "standard_category": "individual_characteristic", + "qds_data_type": "individual_characteristic", + "code_list_id": "2.16.840.1.113883.3.67.1.101.11.721", + "property": "expired", + "type": "characteristic", + "definition": "patient_characteristic_expired", + "hard_status": false, + "negation": false, + "source_data_criteria": "PatientCharacteristicExpiredDeceased", + "inline_code_list": { + "SNOMED-CT": [ + "18632008", + "371828006" + ] + }, + "temporal_references": [ + { + "type": "SAS", + "reference": "MeasurePeriod", + "range": { + "type": "IVL_PQ", + "low": { + "type": "PQ", + "unit": "mo", + "value": "5", + "inclusive?": true, + "derived?": false + }, + "high": { + "type": "PQ", + "unit": "mo", + "value": "6", + "inclusive?": true, + "derived?": false + } + } + } + ] + }, "genderMale": { "title": "Gender", "standard_category": "individual_characteristic", diff --git a/test/unit/hqmf_from_json_javascript_test.rb b/test/unit/hqmf_from_json_javascript_test.rb index a0b3d02..c43e4b5 100644 --- a/test/unit/hqmf_from_json_javascript_test.rb +++ b/test/unit/hqmf_from_json_javascript_test.rb @@ -53,6 +53,42 @@ def test_converted_hqmf assert !@context.eval("hqmfjs.ageBetween40and49(numeratorPatient).isTrue()") assert !@context.eval("hqmfjs.ageBetween50and59(numeratorPatient).isTrue()") assert !@context.eval("hqmfjs.ageBetween60and64(numeratorPatient).isTrue()") + + + # record does not have a death date so false + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2010,11).to_i}") + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2010,10).to_i}") + assert @context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2011,2).to_i}") + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2011,4).to_i}") + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert @context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2011,6).to_i}") + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert @context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert @context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") + + @context.eval("numeratorPatient.json['deathdate']=#{Time.utc(2011,9).to_i}") + assert !@context.eval("hqmfjs.dead3MonthsBeforeMeasurePeriod(numeratorPatient).isTrue()") + assert @context.eval("hqmfjs.dead3MonthsAfterMeasurePeriod(numeratorPatient).isTrue()") + assert !@context.eval("hqmfjs.deadBetween5and6MonthsDuringMeasurePeriod(numeratorPatient).isTrue()") # Birthdate function assert_equal 1, @context.eval("hqmfjs.birthdateThirtyYearsBeforeMeasurementPeriod(numeratorPatient)").count