Skip to content
Open
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
130 changes: 70 additions & 60 deletions data/Templates/eCR/Entry/Pregnancy/entry.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,73 @@
{% else -%}
{% assign templateIds = entry.observation.templateId | to_array -%}
{% for tempId in templateIds -%}
{% if tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.15.3.8' or tempId.root == '2.16.840.1.113883.10.20.22.4.2' or tempId.root == '2.16.840.1.113883.10.20.22.4.4' -%}
{% continue %}
{% elsif tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.30.3.34' -%}
{% include 'Resource/ObservationLastMenstrualPeriod', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.22.4.281' -%}
{% include 'Resource/ObservationPregnancyIntent', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.22.4.294' -%}
{% include 'Resource/ObservationPregnancyLastLiveBirth', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.22.4.285' -%}
{% include 'Resource/ObservationPostpartumStatus', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.22.4.293' -%}
{% comment %} Supplemental pregnancy observation {% endcomment %}
{% include 'Resource/ObservationPregnancyStatus', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId, text: text -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% comment %} Add supplemental pregnancy data {% endcomment %}
{% assign rels = entry.observation.entryRelationship | to_array %}
{% for rel in rels -%}
{% assign relObsId = rel | to_json_string | generate_uuid %}
{% assign fullRelObsId = relObsId | prepend: 'Observation/' %}
{% comment %} Add birth outcome obs with focus on this pregnancy obs {% endcomment %}
{% if rel.typeCode == "COMP" and rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.284' %}
{% include 'Resource/ObservationPregnancyOutcome', observationCategory: 'exam', observationEntry: rel.observation, ID: relObsId, birthOrder: rel.sequenceNumber.value -%}
{% include 'Reference/Observation/Subject', ID: relObsId, REF: fullPatientId -%}
{% include 'Reference/Observation/Focus', ID: relObsId, REF: fullObservationId -%}
{% comment %} Check the entry relationships of the outcome for any procedures (expecting method of delivery) - add as a partOf this outcome obs {% endcomment %}
{% assign procedureRels = rel.observation.entryRelationship | to_array %}
{% for procedureRel in procedureRels %}
{% if procedureRel.procedure.classCode == "PROC" %}
{% assign procedureTemplateIds = procedureRel.procedure.templateId | to_array -%}
{% if procedureTemplateIds.first.root == '2.16.840.1.113883.10.20.22.4.14' or procedureTemplateIds.first.root == '2.16.840.1.113883.10.20.22.4.299' %}
{% assign procedureId = procedureRel.procedure | to_json_string | generate_uuid %}
{% assign fullProcedureId = procedureId | prepend: 'Procedure/' %}
{% include 'Resource/ProcedurePregnancyFinalRouteMethodDelivery.liquid', ID: procedureId, procedureEntry: procedureRel.procedure %}
{% include 'Reference/Observation/PartOf', ID: relObsId, REF: fullProcedureId %}
{% if tempId and tempId.root %}
{% if tempId.root == '2.16.840.1.113883.10.20.15.3.8' or tempId.root == '2.16.840.1.113883.10.20.22.4.2' or tempId.root == '2.16.840.1.113883.10.20.22.4.4' -%}
{% continue %}
{% elsif tempId.root == '2.16.840.1.113883.10.20.30.3.34' -%}
{% include 'Resource/ObservationLastMenstrualPeriod', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId.root == '2.16.840.1.113883.10.20.22.4.281' -%}
{% include 'Resource/ObservationPregnancyIntent', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId.root == '2.16.840.1.113883.10.20.22.4.294' -%}
{% include 'Resource/ObservationPregnancyLastLiveBirth', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId.root == '2.16.840.1.113883.10.20.22.4.285' -%}
{% include 'Resource/ObservationPostpartumStatus', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% elsif tempId.root == '2.16.840.1.113883.10.20.22.4.293' -%}
{% comment %} Supplemental pregnancy observation {% endcomment %}
{% include 'Resource/ObservationPregnancyStatus', observationCategory: 'exam', observationEntry: entry.observation, ID: observationId, text: text -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% comment %} Add supplemental pregnancy data {% endcomment %}
{% assign rels = entry.observation.entryRelationship | to_array %}
{% for rel in rels -%}
{% assign relObsId = rel | to_json_string | generate_uuid %}
{% assign fullRelObsId = relObsId | prepend: 'Observation/' %}
{% comment %} Add birth outcome obs with focus on this pregnancy obs {% endcomment %}
{% if rel.typeCode == "COMP" and rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.284' %}
{% include 'Resource/ObservationPregnancyOutcome', observationCategory: 'exam', observationEntry: rel.observation, ID: relObsId, birthOrder: rel.sequenceNumber.value -%}
{% include 'Reference/Observation/Subject', ID: relObsId, REF: fullPatientId -%}
{% include 'Reference/Observation/Focus', ID: relObsId, REF: fullObservationId -%}
{% comment %} Check the entry relationships of the outcome for any procedures (expecting method of delivery) - add as a partOf this outcome obs {% endcomment %}
{% assign procedureRels = rel.observation.entryRelationship | to_array %}
{% for procedureRel in procedureRels %}
{% if procedureRel.procedure.classCode == "PROC" %}
{% assign procedureTemplateIds = procedureRel.procedure.templateId | to_array -%}
{% if procedureTemplateIds.first.root == '2.16.840.1.113883.10.20.22.4.14' or procedureTemplateIds.first.root == '2.16.840.1.113883.10.20.22.4.299' %}
{% assign procedureId = procedureRel.procedure | to_json_string | generate_uuid %}
{% assign fullProcedureId = procedureId | prepend: 'Procedure/' %}
{% include 'Resource/ProcedurePregnancyFinalRouteMethodDelivery.liquid', ID: procedureId, procedureEntry: procedureRel.procedure %}
{% include 'Reference/Observation/PartOf', ID: relObsId, REF: fullProcedureId %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% comment %} Add other supplemental pregnancy observations as a hasMember on this pregnancy obs {% endcomment %}
{% elsif rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.286' or rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.295' or rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.296' %}
{% include 'Resource/ObservationPregnancySupplementalData', observationEntry: rel.observation, ID: relObsId, templateId: rel.observation.templateId.root -%}
{% include 'Reference/Observation/Subject', ID: relObsId, REF: fullPatientId -%}
{% include 'Reference/Observation/HasMember', ID: observationId, REF: fullRelObsId %}
{% else %} {% comment %} Also handle related findings - may have multiple template ids {% endcomment %}
{% assign templateIds = rel.observation.templateId | to_array -%}
{% if templateIds.first.root == '2.16.840.1.113883.10.20.22.4.4' or templateIds.first.root == '2.16.840.1.113883.10.20.22.4.298' %}
{% include 'Resource/ObservationPregnancySupplementalData', observationEntry: rel.observation, ID: relObsId, templateId: templateIds.first.root -%}
{% endfor %}
{% comment %} Add other supplemental pregnancy observations as a hasMember on this pregnancy obs {% endcomment %}
{% elsif rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.286' or rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.295' or rel.observation.templateId.root == '2.16.840.1.113883.10.20.22.4.296' %}
{% include 'Resource/ObservationPregnancySupplementalData', observationEntry: rel.observation, ID: relObsId, templateId: rel.observation.templateId.root -%}
{% include 'Reference/Observation/Subject', ID: relObsId, REF: fullPatientId -%}
{% include 'Reference/Observation/HasMember', ID: observationId, REF: fullRelObsId %}
{% else %} {% comment %} Also handle related findings - may have multiple template ids {% endcomment %}
{% assign templateIds = rel.observation.templateId | to_array -%}
{% if templateIds.first.root == '2.16.840.1.113883.10.20.22.4.4' or templateIds.first.root == '2.16.840.1.113883.10.20.22.4.298' %}
{% include 'Resource/ObservationPregnancySupplementalData', observationEntry: rel.observation, ID: relObsId, templateId: templateIds.first.root -%}
{% include 'Reference/Observation/Subject', ID: relObsId, REF: fullPatientId -%}
{% include 'Reference/Observation/HasMember', ID: observationId, REF: fullRelObsId %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% else -%}
{% if tempId and tempId.root and tempId.root == '2.16.840.1.113883.10.20.22.4.300' or tempId.root == '2.16.840.1.113883.10.20.22.4.301' %}
{% comment %} [C-CDA PREG] D(Rh) Type or [C-CDA PREG] D(Rh) Sensitized - Labs {% endcomment %}
{% assign observationCategory = 'laboratory' %}
{% else %}
{% assign observationCategory = 'exam' %}
{% endfor %}
{% else -%}
{% if tempId.root == '2.16.840.1.113883.10.20.22.4.300' or tempId.root == '2.16.840.1.113883.10.20.22.4.301' %}
{% comment %} [C-CDA PREG] D(Rh) Type or [C-CDA PREG] D(Rh) Sensitized - Labs {% endcomment %}
{% assign observationCategory = 'laboratory' %}
{% else %}
{% assign observationCategory = 'exam' %}
{% endif -%}
{% include 'Resource/Observation', observationCategory: observationCategory, observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% endif -%}
{% include 'Resource/Observation', observationCategory: observationCategory, observationEntry: entry.observation, ID: observationId -%}
{% include 'Reference/Observation/Subject', ID: observationId, REF: fullPatientId -%}
{% endif -%}
{% endif %}
{% endfor -%}
{% endif -%}
{% elsif entry.substanceAdministration -%}
Expand All @@ -89,4 +91,12 @@
{% endif %}
{% endif %}
{% endfor %}
{% elsif entry.organizer and entry.organizer.templateId.root == '2.16.840.1.113883.10.20.22.4.292' -%}
{% comment %} Pregnancy Summary Organizer {% endcomment %}
{% assign observationId = entry.organizer | to_json_string | generate_uuid -%}
{% include 'Resource/Observation', observationEntry: entry.organizer, ID: observationId -%}
{% assign comps = entry.organizer.component | to_array -%}
{% for component in comps %}
{% include 'Entry/Pregnancy/entry_organizer_component', component: component, organizerId: observationId %}
{% endfor %}
{% endif -%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if component.observation %}
{% assign observationId = component.observation | to_json_string | generate_uuid -%}
{% assign fullObservationId = observationId | prepend: 'Observation/' -%}
{% include 'Resource/Observation', observationCategory: 'social-history', observationEntry: component.observation, ID: observationId -%}
{% include 'Reference/Observation/HasMember', ID: organizerId, REF: fullObservationId -%}
{% endif %}
7 changes: 7 additions & 0 deletions data/Templates/eCR/Resource/Composition.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
{
"reference": "{{ fullSubstanceAdministrationId }}",
},
{% elsif sectionEntry.organizer != nil and component.section.templateId.root == '2.16.840.1.113883.10.20.22.2.80' %}
{% comment %} Pregnancy Summary Organizer {% endcomment %}
{% assign organizerId = sectionEntry.organizer | to_json_string | generate_uuid -%}
{% assign fullOrganizerId = organizerId | prepend: 'Observation/' %}
{
"reference": "{{ fullOrganizerId }}",
},
{% endif -%}
{% endfor -%}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,90 @@ public async System.Threading.Tasks.Task Obs_Status_GivenNoLabObsResultStatus_Re
Assert.Contains(@"""status"":""preliminary""", actualContent);
Assert.DoesNotContain(@"""url"": ""http://terminology.hl7.org/ValueSet/v2-0085""", actualContent);
}

[Fact]
public void PregnancySummaryObservation_AllFields()
{
var xmlString =
@"
<organizer classCode=""CLUSTER"" moodCode=""EVN"">
<!-- [C-CDA PREG] Pregnancy Summary Organizer -->
<templateId root=""2.16.840.1.113883.10.20.22.4.292"" extension=""2018-04-01"" />
<id root=""0a648e8a-c61c-46dd-bd0c-3081db0a9f66"" />
<code code=""10162-6""
displayName=""History of Pregnancies Narrative""
codeSystem=""2.16.840.1.113883.6.1""
codeSystemName=""LOINC"" />
<statusCode code=""active"" />
<effectiveTime value=""201801051015""/>
</organizer>";

var parser = new CcdaDataParser();
var parsedXml = parser.Parse(xmlString) as Dictionary<string, object>;

var attributes = new Dictionary<string, object>
{
{ "ID", "1234" },
{ "observationEntry", parsedXml["organizer"] },
};

var actualFhir = GetFhirObjectFromTemplate<Observation>(ECRPath, attributes);

Assert.Equal("Observation", actualFhir.TypeName);
Assert.NotNull(actualFhir.Id);
Assert.NotEmpty(actualFhir.Identifier);
Assert.Equal("Preliminary", actualFhir.Status.ToString());

Assert.Equal("http://loinc.org", actualFhir.Code.Coding.First().System);
Assert.Equal("10162-6", actualFhir.Code.Coding.First().Code);
Assert.Equal("History of pregnancies Narrative", actualFhir.Code.Coding.First().Display);

Assert.Equal("2018-01-05T10:15:00", (actualFhir.Effective as FhirDateTime)?.Value);
}

[Fact]
public void PregnancySummaryObservationComponent_AllFields()
{
var xmlString =
@"
<observation classCode=""OBS"" moodCode=""EVN"">
<!-- [C-CDA PREG] Gravidity (Total Pregnancies) -->
<templateId root=""2.16.840.1.113883.10.20.22.4.282"" extension=""2018-04-01"" />
<id root=""18701808-d4cb-4a6c-b10b-4eaeb66f1158"" />
<code code=""11996-6""
displayName=""[#] Pregnancies""
codeSystem=""2.16.840.1.113883.6.1""
codeSystemName=""LOINC"" />
<statusCode code=""completed"" />
<effectiveTime value=""201801051015"" />
<value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:type=""INT"" value=""6"" />
</observation>";

var parser = new CcdaDataParser();
var parsedXml = parser.Parse(xmlString) as Dictionary<string, object>;

var attributes = new Dictionary<string, object>
{
{ "ID", "1234" },
{ "observationEntry", parsedXml["observation"] },
};

var actualFhir = GetFhirObjectFromTemplate<Observation>(ECRPath, attributes);

Assert.Equal("Observation", actualFhir.TypeName);
Assert.NotNull(actualFhir.Id);
Assert.NotEmpty(actualFhir.Identifier);
Assert.Equal("Final", actualFhir.Status.ToString());

Assert.Equal("http://loinc.org", actualFhir.Code.Coding.First().System);
Assert.Equal("11996-6", actualFhir.Code.Coding.First().Code);
Assert.Equal("[#] Pregnancies", actualFhir.Code.Coding.First().Display);

Assert.Equal("2018-01-05T10:15:00", (actualFhir.Effective as FhirDateTime)?.Value);

var fhirInteger = actualFhir.Value as Hl7.Fhir.Model.Integer;
Assert.NotNull(fhirInteger);
Assert.Equal(6, fhirInteger.Value);
}
}
}
Loading