I’m using hapi-fhir version 7.2.1 and I’m trying to convert a CDA document in FHIR resource by using FHIR Mapping language and StructureMap resources
I wrote this unit test
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {FhirCda2FhirServerApplication.class})
@ExtendWith(SpringExtension.class)
@Slf4j
public class CdaToFhirTests {
@Autowired
@Qualifier("fhirJsonParser")
private IParser jsonParser;
@Autowired private FhirContext fhirContext;
@Autowired private DefaultProfileValidationSupport defaultProfileValidationSupport;
private static IWorkerContext workerContext;
@Test
public void testCdaToFhirConverter() throws Exception {
log.info("Test CDA to FHIR converter");
// prePopulatedValidationSupport.addStructureDefinition(sd);
HapiWorkerContext hapiWorkerContext =
new HapiWorkerContext(fhirContext, defaultProfileValidationSupport);
hapiWorkerContext.allStructures().stream()
.forEach(
structureDefinition -> {
log.info(
"StructureDefinition type {} url {}",
structureDefinition.getType(),
structureDefinition.getUrl());
});
log.info("ALL STRUCT {}", hapiWorkerContext.allStructures());
FileSystemResource cdaXmlResource = new FileSystemResource("ccda.xml");
StructureMap structureMap =
jsonParser.parseResource(
StructureMap.class, new FileSystemResource("StructureMap.json").getInputStream());
log.info("Loaded StructureMap {}", structureMap);
StructureMapUtilities utils = new StructureMapUtilities(hapiWorkerContext);
Element parsedCda =
Manager.parse(hapiWorkerContext, cdaXmlResource.getInputStream(), FhirFormat.XML);
Bundle target = new Bundle();
utils.transform(null, parsedCda, structureMap, target);
log.info("Bundle {}", jsonParser.encodeResourceToString(target));
}
}
But when I execute it I get this error:
org.hl7.fhir.exceptions.FHIRFormatError: This does not appear to be a
FHIR resource (unknown namespace/name
‘urn:hl7-org:v3::ClinicalDocument’) at line 0 col 0at
org.hl7.fhir.r4.elementmodel.ParserBase.logError(ParserBase.java:104)
at
org.hl7.fhir.r4.elementmodel.ParserBase.getDefinition(ParserBase.java:130)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:181)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:172)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:143)
at org.hl7.fhir.r4.elementmodel.Manager.parse(Manager.java:67) at
it.eng.pnt.fhir.cda2fhir.test.CdaToFhirTests.testCdaToFhirConverter(CdaToFhirTests.java:98)
at java.base/java.lang.reflect.Method.invoke(Method.java:580) at
java.base/java.util.ArrayList.forEach(ArrayList.java:1597) at
java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
I can’t figure out what I’m missing. May anybody give me a tip?