Skip to content

Commit

Permalink
Merge pull request #210 from microsoft/dotliquid
Browse files Browse the repository at this point in the history
prepare for client update
  • Loading branch information
qiwjin authored Feb 25, 2021
2 parents 06126b2 + 695159d commit b7001db
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 59 deletions.
36 changes: 0 additions & 36 deletions data/Templates/Hl7v2/Resource/_Observation.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@
{% endif -%}{% endif -%}
},
},
"valueRange":
{
{% if OBX.2.Value == "SN" -%}
{% include 'DataType/SNRange' SN: OBX.5 -%}
{% endif -%}
"low":
{
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
{% endif -%}
},
"high":
{
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
{% endif -%}
},
},
"interpretation":
[
{ {% include 'DataType/CWECodeableConcept' mapping: 'CodeSystem/InterpretationCode', CWE: OBX.8 -%} },
Expand Down Expand Up @@ -185,24 +167,6 @@
{% endif -%}{% endif -%}
},
},
"valueRange":
{
{% if OBX.2.Value == "SN" -%}
{% include 'DataType/SNRange' SN: OBX.5 -%}
{% endif -%}
"low":
{
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
{% endif -%}
},
"high":
{
{% if OBX.2.Value == "SN" and OBX.5.3.Value == "-" -%}
{% include 'DataType/CWEQuantity' CWE: OBX.6 -%}
{% endif -%}
},
},
"referenceRange":
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hl7.Fhir.R4" Version="2.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Hl7.Fhir.Serialization;
using Microsoft.Health.Fhir.Liquid.Converter.Hl7v2;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand All @@ -26,6 +27,7 @@ public class RuleBasedTests
private static readonly string _hl7DataFolder = Path.Combine(Constants.SampleDataDirectory, "Hl7v2");

private static readonly Hl7v2TemplateProvider _hl7TemplateProvider = new Hl7v2TemplateProvider(_hl7TemplateFolder);
private static readonly FhirJsonParser _fhirParser = new FhirJsonParser();

private static readonly int _maxRevealDepth = 1 << 7;

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

[Fact]
public async Task CheckParserFunctionality()
{
var jsonResult = await Task.FromResult(@"{
""resourceType"": ""Observation"",
""id"": ""209c8566-dafa-22b6-31f6-e4c00e649c61"",
""valueQuantity"": {
""code"": ""mg/dl""
},
""valueRange"": {
""low"": {
""value"": ""182""
}
}
}");
try
{
var bundle = _fhirParser.Parse<Hl7.Fhir.Model.Observation>(jsonResult);
Assert.Null(bundle);
}
catch (FormatException fe)
{
Assert.NotNull(fe);
}
}

[Theory]
[MemberData(nameof(GetHL7V2Cases))]
[MemberData(nameof(GetCCDACases))]
public async Task CheckPassFhirParser(string templateName, string samplePath)
{
var result = await ConvertData(templateName, samplePath);
var jsonResult = JsonConvert.SerializeObject(result, Formatting.Indented);
try
{
var bundle = _fhirParser.Parse<Hl7.Fhir.Model.Bundle>(jsonResult);
Assert.NotNull(bundle);
}
catch (FormatException fe)
{
Assert.Null(fe);
}
}

