diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/acceleratorkit/StructureDefinitionElementBindingVisitor.java b/tooling/src/main/java/org/opencds/cqf/tooling/acceleratorkit/StructureDefinitionElementBindingVisitor.java index 6063b832..7d56262e 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/acceleratorkit/StructureDefinitionElementBindingVisitor.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/acceleratorkit/StructureDefinitionElementBindingVisitor.java @@ -2,10 +2,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; -import org.hl7.fhir.r4.model.CanonicalType; -import org.hl7.fhir.r4.model.ElementDefinition; -import org.hl7.fhir.r4.model.StructureDefinition; -import org.hl7.fhir.r4.model.ValueSet; +import org.hl7.fhir.r4.model.*; import java.util.*; import java.util.concurrent.atomic.AtomicReference; @@ -78,8 +75,7 @@ private void getBindings(String sdName, List eds, String sdUR if(ed.getMin() > 0){sdbo.setCardinalityMin(ed.getMin());} } if(getBindingObjectExtension(ed).equalsIgnoreCase("qicore-keyelement")){ - System.out.println("qicore-keyelement"); - sdbo.setBindingObjectExtension("qicore-keyelement"); + sdbo.setBindingObjectExtension("qicore-keyelement"); } String bindingValueSet = ed.getBinding().getValueSet(); String pipeVersion = ""; @@ -134,6 +130,99 @@ else if (ed.hasExtension()) { } } + private String getBindingObjectExtension(ElementDefinition ed) { + for (Extension ext : ed.getExtension()) { + if (!ext.getUrl().isEmpty()) { + if (ext.getUrl().contains("qicore-keyelement")) { + return "qicore-keyelement"; + } + } + } + return ""; + } + + private void visitExtensions(ElementDefinition ed, Map bindingObjects, String sdName, String sdURL, String sdVersion) { + StructureDefinitionBindingObject sdbo = new StructureDefinitionBindingObject(); + sdbo.setSdName(sdName); + sdbo.setSdURL(sdURL); + sdbo.setSdVersion(sdVersion); + sdbo.setElementId(ed.getId()); + if (ed.getMustSupport()) { + sdbo.setMustSupport("Y"); + } else { + sdbo.setMustSupport("N"); + } + if (ed.hasMin()) { + String edCardinality = ed.getMin() + "..." + ed.getMax(); + sdbo.setCardinality(edCardinality); + } + CanonicalType canonicalType = new CanonicalType(); + Iterable sdList = null; + try { + if (ed.getType().get(0).getProfile().size() != 0) { + canonicalType.setValue(String.valueOf(ed.getType().get(0).getProfile().get(0))); + sdList = this.canonicalResourceDependenciesAtlas.getStructureDefinitions().getByCanonicalUrl(ed.getType().get(0).getProfile().get(0).getValueAsString()); + } else if (ed.getType().get(0).getTargetProfile().size() != 0) { + canonicalType.setValue(String.valueOf(ed.getType().get(0).getTargetProfile())); + sdList = this.canonicalResourceDependenciesAtlas.getStructureDefinitions().getByCanonicalUrl(ed.getType().get(0).getTargetProfile().get(0).getValueAsString()); + } + else{ + return; + } + } catch (Exception ex) { + return; + } + if (sdList != null) { + sdList.forEach((structDef) -> { + List edsds = structDef.getDifferential().getElement(); + edsds.forEach(edsd -> { + if (edsd.hasBinding()) { + sdbo.setBindingStrength(edsd.getBinding().getStrength().toString().toLowerCase()); + String bindingValueSet = edsd.getBinding().getValueSet(); + String pipeVersion = ""; + if (bindingValueSet.contains("|")) { + pipeVersion = bindingValueSet.substring(bindingValueSet.indexOf("|") + 1); + bindingValueSet = bindingValueSet.substring(0, bindingValueSet.indexOf("|")); + } + sdbo.setBindingValueSetURL(bindingValueSet); + String valueSetVersion = ""; + ValueSet elementValueSet = null; + if (null != this.canonicalResourceAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL())) { + valueSetVersion = this.canonicalResourceAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()).getVersion(); + sdbo.setBindingValueSetName(this.canonicalResourceAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()).getName()); + elementValueSet = this.canonicalResourceAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()); + } else if (null != this.canonicalResourceDependenciesAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL())) { + valueSetVersion = this.canonicalResourceDependenciesAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()).getVersion(); + sdbo.setBindingValueSetName(this.canonicalResourceDependenciesAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()).getName()); + elementValueSet = this.canonicalResourceDependenciesAtlas.getValueSets().getByCanonicalUrlWithVersion(sdbo.getBindingValueSetURL()); + } else if (valueSetVersion.isEmpty() && bindingValueSet.contains("|")) { + valueSetVersion = pipeVersion; + } + sdbo.setBindingValueSetVersion(valueSetVersion); + if (null != elementValueSet) { + StringBuilder codeSystemURLs = new StringBuilder(); + Map codeSystemsMap = new HashMap<>(); + getValueSetCodeSystems(elementValueSet, codeSystemsMap); + if (!codeSystemsMap.isEmpty()) { + AtomicReference valueCount = new AtomicReference<>(0); + codeSystemsMap.values().forEach((url) -> { + codeSystemURLs.append(url); + valueCount.set(valueCount.get() + 1); + if (valueCount.get() > 0 && + valueCount.get() < codeSystemsMap.size()) { + codeSystemURLs.append(";"); + } + }); + sdbo.setCodeSystemsURLs(codeSystemURLs.toString()); + } + } + } + }); + }); + } + bindingObjects.put(sdName + "." + sdbo.getElementId(), sdbo); + } + private void getValueSetCodeSystems(ValueSet elementValueSet, Map codeSystemsMap) { ValueSet.ValueSetComposeComponent compose = elementValueSet.getCompose(); if (null != compose) { diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/operation/ProfilesToSpreadsheet.java b/tooling/src/main/java/org/opencds/cqf/tooling/operation/ProfilesToSpreadsheet.java index f1d76899..fc5ed59f 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/operation/ProfilesToSpreadsheet.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/operation/ProfilesToSpreadsheet.java @@ -157,7 +157,7 @@ private void addBindingObjectRowDataToCurrentSheet(XSSFSheet currentSheet, int r if ((null != bo.getBindingStrength() && bo.getBindingStrength().equalsIgnoreCase("required")) || null != bo.getMustSupport() && bo.getMustSupport().equalsIgnoreCase("Y") || null != bo.getBindingObjectExtension() && bo.getBindingObjectExtension().equalsIgnoreCase("qicore-keyElement") || - bo.getCardinalityMin() >0 + bo.getCardinalityMin() > 0 ) { currentCell.setCellValue("Needed"); }