Merge pull request #1016 from hapifhir/do-immunization30_40-notgiven

Fix handling of Immunization notGiven and status
This commit is contained in:
Grahame Grieve 2022-12-01 08:19:38 +11:00 committed by GitHub
commit c3cb8adf97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 392 additions and 24 deletions

View File

@ -26,8 +26,9 @@ public class BaseAdvisor_10_40 extends BaseAdvisor40<org.hl7.fhir.dstu2.model.Ex
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) {
List<String> paths = Arrays.asList(path.split(","));
return (paths.get(paths.size() - 1).equals("Conformance")) && (conformanceIgnoredUrls.contains(url));
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
return (lastPath.equals("Conformance")) && (conformanceIgnoredUrls.contains(url));
}
@Override

View File

@ -24,8 +24,9 @@ public class BaseAdvisor_10_50 extends BaseAdvisor50<org.hl7.fhir.dstu2.model.Ex
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) {
List<String> paths = Arrays.asList(path.split(","));
return (paths.get(paths.size() - 1).equals("Conformance")) && (conformanceIgnoredUrls.contains(url));
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
return (lastPath.equals("Conformance")) && (conformanceIgnoredUrls.contains(url));
}
public boolean ignoreType(@Nonnull String path,

View File

@ -27,8 +27,9 @@ public class BaseAdvisor_14_40 extends BaseAdvisor40<org.hl7.fhir.dstu2016may.mo
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) {
List<String> paths = Arrays.asList(path.split(","));
if ((paths.get(paths.size() - 1).equals("Conformance")) && (conformanceIgnoredUrls.contains(url))) {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if ((lastPath.equals("Conformance")) && (conformanceIgnoredUrls.contains(url))) {
return true;
} else {
return this.ignoredUrls.contains(url);

View File

@ -23,7 +23,8 @@ public class BaseAdvisor_14_50 extends BaseAdvisor50<org.hl7.fhir.dstu2016may.mo
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
return (paths.get(paths.size() - 1).equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url));
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
return (lastPath.equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url));
}
}

View File

@ -13,6 +13,8 @@ public class BaseAdvisor_30_40 extends BaseAdvisor40<org.hl7.fhir.dstu3.model.Ex
final List<String> capabilityStatementIgnoredUrls = Collections.singletonList("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown");
final List<String> immunizationIgnoredUrls = Collections.singletonList("http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven");
public BaseAdvisor_30_40() {
}
@ -23,7 +25,13 @@ public class BaseAdvisor_30_40 extends BaseAdvisor40<org.hl7.fhir.dstu3.model.Ex
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
return (paths.get(paths.size() - 1).equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url));
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if (lastPath.equals("CapabilityStatement")) {
return capabilityStatementIgnoredUrls.contains(url);
} else if (lastPath.equals("Immunization")) {
return immunizationIgnoredUrls.contains(url);
}
return false;
}
}

View File

@ -25,14 +25,15 @@ public class BaseAdvisor_30_50 extends BaseAdvisor50<org.hl7.fhir.dstu3.model.Ex
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
if ((paths.get(paths.size() - 1).equals("ValueSet")) && (valueSetIgnoredUrls.contains(url))) {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if ((lastPath.equals("ValueSet")) && (valueSetIgnoredUrls.contains(url))) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
return true;
} else
return (paths.get(paths.size() - 1).equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url));
return (lastPath.equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url));
}
}

View File

@ -30,12 +30,13 @@ public class BaseAdvisor_40_50 extends BaseAdvisor50<org.hl7.fhir.r4.model.Exten
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
if ((paths.get(paths.size() - 1).equals("TestScript")) && (TestScriptIgnoredUrls.contains(url))) {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if ((lastPath.equals("TestScript")) && (TestScriptIgnoredUrls.contains(url))) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
return true;
} else
return false;

View File

@ -23,12 +23,13 @@ public class BaseAdvisor_43_50 extends BaseAdvisor50<org.hl7.fhir.r4b.model.Exte
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
if ((paths.get(paths.size() - 1).equals("TestScript")) && (TestScriptIgnoredUrls.contains(url))) {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if ((lastPath.equals("TestScript")) && (TestScriptIgnoredUrls.contains(url))) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-ActorDefinition.")) {
return true;
} else if (paths.get(paths.size() - 1).equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
} else if (lastPath.equals("Basic") && url.startsWith("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.")) {
return true;
} else
return false;

