-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added String Value Type for FHIR Mapping transformation (#46)
* Add string value type for CodeValueFhir templates * Updated documentation for new string value type. * Fix unit test to reflect real and valid FHIR component format Co-authored-by: Maurizio Macagno <[email protected]>
- Loading branch information
Showing
11 changed files
with
317 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/lib/Microsoft.Health.Fhir.Ingest/Template/StringFhirValueType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Template | ||
{ | ||
public class StringFhirValueType : FhirValueType | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/lib/Microsoft.Health.Fhir.R4.Ingest/Template/StringFhirValueProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using EnsureThat; | ||
using Hl7.Fhir.Model; | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Template | ||
{ | ||
public class StringFhirValueProcessor : FhirValueProcessor<StringFhirValueType, (DateTime start, DateTime end, IEnumerable<(DateTime, string)> values), Element> | ||
{ | ||
protected override Element CreateValueImpl(StringFhirValueType template, (DateTime start, DateTime end, IEnumerable<(DateTime, string)> values) inValue) | ||
{ | ||
EnsureArg.IsNotNull(template, nameof(template)); | ||
|
||
return new FhirString(inValue.values.Single().Item2); | ||
} | ||
|
||
protected override Element MergeValueImpl(StringFhirValueType template, (DateTime start, DateTime end, IEnumerable<(DateTime, string)> values) inValue, Element existingValue) | ||
{ | ||
if (!(existingValue is FhirString)) | ||
{ | ||
throw new NotSupportedException($"Element {nameof(existingValue)} expected to be of type {typeof(FhirString)}."); | ||
} | ||
|
||
// Only a single value, just replace. | ||
return CreateValueImpl(template, inValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...est.UnitTests/TestInput/data_CodeValueFhirTemplate_CodeableConceptAndStringComponent.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"templateType": "CodeValueFhir", | ||
"template": { | ||
"codes": [ | ||
{ | ||
"code": "deviceEvent", | ||
"system": "https://www.contoso.com/events/v1", | ||
"display": "Device Event" | ||
} | ||
], | ||
"periodInterval": 0, | ||
"typeName": "alarmEvent", | ||
"value": { | ||
"text": "Alarm!", | ||
"codes": [ | ||
{ | ||
"code": "alarmEvent", | ||
"system": "https://www.contoso.com/events/v1", | ||
"display": "Alarm Event" | ||
} | ||
], | ||
"valueName": "alarm", | ||
"valueType": "CodeableConcept" | ||
}, | ||
"components": [ | ||
{ | ||
"codes": [ | ||
{ | ||
"code": "reasonText", | ||
"display": "Reason Text", | ||
"system": "https://www.contoso.com/events/v1" | ||
} | ||
], | ||
"value": { | ||
"valueName": "reason", | ||
"valueType": "String" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,5 @@ | |
} | ||
} | ||
] | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test/Microsoft.Health.Fhir.Ingest.UnitTests/TestInput/data_CodeValueFhirTemplate_String.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"templateType": "CodeValueFhir", | ||
"template": { | ||
"periodInterval": 0, | ||
"typeName": "stringDetail", | ||
"value": { | ||
"valueName": "reasonText", | ||
"valueType": "String" | ||
} | ||
} | ||
} |
132 changes: 66 additions & 66 deletions
132
...emplate/QuanityFhirValueProcessorTests.cs → ...mplate/QuantityFhirValueProcessorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using Hl7.Fhir.Model; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Template | ||
{ | ||
public class QuanityFhirValueProcessorTests | ||
{ | ||
[Fact] | ||
public void GivenValidTemplate_WhenCreateValue_ThenSampledDataProperlyConfigured_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType | ||
{ | ||
Unit = "myUnit", | ||
System = "mySystem", | ||
Code = "myCode", | ||
}; | ||
|
||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "22.4") }); | ||
var result = processor.CreateValue(template, data) as Quantity; | ||
Assert.NotNull(result); | ||
Assert.Equal("myUnit", result.Unit); | ||
Assert.Equal("mySystem", result.System); | ||
Assert.Equal("myCode", result.Code); | ||
Assert.Equal(22.4m, result.Value); | ||
} | ||
|
||
[Fact] | ||
public void GivenInvalidElementType_WhenMergeValue_ThenNotSupportedExceptionThrown_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType(); | ||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "value") }); | ||
|
||
Assert.Throws<NotSupportedException>(() => processor.MergeValue(template, data, new FhirDateTime())); | ||
} | ||
|
||
[Fact] | ||
public void GivenValidTemplate_WhenMergeValue_ThenMergeValueReturned_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType | ||
{ | ||
Unit = "myUnit", | ||
System = "mySystem", | ||
Code = "myCode", | ||
}; | ||
|
||
var oldQuantity = new Quantity { Value = 1, System = "s", Code = "c", Unit = "u" }; | ||
|
||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "22.4") }); | ||
var result = processor.MergeValue(template, data, oldQuantity) as Quantity; | ||
Assert.NotNull(result); | ||
Assert.Equal("myUnit", result.Unit); | ||
Assert.Equal("mySystem", result.System); | ||
Assert.Equal("myCode", result.Code); | ||
Assert.Equal(22.4m, result.Value); | ||
} | ||
} | ||
} | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using Hl7.Fhir.Model; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Template | ||
{ | ||
public class QuantityFhirValueProcessorTests | ||
{ | ||
[Fact] | ||
public void GivenValidTemplate_WhenCreateValue_ThenSampledDataProperlyConfigured_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType | ||
{ | ||
Unit = "myUnit", | ||
System = "mySystem", | ||
Code = "myCode", | ||
}; | ||
|
||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "22.4") }); | ||
var result = processor.CreateValue(template, data) as Quantity; | ||
Assert.NotNull(result); | ||
Assert.Equal("myUnit", result.Unit); | ||
Assert.Equal("mySystem", result.System); | ||
Assert.Equal("myCode", result.Code); | ||
Assert.Equal(22.4m, result.Value); | ||
} | ||
|
||
[Fact] | ||
public void GivenInvalidElementType_WhenMergeValue_ThenNotSupportedExceptionThrown_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType(); | ||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "value") }); | ||
|
||
Assert.Throws<NotSupportedException>(() => processor.MergeValue(template, data, new FhirDateTime())); | ||
} | ||
|
||
[Fact] | ||
public void GivenValidTemplate_WhenMergeValue_ThenMergeValueReturned_Test() | ||
{ | ||
var processor = new QuantityFhirValueProcessor(); | ||
var template = new QuantityFhirValueType | ||
{ | ||
Unit = "myUnit", | ||
System = "mySystem", | ||
Code = "myCode", | ||
}; | ||
|
||
var oldQuantity = new Quantity { Value = 1, System = "s", Code = "c", Unit = "u" }; | ||
|
||
var data = (DateTime.Now, DateTime.UtcNow, new (DateTime, string)[] { (DateTime.UtcNow, "22.4") }); | ||
var result = processor.MergeValue(template, data, oldQuantity) as Quantity; | ||
Assert.NotNull(result); | ||
Assert.Equal("myUnit", result.Unit); | ||
Assert.Equal("mySystem", result.System); | ||
Assert.Equal("myCode", result.Code); | ||
Assert.Equal(22.4m, result.Value); | ||
} | ||
} | ||
} |
Oops, something went wrong.