use of org.hl7.fhir.convertors.conv10_40.VersionConvertor_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.conv10_40.VersionConvertor_10_40 in project org.hl7.fhir.core by hapifhir.
the class ConceptMap10_40 method convertConceptMap.
public static org.hl7.fhir.r4.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.ConceptMap tgt = new org.hl7.fhir.r4.model.ConceptMap();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
if (src.hasIdentifier())
tgt.setIdentifier(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.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(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.hasRequirements())
tgt.setPurpose(src.getRequirements());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
org.hl7.fhir.r4.model.Type r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getSource());
tgt.setSource(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getTarget());
tgt.setTarget(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
for (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent t : src.getElement()) {
List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> ws = convertSourceElementComponent(t);
for (SourceElementComponentWrapper<ConceptMap.SourceElementComponent> w : ws) getGroup(tgt, w.getSource(), w.getTarget()).addElement(w.getComp());
}
return tgt;
}
use of org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40 in project org.hl7.fhir.core by hapifhir.
the class VersionConvertorPrimitiveTypeTests method testCanonicalType10_40Conversion.
@Test
public void testCanonicalType10_40Conversion() {
ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
for (String urlString : URL_STRINGS) {
{
org.hl7.fhir.r4.model.CanonicalType src = new CanonicalType();
src.setValueAsString(urlString);
Assertions.assertEquals(urlString, src.getValueAsString());
org.hl7.fhir.dstu2.model.Reference actualTgt = Canonical10_40.convertCanonicalToReference(src);
Assertions.assertEquals(src.getValueAsString(), actualTgt.getReference());
}
{
org.hl7.fhir.dstu2.model.Reference src = new org.hl7.fhir.dstu2.model.Reference(urlString);
Assertions.assertEquals(urlString, src.getReference());
org.hl7.fhir.r4.model.CanonicalType tgt = Canonical10_40.convertReferenceToCanonical(src);
Assertions.assertEquals(src.getReference(), tgt.getValueAsString());
}
}
ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
}
use of org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40 in project org.hl7.fhir.core by hapifhir.
the class StructureDefinition10_40 method convertStructureDefinition.
public static org.hl7.fhir.r4.model.StructureDefinition convertStructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.StructureDefinition tgt = new org.hl7.fhir.r4.model.StructureDefinition();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_40.convertIdentifier(t));
if (src.hasVersionElement())
tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_40.convertString(src.getNameElement()));
if (src.hasDisplayElement())
tgt.setTitleElement(String10_40.convertString(src.getDisplayElement()));
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.StructureDefinition.StructureDefinitionContactComponent t : src.getContact()) tgt.addContact(convertStructureDefinitionContactComponent(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.hasRequirements())
tgt.setPurpose(src.getRequirements());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
for (org.hl7.fhir.dstu2.model.Coding t : src.getCode()) tgt.addKeyword(Coding10_40.convertCoding(t));
if (src.hasFhirVersion())
tgt.setFhirVersion(org.hl7.fhir.r4.model.Enumerations.FHIRVersion.fromCode(src.getFhirVersion()));
for (org.hl7.fhir.dstu2.model.StructureDefinition.StructureDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertStructureDefinitionMappingComponent(t));
if (src.hasKind())
tgt.setKindElement(convertStructureDefinitionKind(src.getKindElement(), tgt.getId()));
if (src.hasAbstractElement())
tgt.setAbstractElement(Boolean10_40.convertBoolean(src.getAbstractElement()));
for (org.hl7.fhir.dstu2.model.StringType t : src.getContext()) {
org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionContextComponent ec = tgt.addContext();
ec.setTypeElement(convertExtensionContext(src.getContextTypeElement()));
ec.setExpression("*".equals(t.getValue()) ? "Element" : t.getValue());
}
if (src.hasConstrainedType())
tgt.setType(src.getConstrainedType());
else if (src.getSnapshot().hasElement())
tgt.setType(src.getSnapshot().getElement().get(0).getPath());
else if (src.getDifferential().hasElement() && !src.getDifferential().getElement().get(0).getPath().contains("."))
tgt.setType(src.getDifferential().getElement().get(0).getPath());
else
tgt.setType(src.getDifferential().getElement().get(0).getPath().substring(0, src.getDifferential().getElement().get(0).getPath().indexOf(".")));
if (src.hasBase())
tgt.setBaseDefinition(src.getBase());
tgt.setDerivation(src.hasConstrainedType() ? org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule.CONSTRAINT : org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule.SPECIALIZATION);
if (src.hasSnapshot())
tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot()));
if (src.hasDifferential())
tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential()));
if (tgt.hasSnapshot())
tgt.getSnapshot().getElementFirstRep().getType().clear();
if (tgt.hasDifferential())
tgt.getDifferential().getElementFirstRep().getType().clear();
if (tgt.getKind() == StructureDefinitionKind.PRIMITIVETYPE && !tgt.getType().equals(tgt.getId())) {
tgt.setDerivation(TypeDerivationRule.SPECIALIZATION);
tgt.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + tgt.getType());
tgt.setType(tgt.getId());
}
if (tgt.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
for (ElementDefinition ed : tgt.getSnapshot().getElement()) {
if (!ed.hasBase()) {
ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
}
}
}
return tgt;
}
use of org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40 in project org.hl7.fhir.core by hapifhir.
the class VersionConvertorPrimitiveTypeTests method testDirectConversion.
@ParameterizedTest(name = "Test index: {index} Source Class={1} First Value={3} Second Class={4} Second Value={6}")
@MethodSource("getDirectConversionParams")
public <K, L> void testDirectConversion(Class<K> srcTypeClazz, Class<L> tgtTypeClazz, Function<K, L> convertFunction, String[] srcStrings, String[] tgtStrings) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
ConversionContext10_30.INSTANCE.init(mock(VersionConvertor_10_30.class), CONTEXT_PATH);
ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
ConversionContext10_50.INSTANCE.init(mock(VersionConvertor_10_50.class), CONTEXT_PATH);
ConversionContext14_50.INSTANCE.init(mock(VersionConvertor_14_50.class), CONTEXT_PATH);
ConversionContext30_50.INSTANCE.init(mock(VersionConvertor_30_50.class), CONTEXT_PATH);
ConversionContext40_50.INSTANCE.init(mock(VersionConvertor_40_50.class), CONTEXT_PATH);
Method srcSetValueAsStringMethod = srcTypeClazz.getMethod("setValueAsString", String.class);
Method srcGetValueAsString = srcTypeClazz.getMethod("getValueAsString");
Method srcHasValue = srcTypeClazz.getMethod("hasValue");
for (int i = 0; i < srcStrings.length; i++) {
K srcInstance = srcTypeClazz.getDeclaredConstructor().newInstance();
srcSetValueAsStringMethod.invoke(srcInstance, srcStrings[i]);
String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
Assertions.assertEquals(srcStrings[i], srcValueAsString);
boolean srcHasValueReturn = (boolean) srcHasValue.invoke(srcInstance);
L tgtInstance = convertFunction.apply(srcInstance);
Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
Method tgtHasValue = tgtTypeClazz.getMethod("hasValue");
if (srcHasValueReturn) {
String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
Assertions.assertEquals(tgtStrings[i], tgtValueAsString);
} else {
boolean tgtHasValueReturn = (boolean) tgtHasValue.invoke(tgtInstance);
Assertions.assertFalse(tgtHasValueReturn);
}
}
ConversionContext10_30.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext14_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext30_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext40_50.INSTANCE.close(CONTEXT_PATH);
}
Aggregations