use of org.hl7.fhir.utilities.graphql.Operation in project kindling by HL7.
the class ValueSetGenerator method loadOperationOutcomeValueSet.
public void loadOperationOutcomeValueSet(BindingSpecification cd) throws Exception {
ValueSet vs = new ValueSet();
cd.setValueSet(vs);
cd.setBindingMethod(BindingMethod.ValueSet);
vs.setId("operation-outcome");
vs.setUrl("http://hl7.org/fhir/ValueSet/" + vs.getId());
vs.setName("OperationOutcomeCodes");
vs.setTitle("Operation Outcome Codes");
vs.setPublisher("HL7 (FHIR Project)");
vs.setVersion(version);
vs.setUserData("filename", "valueset-" + vs.getId());
if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType("fhir"));
} else {
String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals("fhir"))
System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 11: is " + ec + ", want to set to " + "fhir");
}
vs.setUserData("path", "valueset-" + vs.getId() + ".html");
ContactDetail c = vs.addContact();
c.addTelecom().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
c.addTelecom().setSystem(ContactPointSystem.EMAIL).setValue("fhir@lists.hl7.org");
vs.setDescription("Operation Outcome codes used by FHIR test servers (see Implementation file translations.xml)");
vs.setStatus(PublicationStatus.DRAFT);
if (!vs.hasCompose())
vs.setCompose(new ValueSetComposeComponent());
vs.getCompose().addInclude().setSystem("http://terminology.hl7.org/CodeSystem/operation-outcome");
CodeSystem cs = new CodeSystem();
cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.ISA);
Set<String> codes = translator.listTranslations("ecode");
for (String s : sorted(codes)) {
Map<String, String> langs = translator.translations(s);
ConceptDefinitionComponent cv = cs.addConcept();
cv.setCode(s);
cv.setDisplay(langs.get("en"));
for (String lang : langs.keySet()) {
if (!lang.equals("en")) {
String value = langs.get(lang);
ConceptDefinitionDesignationComponent dc = cv.addDesignation();
dc.setLanguage(lang);
dc.setValue(value);
dc.getUse().setSystem("http://terminology.hl7.org/CodeSystem/designation-usage").setCode("display");
}
}
}
CodeSystemConvertor.populate(cs, vs);
cs.setUrl("http://terminology.hl7.org/CodeSystem/operation-outcome");
cs.setVersion(version);
cs.setCaseSensitive(true);
cs.setContent(CodeSystemContentMode.COMPLETE);
definitions.getCodeSystems().see(cs, packageInfo);
}
use of org.hl7.fhir.utilities.graphql.Operation in project kindling by HL7.
the class OldSpreadsheetParser method readOperations.
private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
Map<String, Operation> ops = new HashMap<String, Operation>();
Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
if (sheet != null) {
for (int row = 0; row < sheet.rows.size(); row++) {
String name = sheet.getColumn(row, "Name");
String use = sheet.getColumn(row, "Use");
String doco = sheet.getColumn(row, "Documentation");
String type = sheet.getColumn(row, "Type");
List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
if (name != null && !name.equals("") && !name.startsWith("!")) {
if (!name.contains(".")) {
if (!type.equals("operation"))
throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
if (!name.toLowerCase().equals(name))
throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
params.clear();
boolean system = false;
boolean istype = false;
boolean instance = false;
for (String c : use.split("\\|")) {
c = c.trim();
if ("system".equalsIgnoreCase(c))
system = true;
else if ("resource".equalsIgnoreCase(c))
istype = true;
else if ("instance".equalsIgnoreCase(c))
instance = true;
else
throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
}
Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
op.setFooter2(sheet.getColumn(row, "Footer2"));
op.setFmm(sheet.getColumn(row, "fmm"));
op.getExamples2().addAll(examples2);
oplist.add(op);
ops.put(name, op);
} else {
String context = name.substring(0, name.lastIndexOf('.'));
String pname = name.substring(name.lastIndexOf('.') + 1);
Operation operation;
List<OperationParameter> plist;
if (context.contains(".")) {
String opname = name.substring(0, name.indexOf('.'));
// inside of a tuple
if (!Utilities.noString(use))
throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
operation = ops.get(opname);
if (operation == null)
throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
OperationParameter param = params.get(context);
if (param == null)
throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
if (!param.getFhirType().equals("Tuple"))
throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
plist = param.getParts();
} else {
if (!use.equals("in") && !use.equals("out"))
throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
operation = ops.get(context);
if (operation == null)
throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
plist = operation.getParameters();
}
String profile = sheet.getColumn(row, "Profile");
String min = sheet.getColumn(row, "Min");
String max = sheet.getColumn(row, "Max");
OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
String bs = sheet.getColumn(row, "Binding");
if (!Utilities.noString(bs))
p.setBs(bindings.get(bs));
plist.add(p);
params.put(name, p);
}
}
}
}
}
use of org.hl7.fhir.utilities.graphql.Operation in project kindling by HL7.
the class OldSpreadsheetParser method readBindings.
// Adds bindings to global definition.bindings. Returns list of
// newly found bindings in the sheet.
private void readBindings(Sheet sheet) throws Exception {
for (int row = 0; row < sheet.rows.size(); row++) {
String bindingName = sheet.getColumn(row, "Binding Name");
}
ValueSetGenerator vsGen = new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo);
for (int row = 0; row < sheet.rows.size(); row++) {
String bindingName = sheet.getColumn(row, "Binding Name");
// Ignore bindings whose name start with "!"
if (Utilities.noString(bindingName) || bindingName.startsWith("!"))
continue;
// if (Character.isLowerCase(bindingName.charAt(0)))
// throw new Exception("binding name "+bindingName+" is illegal - must start with a capital letter");
BindingSpecification cd = new BindingSpecification(usageContext, bindingName, false);
if (definitions != null)
definitions.getAllBindings().add(cd);
cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
cd.setBindingMethod(BindingsParser.readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + folder));
String ref = sheet.getColumn(row, "Reference");
if (!cd.getBinding().equals(BindingMethod.Unbound) && Utilities.noString(ref))
throw new Exception("binding " + cd.getName() + " is missing a reference");
if (cd.getBinding() == BindingMethod.CodeList) {
if (ref.startsWith("#valueset-"))
throw new Exception("don't start code list references with #valueset-");
cd.setValueSet(ValueSetUtilities.makeShareable(new ValueSet()));
valuesets.add(cd.getValueSet());
cd.getValueSet().setVersion(version.toCode());
cd.getValueSet().setId(igSuffix(ig) + ref.substring(1));
cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + igSuffix(ig) + ref.substring(1));
cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
if (!cd.getValueSet().hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
} else {
String ec = ToolingExtensions.readStringExtension(cd.getValueSet(), ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee))
System.out.println("ValueSet " + cd.getValueSet().getUrl() + " WG mismatch 3: is " + ec + ", want to set to " + committee.getCode());
}
if (ig != null) {
cd.getValueSet().setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
} else
cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
if (!cd.getValueSet().getUserData("path").equals(cd.getValueSet().getUserData("filename") + ".html"))
throw new Exception("Mis-identified value set");
if (!ref.startsWith("#"))
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' must started with '#'");
Sheet cs = xls.getSheets().get(ref.substring(1));
if (cs == null)
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' not resolved");
vsGen.updateHeader(cd, cd.getValueSet());
new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version.toCode(), codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), checkV3Mapping(sheet.getColumn(row, "v3")), getIsUtg(bindingName));
} else if (cd.getBinding() == BindingMethod.ValueSet) {
if (ref.startsWith("http:"))
// will sort this out later
cd.setReference(sheet.getColumn(row, "Reference"));
else
cd.setValueSet(loadValueSet(ref));
} else if (cd.getBinding() == BindingMethod.Special) {
if ("#operation-outcome".equals(sheet.getColumn(row, "Reference")))
new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo).loadOperationOutcomeValueSet(cd);
else
throw new Exception("Special bindings are only allowed in bindings.xml");
}
// do this anyway in the short term
cd.setReference(sheet.getColumn(row, "Reference"));
if (cd.getValueSet() != null) {
ValueSet vs = cd.getValueSet();
ValueSetUtilities.makeShareable(vs);
vs.setUserData("filename", "valueset-" + vs.getId());
if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
} else {
String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee.getCode()))
System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 4: is " + ec + ", want to set to " + committee.getCode());
}
if (ig != null) {
vs.setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
vs.setUserData("path", ig.getCode() + "/valueset-" + vs.getId() + ".html");
} else
vs.setUserData("path", "valueset-" + vs.getId() + ".html");
if (!ValueSetUtilities.hasOID(vs))
ValueSetUtilities.setOID(vs, "urn:oid:" + BindingSpecification.DEFAULT_OID_VS + registry.idForUri(vs.getUrl()));
if (vs.getUserData("cs") != null) {
if (!CodeSystemUtilities.hasOID((CodeSystem) vs.getUserData("cs")))
CodeSystemUtilities.setOID((CodeSystem) vs.getUserData("cs"), "urn:oid:" + BindingSpecification.DEFAULT_OID_CS + registry.idForUri(((CodeSystem) vs.getUserData("cs")).getUrl()));
}
if (definitions != null)
definitions.getBoundValueSets().put(vs.getUrl(), vs);
else
ig.getValueSets().add(vs);
} else if (cd.getReference() != null && cd.getReference().startsWith("http:")) {
if (definitions != null)
definitions.getUnresolvedBindings().add(cd);
else
ig.getUnresolvedBindings().add(cd);
}
cd.setDescription(sheet.getColumn(row, "Description"));
if (!Utilities.noString(sheet.getColumn(row, "Example")))
throw new Exception("The 'Example' column is no longer supported");
if (!Utilities.noString(sheet.getColumn(row, "Extensible")))
throw new Exception("The 'Extensible' column is no longer supported");
cd.setStrength(BindingsParser.readBindingStrength(sheet.getColumn(row, "Conformance")));
if (cd.getBinding() == BindingMethod.Unbound) {
cd.setStrength(BindingStrength.EXAMPLE);
}
cd.setSource(name);
cd.setUri(sheet.getColumn(row, "Uri"));
String oid = sheet.getColumn(row, "Oid");
if (!Utilities.noString(oid))
// no cs oid in this case
cd.setVsOid(oid);
cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
cd.setWebSite(sheet.getColumn(row, "Website"));
cd.setEmail(sheet.getColumn(row, "Email"));
cd.setCopyright(sheet.getColumn(row, "Copyright"));
cd.setV2Map(sheet.getColumn(row, "v2"));
cd.setV3Map(checkV3Mapping(sheet.getColumn(row, "v3")));
String max = sheet.getColumn(row, "Max");
if (!Utilities.noString(max))
if (max.startsWith("http:")) {
// will sort this out later
cd.setMaxReference(max);
} else
cd.setMaxValueSet(loadValueSet(max));
bindings.put(cd.getName(), cd);
if (cd.getValueSet() != null) {
ValueSet vs = cd.getValueSet();
vsGen.updateHeader(cd, cd.getValueSet());
}
}
}
use of org.hl7.fhir.utilities.graphql.Operation in project kindling by HL7.
the class Regenerator method generateOperation.
private void generateOperation(String root, ResourceDefn r, Operation op) throws IOException {
OperationDefinition opd = op.getResource().copy();
opd.setId(r.getName() + "-" + op.getName());
opd.setUrl("http://hl7.org/fhir/build/OperationDefinition/" + opd.getId());
if (!Utilities.noString(op.getFooter())) {
opd.addExtension(BuildExtensions.EXT_FOOTER, new MarkdownType(op.getFooter()));
}
if (!Utilities.noString(op.getFooter2())) {
opd.addExtension(BuildExtensions.EXT_FOOTER2, new MarkdownType(op.getFooter2()));
}
for (OperationExample opex : op.getExamples()) {
Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
if (!Utilities.noString(opex.getContent())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
}
if (!Utilities.noString(opex.getComment())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
}
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(1));
opd.addExtension(ex);
}
for (OperationExample opex : op.getExamples2()) {
Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
if (!Utilities.noString(opex.getContent())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
}
if (!Utilities.noString(opex.getComment())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
}
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(2));
opd.addExtension(ex);
}
File fn = new File(Utilities.path(root, opd.fhirType().toLowerCase() + "-" + opd.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), opd);
fn.setLastModified(r.getTimestamp());
}
use of org.hl7.fhir.utilities.graphql.Operation 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));
}
}
}
}
Aggregations