Skip to content

Commit

Permalink
Fix Issues
Browse files Browse the repository at this point in the history
- Remove special characters from resource profiles.
- Remove special characters from strings.
- Skip generating templates for resource Bundle, CodeSystem, DomainResource, OperationOutcome, Resource and ValueSet.
  • Loading branch information
AnjanaSenanayake committed Dec 5, 2023
1 parent 73205c4 commit 8973d52
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.wso2.healthcare.fhir.codegen.ballerina.project.tool.model.SearchParam;

import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -49,6 +50,9 @@ public class BallerinaProjectTool extends AbstractFHIRTool {
private final Map<String, FHIRImplementationGuide> igMap = new HashMap<>();
private final Map<String, BallerinaService> serviceMap = new HashMap<>();
private final Map<String, String> dependenciesMap = new HashMap<>();

private final List<String> EXCLUDED_FHIR_APIS = new ArrayList<>(Arrays.asList("Bundle",
"CodeSystem", "DomainResource", "OperationOutcome", "Resource", "ValueSet"));
private BallerinaProjectToolConfig ballerinaProjectToolConfig;

@Override
Expand Down Expand Up @@ -121,7 +125,8 @@ private void populateBalService() {
// extract structure definitions of resource types
Map<String, FHIRResourceDef> resourceDefMap = new HashMap<>();
entry.getValue().getResources().forEach((k, resourceDef) -> {
if (resourceDef.getDefinition().getKind().toCode().equalsIgnoreCase("RESOURCE")) {
if (!EXCLUDED_FHIR_APIS.contains(resourceDef.getDefinition().getName()) && resourceDef.getDefinition()
.getKind().toCode().equalsIgnoreCase("RESOURCE")) {
resourceDefMap.put(k, resourceDef);
}
});
Expand Down Expand Up @@ -201,7 +206,7 @@ private SearchParam getSearchParam(Map.Entry<String, FHIRSearchParamDef> paramet
SearchParam param = new SearchParam(parameter.getValue().getSearchParameter().getName(),
parameter.getValue().getSearchParameter().getCode());
param.setSearchParamDef(parameter.getValue().getSearchParameter());
param.setDescription(parameter.getValue().getSearchParameter().getDescription());
param.setDescription(parameter.getValue().getSearchParameter().getDescription().replace("\"",""));
param.setDocumentation(parameter.getValue().getSearchParameter().getUrl());
param.setTargetResource(apiName);
if (ballerinaProjectToolConfig.getSearchParamConfigs().contains(param.getSearchParamDef().getCode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.text.CaseUtils;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.wso2.healthcare.fhir.codegen.ballerina.project.tool.config.BallerinaProjectToolConfig;
import org.wso2.healthcare.fhir.codegen.ballerina.project.tool.util.BallerinaProjectUtil;

import java.util.*;

Expand All @@ -47,7 +48,7 @@ public FHIRProfile(StructureDefinition profileDef, String url, String igName, St
this.profileDef = profileDef;
this.url = url;
this.importsList = new HashSet<>();
this.name = profileDef.getName();
this.name = BallerinaProjectUtil.resolveSpecialCharacters(profileDef.getName());
}

public StructureDefinition getProfileDef() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@

import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
* Utility class for Ballerina project generator.
*/
public class BallerinaProjectUtil {

/**
* Aggregate substrings to a camelcase string.
*
* @param substrings list of substrings
* @return aggregated string
*/
public static String aggregateCamelcase(List<String> substrings) {

String aggregatedName = substrings.get(0).toLowerCase();
Expand All @@ -41,4 +48,17 @@ public static String aggregateCamelcase(List<String> substrings) {
}
return aggregatedName;
}

/**
* Resolve for special character
*
* @param specialChar special character
* @return preferred string replacement
*/
public static String resolveSpecialCharacters(String specialChar) {
return specialChar.replaceAll(Pattern.quote("[x]"), "")
.replaceAll(Pattern.quote("/"), "")
.replaceAll("-", "_")
.replaceAll("\\s+", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import $import.toLowerCase();
# Generic type to wrap all implemented profiles.
# Add required profile types here.
# public type $service.getName() $basePackageImportIdentifier:$service.getName()|<other_$service.getName()_Profile>;
public type $service.getName()#**##foreach($profile in $service.getProfileList()) $profile.getPackagePrefix():$profile.getName()#if($foreach.hasNext)| #end#end;
public type $service.getName() #**##foreach($profile in $service.getProfileList())$profile.getPackagePrefix():$profile.getName()#if($foreach.hasNext)|#end#end;

# initialize source system endpoint here

Expand Down

0 comments on commit 8973d52

Please sign in to comment.