use of ca.uhn.fhir.parser.IParser in project gpconnect-demonstrator by nhsconnect.
the class ValueSetValidator method findValueSet.
private ValueSet findValueSet(String systemUrl) {
int valueSetNamePos = systemUrl.lastIndexOf("/") + 1;
String valueSetFilename = String.format("%s.xml", systemUrl.substring(valueSetNamePos));
ValueSet valSet = null;
String xmlContent = null;
if (fhirValueSetsCheckWebFirst == true) {
xmlContent = readValueSetFromWeb(valueSetFilename);
}
if (xmlContent == null) {
xmlContent = readValueSetFromDisk(valueSetFilename);
}
if (fhirValueSetsCheckWebFirst == false && xmlContent == null) {
xmlContent = readValueSetFromWeb(valueSetFilename);
}
if (xmlContent != null) {
try {
FhirContext fhirCtx = FhirContext.forDstu3();
IParser parser = fhirCtx.newXmlParser();
valSet = parser.parseResource(ValueSet.class, xmlContent);
} catch (DataFormatException ex) {
LOG.error(String.format("Error parsing valueSetFilename: %s", valueSetFilename));
}
}
if (valSet == null) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("Could not find or parse Value Set [SystemUrl: %s] at: %s. See system log for details.", systemUrl, valueSetFilename)), SystemCode.REFERENCE_NOT_FOUND, IssueType.NOTFOUND);
}
return valSet;
}
Aggregations