use of org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED in project kindling by HL7.
the class Publisher method processRDF.
private void processRDF() throws Exception, FileNotFoundException {
// first, process the RIM file
String rim = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "tools", "tx", "v3", "rim.ttl"));
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
FhirTurtleGenerator ttl = new FhirTurtleGenerator(tmp, page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
ttl.executeV3(page.getValueSets(), page.getCodeSystems());
rim = rim + tmp.toString();
TextFile.stringToFile(rim, Utilities.path(page.getFolders().dstDir, "rim.ttl"));
ttl = new FhirTurtleGenerator(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "fhir.ttl")), page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
ttl.executeMain();
W5TurtleGenerator w5 = new W5TurtleGenerator(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "w5.ttl")), page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
w5.executeMain();
RDFValidator val = new RDFValidator();
val.validate(Utilities.path(page.getFolders().dstDir, "fhir.ttl"));
val.validate(Utilities.path(page.getFolders().dstDir, "rim.ttl"));
val.validate(Utilities.path(page.getFolders().dstDir, "w5.ttl"));
ZipGenerator zip = new ZipGenerator(Utilities.path(page.getFolders().dstDir, "fhir.rdf.ttl.zip"));
zip.addFileName("fhir.ttl", Utilities.path(page.getFolders().dstDir, "fhir.ttl"), false);
zip.addFileName("rim.ttl", Utilities.path(page.getFolders().dstDir, "rim.ttl"), false);
zip.addFileName("w5.ttl", Utilities.path(page.getFolders().dstDir, "w5.ttl"), false);
zip.close();
// now that the RDF is generated, run any sparql rules that have been defined
Element test = loadDom(new FileInputStream(Utilities.path(page.getFolders().srcDir, "sparql-rules.xml")), false).getDocumentElement();
test = XMLUtil.getFirstChild(test);
while (test != null) {
if (test.getNodeName().equals("assertion")) {
String sparql = test.getTextContent();
page.getValidationErrors().addAll(val.assertion(sparql, test.getAttribute("id"), test.getAttribute("rowtype"), test.getAttribute("message"), test.getAttribute("description"), IssueSeverity.fromCode(test.getAttribute("level"))));
}
test = XMLUtil.getNextSibling(test);
}
checkAllOk();
}
use of org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED in project redmatch by aehrc.
the class RedmatchApi method export.
/**
* Exports the generated FHIR resources that result from running a Redmatch rules document.
*
* @param redmatchRulesFile The Redmatch rules document.
* @param progressReporter An object used to report progress. Can be null.
* @param cancelToken Used to check if the user has cancelled the operation.
* @return List of diagnostic messages.
*/
public List<Diagnostic> export(@NotNull File redmatchRulesFile, ProgressReporter progressReporter, CancelChecker cancelToken) {
try {
Pair<Map<String, DomainResource>, List<Diagnostic>> data = transform(redmatchRulesFile, progressReporter, cancelToken);
// If the resource map is empty then something went wrong or the operation was cancelled by the user
if (data.getValue0().isEmpty()) {
return data.getValue1();
}
Map<String, DomainResource> resourceMap = data.getValue0();
// Group resources by type
final Map<String, List<DomainResource>> grouped = new HashMap<>();
for (String key : resourceMap.keySet()) {
DomainResource dr = resourceMap.get(key);
String resourceType = dr.getResourceType().toString();
List<DomainResource> list = grouped.computeIfAbsent(resourceType, k -> new ArrayList<>());
list.add(dr);
}
File baseFolder = redmatchRulesFile.toPath().getParent().toFile();
Path outputFolder = createOutputFolder(baseFolder).toPath();
save(grouped, outputFolder, progressReporter, cancelToken);
return data.getValue1();
} catch (Exception e) {
log.error(e);
return List.of(new Diagnostic(zeroZero, "Could not complete transformation:" + e.getLocalizedMessage(), DiagnosticSeverity.Error, "API"));
}
}
use of org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED in project org.hl7.fhir.core by hapifhir.
the class CountryCodesConverter method setMetadata.
public void setMetadata(Document src, CodeSystem cs, String id, String url, String partName, String partTitle) {
cs.setId(id);
cs.setUrl(url);
cs.setName("ISOCountryCodes" + partName);
cs.setTitle("ISO Country Codes (ISO-3166)" + partTitle);
cs.setVersion(XMLUtil.getFirstChild(src.getDocumentElement()).getAttribute("version"));
cs.setStatus(PublicationStatus.ACTIVE);
cs.setExperimental(false);
cs.addContact().setName("FHIR Project Team").addTelecom().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
cs.setDateElement(new DateTimeType(src.getDocumentElement().getAttribute("generated")));
cs.setCopyright("Copyright ISO. See https://www.iso.org/obp/ui/#search/code/");
cs.setCaseSensitive(true);
cs.setContent(CodeSystemContentMode.COMPLETE);
cs.setLanguage("en");
}
use of org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateSnapshot.
/**
* Given a base (snapshot) profile structure, and a differential profile, generate a new snapshot profile
*
* @param base - the base structure on which the differential will be applied
* @param differential - the differential to apply to the base
* @param url - where the base has relative urls for profile references, these need to be converted to absolutes by prepending this URL (e.g. the canonical URL)
* @param webUrl - where the base has relative urls in markdown, these need to be converted to absolutes by prepending this URL (this is not the same as the canonical URL)
* @param trimDifferential - if this is true, then the snap short generator will remove any material in the element definitions that is not different to the base
* @return
* @throws FHIRException
* @throws DefinitionException
* @throws Exception
*/
public void generateSnapshot(StructureDefinition base, StructureDefinition derived, String url, String webUrl, String profileName) throws DefinitionException, FHIRException {
if (base == null)
throw new DefinitionException("no base profile provided");
if (derived == null)
throw new DefinitionException("no derived structure provided");
if (snapshotStack.contains(derived.getUrl()))
throw new DefinitionException("Circular snapshot references detected; cannot generate snapshot (stack = " + snapshotStack.toString() + ")");
snapshotStack.add(derived.getUrl());
if (!Utilities.noString(webUrl) && !webUrl.endsWith("/"))
webUrl = webUrl + '/';
derived.setSnapshot(new StructureDefinitionSnapshotComponent());
try {
// so we have two lists - the base list, and the differential list
// the differential list is only allowed to include things that are in the base list, but
// is allowed to include them multiple times - thereby slicing them
// our approach is to walk through the base list, and see whether the differential
// says anything about them.
int baseCursor = 0;
// we need a diff cursor because we can only look ahead, in the bound scoped by longer paths
int diffCursor = 0;
if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty())
throw new Error("type on first differential element!");
for (ElementDefinition e : derived.getDifferential().getElement()) e.clearUserData(GENERATED_IN_SNAPSHOT);
// we actually delegate the work to a subroutine so we can re-enter it with a different cursors
// we make a copy here because we're sometimes going to hack the differential while processing it. Have to migrate user data back afterwards
StructureDefinitionDifferentialComponent diff = cloneDiff(derived.getDifferential());
processPaths("", derived.getSnapshot(), base.getSnapshot(), diff, baseCursor, diffCursor, base.getSnapshot().getElement().size() - 1, derived.getDifferential().hasElement() ? derived.getDifferential().getElement().size() - 1 : -1, url, webUrl, derived.present(), null, null, false, base.getUrl(), null, false, new ArrayList<ElementRedirection>(), base);
if (!derived.getSnapshot().getElementFirstRep().getType().isEmpty())
throw new Error("type on first snapshot element for " + derived.getSnapshot().getElementFirstRep().getPath() + " in " + derived.getUrl() + " from " + base.getUrl());
updateMaps(base, derived);
if (debug) {
System.out.println("Differential: ");
for (ElementDefinition ed : derived.getDifferential().getElement()) System.out.println(" " + ed.getPath() + " : " + typeSummaryWithProfile(ed) + "[" + ed.getMin() + ".." + ed.getMax() + "]" + sliceSummary(ed) + " id = " + ed.getId() + " " + constraintSummary(ed));
System.out.println("Snapshot: ");
for (ElementDefinition ed : derived.getSnapshot().getElement()) System.out.println(" " + ed.getPath() + " : " + typeSummaryWithProfile(ed) + "[" + ed.getMin() + ".." + ed.getMax() + "]" + sliceSummary(ed) + " id = " + ed.getId() + " " + constraintSummary(ed));
}
setIds(derived, false);
// Check that all differential elements have a corresponding snapshot element
for (ElementDefinition e : diff.getElement()) {
if (!e.hasUserData("diff-source"))
throw new Error("Unxpected internal condition - no source on diff element");
else {
if (e.hasUserData(DERIVATION_EQUALS))
((Base) e.getUserData("diff-source")).setUserData(DERIVATION_EQUALS, e.getUserData(DERIVATION_EQUALS));
if (e.hasUserData(DERIVATION_POINTER))
((Base) e.getUserData("diff-source")).setUserData(DERIVATION_POINTER, e.getUserData(DERIVATION_POINTER));
}
if (!e.hasUserData(GENERATED_IN_SNAPSHOT)) {
System.out.println("Error in snapshot generation: Differential for " + derived.getUrl() + " with " + (e.hasId() ? "id: " + e.getId() : "path: " + e.getPath()) + " has an element that is not marked with a snapshot match");
if (exception)
throw new DefinitionException("Snapshot for " + derived.getUrl() + " does not contain an element that matches an existing differential element that has " + (e.hasId() ? "id: " + e.getId() : "path: " + e.getPath()));
else
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url, "Snapshot for " + derived.getUrl() + " does not contain an element that matches an existing differential element that has id: " + e.getId(), ValidationMessage.IssueSeverity.ERROR));
}
}
if (derived.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
for (ElementDefinition ed : derived.getSnapshot().getElement()) {
if (!ed.hasBase()) {
ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
}
}
}
} catch (Exception e) {
// if we had an exception generating the snapshot, make sure we don't leave any half generated snapshot behind
derived.setSnapshot(null);
throw e;
}
}
use of org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus.GENERATED in project org.hl7.fhir.core by hapifhir.
the class XmlSchemaGenerator method start.
private String start(StructureDefinition sd, String ns) throws IOException, FHIRException {
String lang = "en";
if (sd.hasLanguage())
lang = sd.getLanguage();
if (single && writer != null) {
if (!ns.equals(getNs(sd)))
throw new FHIRException("namespace inconsistency: " + ns + " vs " + getNs(sd));
return lang;
}
close();
writer = new OutputStreamWriter(new FileOutputStream(Utilities.path(folder, tail(sd.getType() + ".xsd"))), "UTF-8");
ln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
ln("<!-- ");
ln(license);
ln("");
ln(" Generated on " + genDate + " for FHIR v" + version + " ");
ln("");
ln(" Note: this schema does not contain all the knowledge represented in the underlying content model");
ln("");
ln("-->");
ln("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:fhir=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " + "xmlns:lm=\"" + ns + "\" targetNamespace=\"" + ns + "\" elementFormDefault=\"qualified\" version=\"1.0\">");
ln(" <xs:import schemaLocation=\"fhir-common.xsd\" namespace=\"http://hl7.org/fhir\"/>");
if (useNarrative) {
if (ns.equals("urn:hl7-org:v3"))
ln(" <xs:include schemaLocation=\"cda-narrative.xsd\"/>");
else
ln(" <xs:import schemaLocation=\"cda-narrative.xsd\" namespace=\"urn:hl7-org:v3\"/>");
}
namespaces.clear();
namespaces.put(ns, "lm");
namespaces.put("http://hl7.org/fhir", "fhir");
typeNames.clear();
return lang;
}
Aggregations