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

Validate StructureMap #281

Merged
merged 32 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f79227
Create validateStructureMap command
Wambere Aug 30, 2024
b9c0114
Add parseCompositionFile function
sharon2719 Aug 30, 2024
ed50a2d
Add a function that parses the composition file
sharon2719 Sep 3, 2024
3092362
Update the QRgeneration and call it from validateStructureMap command
Wambere Sep 5, 2024
384440d
Add a folder for saving the QRs
sharon2719 Sep 9, 2024
2268054
Fix failing Validation test class
sharon2719 Sep 9, 2024
98e4b62
Add structueMap validation against QRs
sharon2719 Sep 10, 2024
838876b
Remove default values for SM command
sharon2719 Sep 11, 2024
caef93f
Add extractedResources sub folder
sharon2719 Sep 13, 2024
8b5a983
Add the extractedResources from the bundle to the directory
sharon2719 Sep 13, 2024
727672f
Add validation code for the project
sharon2719 Sep 20, 2024
923f2aa
Fix spotless
sharon2719 Sep 20, 2024
b5bb97b
Fix failing path
sharon2719 Sep 20, 2024
1645232
Add FctValidation for questionnaireToStructureMapId Mapping
sharon2719 Sep 24, 2024
ce7309c
Add test cases for validateStructureMap
sharon2719 Sep 25, 2024
2cd2f64
Use questionnaireProcessor
Wambere Sep 30, 2024
f381186
Update validate Structuremap for project
sharon2719 Oct 2, 2024
7e8d8c9
Finalize tests
sharon2719 Oct 3, 2024
9634c39
Add documentation
sharon2719 Oct 8, 2024
5828f35
Merge branch 'main' into 199-validate-sm
sharon2719 Oct 14, 2024
6cf6cef
Fix structureMap path
sharon2719 Oct 15, 2024
bd37d38
Merge branch 'main' into 199-validate-sm
sharon2719 Oct 16, 2024
a50f592
Merge branch 'main' into 199-validate-sm
pld Oct 16, 2024
adcec92
Merge branch 'main' into 199-validate-sm
sharon2719 Oct 17, 2024
98588c3
Merge branch 'main' into 199-validate-sm
pld Oct 17, 2024
1e14b2e
Merge branch 'main' into 199-validate-sm
sharon2719 Oct 18, 2024
4ea73a5
Merge branch 'main' into 199-validate-sm
sharon2719 Oct 18, 2024
13e3e49
Update suggested changes
sharon2719 Oct 18, 2024
740516d
Fix suggested changes
sharon2719 Oct 22, 2024
9c73443
Run spotless
sharon2719 Oct 22, 2024
602a6f7
Run spotless
sharon2719 Oct 22, 2024
bb79350
Update documentation
sharon2719 Oct 22, 2024
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
18 changes: 18 additions & 0 deletions efsity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ $ 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.

### Validating StructureMap
The tool supports validation of a single structureMap and questionnaire **(single mode)** and validation of all the project files for the questionnaires and structureMaps **(project mode)**. The tool maps the different questionnaires to the specified structureMaps and then generates the questionnaireResponses. Once the questionnaireResponses have been generated, the bundle is then generated with the respective resources ie.(= Patient, Condition). To do this run the following command:

**Options**
```
-i or --input - path to project folder which needs to be validated
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
-v or --validate : (Optional) whether to validate FHIR resources before publishing or not. Optional boolean - default is `false`
-sm or --structure-map - file path to the path to the folder containing the structure maps. These can be nested
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
```

```console (single-mode)
$ fct validateStructureMap -i ~/Workspace/fhir-resources/<project>/questionnaire/resource.json -sm ~/Workspace/fhir-resources/coda/structure_map/coda-child-structure-map.txt
```

