use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40 in project org.hl7.fhir.core by hapifhir.
the class ExtensionDefinitionGenerator method loadResource.
private Resource loadResource(InputStream inputStream, FHIRVersion v) throws IOException, FHIRException {
if (v == FHIRVersion._3_0_1) {
org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(inputStream);
return VersionConvertorFactory_30_40.convertResource(res, new BaseAdvisor_30_40(false));
} else if (v == FHIRVersion._1_4_0) {
org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(inputStream);
return VersionConvertorFactory_14_40.convertResource(res);
} else if (v == FHIRVersion._1_0_2) {
org.hl7.fhir.dstu2.model.Resource res = new org.hl7.fhir.dstu2.formats.JsonParser().parse(inputStream);
BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
return VersionConvertorFactory_10_40.convertResource(res, advisor);
} else if (v == FHIRVersion._4_0_0) {
return new JsonParser().parse(inputStream);
} else
throw new Error("Unsupported version " + v);
}
use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40 in project org.hl7.fhir.core by hapifhir.
the class ValueSet10_40 method convertValueSet.
public static org.hl7.fhir.r4.model.ValueSet convertValueSet(org.hl7.fhir.dstu2.model.ValueSet src, BaseAdvisor_10_40 advisor) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.ValueSet tgt = new org.hl7.fhir.r4.model.ValueSet();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
if (src.hasIdentifier())
tgt.addIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
if (src.hasVersionElement())
tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_40.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
if (src.hasDate())
tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_40.isJurisdiction(t))
tgt.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
else
tgt.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
if (src.hasImmutableElement())
tgt.setImmutableElement(Boolean10_40.convertBoolean(src.getImmutableElement()));
if (src.hasRequirements())
tgt.setPurpose(src.getRequirements());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
if (src.hasExtensible())
tgt.addExtension("http://hl7.org/fhir/StructureDefinition/valueset-extensible", new BooleanType(src.getExtensible()));
if (src.hasCompose()) {
if (src.hasCompose())
tgt.setCompose(convertValueSetComposeComponent(src.getCompose()));
tgt.getCompose().setLockedDate(src.getLockedDate());
}
if (src.hasCodeSystem() && advisor != null) {
org.hl7.fhir.r4.model.CodeSystem tgtcs = new org.hl7.fhir.r4.model.CodeSystem();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgtcs);
tgtcs.setUrl(src.getCodeSystem().getSystem());
tgtcs.addIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
tgtcs.setVersion(src.getCodeSystem().getVersion());
tgtcs.setName(src.getName() + " Code System");
tgtcs.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgtcs.setExperimental(src.getExperimental());
tgtcs.setPublisher(src.getPublisher());
for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact()) tgtcs.addContact(convertValueSetContactComponent(t));
if (src.hasDate())
tgtcs.setDate(src.getDate());
tgtcs.setDescription(src.getDescription());
for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_40.isJurisdiction(t))
tgtcs.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
else
tgtcs.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
tgtcs.setPurpose(src.getRequirements());
tgtcs.setCopyright(src.getCopyright());
tgtcs.setContent(CodeSystemContentMode.COMPLETE);
tgtcs.setCaseSensitive(src.getCodeSystem().getCaseSensitive());
for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent cs : src.getCodeSystem().getConcept()) processConcept(tgtcs.getConcept(), cs, tgtcs);
advisor.handleCodeSystem(tgtcs, tgt);
tgt.setUserData("r2-cs", tgtcs);
tgt.getCompose().addInclude().setSystem(tgtcs.getUrl());
}
if (src.hasExpansion())
tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
return tgt;
}
use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40 in project org.hl7.fhir.core by hapifhir.
the class ValueSet10_40 method convertValueSet.
public static org.hl7.fhir.dstu2.model.ValueSet convertValueSet(org.hl7.fhir.r4.model.ValueSet src, BaseAdvisor_10_40 advisor) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.ValueSet tgt = new org.hl7.fhir.dstu2.model.ValueSet();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
for (org.hl7.fhir.r4.model.Identifier i : src.getIdentifier()) tgt.setIdentifier(Identifier10_40.convertIdentifier(i));
if (src.hasVersionElement())
tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_40.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
for (org.hl7.fhir.r4.model.ContactDetail t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
if (src.hasDate())
tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
tgt.setLockedDate(src.getCompose().getLockedDate());
if (src.hasDescription())
tgt.setDescription(src.getDescription());
for (org.hl7.fhir.r4.model.UsageContext t : src.getUseContext()) if (t.hasValueCodeableConcept())
tgt.addUseContext(CodeableConcept10_40.convertCodeableConcept(t.getValueCodeableConcept()));
for (org.hl7.fhir.r4.model.CodeableConcept t : src.getJurisdiction()) tgt.addUseContext(CodeableConcept10_40.convertCodeableConcept(t));
if (src.hasImmutableElement())
tgt.setImmutableElement(Boolean10_40.convertBoolean(src.getImmutableElement()));
if (src.hasPurpose())
tgt.setRequirements(src.getPurpose());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
if (src.hasExtension("http://hl7.org/fhir/StructureDefinition/valueset-extensible"))
tgt.setExtensible(((BooleanType) src.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/valueset-extensible").getValue()).booleanValue());
org.hl7.fhir.r4.model.CodeSystem srcCS = (CodeSystem) src.getUserData("r2-cs");
if (srcCS == null)
srcCS = advisor.getCodeSystem(src);
if (srcCS != null) {
tgt.getCodeSystem().setSystem(srcCS.getUrl());
tgt.getCodeSystem().setVersion(srcCS.getVersion());
tgt.getCodeSystem().setCaseSensitive(srcCS.getCaseSensitive());
for (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cs : srcCS.getConcept()) processConcept(tgt.getCodeSystem().getConcept(), cs, srcCS);
}
if (src.hasCompose())
tgt.setCompose(convertValueSetComposeComponent(src.getCompose(), srcCS == null ? null : srcCS.getUrl()));
if (src.hasExpansion())
tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
return tgt;
}
use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40 in project org.hl7.fhir.core by hapifhir.
the class Conformance10_40 method convertConformance.
public static org.hl7.fhir.dstu2.model.Conformance convertConformance(org.hl7.fhir.r4.model.CapabilityStatement src, BaseAdvisor_10_40 advisor) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.Conformance tgt = new org.hl7.fhir.dstu2.model.Conformance();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
if (src.hasVersionElement())
tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_40.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
if (src.hasDate())
tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
for (org.hl7.fhir.r4.model.ContactDetail t : src.getContact()) tgt.addContact(convertConformanceContactComponent(t));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
if (src.hasPurpose())
tgt.setRequirements(src.getPurpose());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
if (src.hasKind())
tgt.setKindElement(convertConformanceStatementKind(src.getKindElement()));
if (src.hasSoftware())
tgt.setSoftware(convertConformanceSoftwareComponent(src.getSoftware()));
if (src.hasImplementation())
tgt.setImplementation(convertConformanceImplementationComponent(src.getImplementation()));
if (src.hasFhirVersion())
tgt.setFhirVersion(src.getFhirVersion().toCode());
if (src.hasExtension("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown"))
tgt.setAcceptUnknown(org.hl7.fhir.dstu2.model.Conformance.UnknownContentCode.fromCode(src.getExtensionByUrl("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown").getValue().primitiveValue()));
for (org.hl7.fhir.r4.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue());
for (CapabilityStatementRestComponent r : src.getRest()) for (CapabilityStatementRestResourceComponent rr : r.getResource()) for (org.hl7.fhir.r4.model.CanonicalType t : rr.getSupportedProfile()) tgt.addProfile(Canonical10_40.convertCanonicalToReference(t));
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestComponent t : src.getRest()) tgt.addRest(convertConformanceRestComponent(t));
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementMessagingComponent t : src.getMessaging()) tgt.addMessaging(convertConformanceMessagingComponent(t));
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementDocumentComponent t : src.getDocument()) tgt.addDocument(convertConformanceDocumentComponent(t));
return tgt;
}
use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40 in project org.hl7.fhir.core by hapifhir.
the class Procedure10_40Test method testProcedureConversion.
@Test
@DisplayName("Test 10_40 Procedure conversion")
public void testProcedureConversion() throws IOException {
InputStream dstu2_input = this.getClass().getResourceAsStream("/0_procedure_10.json");
InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_procedure_40.json");
org.hl7.fhir.dstu2.model.Procedure dstu2 = (org.hl7.fhir.dstu2.model.Procedure) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertorFactory_10_40.convertResource(dstu2, advisor);
org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
Assertions.assertTrue(r4_expected.equalsDeep(r4_actual), "Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
Aggregations