use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
public OperationOutcome validate(String location, byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationRecord> record) throws FHIRException, IOException, EOperationOutcome, SAXException {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
if (doNative) {
SchemaValidator.validateSchema(location, cntType, messages);
}
InstanceValidator validator = getValidator(cntType);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
if (showTimes) {
System.out.println(location + ": " + validator.reportTimes());
}
if (record != null) {
record.add(new ValidationRecord(location, messages));
}
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method generate.
public Resource generate(String source, String version) throws FHIRException, IOException, EOperationOutcome {
Content cnt = igLoader.loadContent(source, "validate", false);
Resource res = igLoader.loadResourceByVersion(version, cnt.focus, source);
RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
genResource(res, rc);
return (Resource) res;
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
public OperationOutcome validate(String location, byte[] source, FhirFormat cntType, List<String> profiles, IdStatus resourceIdRule, boolean anyExtensionsAllowed, BestPracticeWarningLevel bpWarnings, CheckDisplayOption displayOption) throws FHIRException, IOException, EOperationOutcome, SAXException {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
if (doNative) {
SchemaValidator.validateSchema(location, cntType, messages);
}
InstanceValidator validator = getValidator(cntType);
validator.setResourceIdRule(resourceIdRule);
validator.setBestPracticeWarningLevel(bpWarnings);
validator.setCheckDisplay(displayOption);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class Scanner method validateScan.
protected List<ScanOutputItem> validateScan(List<String> sources, Set<String> guides) throws FHIRException, IOException, EOperationOutcome {
List<String> refs = new ArrayList<>();
ValidatorUtils.parseSources(sources, refs, getContext());
List<ScanOutputItem> res = new ArrayList();
for (String ref : refs) {
Content cnt = getIgLoader().loadContent(ref, "validate", false);
List<ValidationMessage> messages = new ArrayList<>();
Element e = null;
try {
System.out.println("Validate " + ref);
messages.clear();
e = getValidator().validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType);
res.add(new ScanOutputItem(ref, null, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
} catch (Exception ex) {
res.add(new ScanOutputItem(ref, null, null, exceptionToOutcome(ex)));
}
if (e != null) {
String rt = e.fhirType();
for (String u : guides) {
ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, u);
System.out.println("Check Guide " + ig.getUrl());
String canonical = ig.getUrl().contains("/Impl") ? ig.getUrl().substring(0, ig.getUrl().indexOf("/Impl")) : ig.getUrl();
String url = getGlobal(ig, rt);
if (url != null) {
try {
System.out.println("Validate " + ref + " against " + ig.getUrl());
messages.clear();
getValidator().validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType, url);
res.add(new ScanOutputItem(ref, ig, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
} catch (Exception ex) {
res.add(new ScanOutputItem(ref, ig, null, exceptionToOutcome(ex)));
}
}
Set<String> done = new HashSet<>();
for (StructureDefinition sd : getContext().allStructures()) {
if (!done.contains(sd.getUrl())) {
done.add(sd.getUrl());
if (sd.getUrl().startsWith(canonical) && rt.equals(sd.getType())) {
try {
System.out.println("Validate " + ref + " against " + sd.getUrl());
messages.clear();
validator.validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType, Collections.singletonList(sd));
res.add(new ScanOutputItem(ref, ig, sd, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
} catch (Exception ex) {
res.add(new ScanOutputItem(ref, ig, sd, exceptionToOutcome(ex)));
}
}
}
}
}
}
}
return res;
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class Scanner method genScanOutputItem.
protected void genScanOutputItem(ScanOutputItem item, String filename) throws IOException, FHIRException, EOperationOutcome {
RenderingContext rc = new RenderingContext(getContext(), null, null, "http://hl7.org/fhir", "", null, RenderingContext.ResourceRendererMode.END_USER);
rc.setNoSlowLookup(true);
RendererFactory.factory(item.getOutcome(), rc).render(item.getOutcome());
String s = new XhtmlComposer(XhtmlComposer.HTML).compose(item.getOutcome().getText().getDiv());
String title = item.getTitle();
StringBuilder b = new StringBuilder();
b.append("<html>");
b.append("<head>");
b.append("<title>" + title + "</title>");
b.append("<link rel=\"stylesheet\" href=\"fhir.css\"/>\r\n");
b.append("</head>");
b.append("<body>");
b.append("<h2>" + title + "</h2>");
b.append(s);
b.append("</body>");
b.append("</html>");
TextFile.stringToFile(b.toString(), filename);
}
Aggregations