```console (project-mode)
$ fct validateStructureMap -i ~/Workspace/fhir-resources/<project>/questionnaire/ -sm ~/Workspace/fhir-resources/coda/structure_map/`
```

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

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,
ValidateStructureMapCommand.class,
})
public class Main implements Runnable {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ public void run() {
validateOptions();
if (inputFilePath != null) {
try {
generateResponse(inputFilePath, mode, extrasPath, fhir_base_url, apiKey);
generateResponse(
inputFilePath,
mode,
outputFilePath,
extrasPath,
fhir_base_url,
apiKey,
aiModel,
maxTokens);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -111,8 +119,15 @@ private void validateOptions() {
}
}

private void generateResponse(
String inputFilePath, String mode, String extrasPath, String fhir_base_url, String apiKey)
public static void generateResponse(
String inputFilePath,
String mode,
String outputFilePath,
String extrasPath,
String fhir_base_url,
String apiKey,
String aiModel,
String maxTokens)
throws IOException {
long start = System.currentTimeMillis();

Expand All @@ -127,17 +142,17 @@ private void generateResponse(
String questionnaireResponseString =
(Objects.equals(mode, "populate"))
? populateMode(questionnaireData, fhir_base_url, extrasPath)
: aiMode(questionnaireData, apiKey);
: aiMode(questionnaireData, apiKey, aiModel, maxTokens);

// Write response to file
FctUtils.printInfo("Writing response to file");
String output =
Files.isDirectory(Paths.get(this.outputFilePath))
? this.outputFilePath
Files.isDirectory(Paths.get(outputFilePath))
? outputFilePath
+ File.separator
+ inputFile.getNameWithoutExtension()
+ Constants.QUESTIONNAIRE_RESPONSE_SUFFIX
: this.outputFilePath;
: outputFilePath;

FctUtils.writeJsonFile(output, questionnaireResponseString);
FctUtils.printInfo(
Expand All @@ -148,7 +163,7 @@ private void generateResponse(
FctUtils.printCompletedInDuration(start);
}

Boolean checkResource(
static Boolean checkResource(
String questionnaire_id, String resourceType, JSONObject resource, String fhir_base_url)
throws IOException {
JSONObject request = new JSONObject();
Expand Down Expand Up @@ -305,7 +320,7 @@ static JSONObject generateAnswer(
}
}

JSONArray getAnswers(JSONArray questions, JSONArray responses, JSONObject extras) {
static JSONArray getAnswers(JSONArray questions, JSONArray responses, JSONObject extras) {
for (int i = 0; i < questions.length(); i++) {
JSONObject current_question = questions.getJSONObject(i);
String question_type = current_question.getString("type");
Expand All @@ -327,7 +342,7 @@ JSONArray getAnswers(JSONArray questions, JSONArray responses, JSONObject extras
return responses;
}

String populateMode(String questionnaireData, String fhir_base_url, String extrasPath)
static String populateMode(String questionnaireData, String fhir_base_url, String extrasPath)
throws IOException {
JSONObject resource = new JSONObject(questionnaireData);
String questionnaire_id = resource.getString("id");
Expand Down Expand Up @@ -369,7 +384,8 @@ String populateMode(String questionnaireData, String fhir_base_url, String extra
return String.valueOf(questionnaire_response);
}

String aiMode(String questionnaireData, String apiKey) throws IOException {
static String aiMode(String questionnaireData, String apiKey, String aiModel, String maxTokens)
throws IOException {
if (true) {
throw new IllegalStateException("Sorry, the AI mode is temporarily unsupported");
}
Expand All @@ -383,7 +399,7 @@ String aiMode(String questionnaireData, String apiKey) throws IOException {

// Generate response
String generatedResponseString =
aiGenerated(questionnaireJsonString, apiKey, this.aiModel, this.maxTokens);
aiGenerated(questionnaireJsonString, apiKey, aiModel, maxTokens);
JSONObject obj = new JSONObject(generatedResponseString);
JSONArray choices = obj.getJSONArray("choices");
String questionnaireResponseString = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ public class StructureMapExtractResourcesCommand implements Runnable {
public void run() {

try {
extractResource(qr, sm);
extractResource(qr, sm, output);

} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void extractResource(String qrFilePath, String structureMapFilePath) throws IOException {
static void extractResource(String qrFilePath, String structureMapFilePath, String output)
throws IOException {

long start = System.currentTimeMillis();

FctUtils.printInfo(String.format("Questionnaire Response file path \u001b[35m%s\u001b[0m", qr));
FctUtils.printInfo(String.format("Structure Map file path \u001b[35m%s\u001b[0m", sm));
FctUtils.printInfo(
String.format("Questionnaire Response file path \u001b[35m%s\u001b[0m", qrFilePath));
FctUtils.printInfo(
String.format("Structure Map file path \u001b[35m%s\u001b[0m", structureMapFilePath));

FctFile questionnaireResponse = FctUtils.readFile(qrFilePath);

Expand Down
Loading