use of org.hl7.fhir.r4.utils.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilitiesTest method testSyntax.
@Test
public void testSyntax() throws IOException, FHIRException {
StructureMapUtilities scu = new StructureMapUtilities(context, this);
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map");
System.out.println(fileMap);
StructureMap structureMap = scu.parse(fileMap, "Syntax");
assertSerializeDeserialize(structureMap);
String renderedMap = StructureMapUtilities.render(structureMap);
StructureMap map = scu.parse(renderedMap, "Syntax");
System.out.println(map);
assertSerializeDeserialize(map);
}
use of org.hl7.fhir.r4.utils.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method transformVersion.
public byte[] transformVersion(String source, String targetVer, FhirFormat format, Boolean canDoNative) throws FHIRException, IOException, Exception {
Content cnt = igLoader.loadContent(source, "validate", false);
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(cnt.focus), cnt.cntType);
// if the src has a url, we try to use the java code
if ((canDoNative == null && src.hasChild("url")) || (canDoNative != null && canDoNative)) {
try {
if (VersionUtilities.isR2Ver(version)) {
return VersionConvertor.convertVersionNativeR2(targetVer, cnt, format);
} else if (VersionUtilities.isR2BVer(version)) {
return VersionConvertor.convertVersionNativeR2b(targetVer, cnt, format);
} else if (VersionUtilities.isR3Ver(version)) {
return VersionConvertor.convertVersionNativeR3(targetVer, cnt, format);
} else if (VersionUtilities.isR4Ver(version)) {
return VersionConvertor.convertVersionNativeR4(targetVer, cnt, format);
} else {
throw new FHIRException("Source version not supported yet: " + version);
}
} catch (Exception e) {
System.out.println("Conversion failed using Java convertor: " + e.getMessage());
}
}
// ok, we try converting using the structure maps
System.out.println("Loading hl7.fhir.xver.r4");
igLoader.loadIg(getIgs(), getBinaries(), "hl7.fhir.xver.r4", false);
String type = src.fhirType();
String url = getMapId(type, targetVer);
List<Base> outputs = new ArrayList<Base>();
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs, mapLog, context));
StructureMap map = context.getTransform(url);
if (map == null)
throw new Error("Unable to find map " + url + " (Known Maps = " + context.listMapUrls() + ")");
org.hl7.fhir.r5.elementmodel.Element resource = getTargetResourceFromStructureMap(map);
scu.transform(null, src, map, resource);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
Manager.compose(context, resource, bs, format, OutputStyle.PRETTY, null);
return bs.toByteArray();
}
use of org.hl7.fhir.r4.utils.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method transform.
public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri) throws FHIRException, IOException {
List<Base> outputs = new ArrayList<>();
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs, mapLog, context));
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(source), cntType);
StructureMap map = context.getTransform(mapUri);
if (map == null)
throw new Error("Unable to find map " + mapUri + " (Known Maps = " + context.listMapUrls() + ")");
org.hl7.fhir.r5.elementmodel.Element resource = getTargetResourceFromStructureMap(map);
scu.transform(null, src, map, resource);
return resource;
}
use of org.hl7.fhir.r4.utils.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilitiesTest method testParseRuleName.
@Test
public void testParseRuleName() throws IOException, FHIRException {
StructureMapUtilities scu = new StructureMapUtilities(context, this);
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "ActivityDefinition.map");
StructureMap structureMap = scu.parse(fileMap, "ActivityDefinition3To4");
// StructureMap/ActivityDefinition3to4: StructureMap.group[3].rule[2].name error id value '"expression"' is not valid
Assertions.assertEquals("expression", structureMap.getGroup().get(2).getRule().get(1).getName());
}
use of org.hl7.fhir.r4.utils.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilitiesTest method testSyntax.
@Test
public void testSyntax() throws IOException, FHIRException {
StructureMapUtilities scu = new StructureMapUtilities(context, this);
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map");
System.out.println(fileMap);
StructureMap structureMap = scu.parse(fileMap, "Syntax");
assertSerializeDeserialize(structureMap);
String renderedMap = StructureMapUtilities.render(structureMap);
StructureMap map = scu.parse(renderedMap, "Syntax");
System.out.println(map);
assertSerializeDeserialize(map);
}
Aggregations