diff --git a/src/lib/handlebars-converter/handlebars-helpers.js b/src/lib/handlebars-converter/handlebars-helpers.js index fc9cd939c..a3d804d56 100644 --- a/src/lib/handlebars-converter/handlebars-helpers.js +++ b/src/lib/handlebars-converter/handlebars-helpers.js @@ -643,6 +643,25 @@ module.exports.external = [ } } }, + { + name: 'isRaceUnknown', + description: 'determines if the race is unknown', + func: function isRaceUnknown(patient) { + const raceCodeNullFlavor = !!patient.raceCode?.nullFlavor; + const sdtcRaceCodeNullFlavor = !!patient["sdtc:raceCode"]?.nullFlavor; + return raceCodeNullFlavor || sdtcRaceCodeNullFlavor; + } + }, + { + name: 'isEthnicityUnknown', + description: 'Determines if the Ethnicity is Unknown (has a null flavor)', + func: function isEthnicityUnknown(patient) { + const ethnicGroupCodeNulllavor = !!patient.ethnicGroupCode?.nullFlavor; + const raceCodeNullFlavor = !!patient.raceCode?.nullFlavor; + const sdtcRaceCodeNullFlavor = !!patient["sdtc:raceCode"]?.nullFlavor; + return ethnicGroupCodeNulllavor || raceCodeNullFlavor || sdtcRaceCodeNullFlavor; + } + }, { name: 'getBirthSexInfo', description: "Returns first instance of birthSex id e.g. getBirthSexInfo msg '2.16.840.1.113883.10.20.22.2.14'", diff --git a/src/templates/cda/Extensions/Birthsex.hbs b/src/templates/cda/Extensions/Birthsex.hbs index 3c20d860f..90d02a784 100644 --- a/src/templates/cda/Extensions/Birthsex.hbs +++ b/src/templates/cda/Extensions/Birthsex.hbs @@ -1,5 +1,5 @@ { "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex", - "valueCode": "{{getBirthSexInfo msg '2.16.840.1.113883.10.20.22.4.200'}}" - } \ No newline at end of file + "valueCode": "{{birthsex}}" + } diff --git a/src/templates/cda/Extensions/Ethnicity.hbs b/src/templates/cda/Extensions/Ethnicity.hbs index 904dc6c91..5b2f8bd03 100644 --- a/src/templates/cda/Extensions/Ethnicity.hbs +++ b/src/templates/cda/Extensions/Ethnicity.hbs @@ -16,12 +16,11 @@ {{/if}} }, {{else}} - {{#if (or (eq this.code '2135-2') - (eq this.code '2186-5'))}} + {{#if (or (eq this.code '2135-2') (eq this.code '2186-5'))}} "url" : "ombCategory", {{else}} "url" : "detailed", - {{/if}} + {{/if}} "valueCoding" : {{>DataType/Coding.hbs code=this}}, {{/if}} }, @@ -40,6 +39,6 @@ "valueString":"{{patient.ethnicGroupCode.displayName}}", {{/if}} } - ], + ], {{/if}} } diff --git a/src/templates/cda/Resources/Patient.hbs b/src/templates/cda/Resources/Patient.hbs index 03f7d3df7..45ac19514 100644 --- a/src/templates/cda/Resources/Patient.hbs +++ b/src/templates/cda/Resources/Patient.hbs @@ -24,9 +24,17 @@ "birthDate":"{{addHyphensDate patientRole.patient.birthTime.value}}", "gender":"{{toLower patientRole.patient.administrativeGenderCode.displayName}}", "extension" : [ - {{>Extensions/Race.hbs patient=patientRole.patient}}, - {{>Extensions/Ethnicity.hbs patient=patientRole.patient}}, - {{>Extensions/Birthsex.hbs patient=patientRole.patient msg=msg}}, + {{#unless (isRaceUnknown patientRole.patient)}} + {{>Extensions/Race.hbs patient=patientRole.patient}}, + {{/unless}} + {{#unless (isEthnicityUnknown patientRole.patient)}} + {{>Extensions/Ethnicity.hbs patient=patientRole.patient}}, + {{/unless}} + {{#with (getBirthSexInfo msg '2.16.840.1.113883.10.20.22.4.200') as |birthsex|}} + {{#if birthsex}} + {{>Extensions/Birthsex.hbs patient=patientRole.patient birthsex=birthsex}}, + {{/if}} + {{/with}} ], "address": [