Skip to content

Commit

Permalink
Add packagegen tool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnjanaSenanayake committed Jan 2, 2024
1 parent ad7a6f8 commit 6e46e84
Show file tree
Hide file tree
Showing 168 changed files with 89,271 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// under the License.

// AUTO-GENERATED FILE.
// This file is auto-generated by WSO2 Healthcare.
// This file is auto-generated by Ballerina.

#foreach($import in $imports)
#if($import)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// under the License.

// AUTO-GENERATED FILE.
// This file is auto-generated by WSO2 Healthcare.
// This file is auto-generated by Ballerina.

#foreach($import in $imports)
#if($import)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ballerina/constraint;
import ballerina/test;

@test:Config {}
function testResourceElementConstraints() {
USCoreCareTeam careTeam = {
subject: {
reference: "Patient/123"
},
participant: []
};
USCoreCareTeam|constraint:Error validate = constraint:validate(careTeam, USCoreCareTeam);
if validate is USCoreCareTeam {
test:assertFail("careTeam should not be valid");
} else {
test:assertTrue(true, "careTeam is not valid");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import ballerina/test;
import ballerinax/health.fhir.r4;

@test:Config {}
function testSlicings() {

USCorePulseOximetryProfileCodeCodingPulseOx pulseOx = {};
USCorePulseOximetryProfileCodeCodingO2Sat o2Sat = {};

USCorePulseOximetryProfileCategoryVSCat vsCat = {coding: [{}]};

USCorePulseOximetryProfile pulseOximetry = {
id: "pulseOximetry",
meta: {
profile: ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry"]
},
status: "final",
code: { coding: [ pulseOx, o2Sat ] },
subject: {
reference: "Patient/123"
},
effectiveDateTime: "2020-01-01T00:00:00Z",
effectivePeriod: {
'start: "2020-01-01T00:00:00Z",
end: "2020-01-01T00:00:00Z"
},
category: [vsCat]
};
test:assertEquals(pulseOximetry.category[0], vsCat);
}

function testFixedValues() {

USCorePulseOximetryProfileCodeCodingPulseOx pulseOx = {};
USCorePulseOximetryProfileCodeCodingO2Sat o2Sat = {};

USCorePulseOximetryProfileCategoryVSCat vsCat = {coding: [{}]};

USCorePulseOximetryProfile pulseOximetry = {
id: "pulseOximetry",
meta: {
profile: ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry"]
},
status: "final",
code: { coding: [ pulseOx, o2Sat ] },
subject: {
reference: "Patient/123"
},
effectiveDateTime: "2020-01-01T00:00:00Z",
effectivePeriod: {
'start: "2020-01-01T00:00:00Z",
end: "2020-01-01T00:00:00Z"
},
category: [vsCat]
};

r4:CodeableConcept[]? category = pulseOximetry.category;

if category is r4:CodeableConcept[] {
r4:Coding[]? codings = category[0].coding;
if codings is r4:Coding[] {
r4:Coding coding = codings[0];
test:assertEquals(coding.system, "http://terminology.hl7.org/CodeSystem/observation-category");
test:assertEquals(coding.code, "vital-signs");
} else {
test:assertFail("codings is not populated with fixed values");
}
} else {
test:assertFail("category is not populated with fixed values");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import ballerina/test;
import ballerinax/health.fhir.r4.parser;
import ballerinax/health.fhir.r4;

@test:Config {}
function testParse() returns error? {
json patientPayload = {
"resourceType": "Patient",
"id": "1",
"meta": {
"profile": [
"http://hl7.org.au/fhir/StructureDefinition/au-patient"
]
},
"identifier": [
{
"use": "usual",
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "MR"
}
]
},
"system": "urn:oid:",
"value": "57164",
"_value": {
"extension": [
{
"valueString": "57164",
"url": "http://hl7.org/fhir/StructureDefinition/rendered-value"
}
]
}
}
],
"active":true,
"name":[
{
"use":"official",
"family":"Chalmers",
"given":[
"Peter",
"James"
]
}
],
"gender":"male",
"birthDate":"1974-12-25",
"_birthDate": {
"id": "314159",
"extension" : [{
"url" : "http://example.org/fhir/StructureDefinition/text",
"valueString" : "Easter 1970"
}]
},
"managingOrganization":{
"reference":"Organization/1"
}
};

r4:HumanName[] name = [{
family: "Chalmers",
given: ["Peter", "James"],
use: r4:official
}];

anydata parsedResult = check parser:parse(patientPayload, USCorePatientProfile);
USCorePatientProfile patientModel = check parsedResult.ensureType();
test:assertEquals(patientModel.name, name, "Patient name is not equal");
}

@test:Config {}
function testSerialize() {
USCorePatientProfile patient = {
meta: {
profile: [PROFILE_BASE_USCOREPATIENTPROFILE]
},
active: true,
name: [{
family: "Doe",
given: ["Jhon"],
use: r4:official,
prefix: ["Mr"]
}],
address: [{
line: ["652 S. Lantern Dr."],
city: "New York",
country: "United States",
postalCode: "10022",
'type: r4:physical,
use: r4:home
}],
identifier: [{
system: "http://acme.org/mrns",
value: "12345"
}],
gender: "unknown"
};
r4:FHIRResourceEntity fhirEntity = new(patient);
json|r4:FHIRSerializerError jsonResult = fhirEntity.toJson();
if jsonResult is json {
test:assertEquals(true, patient.active);
} else {
test:assertFail("Error occurred while serializing the patient model");
}
}
84 changes: 83 additions & 1 deletion native/health-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,89 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-packagegen</id>
<phase>test</phase>
<goals>
<goal>copy</goal>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.ballerina</groupId>
<artifactId>fhir-to-bal-lib</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>target/test-classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>test-execution</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>TestRunner</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-ballerina-test</id>
<phase>test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>../fhir-to-bal-lib/src/test/resources/ballerina.tests</directory>
</resource>
</resources>
<outputDirectory>target/test-classes/health.fhir.r4.uscore501/tests/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>bal-test</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bal</executable>
<arguments>
<argument>test</argument>
<argument>target/test-classes/health.fhir.r4.uscore501/</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HealthCmdConstants {
public static final String CMD_MVN_ARTIFACT_NAME = "health-tools";
public static final String CMD_RESOURCE_PATH_SUFFIX = "/modules/health/resources";
public static final String CMD_HELPTEXT_FILENAME = "ballerina-health.help";
public static final String CMD_DEFAULT_IG_NAME = "healthcare.fhir";
public static final String CMD_DEFAULT_IG_NAME = "FHIR";
public static final String CMD_DEFAULT_ORG_NAME = "healthcare";

public class PrintStrings {
Expand Down
Loading

0 comments on commit 6e46e84

Please sign in to comment.