1
1
package org .openmrs .performance .http ;
2
2
3
- import com .google .gson .Gson ;
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .ObjectMapper ;
4
5
import io .gatling .javaapi .http .HttpRequestActionBuilder ;
5
6
6
7
import java .time .ZonedDateTime ;
@@ -79,7 +80,6 @@ public HttpRequestActionBuilder getAppointments(String patientUuid) {
79
80
}
80
81
81
82
public HttpRequestActionBuilder submitVisitForm (String patientUuid , String visitTypeUuid , String locationUuid ) {
82
- Gson gson = new Gson ();
83
83
ZonedDateTime now = ZonedDateTime .now ();
84
84
String startDateTime = now .format (DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" ));
85
85
@@ -88,27 +88,34 @@ public HttpRequestActionBuilder submitVisitForm(String patientUuid, String visit
88
88
requestBodyMap .put ("startDatetime" , startDateTime );
89
89
requestBodyMap .put ("visitType" , visitTypeUuid );
90
90
requestBodyMap .put ("location" , locationUuid );
91
-
92
- return http ("Submit Visit Form" )
93
- .post ("/openmrs/ws/rest/v1/visit" )
94
- .body (StringBody (gson .toJson (requestBodyMap )))
95
- .check (jsonPath ("$.uuid" ).saveAs ("visitUuid" ));
96
- }
91
+
92
+ try {
93
+ return http ("Submit Visit Form" )
94
+ .post ("/openmrs/ws/rest/v1/visit" )
95
+ .body (StringBody (new ObjectMapper ().writeValueAsString (requestBodyMap )))
96
+ .check (jsonPath ("$.uuid" ).saveAs ("visitUuid" ));
97
+ } catch (JsonProcessingException e ) {
98
+ throw new RuntimeException (e );
99
+ }
100
+ }
97
101
98
102
public HttpRequestActionBuilder submitEndVisit (String visitUuid , String locationUuid , String visitTypeUuid ) {
99
- Gson gson = new Gson ();
100
103
ZonedDateTime now = ZonedDateTime .now ();
101
104
String formattedStopDateTime = now .format (DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" ));
102
105
103
106
Map <String , String > requestBodyMap = new HashMap <>();
104
107
requestBodyMap .put ("location" , locationUuid );
105
108
requestBodyMap .put ("visitType" , visitTypeUuid );
106
109
requestBodyMap .put ("stopDatetime" , formattedStopDateTime );
107
-
108
- return http ("End Visit" )
109
- .post ("/openmrs/ws/rest/v1/visit/" + visitUuid )
110
- .body (StringBody (gson .toJson (requestBodyMap )));
111
- }
110
+
111
+ try {
112
+ return http ("End Visit" )
113
+ .post ("/openmrs/ws/rest/v1/visit/" + visitUuid )
114
+ .body (StringBody (new ObjectMapper ().writeValueAsString (requestBodyMap )));
115
+ } catch (JsonProcessingException e ) {
116
+ throw new RuntimeException (e );
117
+ }
118
+ }
112
119
113
120
public HttpRequestActionBuilder getOrderTypes () {
114
121
return http ("Get Order Types" )
@@ -224,12 +231,13 @@ public HttpRequestActionBuilder saveOrder(String patientUuid, String visitUuid,
224
231
encounter .put ("visit" , visitUuid );
225
232
encounter .put ("obs" , new Object [0 ]);
226
233
encounter .put ("orders" , new Object [] { order });
227
-
228
- Gson gson = new Gson ();
229
- String body = gson .toJson (encounter );
230
-
231
- return http ("Save Drug Order" )
232
- .post ("/openmrs/ws/rest/v1/encounter" )
233
- .body (StringBody (body ));
234
- }
234
+
235
+ try {
236
+ return http ("Save Drug Order" )
237
+ .post ("/openmrs/ws/rest/v1/encounter" )
238
+ .body (StringBody (new ObjectMapper ().writeValueAsString (encounter )));
239
+ } catch (JsonProcessingException e ) {
240
+ throw new RuntimeException (e );
241
+ }
242
+ }
235
243
}
0 commit comments