-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into validate_before_publishig
- Loading branch information
Showing
3 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
efsity/src/test/java/org/smartregister/command/ValidateFhirResourcesCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.smartregister.command; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import net.jimblackler.jsonschemafriend.GenerationException; | ||
import net.jimblackler.jsonschemafriend.ValidationException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.smartregister.domain.FctFile; | ||
import org.smartregister.util.FctUtils; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
|
||
import ca.uhn.fhir.parser.DataFormatException; | ||
|
||
public class ValidateFhirResourcesCommandTest { | ||
|
||
private ValidateFhirResourcesCommand validateFhirResourcesCommand; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
validateFhirResourcesCommand = new ValidateFhirResourcesCommand(); | ||
} | ||
@Test | ||
void testValidateResource() throws IOException, ValidationException, GenerationException { | ||
// valid resource | ||
String input = "src/test/resources/raw_questionnaire.json"; | ||
assertDoesNotThrow(() -> validateFhirResourcesCommand.validateFhirResources(input)); | ||
// invalid resource | ||
String invalidInput = "src/test/resources/fhirConfigsJsonSchema.json"; | ||
assertThrows(DataFormatException.class, () -> validateFhirResourcesCommand.validateFhirResources(invalidInput)); | ||
} | ||
|
||
@Test | ||
void testValidateConfig() throws IOException, ValidationException, GenerationException { | ||
// valid config | ||
String input = "src/test/resources/profile_config.json"; | ||
FctFile inputFile = FctUtils.readFile(input); | ||
validateFhirResourcesCommand.configSchema = "src/test/resources/fhirConfigsJsonSchema.json"; | ||
assertDoesNotThrow(() -> validateFhirResourcesCommand.validateConfig(inputFile)); | ||
|
||
// invalid config | ||
String invalidInput = "src/test/resources/raw_questionnaire.json"; | ||
FctFile invalidInputFile = FctUtils.readFile(invalidInput); | ||
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(outputStreamCaptor)); | ||
validateFhirResourcesCommand.validateConfig(invalidInputFile); | ||
System.setOut(System.out); | ||
assertTrue(outputStreamCaptor.toString().contains("Validation error")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"appId": "app_id_name", | ||
"configType": "profile", | ||
"id": "config_id", | ||
"fhirResource": { | ||
"baseResource": { | ||
"resource": "Patient" | ||
}, | ||
"relatedResources": [ | ||
{ | ||
"resource": "Condition", | ||
"searchParameter": "subject" | ||
} | ||
]}, | ||
"rules": [ | ||
{ | ||
"name": "patientFirstName", | ||
"condition": "true", | ||
"actions": [ | ||
"data.put('patientFirstName', fhirPath.extractValue(Patient, \"Patient.name[0].select(given)\"))" | ||
] | ||
}, | ||
{ | ||
"name": "patientMiddleName", | ||
"condition": "true", | ||
"actions": [ | ||
"data.put('patientMiddleName', fhirPath.extractValue(Patient, \"Patient.name[0].select(text[0])\"))" | ||
] | ||
}, | ||
{ | ||
"name": "patientLastName", | ||
"condition": "true", | ||
"actions": [ | ||
"data.put('patientLastName', fhirPath.extractValue(Patient, \"Patient.name[0].select(family)\"))" | ||
] | ||
} | ||
], | ||
"views": [ | ||
{ | ||
"viewType": "COLUMN", | ||
"children": [ | ||
{ | ||
"viewType": "CARD", | ||
"padding": 0 | ||
} | ||
] | ||
} | ||
], | ||
"overFlowMenuItems": [ | ||
{ | ||
"title": "Edit Client Info", | ||
"titleColor": "@{patientTextColor}", | ||
"visible": "true", | ||
"enabled": "@{patientActive}", | ||
"icon": { | ||
"type": "local", | ||
"reference": "ic_user" | ||
} | ||
} | ||
] | ||
} |