Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structure map generation tool to efsity #202

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions efsity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ fhircore-tooling.iml
# build files
bin
target
generated-structure-map.txt
generated-json-map.json
30 changes: 30 additions & 0 deletions efsity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,36 @@ $ fct validateFileStructure -i ~/Workspace/fhir-resources/<project> -s ~/path/to
If the file structure matches the schema then a positive result is printed to the terminal, otherwise an error
is thrown showing the issue.

### Generating a structure map
To generate a Structure Map, you need to provide the questionnaire, the configuration path, and the questionnaire response path. The output will be based on the specified inputs
```console
$ fct generateStructureMap --questionnaire /path/to/questionnaire.json --configPath /path/to/config/StructureMap.xls --questionnaireResponsePath /path/to/questionnaire-response.json
```
This process will generate two output files: a .map file and its JSON equivalent
**Options**
```
-q or --questionnaire Path to the Questionnaire JSON file.
-c or --configPath Path to the Structure Map configuration file (XLS format).
-qr or --questionnaireResponsePath Path to the Questionnaire Response JSON file.
```
**Sample Configuration File**

To help users get started with the Structure Map generation process, we provide a sample configuration file in XLS format. You can download the sample from the link below:

[Download Sample Structure Map Configuration (XLS)](https://github.com/onaio/fhir-tooling/blob/main/sm-gen/src/main/resources/StructureMap%20XLS.xls)

Alternatively, if you have cloned the repository, the sample file can be found in the following path:

console
```
/path/to/your/repository/src/main/resources/StructureMapXLS.xls
```

This sample XLS form includes the required structure and format to define mappings between questionnaire fields and FHIR resources. You can customize it according to your specific needs.

For more documentation please refer to this [documentation](https://github.com/onaio/fhir-tooling/blob/main/efsity/Structure_map_gen.md)


### Localization
Tool that supports localization by the use of the translation extension

Expand Down
38 changes: 38 additions & 0 deletions efsity/Structure_map_gen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# StructureMap tooling

The StructureMap Tooling is a utility designed to generate Structure Maps for FHIR (Fast Healthcare Interoperability Resources) transformations. Structure Maps are used to define how one FHIR resource is transformed into another. This tooling leverages the HL7 FHIRPath language to provide support for creating and managing these transformations.

## Features
**FHIRPath Engine**: Utilizes the FHIRPath engine to evaluate and transform FHIR resources.

**Transformation Support**: Provides services to support the transformation process, ensuring that resources are accurately converted according to the specified Structure Map.

**Automation**: Simplifies the process of generating Structure Maps through automated tooling.

## Files
**FhirPathEngineHostServices.kt**: Contains services for hosting and running the FHIRPath engine.

**Main.kt**: The entry point of the application. It orchestrates the process of reading input, processing it through the FHIRPath engine, and generating the Structure Map.

**TransformSupportServices.kt**: Provides additional support services required for the transformation process.

**Utils.kt**: Contains the main logic for generating the Structure Maps using the FHIRPath engine and transformation support services.

## Prerequisites
- Questionnaire JSON
- XLS form with the required information based on the questionnaire

### Installation
1. Clone the Repository:

```console
git clone https://github.com/your-repo/structuremap-tooling.git
cd structuremap-tooling
```
2. Once the `structuremap-tooling` folder, click on run.
3. A prompt will appear on the CLI `Kindly enter the XLS filepath`: Enter the absolute path of the file's location. Click `Enter`
4. Another prompt will appear on the CLI `Kindly enter the questionnaire filepath`: Enter the absolute path of the file's location. Click `Enter`
5. The structureMap will be generated in the CLI and two complete files in the folder containing the `.json` and `.map` files

## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
4 changes: 4 additions & 0 deletions efsity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ dependencies {
implementation(deps.picocli)
implementation(deps.xstream)
implementation(deps.icu4j)
implementation(deps.poi)
implementation(deps.poiooxml)
implementation(deps.javafaker) { exclude(group = "org.yaml") }
implementation(deps.snakeyaml)
implementation("ca.uhn.hapi.fhir:hapi-fhir-validation:6.8.0")

testImplementation(kotlin("test"))
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-inline:3.12.4")
testImplementation("io.mockk:mockk:1.13.7")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
}

tasks.withType<JavaCompile> { options.encoding = deps.versions.project.build.sourceEncoding.get() }
Expand Down
4 changes: 4 additions & 0 deletions efsity/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ snakeyaml-version="2.3"
spotless-version ="6.20.0"
xstream="1.4.20"
icu4j-version = "75.1"
poi-version = "4.1.1"
poi-ooxml-version = "4.1.1"

[libraries]
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine-version" }
Expand Down Expand Up @@ -50,6 +52,8 @@ picocli = { module = "info.picocli:picocli", version.ref = "info-picocli-version
snakeyaml = { module="org.yaml:snakeyaml", version.ref ="snakeyaml-version"}
xstream = { module = "com.thoughtworks.xstream:xstream", version.ref = "xstream" }
icu4j = { module="com.ibm.icu:icu4j", version.ref = "icu4j-version" }
poi = { module="org.apache.poi:poi", version.ref = "poi-version" }
poiooxml = { module="org.apache.poi:poi-ooxml", version.ref = "poi-ooxml-version" }

[bundles]
cqf-cql = ["cql-to-elm","elm","elm-jackson","model","model-jackson"]
Expand Down
3 changes: 2 additions & 1 deletion efsity/src/main/java/org/smartregister/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
TranslateCommand.class,
QuestionnaireResponseGeneratorCommand.class,
ValidateFileStructureCommand.class,
PublishFhirResourcesCommand.class
PublishFhirResourcesCommand.class,
GenerateStructureMapCommand.class
})
public class Main implements Runnable {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.smartregister.command;

import java.io.IOException;
import org.smartregister.structuremaptool.GenerateStructureMapServiceKt;
import org.smartregister.util.FctUtils;
import picocli.CommandLine;

@CommandLine.Command(name = "generateStructureMap")
public class GenerateStructureMapCommand implements Runnable {
@CommandLine.Option(
names = {"-q", "--questionnaire"},
description = "Questionnaire",
required = true)
private String questionnairePath;

@CommandLine.Option(
names = {"-c", "--configPath"},
description = "StructureMap generation configuration in an excel sheet",
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
required = true)
private String configPath;

@CommandLine.Option(
names = {"-qr", "--questionnaireResponsePath"},
description = "Questionnaire response",
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
required = true)
private String questionnaireResponsePath;

@Override
public void run() {
if (configPath != null) {
try {
generateStructureMap(configPath, questionnairePath, questionnaireResponsePath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

public static void generateStructureMap(
String configPath, String questionnairePath, String questionnaireResponsePath)
throws IOException {
long start = System.currentTimeMillis();
FctUtils.printInfo("Starting StructureMap generation");
GenerateStructureMapServiceKt.main(configPath, questionnairePath, questionnaireResponsePath);

FctUtils.printCompletedInDuration(start);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TransformSupportServices @Inject constructor(val simpleWorkerContext: Simp
override fun createType(appInfo: Any, name: String): Base {
return when (name) {
"RiskAssessment_Prediction" -> RiskAssessmentPredictionComponent()
"RiskAssessment\$RiskAssessmentPredictionComponent" -> RiskAssessmentPredictionComponent()
"Immunization_AppliedProtocol" -> Immunization.ImmunizationProtocolAppliedComponent()
"Immunization_Reaction" -> Immunization.ImmunizationReactionComponent()
"EpisodeOfCare_Diagnosis" -> EpisodeOfCare.DiagnosisComponent()
Expand Down
Loading
Loading