From 4820a997ef00070926d5cfa930e6f6170c2c0697 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Tue, 8 Feb 2022 16:21:34 +0500 Subject: [PATCH] Update Practitioner Details API to add locations in the response payload --- LICENSE.md | 0 practitioner/pom.xml | 2 +- .../PractitionerDetailsResourceProvider.java | 64 ++++++++++++------- 3 files changed, 41 insertions(+), 25 deletions(-) mode change 100644 => 100755 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/practitioner/pom.xml b/practitioner/pom.xml index bd5f75b..b3df013 100755 --- a/practitioner/pom.xml +++ b/practitioner/pom.xml @@ -12,7 +12,7 @@ HAPI FHIR OpenSRP Extensions (Practitioner) jar https://github.com/opensrp/hapi-fhir-opensrp-extensions - 0.0.3-SNAPSHOT + 0.0.4-SNAPSHOT practitioner diff --git a/practitioner/src/main/java/org/smartregister/extension/rest/PractitionerDetailsResourceProvider.java b/practitioner/src/main/java/org/smartregister/extension/rest/PractitionerDetailsResourceProvider.java index a206a74..975bfa4 100755 --- a/practitioner/src/main/java/org/smartregister/extension/rest/PractitionerDetailsResourceProvider.java +++ b/practitioner/src/main/java/org/smartregister/extension/rest/PractitionerDetailsResourceProvider.java @@ -96,29 +96,27 @@ public PractitionerDetails getPractitionerDetails( if (practitionerId != null && practitionerId > 0) { List careTeams = getCareTeams(practitionerId); - List careTeamExtensions = - mapToCareTeamExtensionsList(careTeams); - - fhirPractitionerDetails.setFhirCareTeamExtensionList(careTeamExtensions); + List careTeamsList = mapToCareTeams(careTeams); + fhirPractitionerDetails.setCareTeams(careTeamsList); StringType practitionerIdString = new StringType(); practitionerIdString.setValue(String.valueOf(practitionerId)); fhirPractitionerDetails.setPractitionerId(practitionerIdString); List organizationTeams = getOrganizationsOfPractitioner(practitionerId); - List teamExtensions = - mapToTeamExtensionsList(organizationTeams); - fhirPractitionerDetails.setFhirOrganizationExtensions(teamExtensions); + List teams = mapToTeams(organizationTeams); + fhirPractitionerDetails.setOrganizations(teams); keycloakUserDetails.setId(identifier.getValue()); practitionerDetails.setId(keycloakUserDetails.getId()); practitionerDetails.setUserDetail(keycloakUserDetails); fhirPractitionerDetails.setId(practitionerIdString.getValue()); - List locationsIdReferences = - getLocationIdentifiersByOrganizations(teamExtensions); + List locationsIdReferences = getLocationIdentifiersByOrganizations(teams); List locationIds = getLocationIdsFromReferences(locationsIdReferences); List locationsIdentifiers = getLocationIdentifiersByIds(locationIds); List locationHierarchyList = getLocationsHierarchy(locationsIdentifiers); fhirPractitionerDetails.setLocationHierarchyList(locationHierarchyList); + List locationsList = getLocationsByIds(locationIds); + fhirPractitionerDetails.setLocations(locationsList); practitionerDetails.setFhirPractitionerDetails(fhirPractitionerDetails); } else { practitionerDetails.setId(PRACTITIONER_NOT_FOUND); @@ -207,16 +205,37 @@ private List getCareTeams(Long practitionerId) { : new ArrayList<>(); } - private List mapToCareTeamExtensionsList(List careTeams) { - List fhirCareTeamExtensionList = new ArrayList<>(); + private List getLocationsByIds(List locationIds) { + List locations = new ArrayList<>(); + SearchParameterMap searchParameterMap = new SearchParameterMap(); + for (Long locationId : locationIds) { + TokenAndListParam idParam = new TokenAndListParam(); + TokenParam id = new TokenParam(); + id.setValue(String.valueOf(locationId)); + idParam.addAnd(id); + searchParameterMap.add(ID, idParam); + IBundleProvider locationsBundle = locationIFhirResourceDao.search(searchParameterMap); + List locationsResources = + locationsBundle != null + ? locationsBundle.getResources(0, locationsBundle.size()) + : new ArrayList<>(); + Location locationObj; + for (IBaseResource loc : locationsResources) { + locationObj = (Location) loc; + locations.add(locationObj); + } + } + return locations; + } + + private List mapToCareTeams(List careTeams) { + List careTeamList = new ArrayList<>(); CareTeam careTeamObj; - FhirCareTeamExtension fhirCareTeamExtensionObj = new FhirCareTeamExtension(); for (IBaseResource careTeam : careTeams) { careTeamObj = (CareTeam) careTeam; - fhirCareTeamExtensionObj = fhirCareTeamExtensionObj.mapValues(careTeamObj); - fhirCareTeamExtensionList.add(fhirCareTeamExtensionObj); + careTeamList.add(careTeamObj); } - return fhirCareTeamExtensionList; + return careTeamList; } private List getOrganizationIdentifiers(Long practitionerId) { @@ -266,16 +285,14 @@ private List getOrganizationsOfPractitioner(Long practitionerId) : new ArrayList<>(); } - private List mapToTeamExtensionsList(List teams) { - List fhirOrganizationExtensions = new ArrayList<>(); + private List mapToTeams(List teams) { + List organizations = new ArrayList<>(); Organization organizationObj; - FhirOrganizationExtension fhirOrganizationExtension = new FhirOrganizationExtension(); for (IBaseResource team : teams) { organizationObj = (Organization) team; - fhirOrganizationExtension = fhirOrganizationExtension.mapValues(organizationObj); - fhirOrganizationExtensions.add(fhirOrganizationExtension); + organizations.add(organizationObj); } - return fhirOrganizationExtensions; + return organizations; } private List getLocationsHierarchy(List locationsIdentifiers) { @@ -291,11 +308,10 @@ private List getLocationsHierarchy(List locationsIden return locationHierarchyList; } - private List getLocationIdentifiersByOrganizations( - List teamExtensions) { + private List getLocationIdentifiersByOrganizations(List organizations) { List locationsIdentifiers = new ArrayList<>(); SearchParameterMap searchParameterMap = new SearchParameterMap(); - for (FhirOrganizationExtension team : teamExtensions) { + for (Organization team : organizations) { ReferenceAndListParam thePrimaryOrganization = new ReferenceAndListParam(); ReferenceOrListParam primaryOrganizationRefParam = new ReferenceOrListParam(); ReferenceParam primaryOrganization = new ReferenceParam();