Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: wso2/open-healthcare-codegen-tool-framework
ref: v1.2.3
ref: v2.0.0
path: './open-healthcare-codegen-tool-framework'

- name: Setup Java and Maven
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: wso2/open-healthcare-codegen-tool-framework
ref: v1.2.3
ref: v2.0.0
path: './open-healthcare-codegen-tool-framework'

- name: Setup Maven
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public class BallerinaCDSProjectConstants {
public static final String CONFIG = "config";
public static final String PACKAGE = "package";
public static final String DEPENDENCIES = "dependencies";
public static final String BASE_PACKAGE = "basePackage";
public static final String DEPENDENT_PACKAGE = "dependentPackage";
public static final String HOOKS = "hooks";
public static final String CDS_SERVICES = "cds_services";
public static final String META_CONFIG = "metaConfig";
public static final String PROJECT_PACKAGE_ORG = "project.package.org";
public static final String PROJECT_PACKAGE_VERSION = "project.package.version";
public static final String PROJECT_PACKAGE_BASE_PACKAGE = "project.package.basePackage";
public static final String PROJECT_PACKAGE_DEPENDENT_PACKAGE = "project.package.dependentPackage";
public static final String PROJECT_PACKAGE_NAME_PREFIX = "project.package.namePrefix";
public static final String CMD_MESSAGE_OVERRIDE_OUTPUT_DIRECTORY = "Generated templates already exists. Do you want to overwrite? (y/n): ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_NAME_PREFIX;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_ORG;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_VERSION;

import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.PROJECT_PACKAGE_BASE_PACKAGE;
import static org.wso2.healthcare.cds.codegen.ballerina.tool.BallerinaCDSProjectConstants.BASE_PACKAGE;

/**
* Main config class to hold all the config objects.
Expand All @@ -53,6 +54,7 @@ public class BallerinaCDSProjectToolConfig extends AbstractToolConfig {
private static final Log LOG = LogFactory.getLog(BallerinaCDSProjectToolConfig.class);
private MetadataConfig metadataConfig;
private final List<DependencyConfig> dependencyConfigs = new ArrayList<>();
private String basePackage;
private String dependentPackage;
private final List<CdsHook> cdsHooks = new ArrayList<>();

Expand All @@ -61,9 +63,16 @@ public void configure(ConfigType<?> configObj) throws CodeGenException {
if (Constants.JSON_CONFIG_TYPE.equals(configObj.getType())) {
JsonObject jsonConfigObj = ((JsonConfigType) configObj).getConfigObj();
jsonConfigObj = jsonConfigObj.getAsJsonObject(CONFIG);

this.metadataConfig = new MetadataConfig(jsonConfigObj.getAsJsonObject(PACKAGE));
populateDependencyConfigs(jsonConfigObj.
getAsJsonArray(DEPENDENCIES));

if(jsonConfigObj.getAsJsonPrimitive((BASE_PACKAGE)) != null){
this.basePackage = jsonConfigObj
.getAsJsonPrimitive(BASE_PACKAGE).getAsString();
}

if (jsonConfigObj.getAsJsonPrimitive(DEPENDENT_PACKAGE) != null) {
this.dependentPackage = jsonConfigObj
.getAsJsonPrimitive(DEPENDENT_PACKAGE).getAsString();
Expand Down Expand Up @@ -95,6 +104,9 @@ public void overrideConfig(String jsonPath, JsonElement value) {
case PROJECT_PACKAGE_NAME_PREFIX:
this.metadataConfig.setNamePrefix(value.getAsString());
break;
case PROJECT_PACKAGE_BASE_PACKAGE:
this.basePackage = value.getAsString();
break;
case PROJECT_PACKAGE_DEPENDENT_PACKAGE:
this.dependentPackage = value.getAsString();
break;
Expand All @@ -121,6 +133,10 @@ public List<DependencyConfig> getDependencyConfigs() {
return dependencyConfigs;
}

public String getBasePackage() {
return basePackage;
}

public String getDependentPackage() {
return dependentPackage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ private String hookIdToCamelCase(String text) {
StringBuilder textCopy = new StringBuilder(text);
textCopy.setCharAt(ZERO, Character.toUpperCase(firstCharOfText));
text = textCopy.toString();
return text.replaceAll(UNDERSCORE, "");
return text.replaceAll(UNDERSCORE, StringUtils.EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import org.wso2.healthcare.codegen.tool.framework.commons.core.TemplateGenerator;
import org.wso2.healthcare.codegen.tool.framework.commons.core.ToolContext;
import org.wso2.healthcare.codegen.tool.framework.commons.exception.CodeGenException;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.model.FHIRDataTypeDef;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.config.BallerinaPackageGenToolConfig;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.modelgen.PackageContextGenerator;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.modelgen.PackageContextGeneratorFactory;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.modelgen.AbstractPackageContextGenerator;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.templategen.PackageTemplateGenerator;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.common.FHIRSpecificationData;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.AbstractFHIRTool;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.common.FHIRSpecificationData;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.model.FHIRDataTypeDef;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.model.FHIRImplementationGuide;

import java.util.HashMap;
Expand All @@ -37,7 +38,6 @@
* Ballerina FHIR Package Generator Tool.
*/
public class BallerinaPackageGenTool extends AbstractFHIRTool {

private final Map<String, FHIRImplementationGuide> enabledIgs = new HashMap<>();
private BallerinaPackageGenToolConfig packageGenToolConfig;

Expand All @@ -62,7 +62,8 @@ public TemplateGenerator execute(ToolContext toolContext) throws CodeGenExceptio
if (packageGenToolConfig.isEnabled()) {
String targetRoot = packageGenToolConfig.getTargetDir();
Map<String, FHIRDataTypeDef> dataTypes = ((FHIRSpecificationData) toolContext.getSpecificationData()).getDataTypes();
PackageContextGenerator packageContextGenerator = new PackageContextGenerator(
AbstractPackageContextGenerator packageContextGenerator = PackageContextGeneratorFactory.getPackageContextGenerator(
packageGenToolConfig.getPackageConfig().getFhirVersion(),
packageGenToolConfig,
enabledIgs, toolContext.getSpecificationData());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class ToolConstants {
public static final String CONFIG_PACKAGE_DISTRIBUTION_TOML = "tools.config.package.ballerina_distribution";
public static final String CONFIG_PACKAGE_AUTHORS = "authors";
public static final String CONFIG_PACKAGE_AUTHORS_TOML = "tools.config.package.authors";
public static final String CONFIG_PACKAGE_FHIR_VERSION = "fhirVersion";
public static final String CONFIG_PACKAGE_FHIR_VERSION_TOML = "tools.config.packageConfig.fhirVersion";
public static final String CONFIG_PACKAGE_REPOSITORY = "repository";
public static final String CONFIG_PACKAGE_REPOSITORY_TOML = "tools.config.package.repository";
public static final String CONFIG_BASE_PACKAGE = "basePackage";
Expand Down Expand Up @@ -69,6 +71,7 @@ public class ToolConstants {
public static final String CONFIG_BALLERINA_KEYWORD_REPLACE = "replace";
public static final String CONFIG_BALLERINA_KEYWORD_REPLACE_TOML = "tools.config.ballerina_keyword.replace";
public static final String TEMPLATE_PATH = "templates";
public static final String TEMPLATE_VERSION_PATH = "versions";
public static final String BAL_EXTENSION = ".bal";
public static final String TOML_EXTENSION = ".toml";
public static final String MD_EXTENSION = ".md";
Expand All @@ -84,7 +87,8 @@ public enum TokenPosition {
MIDDLE,
END
}
public static final String FHIR_R4_DEFINITION_URL = "http://hl7.org/fhir/StructureDefinition";
public static final String FHIR_R4_DEFINITION_URL = "https://hl7.org/fhir/R4/structuredefinition.html";
public static final String FHIR_R5_DEFINITION_URL = "https://hl7.org/fhir/R5/structuredefinition.html";
public static final String LICENSE_YEAR = String.valueOf(LocalDate.now().getYear());
public static final String DATA_TYPE_EXTENSION = "Extension";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ public void overrideConfig(String jsonPath, JsonElement value) {
case "packageConfig.name.append":
this.packageConfig.setName(packageConfig.getName() + "." + value.getAsString());
break;
case "packageConfig.fhirVersion":
this.packageConfig.setFhirVersion(value.getAsString());
break;
case "packageConfig.repository":
this.packageConfig.setRepository(value.getAsString());
break;
case "packageConfig.basePackage":
this.packageConfig.setBasePackage(value.getAsString());
break;
case "packageConfig.dependent.igs":
List<String> dependentIgList = new ArrayList<>();
for (JsonElement dependentIgJsonElement : value.getAsJsonArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PackageConfig {
private String version;
private String ballerinaDistribution;
private String authors;
private String fhirVersion;
private String repository;
private String basePackage;
private List<DependencyConfig> dependencyConfigList;
Expand All @@ -53,6 +54,7 @@ public PackageConfig(JsonObject packageConfigJson) {
this.version = packageConfigJson.getAsJsonPrimitive(ToolConstants.CONFIG_PACKAGE_VERSION).getAsString();
this.ballerinaDistribution = packageConfigJson.getAsJsonPrimitive(ToolConstants.CONFIG_PACKAGE_DISTRIBUTION).getAsString();
this.authors = packageConfigJson.getAsJsonArray(ToolConstants.CONFIG_PACKAGE_AUTHORS).getAsString();
this.fhirVersion = packageConfigJson.getAsJsonPrimitive(ToolConstants.CONFIG_PACKAGE_FHIR_VERSION).getAsString();
this.repository = packageConfigJson.getAsJsonPrimitive(ToolConstants.CONFIG_PACKAGE_REPOSITORY).getAsString();
this.basePackage = packageConfigJson.getAsJsonPrimitive(ToolConstants.CONFIG_BASE_PACKAGE).getAsString();
populateDependencies(packageConfigJson.getAsJsonArray(ToolConstants.CONFIG_PACKAGE_DEPENDENCY).getAsJsonArray());
Expand All @@ -64,6 +66,7 @@ public PackageConfig(TomlTable packageConfigToml) {
this.version = packageConfigToml.getString(ToolConstants.CONFIG_PACKAGE_VERSION_TOML);
this.ballerinaDistribution = packageConfigToml.getString(ToolConstants.CONFIG_PACKAGE_DISTRIBUTION_TOML);
this.authors = packageConfigToml.getString(ToolConstants.CONFIG_PACKAGE_AUTHORS_TOML);
this.fhirVersion = packageConfigToml.getString(ToolConstants.CONFIG_PACKAGE_FHIR_VERSION_TOML);
this.repository = packageConfigToml.getString(ToolConstants.CONFIG_PACKAGE_REPOSITORY_TOML);
this.basePackage = packageConfigToml.getString(ToolConstants.CONFIG_BASE_PACKAGE_TOML);
populateDependencies(packageConfigToml.getArrayOrEmpty(ToolConstants.CONFIG_PACKAGE_DEPENDENCY_TOML));
Expand Down Expand Up @@ -106,6 +109,10 @@ public String getAuthors() {
return authors;
}

public String getFhirVersion() {
return fhirVersion;
}

public String getRepository() {
return repository;
}
Expand Down Expand Up @@ -149,6 +156,10 @@ public void setBallerinaDistribution(String ballerinaDistribution) {
this.ballerinaDistribution = ballerinaDistribution;
}

public void setFhirVersion(String fhirVersion) {
this.fhirVersion = fhirVersion;
}

public void setBasePackage(String basePackage) {
this.basePackage = basePackage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class ExtendedElement {
private DataTypeDefinitionAnnotation annotation;
private HashMap<String, Element> elements;

// Store datatype of extended elements extended from a primitive type
// e.g: FHIR R5 EuropeBase --> patient.birthDate
private String primitiveExtendedType;

public String getTypeName() {
return typeName;
}
Expand Down Expand Up @@ -91,4 +95,12 @@ public boolean equals(Object o) {
}
return false;
}

public String getPrimitiveExtendedType() {
return primitiveExtendedType;
}

public void setPrimitiveExtendedType(String primitiveExtendedType) {
this.primitiveExtendedType = primitiveExtendedType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

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 @@ -39,7 +37,7 @@ public class ResourceTemplateContext {
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, Object> 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 @@ -95,11 +93,11 @@ public void setResourceDefinitionAnnotation(ResourceDefinitionAnnotation resourc
this.resourceDefinitionAnnotation = resourceDefinitionAnnotation;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.common.FHIRSpecificationData;
import org.wso2.healthcare.codegen.tool.framework.fhir.core.model.FHIRDataTypeDef;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.model.BallerinaDataType;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.model.DatatypeTemplateContext;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.model.Element;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.model.ExtendedElement;
import org.wso2.healthcare.fhir.ballerina.packagegen.tool.utils.GeneratorUtils;

import java.util.HashMap;
import java.util.Map;

/**
* Abstract class for generating context for FHIR data types.
* This class provides methods to populate and manage the context for FHIR data types.
* Extended by R4DatatypeContextGenerator and R5DatatypeContextGenerator
*/

public abstract class AbstractDatatypeContextGenerator {
private static final Log LOG = LogFactory.getLog(AbstractDatatypeContextGenerator.class);
private final Map<String, FHIRDataTypeDef> datatypeDefnMap;
private final Map<String, DatatypeTemplateContext> dataTypeTemplateContextMap;

public AbstractDatatypeContextGenerator(FHIRSpecificationData fhirSpecificationData) {
this.datatypeDefnMap = fhirSpecificationData.getDataTypes();
this.dataTypeTemplateContextMap = new HashMap<>();
populateDatatypeContext();
}

public Map<String, FHIRDataTypeDef> getDatatypeDefnMap() {
return datatypeDefnMap;
}

public Map<String, DatatypeTemplateContext> getDataTypeTemplateContextMap() {
return dataTypeTemplateContextMap;
}

protected Map<String, FHIRDataTypeDef> getDataTypeDefnMap() {
return datatypeDefnMap;
}

protected Map<String, DatatypeTemplateContext> datatypeTemplateContextMap() {
return dataTypeTemplateContextMap;
}

protected void populateExtendedElementsMap(Element element, DatatypeTemplateContext context) {
LOG.debug("Started: Resource Extended Element Map population");
if (!element.getDataType().equals("Extension")) {
if (element.hasChildElements()) {
for (Map.Entry<String, Element> childEntry : element.getChildElements().entrySet()) {
populateExtendedElementsMap(childEntry.getValue(), context);
}
}
ExtendedElement extendedElement;
String elementDataType = element.getDataType();
if (elementDataType.equals("code") && element.hasChildElements()) {
extendedElement = GeneratorUtils.getInstance().populateExtendedElement(element, BallerinaDataType.Enum, elementDataType,
context.getName());
context.getExtendedElements().putIfAbsent(element.getName(), extendedElement);
element.setExtended(true);
}
}
LOG.debug("Ended: Resource Extended Element Map population");
}

protected abstract void populateDatatypeContext();
}
Loading
Loading