use of org.hl7.fhir.definitions.model.BindingSpecification 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.definitions.model.BindingSpecification in project kindling by HL7.
the class SourceParser method loadGlobalBindings.
private void loadGlobalBindings() throws Exception {
logger.log("Load Common Bindings", LogMessageType.Process);
BindingsParser parser = new BindingsParser(new CSFileInputStream(new CSFile(termDir + "bindings.xml")), termDir + "bindings.xml", srcDir, registry, version.toCode(), definitions.getCodeSystems(), page.getConceptMaps(), genDate, exceptionIfExcelNotNormalised, page.packageInfo());
List<BindingSpecification> cds = parser.parse();
for (BindingSpecification cd : cds) {
definitions.getAllBindings().add(cd);
definitions.getCommonBindings().put(cd.getName(), cd);
if (cd.getValueSet() != null) {
vsGen.updateHeader(cd, cd.getValueSet());
definitions.getBoundValueSets().put(cd.getValueSet().getUrl(), cd.getValueSet());
} else if (cd.getReference() != null && cd.getReference().startsWith("http:")) {
definitions.getUnresolvedBindings().add(cd);
}
if (cd.getMaxValueSet() != null) {
vsGen.updateHeader(cd, cd.getMaxValueSet());
definitions.getBoundValueSets().put(cd.getMaxValueSet().getUrl(), cd.getMaxValueSet());
}
}
if (!page.getDefinitions().getBoundValueSets().containsKey("http://hl7.org/fhir/ValueSet/data-absent-reason"))
throw new Exception("d-a-r not found");
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class ResourceParser method parseBinding.
public BindingSpecification parseBinding(ElementDefinitionBindingComponent binding) throws IOException {
BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName"), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
bs.setStrength(binding.getStrength());
bs.setBindingMethod(BindingMethod.ValueSet);
bs.setDescription(binding.getDescription());
bs.setReference(binding.getValueSet());
if (bs.hasReference()) {
bs.setValueSet(loadValueSet(bs.getReference(), false));
}
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
}
if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
}
if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
}
if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
}
if (binding.hasExtension(BuildExtensions.EXT_URI)) {
bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
}
if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
}
if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
}
if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
}
if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
}
if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
}
if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
}
return bs;
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class ResourceParser method parseBinding.
private BindingSpecification parseBinding(OperationDefinitionParameterBindingComponent binding) throws IOException {
BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString(BuildExtensions.EXT_BINDING_NAME), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
bs.setStrength(binding.getStrength());
bs.setBindingMethod(BindingMethod.ValueSet);
bs.setReference(binding.getValueSet());
if (bs.hasReference()) {
bs.setValueSet(loadValueSet(bs.getReference(), false));
}
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
}
if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
}
if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
}
if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
}
if (binding.hasExtension(BuildExtensions.EXT_URI)) {
bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
}
if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
}
if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
}
if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
}
if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
}
if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
}
if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
}
return bs;
}
use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.
the class TerminologyNotesGenerator method scan.
private void scan(ElementDefn e, String path) throws Exception {
if (e.hasBinding()) {
BindingSpecification cd = e.getBinding();
if (!txusages.containsKey(cd)) {
txusages.put(cd, new ArrayList<CDUsage>());
c++;
txusages.get(cd).add(new CDUsage(String.valueOf(c), null));
}
txusages.get(cd).add(new CDUsage(path, e));
}
for (ElementDefn c : e.getElements()) {
scan(c, path + "." + c.getName());
}
}
Aggregations