1
+ /*
2
+ * Copyright 2021-2023 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
package com .google .fhir .gateway .plugin ;
2
17
3
18
import static org .smartregister .utils .Constants .EMPTY_STRING ;
@@ -66,6 +81,9 @@ public PractitionerDetails getPractitionerDetailsByKeycloakId(String keycloakUUI
66
81
}
67
82
68
83
public Bundle getSupervisorPractitionerDetailsByKeycloakId (String keycloakUUID ) {
84
+
85
+ long start = BenchmarkingHelper .startBenchmarking ();
86
+
69
87
Bundle bundle = new Bundle ();
70
88
71
89
logger .info ("Searching for practitioner with identifier: " + keycloakUUID );
@@ -79,10 +97,18 @@ public Bundle getSupervisorPractitionerDetailsByKeycloakId(String keycloakUUID)
79
97
logger .error ("Practitioner with KC identifier: " + keycloakUUID + " not found" );
80
98
}
81
99
100
+ BenchmarkingHelper .printCompletedInDuration (
101
+ start ,
102
+ "getSupervisorPractitionerDetailsByKeycloakId : params --> keycloakUUID=" + keycloakUUID ,
103
+ logger );
104
+
82
105
return bundle ;
83
106
}
84
107
85
108
private Bundle getAttributedPractitionerDetailsByPractitioner (Practitioner practitioner ) {
109
+
110
+ long start = BenchmarkingHelper .startBenchmarking ();
111
+
86
112
Bundle responseBundle = new Bundle ();
87
113
List <Practitioner > attributedPractitioners = new ArrayList <>();
88
114
PractitionerDetails practitionerDetails = getPractitionerDetailsByPractitioner (practitioner );
@@ -112,6 +138,10 @@ private Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner pract
112
138
113
139
careTeamList .addAll (attributedCareTeams );
114
140
141
+ logger .error (
142
+ "##### OpenSRPHelper.getAttributedPractitionerDetailsByPractitioner() -> CareTeam List"
143
+ + attributedCareTeams );
144
+
115
145
for (CareTeam careTeam : careTeamList ) {
116
146
// Add current supervisor practitioners
117
147
attributedPractitioners .addAll (
@@ -139,11 +169,18 @@ private Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner pract
139
169
140
170
responseBundle .setEntry (bundleEntryComponentList );
141
171
responseBundle .setTotal (bundleEntryComponentList .size ());
172
+
173
+ BenchmarkingHelper .printCompletedInDuration (
174
+ start , "getAttributedPractitionerDetailsByPractitioner: params " + practitioner , logger );
175
+
142
176
return responseBundle ;
143
177
}
144
178
145
179
@ NotNull
146
180
public static List <String > getAttributedLocations (List <LocationHierarchy > locationHierarchies ) {
181
+
182
+ long start = BenchmarkingHelper .startBenchmarking ();
183
+
147
184
List <ParentChildrenMap > parentChildrenList =
148
185
locationHierarchies .stream ()
149
186
.flatMap (
@@ -159,6 +196,10 @@ public static List<String> getAttributedLocations(List<LocationHierarchy> locati
159
196
.flatMap (parentChildren -> parentChildren .getChildIdentifiers ().stream ())
160
197
.map (it -> getReferenceIDPart (it .toString ()))
161
198
.collect (Collectors .toList ());
199
+
200
+ BenchmarkingHelper .printCompletedInDuration (
201
+ start , "getAttributedLocations " + locationHierarchies , logger );
202
+
162
203
return attributedLocationsList ;
163
204
}
164
205
@@ -167,6 +208,8 @@ private List<String> getOrganizationIdsByLocationIds(List<String> attributedLoca
167
208
return new ArrayList <>();
168
209
}
169
210
211
+ long start = BenchmarkingHelper .startBenchmarking ();
212
+
170
213
Bundle organizationAffiliationsBundle =
171
214
getFhirClientForR4 ()
172
215
.search ()
@@ -175,15 +218,21 @@ private List<String> getOrganizationIdsByLocationIds(List<String> attributedLoca
175
218
.returnBundle (Bundle .class )
176
219
.execute ();
177
220
178
- return organizationAffiliationsBundle .getEntry ().stream ()
179
- .map (
180
- bundleEntryComponent ->
181
- getReferenceIDPart (
182
- ((OrganizationAffiliation ) bundleEntryComponent .getResource ())
183
- .getOrganization ()
184
- .getReference ()))
185
- .distinct ()
186
- .collect (Collectors .toList ());
221
+ List <String > organizationIDs =
222
+ organizationAffiliationsBundle .getEntry ().stream ()
223
+ .map (
224
+ bundleEntryComponent ->
225
+ getReferenceIDPart (
226
+ ((OrganizationAffiliation ) bundleEntryComponent .getResource ())
227
+ .getOrganization ()
228
+ .getReference ()))
229
+ .distinct ()
230
+ .collect (Collectors .toList ());
231
+
232
+ BenchmarkingHelper .printCompletedInDuration (
233
+ start , "getOrganizationIdsByLocationIds : params " + attributedLocationsList , logger );
234
+
235
+ return organizationIDs ;
187
236
}
188
237
189
238
private String getPractitionerIdentifier (Practitioner practitioner ) {
@@ -196,31 +245,33 @@ private String getPractitionerIdentifier(Practitioner practitioner) {
196
245
197
246
private PractitionerDetails getPractitionerDetailsByPractitioner (Practitioner practitioner ) {
198
247
248
+ long start = BenchmarkingHelper .startBenchmarking ();
249
+
199
250
PractitionerDetails practitionerDetails = new PractitionerDetails ();
200
251
FhirPractitionerDetails fhirPractitionerDetails = new FhirPractitionerDetails ();
201
252
String practitionerId = getPractitionerIdentifier (practitioner );
202
253
203
- logger .info ("Searching for care teams for practitioner with id: " + practitioner );
254
+ logger .error ("Searching for care teams for practitioner with id: " + practitioner );
204
255
Bundle careTeams = getCareTeams (practitionerId );
205
256
List <CareTeam > careTeamsList = mapBundleToCareTeams (careTeams );
206
257
fhirPractitionerDetails .setCareTeams (careTeamsList );
207
258
fhirPractitionerDetails .setPractitioners (Arrays .asList (practitioner ));
208
259
209
- logger .info ("Searching for Organizations tied with CareTeams: " );
260
+ logger .error ("Searching for Organizations tied with CareTeams: " );
210
261
List <String > careTeamManagingOrganizationIds =
211
262
getManagingOrganizationsOfCareTeamIds (careTeamsList );
212
263
213
264
Bundle careTeamManagingOrganizations = getOrganizationsById (careTeamManagingOrganizationIds );
214
- logger .info ("Managing Organization are fetched" );
265
+ logger .error ("Managing Organization are fetched" );
215
266
216
267
List <Organization > managingOrganizationTeams =
217
268
mapBundleToOrganizations (careTeamManagingOrganizations );
218
269
219
- logger .info ("Searching for organizations of practitioner with id: " + practitioner );
270
+ logger .error ("Searching for organizations of practitioner with id: " + practitioner );
220
271
221
272
List <PractitionerRole > practitionerRoleList =
222
273
getPractitionerRolesByPractitionerId (practitionerId );
223
- logger .info ("Practitioner Roles are fetched" );
274
+ logger .error ("Practitioner Roles are fetched" );
224
275
225
276
List <String > practitionerOrganizationIds =
226
277
getOrganizationIdsByPractitionerRoles (practitionerRoleList );
@@ -237,13 +288,13 @@ private PractitionerDetails getPractitionerDetailsByPractitioner(Practitioner pr
237
288
fhirPractitionerDetails .setPractitionerRoles (practitionerRoleList );
238
289
239
290
Bundle groupsBundle = getGroupsAssignedToPractitioner (practitionerId );
240
- logger .info ("Groups are fetched" );
291
+ logger .error ("Groups are fetched" );
241
292
242
293
List <Group > groupsList = mapBundleToGroups (groupsBundle );
243
294
fhirPractitionerDetails .setGroups (groupsList );
244
295
fhirPractitionerDetails .setId (practitionerId );
245
296
246
- logger .info ("Searching for locations by organizations" );
297
+ logger .error ("Searching for locations by organizations" );
247
298
248
299
Bundle organizationAffiliationsBundle =
249
300
getOrganizationAffiliationsByOrganizationIdsBundle (
@@ -259,17 +310,20 @@ private PractitionerDetails getPractitionerDetailsByPractitioner(Practitioner pr
259
310
260
311
List <String > locationIds = getLocationIdsByOrganizationAffiliations (organizationAffiliations );
261
312
262
- logger .info ("Searching for location hierarchy list by locations identifiers" );
313
+ logger .error ("Searching for location hierarchy list by locations identifiers" );
263
314
List <LocationHierarchy > locationHierarchyList = getLocationsHierarchyByLocationIds (locationIds );
264
315
fhirPractitionerDetails .setLocationHierarchyList (locationHierarchyList );
265
316
266
- logger .info ("Searching for locations by ids" );
317
+ logger .error ("Searching for locations by ids" );
267
318
List <Location > locationsList = getLocationsByIds (locationIds );
268
319
fhirPractitionerDetails .setLocations (locationsList );
269
320
270
321
practitionerDetails .setId (practitionerId );
271
322
practitionerDetails .setFhirPractitionerDetails (fhirPractitionerDetails );
272
323
324
+ BenchmarkingHelper .printCompletedInDuration (
325
+ start , "getPractitionerDetailsByPractitioner : params " + practitioner , logger );
326
+
273
327
return practitionerDetails ;
274
328
}
275
329
@@ -476,6 +530,8 @@ private List<OrganizationAffiliation> mapBundleToOrganizationAffiliation(
476
530
private List <LocationHierarchy > getLocationsHierarchyByLocationIds (List <String > locationIds ) {
477
531
if (locationIds .isEmpty ()) return new ArrayList <>();
478
532
533
+ long start = BenchmarkingHelper .startBenchmarking ();
534
+
479
535
Bundle bundle =
480
536
getFhirClientForR4 ()
481
537
.search ()
@@ -484,9 +540,15 @@ private List<LocationHierarchy> getLocationsHierarchyByLocationIds(List<String>
484
540
.returnBundle (Bundle .class )
485
541
.execute ();
486
542
487
- return bundle .getEntry ().stream ()
488
- .map (it -> ((LocationHierarchy ) it .getResource ()))
489
- .collect (Collectors .toList ());
543
+ List <LocationHierarchy > locationHierarchies =
544
+ bundle .getEntry ().stream ()
545
+ .map (it -> ((LocationHierarchy ) it .getResource ()))
546
+ .collect (Collectors .toList ());
547
+
548
+ BenchmarkingHelper .printCompletedInDuration (
549
+ start , "getLocationsHierarchyByLocationIds : params " + locationIds , logger );
550
+
551
+ return locationHierarchies ;
490
552
}
491
553
492
554
public static String createSearchTagValues (Map .Entry <String , String []> entry ) {
0 commit comments