Skip to content

Commit

Permalink
Add save order to doctor scenario (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasanka-sack authored Aug 23, 2024
1 parent 04a611d commit d6e8747
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/test/java/org/openmrs/performance/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Constants {
public static final String FACULTY_VISIT_TYPE_UUID = "7b0f5697-27e3-40c4-8bae-f4049abfb4ed";

public static final String CARE_SETTING_UUID = "6f0c9a92-6f24-11e3-af88-005056821db0";
public static final String DRUG_ORDER_TYPE_UUID = "131168f4-15f5-102d-96e4-000c29c2a5d7";
public static final String DRUG_ORDER = "131168f4-15f5-102d-96e4-000c29c2a5d7";

// Observation Types
public static final String SYSTOLIC_BLOOD_PRESSURE = "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Expand All @@ -27,4 +27,12 @@ public class Constants {

public static final String PERSON_ATTRIBUTE_PHONE_NUMBER = "14d4f066-15f5-102d-96e4-000c29c2a5d7";

public static final String TABLET = "1513AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
public static final String ORAL = "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
public static final String ONCE_DAILY = "136ebdb7-e989-47cf-8ec2-4e8b2ffe0ab3";
public static final String DAYS = "1072AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
public static final String ORDER = "39da3525-afe4-45ff-8977-c53b7b359158";

public static final String DEFAULT_DOSING_TYPE = "org.openmrs.SimpleDosingInstructions";

}
138 changes: 124 additions & 14 deletions src/test/java/org/openmrs/performance/http/DoctorHttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import java.util.HashMap;
import java.util.Map;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.core.CoreDsl.StringBody;
import static io.gatling.javaapi.core.CoreDsl.bodyString;
import static io.gatling.javaapi.core.CoreDsl.jsonPath;
import static io.gatling.javaapi.http.HttpDsl.http;
import static org.openmrs.performance.Constants.CARE_SETTING_UUID;
import static org.openmrs.performance.Constants.DRUG_ORDER_TYPE_UUID;
import static org.openmrs.performance.Constants.DAYS;
import static org.openmrs.performance.Constants.DEFAULT_DOSING_TYPE;
import static org.openmrs.performance.Constants.DRUG_ORDER;
import static org.openmrs.performance.Constants.ONCE_DAILY;
import static org.openmrs.performance.Constants.ORAL;
import static org.openmrs.performance.Constants.ORDER;
import static org.openmrs.performance.Constants.OUTPATIENT_CLINIC_LOCATION_UUID;
import static org.openmrs.performance.Constants.TABLET;

public class DoctorHttpService extends HttpService {

Expand All @@ -21,21 +30,52 @@ public HttpRequestActionBuilder getVisitTypes() {
}

public HttpRequestActionBuilder getVisitsOfPatient(String patientUuid) {
return http("Get Patient Visits")
.get("/openmrs/ws/rest/v1/visit?patient=" + patientUuid + "&v=custom:(uuid,encounters:(uuid,diagnoses:(uuid,display,rank,diagnosis),form:(uuid,display),encounterDatetime,orders:full,obs:(uuid,concept:(uuid,display,conceptClass:(uuid,display)),display,groupMembers:(uuid,concept:(uuid,display),value:(uuid,display),display),value,obsDatetime),encounterType:(uuid,display,viewPrivilege,editPrivilege),encounterProviders:(uuid,display,encounterRole:(uuid,display),provider:(uuid,person:(uuid,display)))),visitType:(uuid,name,display),startDatetime,stopDatetime,patient,attributes:(attributeType:ref,display,uuid,value)");
String customRepresentation = "custom:(uuid,encounters:(uuid,diagnoses:(uuid,display,rank,diagnosis),"
+ "form:(uuid,display),encounterDatetime,orders:full,"
+ "obs:(uuid,concept:(uuid,display,conceptClass:(uuid,display)),display,"
+ "groupMembers:(uuid,concept:(uuid,display),value:(uuid,display),display),"
+ "value,obsDatetime),encounterType:(uuid,display,viewPrivilege,editPrivilege),"
+ "encounterProviders:(uuid,display,encounterRole:(uuid,display),"
+ "provider:(uuid,person:(uuid,display)))),visitType:(uuid,name,display),"
+ "startDatetime,stopDatetime,patient,"
+ "attributes:(attributeType:ref,display,uuid,value))";

return http("Get Visits of Patient")
.get("/openmrs/ws/rest/v1/visit?patient=" + patientUuid + "&v=" + customRepresentation);
}

public HttpRequestActionBuilder getActiveVisitOfPatient(String patientUuid) {
String customRepresentation = "custom:(uuid,display,voided,indication,startDatetime,stopDatetime,"
+ "encounters:(uuid,display,encounterDatetime,"
+ "form:(uuid,name),location:ref,"
+ "encounterType:ref,"
+ "encounterProviders:(uuid,display,"
+ "provider:(uuid,display))),"
+ "patient:(uuid,display),"
+ "visitType:(uuid,name,display),"
+ "attributes:(uuid,display,attributeType:(name,datatypeClassname,uuid),value),"
+ "location:(uuid,name,display))";

return http("Get Active Visits of Patient")
.get("/openmrs/ws/rest/v1/visit?patient=" + patientUuid + "&v=" + customRepresentation + "&includeInactive=false");
}

public HttpRequestActionBuilder getProgramEnrollments(String patientUuid) {
return http("Get Patient Program Enrollments")
.get("/openmrs/ws/rest/v1/programenrollment?patient=" + patientUuid + "&v=custom:(uuid,display,program,dateEnrolled,dateCompleted,location:(uuid,display))");
String customRepresentation = """
custom:(uuid,display,program,dateEnrolled,dateCompleted,
location:(uuid,display))
""";

return http("Get Program Enrollments of Patient")
.get("/openmrs/ws/rest/v1/programenrollment?patient=" + patientUuid + "&v=" + customRepresentation);
}

public HttpRequestActionBuilder getAppointments(String patientUuid) {
ZonedDateTime now = ZonedDateTime.now();
String startDate = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
String requestBody = String.format("{\"patientUuid\":\"%s\",\"startDate\":\"%s\"}", patientUuid, startDate);

return http("Get Patient Appointments")
return http("Get Appointments of Patient")
.post("/openmrs/ws/rest/v1/appointments/search")
.body(StringBody(requestBody));
}
Expand Down Expand Up @@ -83,22 +123,39 @@ public HttpRequestActionBuilder getAllActiveOrders(String patientUuid) {
}

public HttpRequestActionBuilder getDrugOrders(String patientUuid) {
String customRepresentation = """
custom:(uuid,dosingType,orderNumber,accessionNumber,
patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,
orderType:ref,encounter:ref,
orderer:(uuid,display,person:(display)),
orderReason,orderReasonNonCoded,orderType,urgency,instructions,
commentToFulfiller,
drug:(uuid,display,strength,
dosageForm:(display,uuid),concept),
dose,doseUnits:ref,
frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,
duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)
""";
return http("Get Orders")
.get("/openmrs/ws/rest/v1/order?patient=" + patientUuid + "&careSetting=" + CARE_SETTING_UUID + "&status=any&orderType=" + DRUG_ORDER_TYPE_UUID + "&v=custom:(uuid,dosingType,orderNumber,accessionNumber,patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,orderType:ref,encounter:ref,orderer:(uuid,display,person:(display)),orderReason,orderReasonNonCoded,orderType,urgency,instructions,commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)");
.get("/openmrs/ws/rest/v1/order" +
"?patient=" + patientUuid +
"&careSetting=" + CARE_SETTING_UUID +
"&status=any&orderType=" + DRUG_ORDER +
"&v=" + customRepresentation);
}

public HttpRequestActionBuilder getAllergies(String patientUuid) {
return http("Get Allergies")
return http("Get Allergies of Patient")
.get("/openmrs/ws/fhir2/R4/AllergyIntolerance?patient=" + patientUuid + "&_summary=data");
}

public HttpRequestActionBuilder getConditions(String patientUuid) {
return http("Get Conditions")
return http("Get Conditions of Patient")
.get("/openmrs/ws/fhir2/R4/Condition?patient=" + patientUuid + "&_count=100&_summary=data");
}

public HttpRequestActionBuilder getAttachments(String patientUuid) {
return http("Get Attachments")
return http("Get Attachments of Patient")
.get("/openmrs/ws/rest/v1/attachment?patient=" + patientUuid + "&includeEncounterless=true");
}

Expand All @@ -108,7 +165,7 @@ public HttpRequestActionBuilder getAllowedFileExtensions() {
}

public HttpRequestActionBuilder getLabResults(String patientUuid) {
return http("Get Lab Results")
return http("Get Lab Results of Patient")
.get("/openmrs/ws/fhir2/R4/Observation?category=laboratory&patient=" + patientUuid + "&_count=100&_summary=data")
.check(bodyString().saveAs("labResultsResponse"));
}
Expand All @@ -119,9 +176,62 @@ public HttpRequestActionBuilder getConcept(String conceptUuid) {
}

public HttpRequestActionBuilder getImmunizations(String patientUuid) {
return http("Get Immunizations")
return http("Get Immunizations of Patient")
.get("/openmrs/ws/fhir2/R4/Immunization?patient=" + patientUuid + "&_summary=data");
}


public HttpRequestActionBuilder searchForDrug(String searchQuery) {
String customRepresentation = """
custom:(uuid,display,name,strength,
dosageForm:(display,uuid),
concept:(display,uuid))
""";
return http("Search for Drug")
.get("/openmrs/ws/rest/v1/drug?name=" + searchQuery + "&v=" + customRepresentation);
}

public HttpRequestActionBuilder saveOrder(String patientUuid, String visitUuid, String currentUserUuid, String drugUuid,
String drugConceptUuid) {
Map<String, Object> order = new HashMap<>();
order.put("action", "NEW");
order.put("asNeeded", false);
order.put("asNeededCondition", null);
order.put("careSetting", CARE_SETTING_UUID);
order.put("concept", drugConceptUuid);
order.put("dose", 1);
order.put("doseUnits", TABLET);
order.put("dosingInstructions", "");
order.put("dosingType", DEFAULT_DOSING_TYPE);
order.put("drug", drugUuid);
order.put("duration", null);
order.put("durationUnits", DAYS);
order.put("encounter", visitUuid);
order.put("frequency", ONCE_DAILY);
order.put("numRefills", 0);
order.put("orderReasonNonCoded", "reason");
order.put("orderer", currentUserUuid);
order.put("patient", patientUuid);
order.put("quantity", 1);
order.put("quantityUnits", TABLET);
order.put("route", ORAL);
order.put("type", "drugorder");

Map<String, Object> encounter = new HashMap<>();

encounter.put("encounterDatetime",
ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")));
encounter.put("encounterType", ORDER);
encounter.put("location", OUTPATIENT_CLINIC_LOCATION_UUID);
encounter.put("patient", patientUuid);
encounter.put("visit", visitUuid);
encounter.put("obs", new Object[0]);
encounter.put("orders", new Object[] { order });

Gson gson = new Gson();
String body = gson.toJson(encounter);

return http("Save Drug Order")
.post("/openmrs/ws/rest/v1/encounter")
.body(StringBody(body));
}
}
3 changes: 2 additions & 1 deletion src/test/java/org/openmrs/performance/http/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public HttpRequestActionBuilder loginRequest() {
return http("Login")
.get("/openmrs/ws/rest/v1/session")
.header("Authorization", "Basic YWRtaW46QWRtaW4xMjM=")
.check(jsonPath("$.authenticated").is("true"));
.check(jsonPath("$.authenticated").is("true"))
.check(jsonPath("$.currentProvider.uuid").saveAs("currentUserUuid"));
}

public HttpRequestActionBuilder getLocations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
import java.util.Set;

import static io.gatling.javaapi.core.CoreDsl.exec;
import static org.openmrs.performance.Constants.*;
import static org.openmrs.performance.Constants.ARTERIAL_BLOOD_OXYGEN_SATURATION;
import static org.openmrs.performance.Constants.DIASTOLIC_BLOOD_PRESSURE;
import static org.openmrs.performance.Constants.FACULTY_VISIT_TYPE_UUID;
import static org.openmrs.performance.Constants.HEIGHT_CM;
import static org.openmrs.performance.Constants.MID_UPPER_ARM_CIRCUMFERENCE;
import static org.openmrs.performance.Constants.OUTPATIENT_CLINIC_LOCATION_UUID;
import static org.openmrs.performance.Constants.PULSE;
import static org.openmrs.performance.Constants.RESPIRATORY_RATE;
import static org.openmrs.performance.Constants.SYSTOLIC_BLOOD_PRESSURE;
import static org.openmrs.performance.Constants.TEMPERATURE_C;
import static org.openmrs.performance.Constants.UNKNOWN_OBSERVATION_TYPE;
import static org.openmrs.performance.Constants.WEIGHT_KG;
import static org.openmrs.performance.utils.CommonUtils.extractConceptIds;

public class DoctorRegistry extends Registry<DoctorHttpService>{
Expand Down Expand Up @@ -101,4 +111,16 @@ public ChainBuilder openAttachmentsTab(String patientUuid) {
public ChainBuilder openVisitsTab(String patientUuid) {
return exec(httpService.getVisitsOfPatient(patientUuid));
}

public ChainBuilder addDrugOrder(String patientUuid, String visitUuid, String currentUserUuid) {
String asprin_162_5mg = "a722710f-403b-451f-804b-09f8624b0838";
String asprinConcept = "71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
return exec(
httpService.getActiveVisitOfPatient(patientUuid),
httpService.searchForDrug("asprin"),
httpService.searchForDrug("Tylenol"),
httpService.saveOrder(patientUuid, visitUuid, currentUserUuid, asprin_162_5mg, asprinConcept)
);

}
}
12 changes: 11 additions & 1 deletion src/test/java/org/openmrs/performance/registries/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@

import static io.gatling.javaapi.core.CoreDsl.exec;
import static io.gatling.javaapi.core.CoreDsl.pause;
import static org.openmrs.performance.Constants.*;
import static org.openmrs.performance.Constants.ARTERIAL_BLOOD_OXYGEN_SATURATION;
import static org.openmrs.performance.Constants.DIASTOLIC_BLOOD_PRESSURE;
import static org.openmrs.performance.Constants.HEIGHT_CM;
import static org.openmrs.performance.Constants.MID_UPPER_ARM_CIRCUMFERENCE;
import static org.openmrs.performance.Constants.OUTPATIENT_CLINIC_LOCATION_UUID;
import static org.openmrs.performance.Constants.PULSE;
import static org.openmrs.performance.Constants.RESPIRATORY_RATE;
import static org.openmrs.performance.Constants.SYSTOLIC_BLOOD_PRESSURE;
import static org.openmrs.performance.Constants.TEMPERATURE_C;
import static org.openmrs.performance.Constants.UNKNOWN_OBSERVATION_TYPE;
import static org.openmrs.performance.Constants.WEIGHT_KG;

public abstract class Registry<H extends HttpService> {
public H httpService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ScenarioBuilder getScenarioBuilder() {
.exec(registry.openConditionsTab("#{patient_uuid}"))
.exec(registry.openImmunizationsTab("#{patient_uuid}"))
.exec(registry.openAttachmentsTab("#{patient_uuid}"))
.exec(registry.addDrugOrder("#{patient_uuid}", "#{visitUuid}", "#{currentUserUuid}"))
.exec(registry.endVisit("#{patient_uuid}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.openmrs.performance.personas.ClerkPersona;
import org.openmrs.performance.personas.DoctorPersona;
import org.openmrs.performance.personas.Persona;
import org.openmrs.performance.registries.Registry;
import org.openmrs.performance.scenarios.Scenario;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,7 +18,11 @@
import static io.gatling.javaapi.core.CoreDsl.constantConcurrentUsers;
import static io.gatling.javaapi.core.CoreDsl.rampConcurrentUsers;
import static io.gatling.javaapi.http.HttpDsl.http;
import static org.openmrs.performance.Constants.*;
import static org.openmrs.performance.Constants.BASE_URL;
import static org.openmrs.performance.Constants.ENV_SIMULATION_PRESET;
import static org.openmrs.performance.Constants.ENV_TIER_COUNT;
import static org.openmrs.performance.Constants.ENV_TIER_DURATION;
import static org.openmrs.performance.Constants.ENV_USER_INCREMENT_PER_TIER;

public class OpenMRSClinic extends Simulation {

Expand Down

0 comments on commit d6e8747

Please sign in to comment.