Skip to content

Commit

Permalink
Add fix for issues
Browse files Browse the repository at this point in the history
- Remove special characters in datatype profile names
- Add fix for cardinality discrepancies in slicings against their original datatype definition

Related Issue: https://github.com/wso2-enterprise/open-healthcare/issues/1504
  • Loading branch information
AnjanaSenanayake committed Jan 31, 2024
1 parent 6b3fd7f commit 61d251a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.healthcare.fhir.ballerina.packagegen.tool.model;

import org.hl7.fhir.r4.model.ElementDefinition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -35,6 +37,9 @@ public class ResourceTemplateContext {
private String igName;
private String baseIgName;
private ResourceDefinitionAnnotation resourceDefinitionAnnotation;
// This was added to check the cardinality discrepancies of slice elements against their base elements
// Related issue: https://github.com/wso2-enterprise/open-healthcare/issues/1504
private HashMap<String, ElementDefinition> snapshotElementDefinitions = new HashMap<>();
private HashMap<String, Element> snapshotElements = new HashMap<>();
private List<String> differentialElementIds = new ArrayList<>();
private HashMap<String, Element> resourceElements = new HashMap<>();
Expand Down Expand Up @@ -90,6 +95,14 @@ public void setResourceDefinitionAnnotation(ResourceDefinitionAnnotation resourc
this.resourceDefinitionAnnotation = resourceDefinitionAnnotation;
}

public HashMap<String, ElementDefinition> getSnapshotElementDefinitions() {
return snapshotElementDefinitions;
}

public void setSnapshotElementDefinitions(HashMap<String, ElementDefinition> snapshotElementDefinitions) {
this.snapshotElementDefinitions = snapshotElementDefinitions;
}

public HashMap<String, Element> getSnapshotElements() {
return snapshotElements;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void populateResourceTemplateContexts(FHIRImplementationGuide ig) {
resourceDefinitionAnnotation.setElements(new HashMap<>());
this.resourceTemplateContextInstance.setResourceDefinitionAnnotation(resourceDefinitionAnnotation);

populateElementDefinitionMap(structureDefinition.getSnapshot().getElement());
populateSnapshotElementMap(structureDefinition.getSnapshot().getElement());
populateDifferentialElementIdsList(structureDefinition.getDifferential().getElement());

Expand All @@ -132,6 +133,12 @@ private void populateResourceTemplateContexts(FHIRImplementationGuide ig) {
LOG.debug("Ended: Resource Template Context population");
}

private void populateElementDefinitionMap(List<ElementDefinition> elementDefinitions) {
for (ElementDefinition elementDefinition : elementDefinitions) {
this.resourceTemplateContextInstance.getSnapshotElementDefinitions().put(elementDefinition.getId(), elementDefinition);
}
}

/**
* Populate resource elements map in a hierarchical way
*
Expand Down Expand Up @@ -476,6 +483,12 @@ private void populateResourceSliceElementsMap(Element element) {
if (element.hasChildElements()) {
for (Map.Entry<String, Element> childEntry : element.getChildElements().entrySet()) {
populateResourceSliceElementsMap(childEntry.getValue());
if (element.isSlice()) {
ElementDefinition elementDefinition = this.resourceTemplateContextInstance.getSnapshotElementDefinitions().get(childEntry.getValue().getPath());
if (elementDefinition != null && "*".equals(elementDefinition.getMax()) && childEntry.getValue().getMax() != Integer.MAX_VALUE) {
childEntry.getValue().setArray(true);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public type ${mapEntry.value.name} record {|
#if($elementMapEntry.value.getBalDataType().getType() == 'enum')
public enum $elementMapEntry.value.typeName {
#foreach ($childElementMapEntry in ${elementMapEntry.value.elements.entrySet()})
CODE_${elementMapEntry.value.typeName.toUpperCase()}_${childElementMapEntry.key.toUpperCase()} = "$childElementMapEntry.key"#if($velocityCount != $elementMapEntry.value.elements.entrySet().size()),$util.getNewLine()#end
CODE_${elementMapEntry.value.typeName.toUpperCase()}_$util.resolveSpecialCharacters(${childElementMapEntry.key.toUpperCase()}).toUpperCase() = "$childElementMapEntry.key"#if($velocityCount != $elementMapEntry.value.elements.entrySet().size()),$util.getNewLine()#end
#end
$util.getNewLine()};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public type $util.resolveSpecialCharacters($extendedElement.getTypeName()) recor
@constraint:Array {
minLength: $childElement.getMin()
}
#elseif( ($childElement.min >= $min ) && ($childElement.max > 1) )
#elseif( $childElement.isArray() && ($childElement.min >= $min ) && ($childElement.max >= 1) )
@constraint:Array {
minLength: $childElement.getMin(),
maxLength: $childElement.getMax()
Expand Down

0 comments on commit 61d251a

Please sign in to comment.