use of org.hl7.fhir.validation.ValidationEngine in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConvertService method initValidationEngine.
@EventListener(ApplicationReadyEvent.class)
protected void initValidationEngine() throws IOException, URISyntaxException {
String definitions = VersionUtilities.packageForVersion(PACKAGE_VERSION) + "#" + VersionUtilities.getCurrentVersion(PACKAGE_VERSION);
this.validationEngine = new ValidationEngine(definitions, FhirPublication.R4, PACKAGE_VERSION, new TimeTracker());
// Loading structure definitions from official package and uploading custom definitions if needed from resources
this.validationEngine.loadPackage(SDOH_CLINICAL_CARE_PACKAGE, SDOH_CLINICAL_CARE_VERSION);
// Loading custom structure definitions, copying all resources from jar to local folder to be able for HAPI to
// upload them. Just passing resources folder is not working for "in jar" files.
loadStructureDefinitions();
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationService method validateSources.
public ValidationResponse validateSources(ValidationRequest request) throws Exception {
if (request.getCliContext().getSv() == null) {
String sv = determineVersion(request.getCliContext(), request.sessionId);
request.getCliContext().setSv(sv);
}
String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
String sessionId = initializeValidator(request.getCliContext(), definitions, new TimeTracker(), request.sessionId);
ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
if (request.getCliContext().getProfiles().size() > 0) {
System.out.println(" .. validate " + request.listSourceFiles() + " against " + request.getCliContext().getProfiles().toString());
} else {
System.out.println(" .. validate " + request.listSourceFiles());
}
ValidationResponse response = new ValidationResponse().setSessionId(sessionId);
for (FileInfo fp : request.getFilesToValidate()) {
List<ValidationMessage> messages = new ArrayList<>();
validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), request.getCliContext().getProfiles(), messages);
ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp);
messages.forEach(outcome::addMessage);
response.addOutcome(outcome);
}
System.out.println(" Max Memory: " + Runtime.getRuntime().maxMemory());
return response;
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationService method transform.
public void transform(CliContext cliContext, ValidationEngine validator) throws Exception {
if (cliContext.getSources().size() > 1)
throw new Exception("Can only have one source when doing a transform (found " + cliContext.getSources() + ")");
if (cliContext.getTxServer() == null)
throw new Exception("Must provide a terminology server when doing a transform");
if (cliContext.getMap() == null)
throw new Exception("Must provide a map when doing a transform");
try {
List<StructureDefinition> structures = validator.getContext().allStructures();
for (StructureDefinition sd : structures) {
if (!sd.hasSnapshot()) {
if (sd.getKind() != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
validator.getContext().generateSnapshot(sd, true);
} else {
validator.getContext().generateSnapshot(sd, false);
}
}
}
validator.setMapLog(cliContext.getMapLog());
org.hl7.fhir.r5.elementmodel.Element r = validator.transform(cliContext.getSources().get(0), cliContext.getMap());
System.out.println(" ...success");
if (cliContext.getOutput() != null) {
FileOutputStream s = new FileOutputStream(cliContext.getOutput());
if (cliContext.getOutput() != null && cliContext.getOutput().endsWith(".json"))
new org.hl7.fhir.r5.elementmodel.JsonParser(validator.getContext()).compose(r, s, IParser.OutputStyle.PRETTY, null);
else
new org.hl7.fhir.r5.elementmodel.XmlParser(validator.getContext()).compose(r, s, IParser.OutputStyle.PRETTY, null);
s.close();
}
} catch (Exception e) {
System.out.println(" ...Failure: " + e.getMessage());
e.printStackTrace();
}
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ValidationService method generateSpreadsheet.
public void generateSpreadsheet(CliContext cliContext, ValidationEngine validator) throws Exception {
CanonicalResource cr = validator.loadCanonicalResource(cliContext.getSources().get(0), cliContext.getSv());
boolean ok = true;
if (cr instanceof StructureDefinition) {
new StructureDefinitionSpreadsheetGenerator(validator.getContext(), false, false).renderStructureDefinition((StructureDefinition) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof CodeSystem) {
new CodeSystemSpreadsheetGenerator(validator.getContext()).renderCodeSystem((CodeSystem) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof ValueSet) {
new ValueSetSpreadsheetGenerator(validator.getContext()).renderValueSet((ValueSet) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof ConceptMap) {
new ConceptMapSpreadsheetGenerator(validator.getContext()).renderConceptMap((ConceptMap) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else {
ok = false;
System.out.println(" ...Unable to generate spreadsheet for " + cliContext.getSources().get(0) + ": no way to generate a spreadsheet for a " + cr.fhirType());
}
if (ok) {
System.out.println(" ...generated spreadsheet successfully");
}
}
use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.
the class ComparisonService method compareStructureDefinitions.
public static void compareStructureDefinitions(String dest, ValidationEngine validator, String left, String right, StructureDefinition resLeft, StructureDefinition resRight) throws IOException, FHIRException, EOperationOutcome {
System.out.println("Comparing StructureDefinitions " + left + " to " + right);
ComparisonSession session = new ComparisonSession(validator.getContext(), validator.getContext(), "Comparing Profiles", null);
session.compare(resLeft, resRight);
System.out.println("Generating output to " + dest + "...");
Utilities.createDirectory(dest);
ComparisonRenderer cr = new ComparisonRenderer(validator.getContext(), validator.getContext(), dest, session);
cr.getTemplates().put("CodeSystem", new String(validator.getContext().getBinaries().get("template-comparison-CodeSystem.html")));
cr.getTemplates().put("ValueSet", new String(validator.getContext().getBinaries().get("template-comparison-ValueSet.html")));
cr.getTemplates().put("Profile", new String(validator.getContext().getBinaries().get("template-comparison-Profile.html")));
cr.getTemplates().put("Index", new String(validator.getContext().getBinaries().get("template-comparison-index.html")));
File htmlFile = cr.render(left, right);
Desktop.getDesktop().browse(htmlFile.toURI());
System.out.println("Done");
}
Aggregations