Skip to content

Commit b7001db

Browse files
authored
Merge pull request #210 from microsoft/dotliquid
prepare for client update
2 parents 06126b2 + 695159d commit b7001db

File tree

10 files changed

+68
-59
lines changed

10 files changed

+68
-59
lines changed

data/Templates/Hl7v2/Resource/_Observation.liquid

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,6 @@
5858
{% endif -%}{% endif -%}
5959
},
6060
},
61-
"valueRange":
62-
{
63-
{% if OBX.2.Value == "SN" -%}
64-
{% include 'DataType/SNRange' SN: OBX.5 -%}
65-
{% endif -%}
66-
"low":
67-
{
68-
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
69-
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
70-
{% endif -%}
71-
},
72-
"high":
73-
{
74-
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
75-
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
76-
{% endif -%}
77-
},
78-
},
7961
"interpretation":
8062
[
8163
{ {% include 'DataType/CWECodeableConcept' mapping: 'CodeSystem/InterpretationCode', CWE: OBX.8 -%} },
@@ -185,24 +167,6 @@
185167
{% endif -%}{% endif -%}
186168
},
187169
},
188-
"valueRange":
189-
{
190-
{% if OBX.2.Value == "SN" -%}
191-
{% include 'DataType/SNRange' SN: OBX.5 -%}
192-
{% endif -%}
193-
"low":
194-
{
195-
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
196-
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
197-
{% endif -%}
198-
},
199-
"high":
200-
{
201-
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
202-
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
203-
{% endif -%}
204-
},
205-
},
206170
"referenceRange":
207171
[
208172
{

src/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16+
<PackageReference Include="Hl7.Fhir.R4" Version="2.0.3" />
1617
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
1718
<PackageReference Include="xunit" Version="2.4.1" />
1819
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

src/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests/RuleBasedTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Text;
1313
using System.Text.RegularExpressions;
1414
using System.Threading.Tasks;
15+
using Hl7.Fhir.Serialization;
1516
using Microsoft.Health.Fhir.Liquid.Converter.Hl7v2;
1617
using Newtonsoft.Json;
1718
using Newtonsoft.Json.Linq;
@@ -26,6 +27,7 @@ public class RuleBasedTests
2627
private static readonly string _hl7DataFolder = Path.Combine(Constants.SampleDataDirectory, "Hl7v2");
2728

2829
private static readonly Hl7v2TemplateProvider _hl7TemplateProvider = new Hl7v2TemplateProvider(_hl7TemplateFolder);
30+
private static readonly FhirJsonParser _fhirParser = new FhirJsonParser();
2931

3032
private static readonly int _maxRevealDepth = 1 << 7;
3133

@@ -140,6 +142,50 @@ public async Task CheckPassOfficialValidator(string templateName, string sampleP
140142
Directory.Delete(resultFolder, true);
141143
}
142144

145+
[Fact]
146+
public async Task CheckParserFunctionality()
147+
{
148+
var jsonResult = await Task.FromResult(@"{
149+
""resourceType"": ""Observation"",
150+
""id"": ""209c8566-dafa-22b6-31f6-e4c00e649c61"",
151+
""valueQuantity"": {
152+
""code"": ""mg/dl""
153+
},
154+
""valueRange"": {
155+
""low"": {
156+
""value"": ""182""
157+
}
158+
}
159+
}");
160+
try
161+
{
162+
var bundle = _fhirParser.Parse<Hl7.Fhir.Model.Observation>(jsonResult);
163+
Assert.Null(bundle);
164+
}
165+
catch (FormatException fe)
166+
{
167+
Assert.NotNull(fe);
168+
}
169+
}
170+
171+
[Theory]
172+
[MemberData(nameof(GetHL7V2Cases))]
173+
[MemberData(nameof(GetCCDACases))]
174+
public async Task CheckPassFhirParser(string templateName, string samplePath)
175+
{
176+
var result = await ConvertData(templateName, samplePath);
177+
var jsonResult = JsonConvert.SerializeObject(result, Formatting.Indented);
178+
try
179+
{
180+
var bundle = _fhirParser.Parse<Hl7.Fhir.Model.Bundle>(jsonResult);
181+
Assert.NotNull(bundle);
182+
}
183+
catch (FormatException fe)
184+
{
185+
Assert.Null(fe);
186+
}
187+
}
188+
143189
private async Task<JObject> ConvertData(string templateName, string samplePath)
144190
=> JObject.Parse(new Hl7v2Processor()
145191
.Convert(await File.ReadAllTextAsync(samplePath, Encoding.UTF8), templateName, _hl7TemplateProvider));

src/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests/TestData/Expected/Hl7v2/ORU_R01/ORU-R01-RMGEAD-expected.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@
192192
"valueQuantity": {
193193
"code": "mg/dl"
194194
},
195-
"valueRange": {
196-
"low": {
197-
"value": "182"
198-
}
199-
},
200195
"interpretation": [
201196
{
202197
"coding": [
@@ -223,11 +218,6 @@
223218
"valueQuantity": {
224219
"code": "mg/dl"
225220
},
226-
"valueRange": {
227-
"low": {
228-
"value": "182"
229-
}
230-
},
231221
"referenceRange": [
232222
{
233223
"text": "70_105"

src/Microsoft.Health.Fhir.TemplateManagement.FunctionalTests/OCIArtifactFunctionalTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public async Task GivenAnEmptyInputFolder_WhenPushOCIFiles_OneBaseLayerWillBePus
323323
string testPushNewBaseLayerImageReference = _containerRegistryServer + "/templatetest:empty";
324324
var pushManager = new OCIFileManager(testPushNewBaseLayerImageReference, emptyFolder);
325325
pushManager.PackOCIImage();
326-
await Assert.ThrowsAsync<DirectoryNotFoundException>(() => pushManager.PushOCIImageAsync());
326+
await Assert.ThrowsAsync<OverlayException>(() => pushManager.PushOCIImageAsync());
327327

328328
ClearFolder(emptyFolder);
329329
}

src/Microsoft.Health.Fhir.TemplateManagement.UnitTests/Client/OrasClientTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task GivenAnInValidImageReference_WhenPullAndPushImageUseOras_Excep
108108
File.Copy(_userLayerTemplatePath, "TestData/PushTest/userLayer.tar.gz", true);
109109
string imageReference = _containerRegistryServer + reference;
110110
OrasClient orasClient = new OrasClient(imageReference);
111-
await Assert.ThrowsAsync<OrasException>(() => orasClient.PushImageAsync("TestData/PushTest"));
111+
await Assert.ThrowsAsync<OrasException>(() => orasClient.PushImageAsync("TestData/PushTest", new List<string> { "baseLayer.tar.gz", "userLayer.tar.gz" }));
112112
await Assert.ThrowsAsync<OrasException>(() => orasClient.PullImageAsync("TestData/PushTest"));
113113
ClearFolder("TestData/PushTest");
114114
}
@@ -129,7 +129,7 @@ public async Task GivenValidInputFolder_WhenPushUseOras_ImageWillBePushedAsync(s
129129

130130
string testImageReference = _containerRegistryServer + "/testFolder";
131131
OrasClient testOrasClient = new OrasClient(imageReference);
132-
var ex = await Record.ExceptionAsync(async () => await orasClient.PushImageAsync(outputFolder));
132+
var ex = await Record.ExceptionAsync(async () => await orasClient.PushImageAsync(outputFolder, new List<string> { "TestData/TarGzFiles/baseLayer.tar.gz" }));
133133
Assert.Null(ex);
134134
ClearFolder(outputFolder);
135135
}
@@ -147,7 +147,7 @@ public async Task GivenAValidImageReference_WhenPushImageUseOras_ImageWillBePush
147147
File.Copy(_userLayerTemplatePath, "TestData/PushTest/userLayer.tar.gz", true);
148148
string imageReference = _containerRegistryServer + "/testimage:test";
149149
OrasClient orasClient = new OrasClient(imageReference);
150-
var ex = await Record.ExceptionAsync(() => orasClient.PushImageAsync("TestData/PushTest"));
150+
var ex = await Record.ExceptionAsync(() => orasClient.PushImageAsync("TestData/PushTest", new List<string> { "baseLayer.tar.gz", "userLayer.tar.gz" }));
151151
Assert.Null(ex);
152152
ClearFolder("TestData/PushTest");
153153
}
@@ -163,7 +163,7 @@ public async Task GivenAValidImageReference_WhenPushEmptyFolderUseOras_ImageWill
163163
Directory.CreateDirectory("TestData/Empty");
164164
string imageReference = _containerRegistryServer + "/testimage:test";
165165
OrasClient orasClient = new OrasClient(imageReference);
166-
await Assert.ThrowsAsync<OverlayException>(async () => await orasClient.PushImageAsync("TestData/Empty"));
166+
await Assert.ThrowsAsync<OverlayException>(async () => await orasClient.PushImageAsync("TestData/Empty", new List<string> { }));
167167
}
168168

169169
[Fact]

src/Microsoft.Health.Fhir.TemplateManagement/Client/IOrasClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// -------------------------------------------------------------------------------------------------
55

6+
using System.Collections.Generic;
67
using System.Threading.Tasks;
78

89
namespace Microsoft.Health.Fhir.TemplateManagement.Client
@@ -11,6 +12,6 @@ public interface IOrasClient
1112
{
1213
Task PullImageAsync(string outputFolder);
1314

14-
Task PushImageAsync(string inputFolder);
15+
Task PushImageAsync(string inputFolder, List<string> filePathList);
1516
}
1617
}

src/Microsoft.Health.Fhir.TemplateManagement/Client/OrasClient.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// -------------------------------------------------------------------------------------------------
55

66
using System;
7+
using System.Collections.Generic;
78
using System.Diagnostics;
89
using System.IO;
910
using System.Threading.Tasks;
@@ -30,18 +31,21 @@ public async Task PullImageAsync(string outputFolder)
3031
await OrasExecutionAsync(command, Directory.GetCurrentDirectory());
3132
}
3233

33-
public async Task PushImageAsync(string inputFolder)
34+
public async Task PushImageAsync(string inputFolder, List<string> filePathList)
3435
{
3536
string argument = string.Empty;
3637
string command = $"push \"{_imageReference}\"";
3738

38-
var filePathToPush = Directory.EnumerateFiles(inputFolder, "*.tar.gz", SearchOption.AllDirectories);
39-
4039
// In order to remove image's directory prefix. (e.g. "layers/layer1.tar.gz" --> "layer1.tar.gz"
4140
// Change oras working folder to inputFolder
42-
foreach (var filePath in filePathToPush)
41+
foreach (var filePath in filePathList)
4342
{
44-
argument += $" \"{Path.GetRelativePath(inputFolder, filePath)}\"";
43+
if (!File.Exists(Path.Combine(inputFolder, filePath)))
44+
{
45+
throw new OverlayException(TemplateManagementErrorCode.ImageLayersNotFound, "Image layer not found");
46+
}
47+
48+
argument += $" \"{filePath}\"";
4549
}
4650

4751
if (string.IsNullOrEmpty(argument))

src/Microsoft.Health.Fhir.TemplateManagement/Microsoft.Health.Fhir.TemplateManagement.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3838
</None>
3939
</ItemGroup>
40-
40+
4141
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
4242
<Exec Command="mkdir ..\..\bin &amp; tar -zcvf ../../bin/Hl7v2DefaultTemplates.tar.gz -C ../../data/Templates/Hl7v2 ." />
4343
</Target>

src/Microsoft.Health.Fhir.TemplateManagement/OCIFileManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public void PackOCIImage(bool ignoreBaseLayers = false)
7272

7373
public async Task PushOCIImageAsync()
7474
{
75-
await _orasClient.PushImageAsync(_overlayFS.WorkingImageLayerFolder);
75+
var rawLayers = _overlayFS.ReadImageLayers();
76+
var fileLayers = _overlayOperator.ExtractOCIFileLayers(rawLayers);
77+
var sortedLayers = _overlayOperator.SortOCIFileLayersBySequenceNumber(fileLayers);
78+
await _orasClient.PushImageAsync(_overlayFS.WorkingImageLayerFolder, sortedLayers.Select(layer => layer.FileName).ToList());
7679
}
7780

7881
private OCIFileLayer GenerateBaseFileLayer(List<OCIArtifactLayer> baseArtifactLayers)

0 commit comments

Comments
 (0)