use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.
the class Publisher method processProfile.
private void processProfile(Profile ap, ConstraintStructure profile, String filename, ResourceDefn baseResource) throws Exception {
// create StructureDefinition structures if needed (create differential definitions from spreadsheets)
if (profile.getResource() == null) {
StructureDefinition p = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(ap, profile, profile.getDefn(), profile.getId(), profile.getUsage(), page.getValidationErrors(), baseResource);
p.setUserData("pack", ap);
profile.setResource(p);
if (profile.getResourceInfo() != null) {
profile.getResourceInfo().setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, p);
}
if (page.getProfiles().has(p.getUrl()))
throw new Exception("Duplicate Profile URL " + p.getUrl());
page.getProfiles().see(p, page.packageInfo());
} else {
profile.getResource().setUserData("pack", ap);
sortProfile(profile.getResource());
for (ElementDefinition ed : profile.getResource().getDifferential().getElement()) if (!ed.hasId())
throw new Exception("Missing ID");
// special case: if the profile itself doesn't claim a date, it's date is the date of this publication
if (!profile.getResource().hasDate())
profile.getResource().setDate(page.getGenDate().getTime());
if (profile.getResource().hasBaseDefinition() && !profile.getResource().hasSnapshot()) {
// cause it probably doesn't, coming from the profile directly
StructureDefinition base = getSnapShotForProfile(profile.getResource().getBaseDefinition());
new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSnapshot(base, profile.getResource(), profile.getResource().getBaseDefinition().split("#")[0], "http://hl7.org/fhir", profile.getResource().getName());
}
if (page.getProfiles().has(profile.getResource().getUrl()))
throw new Exception("Duplicate Profile URL " + profile.getResource().getUrl());
System.out.println("register " + profile.getResource().getUrl());
page.getProfiles().see(profile.getResource(), page.packageInfo());
}
if (!Utilities.noString(filename))
profile.getResource().setUserData("filename", filename + ".html");
if (Utilities.noString(profile.getResource().getUserString("path"))) {
String path = "";
ImplementationGuideDefn ig = page.getDefinitions().getUsageIG(ap.getCategory(), "processProfile");
if (ig != null && !ig.isCore())
path = ig.getCode() + File.separator;
profile.getResource().setUserData("path", path + filename + ".html");
}
}
use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.
the class Publisher method genPrimitiveTypeProfile.
private void genPrimitiveTypeProfile(DefinedStringPattern t) throws Exception {
StructureDefinition profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
if (page.getProfiles().has(profile.getUrl()))
throw new Exception("Duplicate Profile URL " + profile.getUrl());
page.getProfiles().see(profile, page.packageInfo());
t.setProfile(profile);
// DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getCode(), true);
// t.setProfile(profile);
// t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
// t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t));
}
use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.
the class SourceParser method genTypeProfile.
private void genTypeProfile(org.hl7.fhir.definitions.model.TypeDefn t) throws Exception {
StructureDefinition profile;
try {
profile = new ProfileGenerator(definitions, context, page, genDate, version, null, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
t.setProfile(profile);
DataTypeTableGenerator dtg = new DataTypeTableGenerator(dstDir, page, t.getName(), true, version);
t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t, null, false));
if (context.hasResource(StructureDefinition.class, t.getProfile().getUrl()))
throw new Exception("Duplicate Profile " + t.getProfile().getUrl());
context.cacheResource(t.getProfile());
} catch (Exception e) {
throw new Exception("Error generating profile for '" + t.getName() + "': " + e.getMessage(), e);
}
}
use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.
the class Publisher method genTypeProfile.
private void genTypeProfile(TypeDefn t) throws Exception {
StructureDefinition profile;
try {
profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
page.getProfiles().see(profile, page.packageInfo());
t.setProfile(profile);
DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getName(), true, page.getVersion());
t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t, null, false));
} catch (Exception e) {
throw new Exception("Error generating profile for '" + t.getName() + "': " + e.getMessage(), e);
}
}
use of org.hl7.fhir.definitions.generators.specification.ProfileGenerator in project kindling by HL7.
the class Publisher method produceTypeProfile.
private void produceTypeProfile(TypeDefn type) throws Exception {
// ProfileDefn p = new ProfileDefn();
// p.putMetadata("id", type.getName());
// p.putMetadata("name", "Basic StructureDefinition for " + type.getName());
// p.putMetadata("author.name", "FHIR Specification");
// p.putMetadata("author.ref", "http://hl7.org/fhir");
// p.putMetadata("description", "Basic StructureDefinition for " + type.getName() + " for validation support");
// p.putMetadata("status", "draft");
// p.putMetadata("date", new SimpleDateFormat("yyyy-MM-dd", new Locale("en", "US")).format(new Date()));
// p.getElements().add(type);
// ProfileGenerator pgen = new ProfileGenerator(page.getDefinitions());
// String fn = "type-" + type.getName() + ".profile.xml";
// StructureDefinition rp = pgen.generate(p, "type-" + type.getName() + ".profile", "<div>Type definition for " + type.getName() + " from <a href=\"http://hl7.org/fhir/datatypes.html#" + type.getName()
// + "\">FHIR Specification</a></div>");
String fn = type.getName().toLowerCase() + ".profile.xml";
StructureDefinition rp = type.getProfile();
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
addToResourceFeed(rp, page.getTypeBundle(), fn);
// saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
// + File.separator + "datatypes.html"));
cloneToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), false, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
jsonToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Json(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
ttlToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Ttl(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
shexToXhtml(type.getName().toLowerCase(), "ShEx statement for " + type.getName(), shex, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
}
Aggregations