private async Task<JObject> ConvertData(string templateName, string samplePath)
=> JObject.Parse(new Hl7v2Processor()
.Convert(await File.ReadAllTextAsync(samplePath, Encoding.UTF8), templateName, _hl7TemplateProvider));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@
"valueQuantity": {
"code": "mg/dl"
},
"valueRange": {
"low": {
"value": "182"
}
},
"interpretation": [
{
"coding": [
Expand All @@ -223,11 +218,6 @@
"valueQuantity": {
"code": "mg/dl"
},
"valueRange": {
"low": {
"value": "182"
}
},
"referenceRange": [
{
"text": "70_105"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public async Task GivenAnEmptyInputFolder_WhenPushOCIFiles_OneBaseLayerWillBePus
string testPushNewBaseLayerImageReference = _containerRegistryServer + "/templatetest:empty";
var pushManager = new OCIFileManager(testPushNewBaseLayerImageReference, emptyFolder);
pushManager.PackOCIImage();
await Assert.ThrowsAsync<DirectoryNotFoundException>(() => pushManager.PushOCIImageAsync());
await Assert.ThrowsAsync<OverlayException>(() => pushManager.PushOCIImageAsync());

ClearFolder(emptyFolder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task GivenAnInValidImageReference_WhenPullAndPushImageUseOras_Excep
File.Copy(_userLayerTemplatePath, "TestData/PushTest/userLayer.tar.gz", true);
string imageReference = _containerRegistryServer + reference;
OrasClient orasClient = new OrasClient(imageReference);
await Assert.ThrowsAsync<OrasException>(() => orasClient.PushImageAsync("TestData/PushTest"));
await Assert.ThrowsAsync<OrasException>(() => orasClient.PushImageAsync("TestData/PushTest", new List<string> { "baseLayer.tar.gz", "userLayer.tar.gz" }));
await Assert.ThrowsAsync<OrasException>(() => orasClient.PullImageAsync("TestData/PushTest"));
ClearFolder("TestData/PushTest");
}
Expand All @@ -129,7 +129,7 @@ public async Task GivenValidInputFolder_WhenPushUseOras_ImageWillBePushedAsync(s

string testImageReference = _containerRegistryServer + "/testFolder";
OrasClient testOrasClient = new OrasClient(imageReference);
var ex = await Record.ExceptionAsync(async () => await orasClient.PushImageAsync(outputFolder));
var ex = await Record.ExceptionAsync(async () => await orasClient.PushImageAsync(outputFolder, new List<string> { "TestData/TarGzFiles/baseLayer.tar.gz" }));
Assert.Null(ex);
ClearFolder(outputFolder);
}
Expand All @@ -147,7 +147,7 @@ public async Task GivenAValidImageReference_WhenPushImageUseOras_ImageWillBePush
File.Copy(_userLayerTemplatePath, "TestData/PushTest/userLayer.tar.gz", true);
string imageReference = _containerRegistryServer + "/testimage:test";
OrasClient orasClient = new OrasClient(imageReference);
var ex = await Record.ExceptionAsync(() => orasClient.PushImageAsync("TestData/PushTest"));
var ex = await Record.ExceptionAsync(() => orasClient.PushImageAsync("TestData/PushTest", new List<string> { "baseLayer.tar.gz", "userLayer.tar.gz" }));
Assert.Null(ex);
ClearFolder("TestData/PushTest");
}
Expand All @@ -163,7 +163,7 @@ public async Task GivenAValidImageReference_WhenPushEmptyFolderUseOras_ImageWill
Directory.CreateDirectory("TestData/Empty");
string imageReference = _containerRegistryServer + "/testimage:test";
OrasClient orasClient = new OrasClient(imageReference);
await Assert.ThrowsAsync<OverlayException>(async () => await orasClient.PushImageAsync("TestData/Empty"));
await Assert.ThrowsAsync<OverlayException>(async () => await orasClient.PushImageAsync("TestData/Empty", new List<string> { }));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Threading.Tasks;

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

Task PushImageAsync(string inputFolder);
Task PushImageAsync(string inputFolder, List<string> filePathList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// -------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -30,18 +31,21 @@ public async Task PullImageAsync(string outputFolder)
await OrasExecutionAsync(command, Directory.GetCurrentDirectory());
}

public async Task PushImageAsync(string inputFolder)
public async Task PushImageAsync(string inputFolder, List<string> filePathList)
{
string argument = string.Empty;
string command = $"push \"{_imageReference}\"";

var filePathToPush = Directory.EnumerateFiles(inputFolder, "*.tar.gz", SearchOption.AllDirectories);

// In order to remove image's directory prefix. (e.g. "layers/layer1.tar.gz" --> "layer1.tar.gz"
// Change oras working folder to inputFolder
foreach (var filePath in filePathToPush)
foreach (var filePath in filePathList)
{
argument += $" \"{Path.GetRelativePath(inputFolder, filePath)}\"";
if (!File.Exists(Path.Combine(inputFolder, filePath)))
{
throw new OverlayException(TemplateManagementErrorCode.ImageLayersNotFound, "Image layer not found");
}

argument += $" \"{filePath}\"";
}

if (string.IsNullOrEmpty(argument))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="mkdir ..\..\bin &amp; tar -zcvf ../../bin/Hl7v2DefaultTemplates.tar.gz -C ../../data/Templates/Hl7v2 ." />
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public void PackOCIImage(bool ignoreBaseLayers = false)

public async Task PushOCIImageAsync()
{
await _orasClient.PushImageAsync(_overlayFS.WorkingImageLayerFolder);
var rawLayers = _overlayFS.ReadImageLayers();
var fileLayers = _overlayOperator.ExtractOCIFileLayers(rawLayers);
var sortedLayers = _overlayOperator.SortOCIFileLayersBySequenceNumber(fileLayers);
await _orasClient.PushImageAsync(_overlayFS.WorkingImageLayerFolder, sortedLayers.Select(layer => layer.FileName).ToList());
}

private OCIFileLayer GenerateBaseFileLayer(List<OCIArtifactLayer> baseArtifactLayers)
Expand Down

0 comments on commit b7001db

Please sign in to comment.