use of org.hl7.fhir.definitions.model.WorkGroup in project kindling by HL7.
the class PageProcessor method loadXmlNotes.
public String loadXmlNotes(String name, String suffix, boolean checkHeaders, String definition, ResourceDefn resource, List<String> tabs, ImplementationGuideDefn ig, WorkGroup wg) throws Exception {
String filename;
if (definitions.hasLogicalModel(name)) {
LogicalModel lm = definitions.getLogicalModel(name);
filename = Utilities.changeFileExt(lm.getSource(), "-" + suffix + ".xml");
} else
filename = folders.srcDir + name + File.separatorChar + name + "-" + suffix + ".xml";
return loadXmlNotesFromFile(filename, checkHeaders, definition, resource, tabs, ig, wg);
}
use of org.hl7.fhir.definitions.model.WorkGroup in project kindling by HL7.
the class PageProcessor method loadXmlNotesFromFile.
public String loadXmlNotesFromFile(String filename, boolean checkHeaders, String definition, ResourceDefn r, List<String> tabs, ImplementationGuideDefn ig, WorkGroup wg) throws Exception {
if (!new CSFile(filename).exists()) {
TextFile.stringToFile(HTML_PREFIX1 + "\r\n<!-- content goes here -->\r\n\r\n" + HTML_SUFFIX, filename);
return "";
}
String res;
String cnt = TextFile.fileToString(filename);
Map<String, String> others = new HashMap<String, String>();
others.put("definition", definition);
cnt = processPageIncludes(filename, cnt, "notes", others, null, tabs, "--", ig, r, wg).trim() + "\r\n";
if (cnt.startsWith("<div")) {
if (!cnt.startsWith(HTML_PREFIX1) && !cnt.startsWith(HTML_PREFIX2))
throw new Exception("unable to process start xhtml content " + filename + " : \r\n" + cnt.substring(0, HTML_PREFIX1.length()) + " - should be \r\n'" + HTML_PREFIX1 + "' or \r\n'" + HTML_PREFIX2 + "'");
else if (!cnt.endsWith(HTML_SUFFIX))
throw new Exception("unable to process end xhtml content " + filename + " : " + cnt.substring(cnt.length() - HTML_SUFFIX.length()));
else if (cnt.startsWith(HTML_PREFIX2))
res = cnt.substring(HTML_PREFIX2.length(), cnt.length() - (HTML_SUFFIX.length())).trim();
else
res = cnt.substring(HTML_PREFIX1.length(), cnt.length() - (HTML_SUFFIX.length())).trim();
} else {
res = HTML_PREFIX1 + cnt + HTML_SUFFIX;
TextFile.stringToFile(res, filename);
}
if (checkHeaders) {
checkFormat(filename, res, r);
}
return res;
}
use of org.hl7.fhir.definitions.model.WorkGroup in project kindling by HL7.
the class OldSpreadsheetParser method processExtension.
private int processExtension(ElementDefn extensions, Sheet sheet, int row, Definitions definitions, String uri, Profile ap, List<ValidationMessage> issues, Map<String, Invariant> invariants, WorkGroup wg) throws Exception {
// first, we build the extension definition
StructureDefinition ex = new StructureDefinition();
ex.setUserData(ToolResourceUtilities.NAME_RES_IG, ig == null ? "core" : ig.getCode());
ex.setUserData("profile", ap);
ex.setKind(StructureDefinitionKind.COMPLEXTYPE);
ex.setType("Extension");
ex.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Extension");
ex.setDerivation(TypeDerivationRule.CONSTRAINT);
ex.setAbstract(false);
ex.setFhirVersion(version);
ex.setVersion(version.toCode());
if (wg != null)
ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
String fmm = sheet.getColumn(row, "FMM");
if (Utilities.noString(fmm))
// default fmm value for extensions
fmm = "1";
ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
if (ap.hasMetadata("fmm-level"))
ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(ap.getFmmLevel()));
if (ap.hasMetadata("workgroup"))
ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, ap.getWg());
ToolResourceUtilities.updateUsage(ex, ap.getCategory());
String name = sheet.getColumn(row, "Code");
String context = null;
if (Utilities.noString(name))
throw new Exception("No code found on Extension at " + getLocation(row));
if (name.contains("."))
throw new Exception("Extension Definition Error: Extension names cannot contain '.': " + name + " at " + getLocation(row));
ex.setUrl(uri + name);
ex.setId(tail(ex.getUrl()));
ex.setUserData("path", "extension-" + ex.getId().toLowerCase() + ".html");
ap.getExtensions().add(ex);
if (context == null) {
ExtensionContextType ct = readContextType(sheet.getColumn(row, "Context Type"), row);
if (sheet.hasColumn("Context Invariant"))
for (String s : sheet.getColumn(row, "Context Invariant").split("~")) ex.addContextInvariant(s);
String cc = checkContextMacro(sheet.getColumn(row, "Context"));
if (!Utilities.noString(cc))
for (String c : cc.split("\\;")) {
StructureDefinitionContextComponent ec = ex.addContext();
ec.setExpression(c.trim());
ec.setType(ct);
if (definitions != null) {
definitions.checkContextValid(ec, this.name, this.context);
}
}
}
ex.setTitle(sheet.getColumn(row, "Display"));
ElementDefn exe = new ElementDefn();
exe.setName(sheet.getColumn(row, "Code"));
ElementDefn exu = new ElementDefn();
exu.setName("url");
exu.setXmlAttribute(true);
exe.getElements().add(exu);
exu.setFixed(new UriType(ex.getUrl()));
exu.getTypes().add(new TypeRef().setName("uri"));
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (inv.getContext().equals(name))
exe.getInvariants().put(inv.getId(), inv);
}
}
parseExtensionElement(sheet, row, definitions, exe, false);
String sl = exe.getShortDefn();
ex.setName(sheet.getColumn(row, "Name"));
if (!ex.hasName())
ex.setName(exe.getName());
if (!ex.hasName())
ex.setName(ex.getTitle());
if (!ex.hasName() && !Utilities.noString(sl))
ex.setName(sl);
if (!ex.hasName())
throw new Exception("Extension " + ex.getUrl() + " missing name at " + getLocation(row));
ex.setDescription(preProcessMarkdown(exe.getDefinition(), "Extension Definition"));
ex.setPublisher(ap.metadata("author.name"));
if (ap.hasMetadata("author.reference"))
ex.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, ap.metadata("author.reference")));
// <code> opt Zero+ Coding assist with indexing and finding</code>
if (ap.hasMetadata("date"))
ex.setDateElement(Factory.newDateTime(ap.metadata("date").substring(0, 10)));
else
ex.setDate(genDate.getTime());
if (ap.hasMetadata("status"))
ex.setStatus(PublicationStatus.fromCode(ap.metadata("status")));
row++;
if (ig == null || ig.isCore()) {
if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") && !ex.getUrl().startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
throw new Exception("extension " + ex.getUrl() + " is not valid in the publication tooling");
} else {
if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
throw new Exception("extension " + ex.getUrl() + " is not valid for the IG " + ig.getCode() + " in the publication tooling");
}
while (row < sheet.getRows().size() && sheet.getColumn(row, "Code").startsWith(name + ".")) {
String n = sheet.getColumn(row, "Code");
ElementDefn p = findContext(exe, n.substring(0, n.lastIndexOf(".")), "Extension Definition " + name);
ElementDefn child = new ElementDefn();
p.getElements().add(child);
child.setName(n.substring(n.lastIndexOf(".") + 1));
child.setProfileName(child.getName());
parseExtensionElement(sheet, row, definitions, child, true);
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (inv.getContext().equals(n))
child.getInvariants().put(inv.getId(), inv);
}
}
row++;
}
ProfileGenerator gen = new ProfileGenerator(definitions, null, pkp, null, version, null, fpUsages, null, null, rc);
ProfileUtilities utils = new ProfileUtilities(this.context, issues, pkp);
gen.convertElements(exe, ex, null);
ex.getDifferential().getElementFirstRep().getType().clear();
utils.setIds(ex, false);
StructureDefinition base = definitions != null ? definitions.getSnapShotForType("Extension") : this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Extension");
List<String> errors = new ArrayList<String>();
utils.sortDifferential(base, ex, "extension " + ex.getUrl(), errors, false);
assert (errors.size() == 0);
utils.generateSnapshot(base, ex, ex.getUrl(), "http://hl7.org/fhir", ex.getName());
utils.setIds(ex, true);
new ExtensionDefinitionValidator(context).validate(ex);
this.context.cacheResource(ex);
return row;
}
use of org.hl7.fhir.definitions.model.WorkGroup in project kindling by HL7.
the class SourceParser method parseConformanceDocument.
private void parseConformanceDocument(Profile pack, String n, File file, String usage, WorkGroup wg) throws Exception {
try {
Resource rf = new XmlParser().parse(new CSFileInputStream(file));
if (!(rf instanceof Bundle))
throw new Exception("Error parsing Profile: neither a spreadsheet nor a bundle");
Bundle b = (Bundle) rf;
if (b.getType() != BundleType.DOCUMENT)
throw new Exception("Error parsing profile: neither a spreadsheet nor a bundle that is a document");
for (BundleEntryComponent ae : ((Bundle) rf).getEntry()) {
if (ae.getResource() instanceof Composition)
pack.loadFromComposition((Composition) ae.getResource(), file.getAbsolutePath());
else if (ae.getResource() instanceof StructureDefinition && !((StructureDefinition) ae.getResource()).getType().equals("Extension")) {
StructureDefinition ed = (StructureDefinition) ae.getResource();
for (StructureDefinitionContextComponent s : ed.getContext()) definitions.checkContextValid(s, file.getName(), this.context);
ToolResourceUtilities.updateUsage(ed, pack.getCategory());
pack.getProfiles().add(new ConstraintStructure(ed, definitions.getUsageIG(usage, "Parsing " + file.getAbsolutePath()), wg == null ? wg(ed) : wg, fmm(ed), ed.getExperimental()));
} else if (ae.getResource() instanceof StructureDefinition) {
StructureDefinition ed = (StructureDefinition) ae.getResource();
if (Utilities.noString(ed.getBaseDefinition()))
ed.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Extension");
ed.setDerivation(TypeDerivationRule.CONSTRAINT);
if (ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_WORKGROUP) == null)
ToolingExtensions.setCodeExtension(ed, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
if (!ed.hasUrl())
if (ae.hasFullUrl())
ed.setUrl(ae.getFullUrl());
else
ed.setUrl("http://hl7.org/fhir/StructureDefinition/" + ed.getId());
context.cacheResource(ed);
pack.getExtensions().add(ed);
}
}
} catch (Exception e) {
throw new Exception("Error Parsing profile: '" + n + "': " + e.getMessage(), e);
}
}
use of org.hl7.fhir.definitions.model.WorkGroup in project kindling by HL7.
the class SourceParser method loadResource.
private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
String folder = n;
WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
if (wg == null)
throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
if (isTemplate) {
File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
ResourceDefn root;
try {
root = sparser.parseResource(isTemplate);
} catch (Exception e) {
throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
}
root.setAbstract(isAbstract);
root.setInterface(isInterface);
errors.addAll(sparser.getErrors());
setResourceProps(n, wg, root);
String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
if (sc != null) {
root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
} else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
for (EventDefn e : sparser.getEvents()) {
processEvent(e, root.getRoot());
}
if (map != null) {
map.put(root.getName(), root);
}
if (!isTemplate) {
definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
context.getResourceNames().add(root.getName());
}
if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
root.setStatus(StandardsStatus.NORMATIVE);
}
if (f.exists()) {
parseSvgFile(f, root.getLayout(), f.getName());
}
if (map != null) {
map.put(root.getName(), root);
}
return root;
} else {
try {
new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
} catch (Exception e) {
System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
}
new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
if (f.exists()) {
parseSvgFile(f, rootNew.getLayout(), f.getName());
}
if (!isTemplate) {
definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
context.getResourceNames().add(rootNew.getName());
}
setResourceProps(n, wg, rootNew);
if (map != null) {
map.put(rootNew.getName(), rootNew);
}
return rootNew;
}
}
Aggregations