use of org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50 in project org.hl7.fhir.core by hapifhir.
the class DocumentReference10_50 method convertDocumentReference.
public static org.hl7.fhir.dstu2.model.DocumentReference convertDocumentReference(org.hl7.fhir.r5.model.DocumentReference src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.DocumentReference tgt = new org.hl7.fhir.dstu2.model.DocumentReference();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
// tgt.setMasterIdentifier(VersionConvertor_10_50.convertIdentifier(src.getMasterIdentifier()));
for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
if (src.hasSubject())
tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
if (src.hasType())
tgt.setType(CodeableConcept10_50.convertCodeableConcept(src.getType()));
if (src.hasCategory())
tgt.setClass_(CodeableConcept10_50.convertCodeableConcept(src.getCategoryFirstRep()));
if (src.hasCustodian())
tgt.setCustodian(Reference10_50.convertReference(src.getCustodian()));
for (DocumentReferenceAttesterComponent t : src.getAttester()) {
if (t.getMode() == DocumentAttestationMode.OFFICIAL)
tgt.setAuthenticator(Reference10_50.convertReference(t.getParty()));
}
if (src.hasDate())
tgt.setCreated(src.getDate());
if (src.hasStatus())
tgt.setStatusElement(convertDocumentReferenceStatus(src.getStatusElement()));
if (src.hasDocStatus())
tgt.setDocStatus(convertDocStatus(src.getDocStatus()));
for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceRelatesToComponent t : src.getRelatesTo()) tgt.addRelatesTo(convertDocumentReferenceRelatesToComponent(t));
if (src.hasDescriptionElement())
tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
for (org.hl7.fhir.r5.model.CodeableConcept t : src.getSecurityLabel()) tgt.addSecurityLabel(CodeableConcept10_50.convertCodeableConcept(t));
for (org.hl7.fhir.r5.model.DocumentReference.DocumentReferenceContentComponent t : src.getContent()) tgt.addContent(convertDocumentReferenceContentComponent(t));
convertDocumentReferenceContextComponent(tgt.getContext(), src);
return tgt;
}
use of org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50 in project org.hl7.fhir.core by hapifhir.
the class ValueSet10_50 method convertValueSet.
public static org.hl7.fhir.r5.model.ValueSet convertValueSet(org.hl7.fhir.dstu2.model.ValueSet src, BaseAdvisor_10_50 advisor) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r5.model.ValueSet tgt = new org.hl7.fhir.r5.model.ValueSet();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
if (src.hasIdentifier())
tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
if (src.hasVersionElement())
tgt.setVersionElement(String10_50.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_50.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
if (src.hasDate())
tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_50.isJurisdiction(t))
tgt.addJurisdiction(CodeableConcept10_50.convertCodeableConcept(t));
else
tgt.addUseContext(CodeableConcept10_50.convertCodeableConceptToUsageContext(t));
if (src.hasImmutableElement())
tgt.setImmutableElement(Boolean10_50.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.r5.model.CodeSystem tgtcs = new org.hl7.fhir.r5.model.CodeSystem();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgtcs);
tgtcs.setUrl(src.getCodeSystem().getSystem());
tgtcs.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
tgtcs.setVersion(src.getCodeSystem().getVersion());
tgtcs.setName(src.getName() + " Code System");
tgtcs.setStatusElement(Enumerations10_50.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_50.isJurisdiction(t))
tgtcs.addJurisdiction(CodeableConcept10_50.convertCodeableConcept(t));
else
tgtcs.addUseContext(CodeableConcept10_50.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_50.VersionConvertor_10_50 in project kindling by HL7.
the class DSTU2ValidationConvertor method convert.
public void convert(String bundleSource, String bundleTarget) throws Exception {
System.out.println("Convert " + bundleSource);
try {
source = (Bundle) new XmlParser().parse(new FileInputStream(bundleSource));
org.hl7.fhir.dstu2.model.Bundle target = (org.hl7.fhir.dstu2.model.Bundle) VersionConvertor_10_50.convertResource(source, this);
new org.hl7.fhir.dstu2.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(bundleTarget), target);
} catch (Exception e) {
throw new Exception(e);
}
}
use of org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50 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);
}
use of org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50 in project org.hl7.fhir.core by hapifhir.
the class ConceptMap10_50 method convertConceptMap.
public static org.hl7.fhir.r5.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r5.model.ConceptMap tgt = new org.hl7.fhir.r5.model.ConceptMap();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
if (src.hasIdentifier())
tgt.addIdentifier(Identifier10_50.convertIdentifier(src.getIdentifier()));
if (src.hasVersionElement())
tgt.setVersionElement(String10_50.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_50.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
if (src.hasDate())
tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_50.isJurisdiction(t))
tgt.addJurisdiction(CodeableConcept10_50.convertCodeableConcept(t));
else
tgt.addUseContext(CodeableConcept10_50.convertCodeableConceptToUsageContext(t));
if (src.hasRequirements())
tgt.setPurpose(src.getRequirements());
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
org.hl7.fhir.r5.model.DataType r = ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getSource());
tgt.setSource(r instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) r).getReference()) : r);
r = ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getTarget());
tgt.setTarget(r instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.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;
}
Aggregations