View File

@ -10,10 +10,17 @@ import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Bool
import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Date30_40;
import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Immunization;
public class Immunization30_40 {
public static final String NOT_GIVEN_EXTENSION_URL = "http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven";
public static org.hl7.fhir.r4.model.Immunization convertImmunization(org.hl7.fhir.dstu3.model.Immunization src) throws FHIRException {
if (src == null)
return null;
@ -23,6 +30,14 @@ public class Immunization30_40 {
tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
if (src.hasStatus())
tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
if (src.hasNotGiven()) {
if (src.getNotGiven()) {
org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Immunization.ImmunizationStatus> notDoneElement = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Immunization.ImmunizationStatusEnumFactory());
notDoneElement.setValue(Immunization.ImmunizationStatus.NOTDONE);
tgt.setStatusElement(notDoneElement);
}
tgt.addExtension(getExtensionForNotGiven(src.getNotGiven()));
}
if (src.hasVaccineCode())
tgt.setVaccineCode(CodeableConcept30_40.convertCodeableConcept(src.getVaccineCode()));
if (src.hasPatient())
@ -57,6 +72,13 @@ public class Immunization30_40 {
return tgt;
}
public static org.hl7.fhir.r4.model.Extension getExtensionForNotGiven(boolean notGiven) {
org.hl7.fhir.r4.model.Extension extension = new org.hl7.fhir.r4.model.Extension();
extension.setUrl(NOT_GIVEN_EXTENSION_URL);
extension.setValue(new org.hl7.fhir.r4.model.BooleanType(notGiven));
return extension;
}
public static org.hl7.fhir.dstu3.model.Immunization convertImmunization(org.hl7.fhir.r4.model.Immunization src) throws FHIRException {
if (src == null)
return null;
@ -64,8 +86,18 @@ public class Immunization30_40 {
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
if (src.hasStatus())
if (src.hasStatus()) {
tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
if (src.getStatusElement().getValue() == Immunization.ImmunizationStatus.NOTDONE)
tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(true));
else
tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(false));
}
if (src.hasExtension(NOT_GIVEN_EXTENSION_URL)) {
Extension notGivenExtension = src.getExtensionByUrl(NOT_GIVEN_EXTENSION_URL);
if (notGivenExtension.hasValue() && notGivenExtension.getValueAsPrimitive() instanceof org.hl7.fhir.r4.model.BooleanType)
tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(((org.hl7.fhir.r4.model.BooleanType)notGivenExtension.getValueAsPrimitive()).getValue()));
}
if (src.hasVaccineCode())
tgt.setVaccineCode(CodeableConcept30_40.convertCodeableConcept(src.getVaccineCode()));
if (src.hasPatient())
@ -97,6 +129,8 @@ public class Immunization30_40 {
for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
tgt.getExplanation().addReason(CodeableConcept30_40.convertCodeableConcept(t));
return tgt;
}
@ -131,6 +165,7 @@ public class Immunization30_40 {
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
switch (src.getValue()) {
case COMPLETED:
case NOTDONE:
tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.COMPLETED);
break;
case ENTEREDINERROR:

View File

@ -0,0 +1,66 @@
package org.hl7.fhir.convertors.conv30_40;
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
public class Immunization30_40Test {
private org.hl7.fhir.r4.formats.JsonParser r4Parser = new org.hl7.fhir.r4.formats.JsonParser();
private org.hl7.fhir.dstu3.formats.JsonParser dstu3Parser = new org.hl7.fhir.dstu3.formats.JsonParser();
public static Stream<Arguments> getR4toDSTU3Arguments() {
return Stream.of(
Arguments.of("not-done no notGiven extension", "/immunization_40_not-done.json", "/immunization_30_completed_notGiven.json"),
Arguments.of("completed no notGiven extension", "/immunization_40_completed.json", "/immunization_30_completed_given.json"),
Arguments.of("entered-in-error no notGiven extension", "/immunization_40_entered-in-error.json", "/immunization_30_entered-in-error_given.json"),
Arguments.of("entered-in-error notGiven extension", "/immunization_40_entered-in-error_notGiven-extension.json", "/immunization_30_entered-in-error_notGiven.json")
);
}
@ParameterizedTest(name = "Test r4 -> dstu3 immunization conversions: {0}")
@MethodSource("getR4toDSTU3Arguments")
public void R4toDSTU3Tests(String testName, String r4InputResource, String dstu3ExpectedOutputResource) throws IOException {
InputStream r4_input = this.getClass().getResourceAsStream(r4InputResource);
InputStream dstu3ExpectedOutput = this.getClass().getResourceAsStream(dstu3ExpectedOutputResource);
org.hl7.fhir.r4.model.Immunization r4Actual = (org.hl7.fhir.r4.model.Immunization) r4Parser.parse(r4_input);
org.hl7.fhir.dstu3.model.Resource dstu3Converted = VersionConvertorFactory_30_40.convertResource(r4Actual, new BaseAdvisor_30_40(false));
org.hl7.fhir.dstu3.model.Resource dstu3Expected = dstu3Parser.parse(dstu3ExpectedOutput);
Assertions.assertTrue(dstu3Expected.equalsDeep(dstu3Converted),
"Failed comparing\n" + dstu3Parser.composeString(dstu3Expected) + "\nand\n" + dstu3Parser.composeString(dstu3Converted));
}
public static Stream<Arguments> getDSTU3toR4Arguments() {
return Stream.of(
Arguments.of("completed notGiven=true", "/immunization_30_completed_notGiven.json", "/immunization_40_not-done_notGiven-extension.json"),
Arguments.of("completed notGiven=false", "/immunization_30_completed_given.json", "/immunization_40_completed_given-extension.json"),
Arguments.of("entered-in-error notGiven=true", "/immunization_30_entered-in-error_notGiven.json", "/immunization_40_not-done_notGiven-extension.json")
);
}
@ParameterizedTest(name = "Test dstu3 -> r4 immunization conversions: {0}")
@MethodSource("getDSTU3toR4Arguments")
public void DSTU3toR4Tests(String testName, String dstu3InputResource, String r4ExpectedOutputResource) throws IOException {
InputStream dstu3_input = this.getClass().getResourceAsStream(dstu3InputResource);
org.hl7.fhir.dstu3.model.Immunization dstu3_actual = (org.hl7.fhir.dstu3.model.Immunization) dstu3Parser.parse(dstu3_input);
org.hl7.fhir.r4.model.Resource r4_conv = VersionConvertorFactory_30_40.convertResource(dstu3_actual, new BaseAdvisor_30_40(false));
InputStream r4_expected_output = this.getClass().getResourceAsStream(r4ExpectedOutputResource);
org.hl7.fhir.r4.model.Resource r4_expected = r4Parser.parse(r4_expected_output);
Assertions.assertTrue(r4_expected.equalsDeep(r4_conv),
"Failed comparing\n" + r4Parser.composeString(r4_expected) + "\nand\n" + r4Parser.composeString(r4_conv));
}
}

View File

@ -0,0 +1,24 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "completed",
"notGiven": false,
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"date": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,24 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "completed",
"notGiven": true,
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"date": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,24 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "entered-in-error",
"notGiven": false,
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"date": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,24 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "entered-in-error",
"notGiven": true,
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"date": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,23 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "completed",
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,29 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "completed",
"extension":[
{
"url":"http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven",
"valueBoolean":false
}
],
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,23 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "entered-in-error",
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,29 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"extension":[
{
"url":"http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven",
"valueBoolean":true
}
],
"status": "entered-in-error",
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,23 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"status": "not-done",
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}

View File

@ -0,0 +1,29 @@
{
"resourceType": "Immunization",
"id": "notGiven",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">dummyDiv</div>"
},
"extension":[
{
"url":"http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven",
"valueBoolean":true
}
],
"status": "not-done",
"vaccineCode": {
"coding": [
{
"system": "http://hl7.org/fhir/sid/cvx",
"code": "01",
"display": "DTP"
}
]
},
"patient": {
"reference": "Patient/example"
},
"occurrenceDateTime": "2013-01-10",
"primarySource": true
}