use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class BuildWorkerContext method generateSnapshot.
public void generateSnapshot(StructureDefinition p, boolean ifLogical) throws DefinitionException, FHIRException {
if (!p.hasSnapshot() && (ifLogical || p.getKind() != StructureDefinitionKind.LOGICAL)) {
if (!p.hasBaseDefinition())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") has no base and no snapshot");
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
if (sd == null)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") base " + p.getBaseDefinition() + " could not be resolved");
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
List<String> errors = new ArrayList<String>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.setThrowException(false);
pu.sortDifferential(sd, p, p.getUrl(), errors, true);
for (String err : errors) msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: " + err, ValidationMessage.IssueSeverity.ERROR));
pu.generateSnapshot(sd, p, p.getUrl(), Utilities.extractBaseUrl(sd.getUserString("path")), p.getName());
for (ValidationMessage msg : msgs) {
if ((msg.getLevel() == ValidationMessage.IssueSeverity.ERROR) || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot: " + msg.getMessage());
}
if (!p.hasSnapshot())
throw new FHIRException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot");
pu = null;
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class CDAGenerator method processClass.
private void processClass(List<Element> classes, List<Element> associations, String className, Element parentTarget) throws FHIRFormatError, DefinitionException {
Element cclass = null;
for (Element cclss : classes) {
String cname = XMLUtil.getNamedChildAttribute(cclss, "class", "name");
if (cname.equals(className)) {
cclass = cclss;
break;
}
}
if (cclass == null)
throw new Error("Unable to find class " + className);
processed.add(className);
waiting.removeIf((WaitingEntry entry) -> entry.className.equals(className));
StructureDefinition sd = new StructureDefinition();
sd.setId(className);
sd.setUrl("http://hl7.org/fhir/cda/StructureDefinition/" + className);
library.put(sd.getUrl(), sd);
sd.setName("CDAR2." + className);
sd.setTitle("FHIR Definition for CDA R2 Class " + className);
sd.setStatus(PublicationStatus.ACTIVE);
sd.setExperimental(false);
sd.setPublisher("HL7");
sd.setType(sd.getUrl());
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:v3"));
if ("ClinicalDocument".equals(className)) {
sd.setDescription("This is a generated StructureDefinition that describes CDA - that is, CDA as it actually is for R2. " + "The intent of this StructureDefinition is to enable CDA to be a FHIR resource. That enables the FHIR infrastructure " + "- API, conformance, query - to be used directly against CDA");
}
sd.setKind(StructureDefinitionKind.LOGICAL);
sd.setAbstract(false);
sd.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
ElementDefinition ed = new ElementDefinition();
ed.setPath(className);
seePath(ed);
ed.setMin(1);
ed.setMax("1");
sd.getDifferential().getElement().add(ed);
sd.getSnapshot().getElement().add(popBase(ed));
processClassAttributes(classes, associations, sd.getDifferential().getElement(), sd.getSnapshot().getElement(), cclass, className, parentTarget);
new ProfileUtilities(null, null, null).setIds(sd, true);
structures.add(sd);
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class MarkDownPreProcessor method process.
public static String process(Definitions definitions, BuildWorkerContext workerContext, List<ValidationMessage> validationErrors, String text, String location, String prefix) throws Exception {
if (Utilities.noString(text))
return "";
text = text.replace("||", "\r\n\r\n");
while (text.contains("[[[")) {
String left = text.substring(0, text.indexOf("[[["));
if (text.indexOf("]]]") < 0)
throw new Error(location + ": Missing closing ]]] in markdown text: " + text);
String linkText = text.substring(text.indexOf("[[[") + 3, text.indexOf("]]]"));
String right = text.substring(text.indexOf("]]]") + 3);
if (linkText.startsWith("valueset:")) {
String vsid = linkText.substring(9);
ValueSet vs = workerContext.fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/" + vsid);
ValueSetExpansionOutcome exp = workerContext.expandVS(vs, true, false);
if (exp.getValueset() != null)
text = left + presentExpansion(exp.getValueset().getExpansion().getContains(), workerContext) + right;
else
text = left + "[" + vs.getName() + "](" + vs.getUserData("path") + ")" + right;
} else {
String url = "";
String[] parts = linkText.split("\\#");
if (parts[0].contains("/StructureDefinition/")) {
StructureDefinition ed = workerContext.getExtensionStructure(null, parts[0]);
if (ed == null)
throw new Error(location + ": Unable to find extension " + parts[0]);
url = ed.getUserString("path");
if (url == null && ed.hasUserData("filename")) {
url = ed.getUserData("filename") + ".html";
}
if (url == null) {
System.out.println("Broken link for " + ed.getUrl());
}
}
if (Utilities.noString(url)) {
String[] paths = parts[0].split("\\.");
StructureDefinition p = new ProfileUtilities(workerContext, null, null).getProfile(null, paths[0]);
if (p != null) {
String suffix = (paths.length > 1) ? "-definitions.html#" + parts[0] : ".html";
if (p.getUserData("filename") == null)
url = paths[0].toLowerCase() + suffix;
else
url = p.getUserData("filename") + suffix;
} else if (definitions.hasResource(linkText)) {
url = linkText.toLowerCase() + ".html#";
} else if (definitions.hasResource(paths[0])) {
url = paths[0].toLowerCase() + "-definitions.html#" + linkText;
} else if (definitions.hasElementDefn(linkText)) {
url = definitions.getSrcFile(linkText) + ".html#" + linkText;
} else if (definitions.hasPrimitiveType(linkText)) {
url = "datatypes.html#" + linkText;
} else if (definitions.getPageTitles().containsKey(linkText)) {
url = definitions.getPageTitles().get(linkText);
} else if (definitions.getLogicalModel(linkText.toLowerCase()) != null) {
url = definitions.getLogicalModel(linkText.toLowerCase()).getId() + ".html";
} else if (validationErrors != null) {
validationErrors.add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, location, "Unresolved logical URL '" + linkText + "'", IssueSeverity.WARNING));
// throw new Exception("Unresolved logical URL "+url);
} else
url = "??";
}
text = left + "[" + linkText + "](" + url + ")" + right;
}
}
// 1. if prefix <> "", then check whether we need to insert the prefix
if (!Utilities.noString(prefix)) {
int i = text.length() - 3;
while (i > 0) {
if (text.substring(i, i + 2).equals("](")) {
if (!text.substring(i, i + 7).equals("](http:")) {
// && !text.substring(i, i+8).equals("](https:"));
text = text.substring(0, i) + "](" + prefix + text.substring(i + 2);
}
}
i--;
}
}
return text;
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class CDAGenerator method buildSXPR.
private void buildSXPR() throws DefinitionException {
StructureDefinition sd = new StructureDefinition();
sd.setId(fix("SXPR_TS"));
sd.setUrl("http://hl7.org/fhir/cda/StructureDefinition/" + fix("SXPR_TS"));
library.put(sd.getUrl(), sd);
sd.setName("V3 Data type SXPR_TS (A set-component that is itself made up of set-components that are evaluated as one value)");
sd.setTitle("SXPR_TS - Component part of GTS");
sd.setStatus(PublicationStatus.ACTIVE);
sd.setExperimental(false);
sd.setPublisher("HL7");
sd.setDescription("A set-component that is itself made up of set-components that are evaluated as one value");
sd.setKind(StructureDefinitionKind.LOGICAL);
sd.setAbstract(false);
sd.setType(sd.getUrl());
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:v3"));
sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/SXCM_TS");
sd.setDerivation(TypeDerivationRule.SPECIALIZATION);
ElementDefinition edb = new ElementDefinition();
edb.setPath(sd.getId());
edb.setMin(1);
edb.setMax("*");
edb.addType().setCode("Element");
sd.getDifferential().getElement().add(edb);
ElementDefinition ed = new ElementDefinition();
ed.setPath("SXPR_TS.comp");
seePath(ed);
ed.setMin(1);
ed.setMax("*");
ed.addRepresentation(PropertyRepresentation.TYPEATTR);
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS");
sd.getDifferential().getElement().add(ed);
new ProfileUtilities(null, null, null).setIds(sd, true);
structures.add(sd);
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(Profile pack, ConstraintStructure profile, ResourceDefn resource, String id, String html, ImplementationGuideDefn usage, List<ValidationMessage> issues, ResourceDefn baseResource) throws Exception {
if (profile.getResource() != null)
return profile.getResource();
StructureDefinition p = new StructureDefinition();
p.setId(FormatUtilities.makeId(id));
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + id);
if (usage != null && !usage.isCore()) {
if (!id.startsWith(usage.getCode() + "-"))
throw new Exception("Error: " + id + " must start with " + usage.getCode() + "-");
}
if (!resource.getRoot().getTypes().isEmpty() && (resource.getRoot().getTypes().get(0).getProfile() != null))
p.setBaseDefinition(resource.getRoot().getTypes().get(0).getProfile());
else
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + resource.getName());
if (definitions.hasType(resource.getName()))
p.setKind(StructureDefinitionKind.COMPLEXTYPE);
else
p.setKind(StructureDefinitionKind.RESOURCE);
p.setType(resource.getName());
p.setDerivation(TypeDerivationRule.CONSTRAINT);
p.setAbstract(false);
p.setUserData("filename", id);
p.setUserData("path", ((usage == null || usage.isCore()) ? "" : usage.getCode() + File.separator) + id + ".html");
p.setTitle(pack.metadata("display"));
p.setFhirVersion(version);
p.setVersion(version.toCode());
if (pack.hasMetadata("summary-" + profile.getTitle()))
ToolingExtensions.addMarkdownExtension(p, "http://hl7.org/fhir/StructureDefinition/structuredefinition-summary", pack.metadata("summary-" + profile.getTitle()));
ToolResourceUtilities.updateUsage(p, usage.getCode());
p.setName(pack.metadata("name"));
p.setPublisher(pack.metadata("author.name"));
if (pack.hasMetadata("author.reference"))
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, pack.metadata("author.reference")));
// <code> opt Zero+ Coding assist with indexing and finding</code>
p.setDescription(resource.getRoot().getShortDefn());
if (!p.hasDescriptionElement() && pack.hasMetadata("description"))
p.setDescription(preProcessMarkdown(pack.metadata("description"), "pack.description"));
p.setPurpose(resource.getRoot().getRequirements());
if (!p.hasPurpose() && pack.hasMetadata("requirements"))
p.setPurpose(pack.metadata("requirements"));
p.setExperimental(Utilities.existsInList(pack.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
if (pack.hasMetadata("date"))
p.setDateElement(Factory.newDateTime(pack.metadata("date").substring(0, 10)));
else
p.setDate(genDate.getTime());
if (pack.hasMetadata("fmm-level"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.getFmmLevel()));
else if (pack.hasMetadata("fmm"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.metadata("fmm")));
else if (!Utilities.noString(resource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(resource.getFmmLevel()));
else if (baseResource != null && !Utilities.noString(baseResource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(baseResource.getFmmLevel()));
if (pack.hasMetadata("workgroup"))
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, pack.getWg());
else if (resource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, resource.getWg().getCode());
else if (baseResource != null && baseResource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, baseResource.getWg().getCode());
if (pack.hasMetadata("Standards-Status"))
ToolingExtensions.setStandardsStatus(p, StandardsStatus.fromCode(pack.metadata("Standards-Status")), null);
else
ToolingExtensions.setStandardsStatus(p, resource.getStatus(), null);
if (pack.hasMetadata("status"))
p.setStatus(PublicationStatus.fromCode(pack.metadata("status")));
if (pack.getMetadata().containsKey("code"))
for (String s : pack.getMetadata().get("code")) if (!Utilities.noString(s))
p.getKeyword().add(Factory.makeCoding(s));
if (pack.hasMetadata("datadictionary"))
ToolingExtensions.setStringExtension(p, "http://hl7.org/fhir/StructureDefinition/datadictionary", pack.metadata("datadictionary"));
Set<String> containedSlices = new HashSet<String>();
p.setDifferential(new StructureDefinitionDifferentialComponent());
defineElement(pack, p, p.getDifferential().getElement(), resource.getRoot(), resource.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, null, null, false);
List<String> names = new ArrayList<String>();
names.addAll(resource.getSearchParams().keySet());
Collections.sort(names);
for (String pn : names) {
pack.getSearchParameters().add(makeSearchParam(p, pack.getId() + "-" + resource.getName() + "-" + pn, resource.getName(), resource.getSearchParams().get(pn), resource));
}
StructureDefinition base = definitions.getSnapShotForBase(p.getBaseDefinition());
List<String> errors = new ArrayList<String>();
new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, false);
for (String s : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), s, IssueSeverity.WARNING));
reset();
// ok, c is the differential. now we make the snapshot
new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + p.getType(), "http://hl7.org/fhir", p.getName());
reset();
p.getDifferential().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).getType().clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
new ProfileUtilities(context, issues, pkp).setIds(p, false);
checkHasTypes(p);
return p;
}
Aggregations