Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: social history conversion #7

Merged
merged 15 commits into from
Nov 14, 2024
Merged
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
55 changes: 22 additions & 33 deletions data/Templates/eCR/Entry/SocialHistory/_entry.liquid
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
{% if entry.observation -%}
{% assign observationId = entry.observation | to_json_string | generate_uuid -%}
{% if entry.observation.code.nullFlavor or entry.observation.value.nullFlavor -%}
{% else -%}
{% if entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.34.3.45' -%}
{% elsif entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.200' -%}
{% assign birthSObs = entry.observation %}
{% elsif entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.15.2.3.48' -%}
{% else -%}
{% if entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.109' -%}
{% include 'Resource/ObservationHomeEnv' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% elsif entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.15.2.3.47' -%}
{% include 'Resource/ObservationDisabilityStatus' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% elsif entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.217' -%}
{% include 'Resource/ObservationPastPresentOccupation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% elsif entry.observation.templateId and entry.observation.templateId.root and entry.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.221' -%}
{% include 'Resource/ObservationUsualWork' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% else -%}
{% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% endif -%}
{% capture shouldRender -%}
{%- include 'Utils/IsSocialHistoryObservation' observation: entry.observation -%}
{%- endcapture -%}
{% if shouldRender contains "true" -%}
{% assign observationId = entry.observation | to_json_string | generate_uuid -%}
{% assign firstTemplate = entry.observation.templateId | to_array | first -%}
{% if firstTemplate.root == '2.16.840.1.113883.10.20.22.4.109' -%}
{% include 'Resource/ObservationHomeEnv' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.15.2.3.47' -%}
{% include 'Resource/ObservationDisabilityStatus' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.22.4.217' -%}
{% include 'Resource/ObservationPastPresentOccupation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.22.4.221' -%}
{% include 'Resource/ObservationUsualWork' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.15.3.8' -%}
{% include 'Resource/ObservationPregnancyStatus' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% elsif entry.observation.code.code == '76690-7' -%}
{% include 'Resource/ObservationSexualOrientation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% else -%}
{% include 'Resource/Observation' observationCategory: 'social-history', observationEntry: entry.observation, ID: observationId -%}
{% endif -%}
{% endif -%}
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% endif %}
{% elsif entry.act %}
{% assign observationId = entry.act | to_json_string | generate_uuid -%}
{% if entry.act.templateId and entry.act.templateId.root and entry.act.templateId.root == "2.16.840.1.113883.10.20.15.2.3.1" %}
{% include 'Resource/ObservationTravelHistory' observationCategory: 'social-history', observationEntry: entry.act, ID: observationId -%}
{% endif %}
{% endif -%}

{% for socialObservation in SOCIALOBS -%}
{% assign observationId = socialObservation.observation | to_json_string | generate_uuid -%}
{% if socialObservation.observation.templateId and socialObservation.observation.templateId[0] and socialObservation.observation.templateId[0].root and socialObservation.observation.templateId[0].root == '2.16.840.1.113883.10.20.22.4.38' and socialObservation.observation.code and socialObservation.observation.code.code == '76690-7' -%}
{% include 'Resource/ObservationSexualOrientation' observationCategory: 'social-history', observationEntry: socialObservation.observation, ID: observationId -%},
{% include 'Reference/Observation/Subject' ID: observationId, REF: fullPatientId -%}
{% endif -%}
{% endfor -%}
8 changes: 2 additions & 6 deletions data/Templates/eCR/Extension/_BirthSex.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"extension" : [
{
"url" : "value",
"valueCodeableConcept" : {
"coding" : [
{ {% include 'DataType/Coding' Coding: birthSObs.value -%} },
]
},
{% include 'Utils/ValueHelper' value: birthSobs.value, origText: SOCIALTEXT -%}
},
],
{% endif -%}
{% endif -%}
8 changes: 2 additions & 6 deletions data/Templates/eCR/Extension/_GenderIdentity.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"extension" : [
{
"url" : "value",
"valueCodeableConcept" : {
"coding" : [
{ {% include 'DataType/Coding' Coding: gendIdOb.value -%} },
]
},
{% include 'Utils/ValueHelper' value: gendIdOb.value, origText: SOCIALTEXT -%}
},
],
{% endif -%}
{% endif -%}
4 changes: 2 additions & 2 deletions data/Templates/eCR/Extension/_TribalAffiliation.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{% if tribeAOb.value -%}
{
"url" : "EnrolledTribeMember",
"valueBoolean" : {{tribeAOb.value.value}}
{% include 'Utils/ValueHelper' value: tribeAOb.value, origText: SOCIALTEXT -%}
},
{% endif -%}
],
{% endif -%}
{% endif -%}
4 changes: 2 additions & 2 deletions data/Templates/eCR/Header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@

{% if msg.ClinicalDocument.recordTarget.patientRole -%}
{% assign patientSectionObservations = true -%}
{% include 'Section/SocialHistory' SOCIALOBS: socialObs -%}
{% include 'Resource/Patient' patientRole: msg.ClinicalDocument.recordTarget.patientRole ID: patientId SOCIALOBS: socialObs contact: msg.ClinicalDocument.participant.associatedEntity -%}
{% include 'Section/SocialHistory' SOCIALOBS: socialObs SOCIALTEXT: socialHistoryText -%}
{% include 'Resource/Patient' patientRole: msg.ClinicalDocument.recordTarget.patientRole ID: patientId SOCIALOBS: socialObs SOCIALTEXT: socialHistoryText contact: msg.ClinicalDocument.participant.associatedEntity -%}
Comment on lines +140 to +141
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socialHistoryText isn't defined yet right? So is the point of passing the blank socialHistoryText to Section/SocialHistory to give it a value that can be used in Resource/Patient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's a weird hack that takes advantage of leaky variable scopes 😬

{% assign careTeam = msg | get_first_ccda_sections_by_template_id: '2.16.840.1.113883.10.20.22.2.500' %}
{% if careTeam %}
{% assign careTeamId = careTeam.2_16_840_1_113883_10_20_22_2_500 | to_json_string | generate_uuid -%}
Expand Down
17 changes: 11 additions & 6 deletions data/Templates/eCR/Resource/_Composition.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,17 @@
{
"reference": "{{ fullObservationId }}",
},
{% elsif sectionEntry.observation.templateId and sectionEntry.observation.templateId[0] and sectionEntry.observation.templateId[0].root and sectionEntry.observation.templateId[0].root == '2.16.840.1.113883.10.20.22.4.38' and sectionEntry.observation.code and sectionEntry.observation.code.code == '76690-7' -%}
{% assign observationId = sectionEntry.observation | to_json_string | generate_uuid -%}
{% assign fullObservationId = observationId | prepend: 'Observation/' -%}
{
"reference": "{{ fullObservationId }}",
},
{% elsif component.section.code.code == "29762-2" -%}
{% capture shouldRender -%}
{%- include 'Utils/IsSocialHistoryObservation' observation: sectionEntry.observation -%}
{%- endcapture -%}
{%- if shouldRender contains "true" -%}
{% assign observationId = sectionEntry.observation | to_json_string | generate_uuid -%}
{% assign fullObservationId = observationId | prepend: 'Observation/' -%}
{
"reference": "{{ fullObservationId }}",
},
{% endif -%}
{% endif -%}
{% endfor -%}
],
Expand Down
4 changes: 2 additions & 2 deletions data/Templates/eCR/Resource/_Condition.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
{% assign templateIdString = relatedEntry.act.templateId.root | to_json_string -%}
{% if templateIdString contains '"2.16.840.1.113883.10.20.22.4.64"' or templateIdString contains "2.16.840.1.113883.10.20.22.4.202" and relatedEntry.act.text.reference.value -%}
{% assign commentRefVal = relatedEntry.act.text.reference.value | replace: '#', '' -%}
{% assign commentText = text._innerText | find_inner_text_by_id: commentRefVal -%}
"text": "{{ commentText | escape_special_chars }}",
{% assign commentText = text._innerText | find_inner_text_by_id: commentRefVal -%}
"text": "{{ commentText | clean_string_from_tabs | escape_special_chars }}",
{% endif -%}
{% endfor -%}

Expand Down
30 changes: 1 addition & 29 deletions data/Templates/eCR/Resource/_Observation.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,7 @@
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.targetSiteCode -%}
},
{% if observationEntry.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.value -%}
},
{% elsif observationEntry.value.value -%}
"valueQuantity":
{
"value":{{ observationEntry.value.value }},
{% if observationEntry.value.unit and observationEntry.value.unit != "null" -%}
"unit":"{{ observationEntry.value.unit }}",
{% endif -%}
},
{% else -%}
{% if observationEntry.value._ %}
"valueString":"{{ observationEntry.value._ }}",
{% else %}
{% assign obsRefVal = observationEntry.value.reference.value | replace: '#', '' -%}
{% assign valueStringObject = text | find_object_by_id: obsRefVal -%}
{% if valueStringObject != null %}
{% if valueStringObject._ != null %}
{% assign valueString = valueStringObject._ | concat_strings %}
{% elsif valueStringObject.content != null %}
{% assign valueString = valueStringObject.content | concat_strings %}
{% endif %}
"valueString": "{{ valueString | replace: '\n', '\\n' }}",
{% endif %}
{% endif %}
{% endif -%}
{% include 'Utils/ValueHelper' value: observationEntry.value, origText: text._innerText %}
"referenceRange":
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@
{% if observationEntry.effectiveTime.low.value == null -%}
"effectiveDateTime":"{{ observationEntry.effectiveTime.value | format_as_date_time }}",
{% endif -%}
{% if observationEntry.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.value -%}
},
{% elsif observationEntry.value.value -%}
"valueBoolean": {{ observationEntry.value.value }},
{% endif -%}
{% include 'Utils/ValueHelper' value: observationEntry.value, origText: text._innerText -%}
},
"request":{
"method":"PUT",
Expand Down
15 changes: 1 addition & 14 deletions data/Templates/eCR/Resource/_ObservationHomeEnv.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,7 @@
{% if observationEntry.effectiveTime.low.value == null -%}
"effectiveDateTime":"{{ observationEntry.effectiveTime.value | format_as_date_time }}",
{% endif -%}
{% if observationEntry.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.value -%}
},
{% elsif observationEntry.value.value -%}
"valueQuantity":
{
"value":{{ observationEntry.value.value }},
"unit":"{{ observationEntry.value.unit }}",
},
{% else -%}
"valueString":"{{ observationEntry.value._ }}",
{% endif -%}
{% include 'Utils/ValueHelper' value: observationEntry.value, origText: text._innerText %}
},
"request":{
"method":"PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,7 @@
{% if observationEntry.effectiveTime.low.value == null -%}
"effectiveDateTime":"{{ observationEntry.effectiveTime.value | format_as_date_time }}",
{% endif -%}
{% if observationEntry.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.value -%},
{% assign obsValueTrans = observationEntry.value.translation | to_array -%}
{% if obsValueTrans.first -%}
{% for obsValueTran in obsValueTrans -%}
{% include 'DataType/CodeableConcept' CodeableConcept: obsValueTran -%},
{% endfor -%}
{% endif -%}
},
{% elsif observationEntry.value.value -%}
"valueQuantity":
{
"value":{{ observationEntry.value.value }},
"unit":"{{ observationEntry.value.unit }}",
},
{% else -%}
"valueString":"{{ observationEntry.value._ }}",
{% endif -%}
{% include 'Utils/ValueHelper' value: observationEntry.value, origText: text._innerText -%}
"component" : [
{% assign obsRelationships = observationEntry.entryRelationship | to_array -%}
{% for obsRelation in obsRelationships -%}
Expand All @@ -91,26 +72,7 @@
{% include 'DataType/CodeableConcept' CodeableConcept: obsRelation.observation.code -%}
{% endif -%}
},
{% if obsRelation.observation.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: obsRelation.observation.value -%},
{% assign obsValueTransRel = obsRelation.observation.value.translation | to_array -%}
{% if obsValueTransRel.first -%}
{% for obsValueTranRel in obsValueTransRel -%}
{% include 'DataType/CodeableConcept' CodeableConcept: obsValueTranRel -%},
{% endfor -%}
{% endif -%}
},
{% elsif obsRelation.observation.value.value -%}
"valueQuantity":
{
"value":{{ obsRelation.observation.value.value }},
"unit":"{{ obsRelation.observation.value.unit }}",
},
{% else -%}
"valueString":"{{ obsRelation.observation.value._ }}",
{% endif -%}
{% include 'Utils/ValueHelper' value: obsRelation.observation.value, origText: text._innerText -%}
},
{% endfor -%}
],
Expand Down
42 changes: 2 additions & 40 deletions data/Templates/eCR/Resource/_ObservationPregnancyStatus.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,7 @@
{% if observationEntry.effectiveTime.low.value == null -%}
"effectiveDateTime":"{{ observationEntry.effectiveTime.value | format_as_date_time }}",
{% endif -%}
{% if observationEntry.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: observationEntry.value -%},
{% assign obsValueTrans = observationEntry.value.translation | to_array -%}
{% if obsValueTrans.first -%}
{% for obsValueTran in obsValueTrans -%}
{% include 'DataType/CodeableConcept' CodeableConcept: obsValueTran -%},
{% endfor -%}
{% endif -%}
},
{% elsif observationEntry.value.value -%}
"valueQuantity":
{
"value":{{ observationEntry.value.value }},
"unit":"{{ observationEntry.value.unit }}",
},
{% else -%}
"valueString":"{{ observationEntry.value._ }}",
{% endif -%}
{% include 'Utils/ValueHelper' value: observationEntry.value, origText: text._innerText -%}
"component" : [
{% assign obsRelationships = observationEntry.entryRelationship | to_array -%}
{% for obsRelation in obsRelationships -%}
Expand All @@ -91,26 +72,7 @@
{% include 'DataType/CodeableConcept' CodeableConcept: obsRelation.observation.code -%}
{% endif -%}
},
{% if obsRelation.observation.value.code -%}
"valueCodeableConcept":
{
{% include 'DataType/CodeableConcept' CodeableConcept: obsRelation.observation.value -%},
{% assign obsValueTransRel = obsRelation.observation.value.translation | to_array -%}
{% if obsValueTransRel.first -%}
{% for obsValueTranRel in obsValueTransRel -%}
{% include 'DataType/CodeableConcept' CodeableConcept: obsValueTranRel -%},
{% endfor -%}
{% endif -%}
},
{% elsif obsRelation.observation.value.value -%}
"valueQuantity":
{
"value":{{ obsRelation.observation.value.value }},
"unit":"{{ obsRelation.observation.value.unit }}",
},
{% else -%}
"valueString":"{{ obsRelation.observation.value._ }}",
{% endif -%}
{% include 'Utils/ValueHelper' value: obsRelation.observation.value, origText: text._innerText -%}
},
{% endfor -%}
],
Expand Down
Loading
Loading