Skip to content

Commit

Permalink
Add race and ethnicity bindings to bindings collection (#531)
Browse files Browse the repository at this point in the history
* added extension bindings

* added org.reflections to pom

* changes for PR

---------

Co-authored-by: c-schuler <[email protected]>
  • Loading branch information
bryantaustin13 and c-schuler authored Aug 20, 2024
1 parent 7a04aaf commit 6dd2f5c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tooling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,4 @@
</dependencyManagement>


</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public Map<String, StructureDefinitionBindingObject> visitStructureDefinition(St
getBindings(sdName, eds, sdURL, sdVersion, bindingObjects);
}
if (sd.hasBaseDefinition()) {
bindingObjects.putAll(visitStructureDefinition(this.canonicalResourceDependenciesAtlas.getStructureDefinitions().getByCanonicalUrlWithVersion(sd.getBaseDefinition()), snapshotOnly)); }
bindingObjects.putAll(visitStructureDefinition(this.canonicalResourceDependenciesAtlas.getStructureDefinitions().getByCanonicalUrlWithVersion(sd.getBaseDefinition()), snapshotOnly));
}
}
return bindingObjects;
}
Expand Down Expand Up @@ -71,7 +72,7 @@ private void getBindings(String sdName, List<ElementDefinition> eds, String sdUR
sdbo.setSdURL(sdURL);
sdbo.setSdVersion(sdVersion);
sdbo.setBindingStrength(ed.getBinding().getStrength().toString().toLowerCase());
if(ed.hasMin() && ed.hasMax()){
if (ed.hasMin() && ed.hasMax()) {
String edCardinality = ed.getMin() + "..." + ed.getMax();
sdbo.setCardinality(edCardinality);
}
Expand All @@ -97,16 +98,16 @@ private void getBindings(String sdName, List<ElementDefinition> eds, String sdUR
valueSetVersion = pipeVersion;
}
if (null != elementValueSet) {
StringBuilder codeSystemURLs = new StringBuilder();;
StringBuilder codeSystemURLs = new StringBuilder();
Map<String, String> codeSystemsMap = new HashMap<>();
getValueSetCodeSystems(elementValueSet, codeSystemsMap);
if(null != codeSystemsMap && !codeSystemsMap.isEmpty()) {
AtomicReference <Integer> valueCount = new AtomicReference<>(0);
codeSystemsMap.values().forEach((url)->{
if (null != codeSystemsMap && !codeSystemsMap.isEmpty()) {
AtomicReference<Integer> valueCount = new AtomicReference<>(0);
codeSystemsMap.values().forEach((url) -> {
codeSystemURLs.append(url);
valueCount.set(valueCount.get() + 1);
if(valueCount.get() > 0 &&
valueCount.get() < codeSystemsMap.size()) {
if (valueCount.get() > 0 &&
valueCount.get() < codeSystemsMap.size()) {
codeSystemURLs.append(";");
}
});
Expand All @@ -121,15 +122,100 @@ private void getBindings(String sdName, List<ElementDefinition> eds, String sdUR
sdbo.setBindingValueSetVersion(valueSetVersion);
bindingObjects.put(sdName + "." + sdbo.getElementId(), sdbo);
}
else if (ed.hasExtension()) {
visitExtensions(ed, bindingObjects, sdName, sdURL, sdVersion);
}
index.set(index.get() + 1);
}
}

private void visitExtensions(ElementDefinition ed, Map<String, StructureDefinitionBindingObject> 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<StructureDefinition> 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<ElementDefinition> 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<String, String> codeSystemsMap = new HashMap<>();
getValueSetCodeSystems(elementValueSet, codeSystemsMap);
if (!codeSystemsMap.isEmpty()) {
AtomicReference<Integer> 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<String, String> codeSystemsMap) {
ValueSet.ValueSetComposeComponent compose = elementValueSet.getCompose();
if (null != compose) {
for (ValueSet.ConceptSetComponent include : compose.getInclude()) {
if(include.hasSystem()){
if (include.hasSystem()) {
codeSystemsMap.put(include.getSystem(), include.getSystem());
}
for (CanonicalType r : include.getValueSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ private void createOutput(List<StructureDefinitionBindingObject> bindingObjects)
XSSFRow currentRow = firstSheet.createRow(rowCount.getAndAccumulate(1, ibo));
SpreadsheetCreatorHelper.createHeaderRow(workBook, createHeaderNameList(), currentRow);
bindingObjects.forEach((bindingObject) -> {
addBindingObjectRowDataToCurrentSheet(firstSheet, rowCount.getAndAccumulate(1, ibo), bindingObject);
try {
addBindingObjectRowDataToCurrentSheet(firstSheet, rowCount.getAndAccumulate(1, ibo), bindingObject);
}catch(Exception ex){
ex.printStackTrace();
}
});
SpreadsheetCreatorHelper.writeSpreadSheet(workBook,
IOUtils.concatFilePath(getOutputPath(), modelName + modelVersion + ".xlsx"));
IOUtils.concatFilePath(getOutputPath(), modelName + " " + modelVersion + " Profile Elements.xlsx"));
}

private List<String> createHeaderNameList() {
Expand All @@ -95,7 +99,7 @@ private List<String> createHeaderNameList() {
add("Conformance");
add("ValueSet");
add("ValueSetURL");
add("Version");
add("Binding ValueSet Version");
add("Code System URLs");
add("Must Support Y/N");
add("Cardinality");
Expand Down Expand Up @@ -129,11 +133,13 @@ private void addBindingObjectRowDataToCurrentSheet(XSSFSheet currentSheet, int r
currentCell.setCellValue(bo.getBindingValueSetName());

currentCell = currentRow.createCell(cellCount++);
currentCell.setCellValue(bo.getBindingValueSetURL());
link = (XSSFHyperlink)helper.createHyperlink(HyperlinkType.URL);
link.setAddress(bo.getBindingValueSetURL());
currentCell.setHyperlink(link);
currentCell.setCellStyle(linkStyle);
if(bo.getBindingValueSetURL() != null) {
currentCell.setCellValue(bo.getBindingValueSetURL());
link = (XSSFHyperlink) helper.createHyperlink(HyperlinkType.URL);
link.setAddress(bo.getBindingValueSetURL());
currentCell.setHyperlink(link);
currentCell.setCellStyle(linkStyle);
}

currentCell = currentRow.createCell(cellCount++);
currentCell.setCellValue(bo.getBindingValueSetVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class QICoreElementsToSpreadsheet extends StructureDefinitionToSpreadshee
private int ConstraintColumn = 7;
private int ConstraintColumnWidth = 85 * 256;

// example call: -ProfilesToSpreadsheet -ip=/Users/bryantaustin/Projects/FHIR-Spec -op=output -rp="4.0.1;US-Core/3.1.0;QI-Core/4.1.0" -sp=true -mn=QICore -mv=4.1.0
// example call: -QICoreElementsToSpreadsheet -ip=/Users/bryantaustin/Projects/FHIR-Spec -op=output -rp="4.0.1;US-Core/3.1.0;QI-Core/4.1.0" -sp=true -mn=QICore -mv=4.1.0
@Override
public void execute(String[] args) {
for (String arg : args) {
Expand Down Expand Up @@ -93,7 +93,7 @@ private void createOutput(List<StructureDefinitionElementObject> elementObjects)
firstSheet.setColumnWidth(ConstraintColumn, ConstraintColumnWidth);
// firstSheet.autoSizeColumn(ConstraintColumn);
SpreadsheetCreatorHelper.writeSpreadSheet(workBook,
IOUtils.concatFilePath(getOutputPath(), modelName + modelVersion + ".xlsx"));
IOUtils.concatFilePath(getOutputPath(), modelName + modelVersion + " Data Elements" + ".xlsx"));
}

private List<String> createHeaderNameList() {
Expand Down

0 comments on commit 6dd2f5c

Please sign in to comment.