Skip to content

Commit

Permalink
Merge pull request #177 from microsoft/dotliquid
Browse files Browse the repository at this point in the history
Upgrade DotLiquid converter to v3.2
  • Loading branch information
BoyaWu10 authored Jan 13, 2021
2 parents 6f106e9 + 3376786 commit cbe5eab
Show file tree
Hide file tree
Showing 42 changed files with 731 additions and 254 deletions.
43 changes: 24 additions & 19 deletions data/Templates/Hl7v2/ADT_A01.liquid
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"resourceType": "Bundle",
"type": "transaction",
"type": "batch",
"entry": [
{% assign firstSegments = hl7v2Data | get_first_segments: 'PID|PD1|PV1|PV2|PR1|AVR|MSH' -%}
{% assign firstSegments = hl7v2Data | get_first_segments: 'PID|PD1|PV1|PV2|AVR|MSH' -%}

{% evaluate messageHeaderId using 'ID/MessageHeader' MSH: firstSegments.MSH -%}
{% if messageHeaderId -%}
Expand All @@ -15,7 +15,7 @@
{% include 'Resource/Patient' PID: firstSegments.PID, PD1: firstSegments.PD1, ID: patientId -%}
{% endif -%}

{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseID: patientId -%}
{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseId: patientId -%}
{% if provenanceId -%}
{% include 'Resource/Provenance' MSH: firstSegments.MSH, ORC: firstSegments.ORC, ID: provenanceId -%}
{% endif -%}
Expand All @@ -34,34 +34,39 @@
{% if encounterId -%}
{% include 'Resource/Encounter' PV1: firstSegments.PV1, PV2: firstSegments.PV2, ID: encounterId -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId -%}
{% evaluate locationId3 using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId3 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId3 -%}
{% endif -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId -%}
{% evaluate locationId6 using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId6 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId6 -%}
{% endif -%}

{% include 'Resource/Encounter' PV1: firstSegments.PV1, Location_ID_PV1_3: locationId3, Location_ID_PV1_6: locationId6, ID: encounterId -%}

{% if patientId -%}
{% include 'Reference/Encounter/Subject' ID: encounterId, REF: fullPatientId -%}
{% endif -%}
{% endif -%}

{% evaluate procedureId using 'ID/Procedure' PR1: firstSegments.PR1, baseId: patientId -%}
{% if procedureId -%}
{% include 'Resource/Procedure' PR1: firstSegments.PR1, ID: procedureId -%}
{% assign pr1SegmentLists = hl7v2Data | get_segment_lists: 'PR1' -%}
{% for pr1Segment in pr1SegmentLists.PR1 -%}
{% evaluate procedureId using 'ID/Procedure' PR1: pr1Segment, baseId: patientId -%}
{% if procedureId -%}
{% include 'Resource/Procedure' PR1: pr1Segment, ID: procedureId -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PR1.23 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PR1.23, ID: locationId -%}
{% endif -%}
{% evaluate locationId using 'ID/Location' PL: pr1Segment.23 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: pr1Segment.23, ID: locationId -%}
{% endif -%}

{% if patientId -%}
{% include 'Reference/Procedure/Subject' ID: procedureId, REF: fullPatientId -%}
{% if patientId -%}
{% include 'Reference/Procedure/Subject' ID: procedureId, REF: fullPatientId -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% endfor -%}

{% assign nk1SegmentLists = hl7v2Data | get_segment_lists: 'NK1' -%}
{% for nk1Segment in nk1SegmentLists.NK1 -%}
Expand Down
18 changes: 10 additions & 8 deletions data/Templates/Hl7v2/OML_O21.liquid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "Bundle",
"type": "transaction",
"type": "batch",
"entry": [
{% assign firstSegments = hl7v2Data | get_first_segments: 'PID|PD1|PV1|PV2|ORC|MSH' -%}

Expand All @@ -15,7 +15,7 @@
{% include 'Resource/Patient' PID: firstSegments.PID, PD1: firstSegments.PD1, ID: patientId -%}
{% endif -%}

{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseID: patientId -%}
{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseId: patientId -%}
{% if provenanceId -%}
{% include 'Resource/Provenance' MSH: firstSegments.MSH, ORC: firstSegments.ORC, ID: provenanceId -%}
{% endif -%}
Expand All @@ -35,16 +35,18 @@
{% assign fullEncounterId = encounterId | prepend: 'Encounter/' -%}
{% include 'Resource/Encounter' PV1: firstSegments.PV1, PV2: firstSegments.PV2, ID: encounterId -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId -%}
{% evaluate locationId3 using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId3 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId3 -%}
{% endif -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId -%}
{% evaluate locationId6 using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId6 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId6 -%}
{% endif -%}

{% include 'Resource/Encounter' PV1: firstSegments.PV1, Location_ID_PV1_3: locationId3, Location_ID_PV1_6: locationId6, ID: encounterId -%}

{% if patientId -%}
{% include 'Reference/Encounter/Subject' ID: encounterId, REF: fullPatientId -%}
{% endif -%}
Expand Down
20 changes: 11 additions & 9 deletions data/Templates/Hl7v2/ORU_R01.liquid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "Bundle",
"type": "transaction",
"type": "batch",
"entry": [
{% assign firstSegments = hl7v2Data | get_first_segments: 'PID|PD1|NK1|PV1|PV2|MSH' -%}

Expand All @@ -15,7 +15,7 @@
{% include 'Resource/Patient' PID: firstSegments.PID, PD1: firstSegments.PD1, ID: patientId -%}
{% endif -%}

{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseID: patientId -%}
{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseId: patientId -%}
{% if provenanceId -%}
{% include 'Resource/Provenance' MSH: firstSegments.MSH, ORC: firstSegments.ORC, ID: provenanceId -%}
{% endif -%}
Expand All @@ -35,16 +35,18 @@
{% assign fullEncounterId = encounterId | prepend: 'Encounter/' -%}
{% include 'Resource/Encounter' PV1: firstSegments.PV1, PV2: firstSegments.PV2, ID: encounterId -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId -%}
{% evaluate locationId3 using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId3 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId3 -%}
{% endif -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId -%}
{% evaluate locationId6 using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId6 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId6 -%}
{% endif -%}


{% include 'Resource/Encounter' PV1: firstSegments.PV1, Location_ID_PV1_3: locationId3, Location_ID_PV1_6: locationId6, ID: encounterId -%}

{% if patientId -%}
{% include 'Reference/Encounter/Subject' ID: encounterId, REF: fullPatientId -%}
{% endif -%}
Expand Down
14 changes: 7 additions & 7 deletions data/Templates/Hl7v2/Resource/_Encounter.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
{
"location":
{
{% if PV1.3 -%}
"reference":"Location/{{generateUUID PV1-3}}",
{% if Location_ID_PV1_3 -%}
"reference":"Location/{{ Location_ID_PV1_3 }}",
{% endif -%}
},
{% if PV1.2.1.Value != "P" -%}
{% if PV1.2.1.Value != "P" and Location_ID_PV1_3 -%}
"status":"active",
{% endif -%}
{% if PV1.2.1.Value == "P" -%}
{% if PV1.2.1.Value == "P" and Location_ID_PV1_3 -%}
"status":"planned",
{% endif -%}
},
{
"location":
{
{% if PV1.6 -%}
"reference":"Location/{{generateUUID PV1-6}}",
{% if Location_ID_PV1_6 -%}
"reference":"Location/{{ Location_ID_PV1_6 }}",
{% endif -%}
},
{% if PV1.6 -%}
{% if PV1.6 and Location_ID_PV1_6 -%}
"status":"completed",
{% endif -%}
},
Expand Down
8 changes: 6 additions & 2 deletions data/Templates/Hl7v2/Resource/_Patient.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
],
"name":
[
{% for p in PID.5.Repeats -%}
{
{% include 'DataType/XPN' XPN: PID.5 -%}
{% include 'DataType/XPN' XPN: p -%}
},
{% endfor -%}
{
{% include 'DataType/XPN' XPN: PID.9 -%}
},
Expand All @@ -53,9 +55,11 @@
"gender":"{{ PID.8.Value | get_property: 'CodeSystem/Gender', 'code' }}",
"address":
[
{% for p in PID.11.Repeats -%}
{
{% include 'DataType/XAD' XAD: PID.11 -%}
{% include 'DataType/XAD' XAD: p -%}
},
{% endfor -%}
{
"district":"{{ PID.12.Value }}",
},
Expand Down
4 changes: 2 additions & 2 deletions data/Templates/Hl7v2/Resource/_PractitionerRole.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"location":
[
{
{% if ROL.13 -%}
"reference":"Location/{{generateUUID ROL-13}}",
{% if Location_ID_ROL_13 -%}
"reference":"Location/{{ Location_ID_ROL_13 }}",
{% endif -%}
},
],
Expand Down
4 changes: 2 additions & 2 deletions data/Templates/Hl7v2/Resource/_Procedure.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
],
"location":
{
{% if PR1.23 -%}
"reference":"Location/{{generateUUID PR1-23}}",
{% if Location_ID_PR1_23 -%}
"reference":"Location/{{ Location_ID_PR1_23 }}",
{% endif -%}
},
},
Expand Down
18 changes: 10 additions & 8 deletions data/Templates/Hl7v2/VXU_V04.liquid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resourceType": "Bundle",
"type": "transaction",
"type": "batch",
"entry": [
{% assign firstSegments = hl7v2Data | get_first_segments: 'PID|PD1|PV1|ORC|MSH' -%}

Expand All @@ -15,7 +15,7 @@
{% include 'Resource/Patient' PID: firstSegments.PID, PD1: firstSegments.PD1, ID: patientId -%}
{% endif -%}

{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseID: patientId -%}
{% evaluate provenanceId using 'ID/Provenance' MSH: firstSegments.MSH, baseId: patientId -%}
{% if provenanceId -%}
{% include 'Resource/Provenance' MSH: firstSegments.MSH, ORC: firstSegments.ORC, ID: provenanceId -%}
{% endif -%}
Expand All @@ -34,15 +34,17 @@
{% if encounterId -%}
{% include 'Resource/Encounter' PV1: firstSegments.PV1, ID: encounterId -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId -%}
{% evaluate locationId3 using 'ID/Location' PL: firstSegments.PV1.3 -%}
{% if locationId3 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.3, ID: locationId3 -%}
{% endif -%}

{% evaluate locationId using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId -%}
{% evaluate locationId6 using 'ID/Location' PL: firstSegments.PV1.6 -%}
{% if locationId6 -%}
{% include 'Resource/Location' PL: firstSegments.PV1.6, ID: locationId6 -%}
{% endif -%}

{% include 'Resource/Encounter' PV1: firstSegments.PV1, Location_ID_PV1_3: locationId3, Location_ID_PV1_6: locationId6, ID: encounterId -%}

{% if patientId -%}
{% include 'Reference/Encounter/Subject' ID: encounterId, REF: fullPatientId -%}
Expand Down
26 changes: 22 additions & 4 deletions release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variables:
functionalTests: "**/*FunctionalTests/*.csproj"
buildConfiguration: 'Release'
major: 3
minor: 1
minor: 2
bulidnum: $[counter(format('{0}.{1}',variables['major'],variables['minor']), 100)]
revision: $[counter(format('{0:yyyyMMdd}', pipeline.startTime), 1)]
version: $(major).$(minor).$(bulidnum).$(revision)
Expand All @@ -29,6 +29,16 @@ stages:
- job: Build
steps:
- script: echo $(version)

- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: 'restore'
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration)'
feedsToUse: 'select'
vstsFeed: '7621b231-1a7d-4364-935b-2f72b911c43d/a60b7c8b-c6ae-4a8e-bd15-a526b603a1f2'

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
Expand Down Expand Up @@ -81,7 +91,7 @@ stages:
includeRootFolder: false
archiveType: 'tar'
tarCompression: 'gz'
archiveFile: '$(Build.SourcesDirectory)/data/Templates/DefaultTemplates.tar.gz'
archiveFile: '$(Build.SourcesDirectory)/data/Templates/Hl7v2DefaultTemplates.tar.gz'

- task: CopyFiles@2
displayName: 'copy DefaultTemplates to artifacts'
Expand Down Expand Up @@ -127,7 +137,10 @@ stages:
artifactName: FhirConverterBuild
downloadPath: $(System.DefaultWorkingDirectory)
- script: |
docker run --rm -d -p 5000:5000 --name registry stefanscherer/registry-windows:2.6.2
git clone -q https://github.com/sowu880/dockerfiles-windows.git
cd dockerfiles-windows/registry/
docker build -t registry-windows:2.7.1 .
docker run --rm -d -p 5000:5000 --name registry registry-windows:2.7.1
displayName: start registry
# - script: |
Expand Down Expand Up @@ -158,6 +171,11 @@ stages:
artifactName: FhirConverterBuild
downloadPath: $(System.DefaultWorkingDirectory)
- script: |
curl -LO https://github.com/deislabs/oras/releases/download/v0.8.1/oras_0.8.1_linux_amd64.tar.gz
mkdir -p oras-install/
tar -zxf oras_0.8.1_*.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras_0.8.1_*.tar.gz oras-install/
docker run --rm -d -p 5000:5000 --name registry registry:2
displayName: start registry
- script: |
Expand Down Expand Up @@ -194,7 +212,7 @@ stages:
tag: v$(major).$(minor).$(bulidnum)
assets: |
$(System.DefaultWorkingDirectory)/FhirConverterBuild/bin/**
$(System.DefaultWorkingDirectory)/FhirConverterBuild/data/Templates/DefaultTemplates.tar.gz
$(System.DefaultWorkingDirectory)/FhirConverterBuild/data/Templates/Hl7v2DefaultTemplates.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,22 @@ public void GivenAnInvalidTemplate_WhenConverting_ExceptionsShouldBeThrown()
var exception = Assert.Throws<RenderException>(() => hl7v2Processor.Convert(@"MSH|^~\&|", "template", new Hl7v2TemplateProvider(templateCollection)));
Assert.True(exception.InnerException is DotLiquid.Exceptions.StackLevelException);
}

[Fact]
public void GivenEscapedMessage_WhenConverting_ExpectedCharacterShouldbeReturned()
{
var hl7v2Processor = new Hl7v2Processor();
var templateDirectory = Path.Join(AppDomain.CurrentDomain.BaseDirectory, Constants.TemplateDirectory, "Hl7v2");
var inputContent = string.Join("\n", new List<string>
{
@"MSH|^~\&|FOO|BAR|FOO|BAR|20201225000000|FOO|ADT^A01|123456|P|2.3|||||||||||",
@"PR1|1|FOO|FOO^ESCAPED ONE \T\ ESCAPED TWO^BAR|ESCAPED THREE \T\ ESCAPED FOUR|20201225000000||||||||||",
});
var result = JObject.Parse(hl7v2Processor.Convert(inputContent, "ADT_A01", new Hl7v2TemplateProvider(templateDirectory)));

var texts = result.SelectTokens("$.entry[?(@.resource.resourceType == 'Procedure')].resource.code.text").Select(Convert.ToString);
var expected = new List<string> { "ESCAPED ONE & ESCAPED TWO", "ESCAPED THREE & ESCAPED FOUR" };
Assert.NotEmpty(texts.Intersect(expected));
}
}
}
Loading

0 comments on commit cbe5eab

Please sign in to comment.