use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class Regenerator method generateExtension.
private CanonicalResource generateExtension(String root, ResourceDefn r, Profile p, StructureDefinition sd) throws IOException {
File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-extension-" + sd.getId() + ".gen.xml"));
sd.setSnapshot(null);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
fn.setLastModified(r.getTimestamp());
return sd;
}
use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class Regenerator method generateCP.
private void generateCP(String root, ResourceDefn r, Profile p) throws IOException {
ImplementationGuide ig = new ImplementationGuide();
ig.setId(r.getName() + "-" + p.getCategory());
ig.setTitle(p.getTitle());
ig.setStatus(PublicationStatus.ACTIVE);
ig.setDate(new Date(r.getTimestamp()));
for (String s : p.getMetadata().keySet()) {
List<String> vl = p.getMetadata().get(s);
for (String v : vl) {
if (!Utilities.noString(v)) {
switch(s) {
// case "id": ig.setId(v); break;
case "name":
ig.setName(v);
break;
case "author.name":
ig.setPublisher(v);
break;
case "code":
ig.addExtension(BuildExtensions.EXT_CODE, new CodeType(v));
break;
case "fmm":
ig.addExtension(ToolingExtensions.EXT_FMM_LEVEL, new CodeType(v));
break;
case "description":
ig.setDescription(v);
break;
case "status":
ig.setStatus(PublicationStatus.fromCode(v));
break;
case "publication.status":
break;
case "version":
ig.setVersion(v);
break;
case "display":
ig.setTitle(v);
break;
case "workgroup":
ig.addExtension(ToolingExtensions.EXT_WORKGROUP, new CodeType(v));
break;
case "date":
ig.getDateElement().setValueAsString(v);
break;
case "Experimental":
ig.setExperimental(Utilities.existsInList(v.toLowerCase(), "y", "yes", "1", "true"));
break;
default:
if (s.startsWith("fmm-") || Utilities.existsInList(s, "extension.uri", "author.reference", "published.structure", "notes", "introduction") || s.startsWith("!")) {
// ignore these
} else if (s.startsWith("summary-")) {
String n = s.substring(8);
for (ConstraintStructure cs : p.getProfiles()) {
if (n.equals(cs.getTitle()) || n.equals(cs.getId())) {
cs.setSummary(v);
}
}
} else {
System.out.println("Unknown metadata item: " + s + "=" + v);
}
}
}
}
}
if (!Utilities.noString(p.getIntroduction())) {
ig.addExtension(BuildExtensions.EXT_INTRODUCTION, new StringType(p.getIntroduction()));
}
if (!Utilities.noString(p.getNotes())) {
ig.addExtension(BuildExtensions.EXT_NOTES, new StringType(p.getNotes()));
}
for (ConstraintStructure cs : p.getProfiles()) {
CanonicalResource cr = generateProfile(root, r, p, cs);
ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
}
for (StructureDefinition cs : p.getExtensions()) {
CanonicalResource cr = generateExtension(root, r, p, cs.copy());
ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
}
for (SearchParameter cs : p.getSearchParameters()) {
CanonicalResource cr = generateSearchParameter(root, r, p, cs);
ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
}
for (Example cs : p.getExamples()) {
ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
generateExample(root, r, p, cs, res);
}
File fn = new File(Utilities.path(root, ig.fhirType().toLowerCase() + "-" + ig.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), ig);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class Regenerator method generateInner.
public void generateInner(ResourceDefn r) throws FileNotFoundException, IOException {
String root = Utilities.path(srcFolder, r.getName());
generateSearchParams(root, r);
generateExamples(root, r);
generateOperations(r, root);
generatePacks(r, root);
// private List<Profile> conformancePackages = new ArrayList<Profile>();
// private Profile conformancePack;
StructureDefinition sd = r.getProfile().copy();
sd.setSnapshot(null);
sd.setText(null);
if (r.getEnteredInErrorStatus() != null) {
sd.addExtension(BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS, new CodeType(r.getEnteredInErrorStatus()));
}
if (r.getProposedOrder() != null) {
sd.addExtension(BuildExtensions.EXT_PROPOSED_ORDER, new StringType(r.getProposedOrder()));
}
if (r.getTemplate() != null) {
sd.addExtension(BuildExtensions.EXT_TEMPLATE, new StringType(r.getTemplate().getName()));
}
// now, walk through the elements.
generateElement(root, r.getName(), sd.getDifferential(), r, r.getRoot());
File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-" + sd.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class Regenerator method generateExamples.
private void generateExamples(String root, ResourceDefn r) throws FileNotFoundException, IOException {
ListResource list = new ListResource();
list.setId(r.getName() + "-examples");
list.setStatus(ListStatus.CURRENT);
list.setMode(ListMode.WORKING);
for (Example ex : r.getExamples()) {
ListResourceEntryComponent li = list.addEntry();
li.getItem().setReference(ex.getResourceName() + "/" + ex.getId());
li.getItem().setDisplay(ex.getName());
if (ex.getDescription() != null) {
li.addExtension(BuildExtensions.EXT_DESCRIPTION, new StringType(ex.getDescription()));
}
if (ex.getTitle() != null) {
li.addExtension(BuildExtensions.EXT_TITLE, new StringType(ex.getTitle()));
}
switch(ex.getType()) {
case Container:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container", null);
break;
case CsvFile:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv", null);
break;
case Tool:
li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool", null);
break;
default:
break;
}
if (!ex.isRegistered()) {
li.addExtension(BuildExtensions.EXT_NOT_REGISTERED, new BooleanType(!ex.isRegistered()));
}
if (ex.getIg() != null) {
li.addExtension(BuildExtensions.EXT_IG, new CodeType(ex.getIg()));
}
if (ex.getExampleFor() != null) {
li.addExtension(BuildExtensions.EXT_EXAMPLE_FOR, new StringType(ex.getExampleFor()));
}
}
File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class Regenerator method generateSearchParameter.
private CanonicalResource generateSearchParameter(String root, ResourceDefn r, Profile p, SearchParameter sp) throws IOException {
File fn = new File(Utilities.path(root, sp.fhirType().toLowerCase() + "-profile-" + sp.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sp);
fn.setLastModified(r.getTimestamp());
return sp;
}
Aggregations