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

Implement test cases for epic-fhirr4-workflow-api-service #56

Open
wants to merge 1 commit 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
20 changes: 10 additions & 10 deletions ehr-connectivity/epic-fhirr4-workflow-api-service/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ service / on new fhirr4:Listener(9090, scheduleApiConfig) {
}

// Search for resources based on some filter criteria.
isolated resource function search fhir/r4/Schedule(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
isolated resource function get fhir/r4/Schedule(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Schedule", fhirContext, (), (), Schedule).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Schedule search interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -56,7 +56,7 @@ service / on new fhirr4:Listener(9090, scheduleApiConfig) {
}

// Create a new resource with a server assigned id.
isolated resource function create fhir/r4/Schedule(r4:FHIRContext fhirContext, international401:Schedule schedule) returns @http:Payload {mediaType: ["application/fhir+json"]} Schedule|r4:FHIRError {
isolated resource function post fhir/r4/Schedule(r4:FHIRContext fhirContext, international401:Schedule schedule) returns @http:Payload {mediaType: ["application/fhir+json"]} Schedule|r4:FHIRError {
Schedule|error fhirInteractionResult = executeFhirInteraction("Schedule", fhirContext, (), schedule, Schedule).ensureType(Schedule);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Schedule create interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -79,7 +79,7 @@ service / on new fhirr4:Listener(9091, slotApiConfig) {
}

// Search for resources based on some filter criteria.
isolated resource function search fhir/r4/Slot(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
isolated resource function get fhir/r4/Slot(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Slot", fhirContext, (), (), Slot).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Slot search interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -89,7 +89,7 @@ service / on new fhirr4:Listener(9091, slotApiConfig) {
}

// Create a new resource with a server assigned id.
isolated resource function create fhir/r4/Slot(r4:FHIRContext fhirContext, international401:Slot slot) returns @http:Payload {mediaType: ["application/fhir+json"]} Slot|r4:FHIRError {
isolated resource function post fhir/r4/Slot(r4:FHIRContext fhirContext, international401:Slot slot) returns @http:Payload {mediaType: ["application/fhir+json"]} Slot|r4:FHIRError {
Slot|error fhirInteractionResult = executeFhirInteraction("Slot", fhirContext, (), slot, Slot).ensureType(Slot);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Slot create interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -112,7 +112,7 @@ service / on new fhirr4:Listener(9092, appointmentApiConfig) {
}

// Search for resources based on some filter criteria.
isolated resource function search fhir/r4/Appointment(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
isolated resource function get fhir/r4/Appointment(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Appointment", fhirContext, (), (), Appointment).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Appointment search interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -122,7 +122,7 @@ service / on new fhirr4:Listener(9092, appointmentApiConfig) {
}

// Create a new resource with a server assigned id.
isolated resource function create fhir/r4/Appointment(r4:FHIRContext fhirContext, international401:Appointment appointment) returns @http:Payload {mediaType: ["application/fhir+json"]} Appointment|r4:FHIRError {
isolated resource function post fhir/r4/Appointment(r4:FHIRContext fhirContext, international401:Appointment appointment) returns @http:Payload {mediaType: ["application/fhir+json"]} Appointment|r4:FHIRError {
Appointment|error fhirInteractionResult = executeFhirInteraction("Appointment", fhirContext, (), appointment, Appointment).ensureType(Appointment);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Appointment create interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -145,7 +145,7 @@ service / on new fhirr4:Listener(9093, appointmentResponseApiConfig) {
}

// Search for resources based on some filter criteria.
isolated resource function search fhir/r4/AppointmentResponse(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
isolated resource function get fhir/r4/AppointmentResponse(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("AppointmentResponse", fhirContext, (), (), AppointmentResponse).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the AppointmentResponse search interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -155,7 +155,7 @@ service / on new fhirr4:Listener(9093, appointmentResponseApiConfig) {
}

// Create a new resource with a server assigned id.
isolated resource function create fhir/r4/AppointmentResponse(r4:FHIRContext fhirContext, international401:AppointmentResponse appointmentResponse) returns @http:Payload {mediaType: ["application/fhir+json"]} AppointmentResponse|r4:FHIRError {
isolated resource function post fhir/r4/AppointmentResponse(r4:FHIRContext fhirContext, international401:AppointmentResponse appointmentResponse) returns @http:Payload {mediaType: ["application/fhir+json"]} AppointmentResponse|r4:FHIRError {
AppointmentResponse|error fhirInteractionResult = executeFhirInteraction("AppointmentResponse", fhirContext, (), appointmentResponse, AppointmentResponse).ensureType(AppointmentResponse);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the AppointmentResponse create interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -178,7 +178,7 @@ service / on new fhirr4:Listener(9094, serviceRequestApiConfig) {
}

// Search for resources based on some filter criteria.
isolated resource function search fhir/r4/ServiceRequest(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
isolated resource function get fhir/r4/ServiceRequest(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("ServiceRequest", fhirContext, (), (), ServiceRequest).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the ServiceRequest search interaction.", r4:CODE_SEVERITY_ERROR,
Expand All @@ -188,7 +188,7 @@ service / on new fhirr4:Listener(9094, serviceRequestApiConfig) {
}

// Create a new resource with a server assigned id.
isolated resource function create fhir/r4/ServiceRequest(r4:FHIRContext fhirContext, international401:ServiceRequest serviceRequest) returns @http:Payload {mediaType: ["application/fhir+json"]} ServiceRequest|r4:FHIRError {
isolated resource function post fhir/r4/ServiceRequest(r4:FHIRContext fhirContext, international401:ServiceRequest serviceRequest) returns @http:Payload {mediaType: ["application/fhir+json"]} ServiceRequest|r4:FHIRError {
ServiceRequest|error fhirInteractionResult = executeFhirInteraction("ServiceRequest", fhirContext, (), serviceRequest, ServiceRequest).ensureType(ServiceRequest);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the ServiceRequest create interaction.", r4:CODE_SEVERITY_ERROR,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import ballerina/http;
import ballerina/io;
import ballerina/log;
import ballerina/test;
import ballerinax/health.fhir.r4.international401;

http:Client testClient2 = check new ("http://localhost:9092");

@test:BeforeGroups {value: ["appointment_api"]}
function before_appointment_api_test() {
checkpanic log:setOutputFile("./tests/myfile.log", log:OVERWRITE);
io:println("Starting the appointment api tests");
}

@test:Config {groups: ["appointment_api"]}
function test_get_appointment_with_valid_id() {
string appointmentId = "1";
http:Response response = checkpanic testClient2->get("/fhir/r4/Appointment/" + appointmentId);
test:assertEquals(response.statusCode, 200);
string contentType = checkpanic response.getHeader("Content-Type");
test:assertEquals(contentType, "application/fhir+json");
json result = checkpanic response.getJsonPayload();
test:assertEquals(result.resourceType, "appointment");
}

@test:Config {groups: ["appointment_api"]}
function test_get_appointment_with_invalid_id() {
string appointmentId = "1";
log:printInfo("Test with InValid Id");
http:Response response = checkpanic testClient2->get("/fhir/r4/Appointment/" + appointmentId);
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid Id");
test:assertEquals(getLogMessage, "Error occurred while retrieving the response from Epic");
}

@test:Config {groups: ["appointment_api"]}
function test_get_appointment_with_invalid_fhir_response() {
string appointmentId = "1";
log:printInfo("Test with InValid fhir response");
http:Response response = checkpanic testClient2->get("/fhir/r4/Appointment/" + appointmentId);
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid fhir response");
test:assertEquals(getLogMessage, "Error occurred while parsing the response");
}

@test:Config {groups: ["appointment_api"]}
function test_get_appointment_with_valid_params() {
http:Response response = checkpanic testClient2->get("/fhir/r4/Appointment/?status=free");
test:assertEquals(response.statusCode, 200);
string contentType = checkpanic response.getHeader("Content-Type");
test:assertEquals(contentType, "application/fhir+json");
}

@test:Config {groups: ["appointment_api"]}
function test_get_appointment_with_invalid_params() {
log:printInfo("Test with InValid appointment parameters");
http:Response response = checkpanic testClient2->get("/fhir/r4/Appointment/?status=adbc");
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid appointment parameters");
test:assertEquals(getLogMessage, "Error occurred while retrieving the response from Epic.");
}

@test:Config {groups: ["appointment_api"]}
function test_post_valid_appointment() {
international401:Appointment payload = {
resourceType: "Appointment",
participant: [
{
actor: {
reference: "Practitioner/example"
},
required: "required",
status: "accepted"
}
],
status: "booked"
};
http:Response response = checkpanic testClient2->post("/fhir/r4/Appointment", payload, {"Content-Type": "application/fhir+json"});
test:assertEquals(response.statusCode, 201);
}

@test:Config {groups: ["appointment_api"]}
function test_post_invalid_appointment() {
international401:Appointment payload = {
resourceType: "Appointment",
participant: [
{
actor: {
reference: "Practitioner/example"
},
required: "required",
status: "accepted"
}
],
status: "booked"
};
log:printInfo("Test with InValid fhir appointment");
http:Response response = checkpanic testClient2->post("/fhir/r4/Appointment", payload, {"Content-Type": "application/fhir+json"});
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid fhir appointment");
test:assertEquals(getLogMessage, "Error occurred while retrieving the response from Epic.");
}

@test:Config {groups: ["appointment_api"]}
function test_post_invalid_fhir_response_appointment() {
international401:Appointment payload = {
resourceType: "Appointment",
participant: [
{
actor: {
reference: "Practitioner/example"
},
required: "required",
status: "accepted"
}
],
status: "booked"
};
log:printInfo("Test with InValid fhir response post appointment");
http:Response response = checkpanic testClient2->post("/fhir/r4/Appointment", payload, {"mediaType": "application/fhir+json"});
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid fhir response post appointment");
test:assertEquals(getLogMessage, "Error occurred while parsing the response");
}

@test:Config {groups: ["appointment_api"]}
function test_appointment_with_invalid_method_put() {
international401:Appointment payload = {
resourceType: "Appointment",
participant: [
{
actor: {
reference: "Practitioner/example"
},
required: "required",
status: "accepted"
}
],
status: "booked"
};
string appointmentId = "1";
log:printInfo("Test with InValid method - put appointment");
http:Response response = checkpanic testClient2->put("/fhir/r4/Appointment/" + appointmentId, payload, {"Content-Type": "application/fhir+json"});
test:assertEquals(response.statusCode, 500);
string getLogMessage = get_log_message("Test with InValid method - put appointment");
test:assertEquals(getLogMessage, "Unsupported interaction type.");
}

@test:AfterGroups {value: ["appointment_api"]}
function after_appointment_api_test() {
io:println("Completed the appointment api tests");
}
Loading