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

O3-4280: implement Save a note in Visit Patient scenario #66

Merged
merged 9 commits into from
Feb 25, 2025
6 changes: 6 additions & 0 deletions src/test/java/org/openmrs/performance/Constants.java
Original file line number Diff line number Diff line change
@@ -42,4 +42,10 @@ public class Constants {
public static final String ALLERGY_REACTION_UUID = "162553AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
public static final String CODED_ALLERGEN_UUID = "71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
public static final String SEVERITY_UUID = "1498AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

//Save Visits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Save Visits
// Visit Notes

public static final String VISIT_NOTE_FORM_UUID = "c75f120a-04ec-11e3-8780-2b40bef9a44b";
public static final String CLINICIAN_ENCOUNTER_ROLE = "240b26f9-dd88-4172-823d-4a8bfeb7841f";
public static final String VISIT_NOTE_ENCOUNTER_TYPE_UUID = "d7151f82-c1f3-4152-a605-2f9ea7414a79";
public static final String VISIT_NOTE_CONCEPT_UUID = "162169AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
}
66 changes: 66 additions & 0 deletions src/test/java/org/openmrs/performance/http/DoctorHttpService.java
Original file line number Diff line number Diff line change
@@ -13,10 +13,12 @@

import static io.gatling.javaapi.core.CoreDsl.StringBody;
import static io.gatling.javaapi.core.CoreDsl.bodyString;
import static io.gatling.javaapi.core.CoreDsl.exec;
import static io.gatling.javaapi.core.CoreDsl.jsonPath;
import static io.gatling.javaapi.http.HttpDsl.http;
import static org.openmrs.performance.Constants.ALLERGY_REACTION_UUID;
import static org.openmrs.performance.Constants.CARE_SETTING_UUID;
import static org.openmrs.performance.Constants.CLINICIAN_ENCOUNTER_ROLE;
import static org.openmrs.performance.Constants.CODED_ALLERGEN_UUID;
import static org.openmrs.performance.Constants.DAYS;
import static org.openmrs.performance.Constants.DEFAULT_DOSING_TYPE;
@@ -27,6 +29,9 @@
import static org.openmrs.performance.Constants.OUTPATIENT_CLINIC_LOCATION_UUID;
import static org.openmrs.performance.Constants.SEVERITY_UUID;
import static org.openmrs.performance.Constants.TABLET;
import static org.openmrs.performance.Constants.VISIT_NOTE_CONCEPT_UUID;
import static org.openmrs.performance.Constants.VISIT_NOTE_ENCOUNTER_TYPE_UUID;
import static org.openmrs.performance.Constants.VISIT_NOTE_FORM_UUID;

public class DoctorHttpService extends HttpService {

@@ -287,4 +292,65 @@ public HttpRequestActionBuilder saveOrder(String patientUuid, String visitUuid,
throw new RuntimeException(e);
}
}

public HttpRequestActionBuilder saveVisitNote(String patientUuid, String currentUser, String value) {
Map<String, Object> visitNote = new HashMap<>();
visitNote.put("form", VISIT_NOTE_FORM_UUID);
visitNote.put("patient", patientUuid);
visitNote.put("location", OUTPATIENT_CLINIC_LOCATION_UUID);
visitNote.put("encounterType", VISIT_NOTE_ENCOUNTER_TYPE_UUID);

Map<String, Object> encounterProvider = new HashMap<>();
encounterProvider.put("encounterRole", CLINICIAN_ENCOUNTER_ROLE);
encounterProvider.put("provider", currentUser);

Map<String, Object> obs = new HashMap<>();
obs.put("concept", Map.of("uuid", VISIT_NOTE_CONCEPT_UUID));
obs.put("value", value);

visitNote.put("encounterProviders", List.of(encounterProvider));
visitNote.put("obs", List.of(obs));

try {
String body = new ObjectMapper().writeValueAsString(visitNote); // Convert Map to JSON

return http("Save Visit Note")
.post("/openmrs/ws/rest/v1/encounter")
.body(StringBody(body))
.check(jsonPath("$.uuid").saveAs("encounterUuid")); // Store encounter UUID
} catch (JsonProcessingException e) {
throw new RuntimeException("Error converting visitNote to JSON", e);
}
}


public HttpRequestActionBuilder saveDiagnosis(String patientUuid, String encounterUuid, String diagnosisUuid,String certainty, int rank) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to a separate PR

try {
Map<String, Object> patientDiagnosis = new HashMap<>();
patientDiagnosis.put("patient", patientUuid);
patientDiagnosis.put("encounter", encounterUuid);
patientDiagnosis.put("certainty", certainty);
patientDiagnosis.put("rank", rank);
patientDiagnosis.put("condition", null);

Map<String, Object> diagnosis = new HashMap<>();
diagnosis.put("coded", diagnosisUuid);
patientDiagnosis.put("diagnosis", diagnosis);

ObjectMapper objectMapper = new ObjectMapper();
String body = objectMapper.writeValueAsString(patientDiagnosis);

exec(seassion -> {
System.out.println(body);
return seassion;
});

return http("Save Patient Diagnosis")
.post("/openmrs/ws/rest/v1/patientdiagnoses")
.body(StringBody(body));

} catch (Exception e) {
throw new RuntimeException("Error while serializing diagnosis data", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -144,4 +144,11 @@ public ChainBuilder addDrugOrder(String patientUuid, String visitUuid, String cu
);

}

public ChainBuilder addVisitNote(String patientUuid, String currentUserUuid) {
String visitNoteText = "Patient visit note";
return exec(
httpService.saveVisitNote(patientUuid, currentUserUuid, visitNoteText)
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks a bit weird.

}
}
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ public ScenarioBuilder getScenarioBuilder() {
.exec(registry.openImmunizationsTab("#{patient_uuid}"))
.exec(registry.openAttachmentsTab("#{patient_uuid}"))
.exec(registry.addDrugOrder("#{patient_uuid}", "#{visitUuid}", "#{currentUserUuid}"))
.exec(registry.addVisitNote("#{patient_uuid}", "#{currentUserUuid}"))
.exec(registry.endVisit("#{patient_uuid}"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some pauses to make it realistic. In real world, users takes time to perform actions. Also this may fix the Cannot contain encounters whose dates are after the stop of the visit. error.

Suggested change
.exec(registry.addDrugOrder("#{patient_uuid}", "#{visitUuid}", "#{currentUserUuid}"))
.exec(registry.addVisitNote("#{patient_uuid}", "#{currentUserUuid}"))
.exec(registry.endVisit("#{patient_uuid}"));
.exec(registry.addDrugOrder("#{patient_uuid}", "#{visitUuid}", "#{currentUserUuid}"))
.pause(5)
.exec(registry.addVisitNote("#{patient_uuid}", "#{currentUserUuid}"))
.pause(10)
.exec(registry.endVisit("#{patient_uuid}"));

}
}
Loading
Oops, something went wrong.