use of org.hl7.fhir.definitions.parsers.TypeParser in project kindling by HL7.
the class SourceParser method loadCompositeType.
private String loadCompositeType(String n, Map<String, org.hl7.fhir.definitions.model.TypeDefn> map, String fmm, boolean isAbstract) throws Exception {
TypeParser tp = new TypeParser(version.toString());
List<TypeRef> ts = tp.parse(n, false, null, context, true);
definitions.getKnownTypes().addAll(ts);
StandardsStatus status = loadStatus(n);
String nv = loadNormativeVersion(n);
try {
TypeRef t = ts.get(0);
File csv = new CSFile(dtDir + t.getName().toLowerCase() + ".xml");
if (csv.exists()) {
OldSpreadsheetParser p = new OldSpreadsheetParser("core", new CSFileInputStream(csv), csv.getName(), csv.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, true, ini, wg("fhir"), definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
org.hl7.fhir.definitions.model.TypeDefn el = p.parseCompositeType();
el.setFmmLevel(fmm);
el.setStandardsStatus(status);
el.setNormativeVersion(nv);
map.put(t.getName(), el);
genTypeProfile(el);
errors.addAll(p.getErrors());
return el.getName();
} else {
String p = ini.getStringProperty("types", n);
csv = new CSFile(dtDir + p.toLowerCase() + ".xml");
if (!csv.exists())
throw new Exception("unable to find a definition for " + n + " in " + p);
XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(csv), csv.getAbsolutePath());
new XLSXmlNormaliser(csv.getAbsolutePath(), exceptionIfExcelNotNormalised).go();
Sheet sheet = xls.getSheets().get("Restrictions");
boolean found = false;
for (int i = 0; i < sheet.rows.size(); i++) {
if (sheet.getColumn(i, "Name").equals(n)) {
found = true;
Invariant inv = new Invariant();
inv.setId(n);
inv.setEnglish(sheet.getColumn(i, "Rules"));
inv.setOcl(sheet.getColumn(i, "OCL"));
inv.setXpath(sheet.getColumn(i, "XPath"));
inv.setExpression(sheet.getColumn(i, "Expression"));
inv.setExplanation(sheet.getColumn(i, "Explanation"));
inv.setTurtle(sheet.getColumn(i, "RDF"));
ProfiledType pt = new ProfiledType();
pt.setDefinition(sheet.getColumn(i, "Definition"));
pt.setDescription(sheet.getColumn(i, "Rules"));
String structure = sheet.getColumn(i, "Structure");
if (!Utilities.noString(structure)) {
String[] parts = structure.split("\\;");
for (String pp : parts) {
String[] words = pp.split("\\=");
pt.getRules().put(words[0], words[1]);
}
}
pt.setName(n);
pt.setBaseType(p);
pt.setInvariant(inv);
definitions.getConstraints().put(n, pt);
}
}
if (!found)
throw new Exception("Unable to find definition for " + n);
return n;
}
} catch (Exception e) {
throw new Exception("Unable to load " + n + ": " + e.getMessage(), e);
}
}
use of org.hl7.fhir.definitions.parsers.TypeParser in project kindling by HL7.
the class SourceParser method checkConditions.
public void checkConditions(List<String> errors, Map<String, Long> dates) throws Exception {
Utilities.checkFolder(srcDir, errors);
Utilities.checkFolder(termDir, errors);
Utilities.checkFolder(imgDir, errors);
this.dates = dates;
checkFile("required", termDir, "bindings.xml", errors, "all");
checkFile("required", dtDir, "primitives.xml", errors, "all");
for (String n : ini.getPropertyNames("types")) if (ini.getStringProperty("types", n).equals("")) {
TypeRef t = new TypeParser(version.toString()).parse(n, false, null, context, true).get(0);
checkFile("type definition", dtDir, t.getName().toLowerCase() + ".xml", errors, "all");
}
String[] shared = ini.getPropertyNames("shared");
if (shared != null)
for (String n : shared) checkFile("shared structure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
for (String n : ini.getPropertyNames("infrastructure")) checkFile("infrastructure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
for (String n : ini.getPropertyNames("resources")) {
if (!new File(srcDir + n).exists())
errors.add("unable to find folder for resource " + n);
else {
for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
}
}
for (String n : ini.getPropertyNames("special-resources")) {
// now iterate all the files in the directory checking data
for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
}
}
use of org.hl7.fhir.definitions.parsers.TypeParser in project kindling by HL7.
the class SpreadSheetReloader method parseType.
private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
ed.getType().clear();
ed.setContentReferenceElement(null);
if (ed.getPath().equals("Resource.id")) {
ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
} else {
if (Utilities.noString(value)) {
if (ed.getPath().contains(".")) {
ed.addType().setCode("BackboneElement");
}
} else if (value.startsWith("#")) {
ed.setContentReference(value);
} else {
List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
for (TypeRef tr : tl) {
TypeRefComponent t = ed.addType().setCode(tr.getName());
if ("SimpleQuantity".equals(t.getCode())) {
t.setCode("Quantity");
t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
}
for (String p : tr.getParams()) {
if (p.equals("Definition")) {
t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
} else {
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
}
if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
}
}
}
}
}
use of org.hl7.fhir.definitions.parsers.TypeParser in project kindling by HL7.
the class ProfileGenerator method produceOpParam.
private void produceOpParam(String path, List<OperationDefinitionParameterComponent> opd, OperationParameter p, OperationParameterUse defUse) throws Exception {
OperationDefinitionParameterComponent pp = new OperationDefinitionParameterComponent();
pp.setName(p.getName());
if (path.contains("."))
pp.setUse(defUse);
else if (p.getUse().equals("in"))
pp.setUse(OperationParameterUse.IN);
else if (p.getUse().equals("out"))
pp.setUse(OperationParameterUse.OUT);
else
// but this is validated elsewhere
throw new Exception("Unable to determine parameter use: " + p.getUse() + " at " + path + "." + p.getName());
pp.setDocumentation(preProcessMarkdown(p.getDoc(), "Operation Parameter Doco"));
pp.setMin(p.getMin());
pp.setMax(p.getMax());
if (p.getBs() != null) {
if (p.getBs().hasMax())
throw new Error("Max binding not handled yet");
pp.setBinding(new OperationDefinitionParameterBindingComponent().setStrength(p.getBs().getStrength()).setValueSet(buildValueSetReference(p.getBs())));
if (!Utilities.noString(p.getBinding().getName())) {
pp.getBinding().addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", new StringType(p.getBinding().getName()));
}
}
if (!Utilities.noString(p.getProfile())) {
pp.addTargetProfile(p.getProfile());
}
opd.add(pp);
if (p.getFhirType().equals("Tuple")) {
for (OperationParameter part : p.getParts()) {
produceOpParam(path + "." + p.getName(), pp.getPart(), part, pp.getUse());
}
} else {
List<TypeRef> trs = new TypeParser(version.toCode()).parse(p.getFhirType(), false, null, null, false);
if (trs.size() > 1) {
if (p.getSearchType() != null)
pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
pp.setType(Enumerations.FHIRAllTypes.fromCode("Element"));
for (TypeRef tr : trs) {
pp.addExtension(ToolingExtensions.EXT_ALLOWED_TYPE, new UriType(tr.getName()));
if (tr.getParams().size() > 0)
throw new Error("Multiple types for an operation parameter, where one is a reference, is not supported by the build tools");
}
} else {
TypeRef tr = trs.get(0);
if (definitions.getConstraints().containsKey(tr.getName())) {
ProfiledType pt = definitions.getConstraints().get(tr.getName());
pp.setType(Enumerations.FHIRAllTypes.fromCode(pt.getBaseType().equals("*") ? "Type" : pt.getBaseType()));
pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
} else {
if (p.getSearchType() != null)
pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
pp.setType(Enumerations.FHIRAllTypes.fromCode(tr.getName().equals("*") ? "Type" : tr.getName()));
if (tr.getParams().size() == 1 && !tr.getParams().get(0).equals("Any"))
pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + tr.getParams().get(0));
}
}
}
}
use of org.hl7.fhir.definitions.parsers.TypeParser in project kindling by HL7.
the class PageProcessor method dictForDt.
// private boolean notime;
private String dictForDt(String dt) throws Exception {
File tmp = Utilities.createTempFile("tmp", ".tmp");
DictHTMLGenerator gen = new DictHTMLGenerator(new FileOutputStream(tmp), this, "");
TypeParser tp = new TypeParser(version.toCode());
TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
ElementDefn e;
if (t.getName().equals("Resource"))
e = definitions.getBaseResources().get("DomainResource").getRoot();
else
e = definitions.getElementDefn(t.getName());
if (e == null) {
gen.close();
throw new Exception("unable to find definition for " + dt);
} else {
gen.generate(e);
gen.close();
}
String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
tmp.delete();
return val;
}
Aggregations