use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30 in project org.hl7.fhir.core by hapifhir.
the class VersionConvertorPrimitiveType10_30Test method testNullValueDstu2Primitive.
@ParameterizedTest(name = "Testing dstu2 -> dstu3 conversion of null value {0}.")
@MethodSource("dstu2PrimitiveTypes")
public <T extends PrimitiveType> void testNullValueDstu2Primitive(String classname, T obj) {
obj.addExtension().setUrl("http://example.com/AnyValue").setValue(new StringType("A value"));
Assertions.assertNull(((org.hl7.fhir.dstu3.model.PrimitiveType) VersionConvertorFactory_10_30.convertType(obj)).getValue());
}
use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30 in project org.hl7.fhir.core by hapifhir.
the class R2ToR3Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r2;
if (isJson)
r2 = new JsonParser().parse(stream);
else
r2 = new XmlParser().parse(stream);
org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_10_30.convertResource(r2, advisor_10_30);
Bundle b;
if (r3 instanceof Bundle) {
b = (Bundle) r3;
} else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r3).setFullUrl(r3 instanceof MetadataResource ? ((MetadataResource) r3).getUrl() : null);
}
advisor_10_30.getCslist().forEach(cs -> {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
});
advisor_10_30.getCslist().clear();
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
if (patchUrls) {
b.getEntry().stream().filter(be -> be.hasResource() && be.getResource() instanceof StructureDefinition).map(be -> (StructureDefinition) be.getResource()).forEach(sd -> {
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
});
}
return b;
}
use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30 in project org.hl7.fhir.core by hapifhir.
the class TimingRepeatComponent10_30Test method testMedicationRequestConversion.
@Test
@DisplayName("Issue #383 - Test 10_30 TimingRepeatComponent with Timing.when as null")
public void testMedicationRequestConversion() {
final int SET_COUNT = 11;
org.hl7.fhir.dstu2.model.Timing src_timing = new org.hl7.fhir.dstu2.model.Timing();
org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent src_timing_repeat = new org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent();
src_timing_repeat.setCount(SET_COUNT);
src_timing.setRepeat(src_timing_repeat);
org.hl7.fhir.dstu3.model.Timing tgt_timing = (Timing) VersionConvertorFactory_10_30.convertType(src_timing);
org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent tgt_timing_repeat = tgt_timing.getRepeat();
Assertions.assertEquals(SET_COUNT, tgt_timing_repeat.getCount(), "Count field not preserved through version conversion.");
Assertions.assertFalse(tgt_timing_repeat.hasWhen(), "hasWhen() should return false for this conversion.");
Assertions.assertTrue(tgt_timing_repeat.getWhen().isEmpty(), "When no _when time_ is provided, getWhen() should return an empty list.");
}
use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30 in project org.hl7.fhir.core by hapifhir.
the class VersionConvertor method convertVersionNativeR2b.
public static byte[] convertVersionNativeR2b(String targetVer, Content cnt, Manager.FhirFormat format) throws IOException, Exception {
org.hl7.fhir.dstu2016may.model.Resource r2b;
switch(cnt.cntType) {
case JSON:
r2b = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt.focus);
break;
case XML:
r2b = new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(cnt.focus);
break;
default:
throw new FHIRException("Unsupported input format: " + cnt.cntType.toString());
}
if (VersionUtilities.isR2Ver(targetVer)) {
org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_14_30.convertResource(r2b);
org.hl7.fhir.dstu2.model.Resource r2 = VersionConvertorFactory_10_30.convertResource(r3);
return getBytesDstu2(cnt, format, r2);
} else if (VersionUtilities.isR2BVer(targetVer)) {
return getBytesDstu2016(cnt, format, r2b);
} else if (VersionUtilities.isR3Ver(targetVer)) {
return getBytesDstu3(cnt, format, VersionConvertorFactory_14_30.convertResource(r2b));
} else if (VersionUtilities.isR4Ver(targetVer)) {
return getBytesR4(cnt, format, VersionConvertorFactory_14_40.convertResource(r2b));
} else {
throw new FHIRException("Target Version not supported yet: " + targetVer);
}
}
use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30 in project org.hl7.fhir.core by hapifhir.
the class AdministrativeGender10_30Test method testMedicationRequestConversion.
@Test
@DisplayName("Test 10_30 extension present, value is not")
public void testMedicationRequestConversion() throws IOException {
InputStream dstu2_input = this.getClass().getResourceAsStream("/administrative_gender_null.json");
org.hl7.fhir.dstu2.model.Patient dstu2 = (org.hl7.fhir.dstu2.model.Patient) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
VersionConvertorFactory_10_30.convertResource(dstu2, new BaseAdvisor_10_30());
}
Aggregations