Skip to content

Commit

Permalink
Update Practitioner Details API to add locations in the response payload
Browse files Browse the repository at this point in the history
  • Loading branch information
rehammuzzamil committed Feb 8, 2022
1 parent f9f7943 commit 4820a99
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion practitioner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<name>HAPI FHIR OpenSRP Extensions (Practitioner)</name>
<packaging>jar</packaging>
<url>https://github.com/opensrp/hapi-fhir-opensrp-extensions</url>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.4-SNAPSHOT</version>
<artifactId>practitioner</artifactId>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,27 @@ public PractitionerDetails getPractitionerDetails(

if (practitionerId != null && practitionerId > 0) {
List<IBaseResource> careTeams = getCareTeams(practitionerId);
List<FhirCareTeamExtension> careTeamExtensions =
mapToCareTeamExtensionsList(careTeams);

fhirPractitionerDetails.setFhirCareTeamExtensionList(careTeamExtensions);
List<CareTeam> careTeamsList = mapToCareTeams(careTeams);
fhirPractitionerDetails.setCareTeams(careTeamsList);
StringType practitionerIdString = new StringType();
practitionerIdString.setValue(String.valueOf(practitionerId));
fhirPractitionerDetails.setPractitionerId(practitionerIdString);
List<IBaseResource> organizationTeams =
getOrganizationsOfPractitioner(practitionerId);
List<FhirOrganizationExtension> teamExtensions =
mapToTeamExtensionsList(organizationTeams);
fhirPractitionerDetails.setFhirOrganizationExtensions(teamExtensions);
List<Organization> teams = mapToTeams(organizationTeams);
fhirPractitionerDetails.setOrganizations(teams);
keycloakUserDetails.setId(identifier.getValue());
practitionerDetails.setId(keycloakUserDetails.getId());
practitionerDetails.setUserDetail(keycloakUserDetails);
fhirPractitionerDetails.setId(practitionerIdString.getValue());
List<String> locationsIdReferences =
getLocationIdentifiersByOrganizations(teamExtensions);
List<String> locationsIdReferences = getLocationIdentifiersByOrganizations(teams);
List<Long> locationIds = getLocationIdsFromReferences(locationsIdReferences);
List<String> locationsIdentifiers = getLocationIdentifiersByIds(locationIds);
List<LocationHierarchy> locationHierarchyList =
getLocationsHierarchy(locationsIdentifiers);
fhirPractitionerDetails.setLocationHierarchyList(locationHierarchyList);
List<Location> locationsList = getLocationsByIds(locationIds);
fhirPractitionerDetails.setLocations(locationsList);
practitionerDetails.setFhirPractitionerDetails(fhirPractitionerDetails);
} else {
practitionerDetails.setId(PRACTITIONER_NOT_FOUND);
Expand Down Expand Up @@ -207,16 +205,37 @@ private List<IBaseResource> getCareTeams(Long practitionerId) {
: new ArrayList<>();
}

private List<FhirCareTeamExtension> mapToCareTeamExtensionsList(List<IBaseResource> careTeams) {
List<FhirCareTeamExtension> fhirCareTeamExtensionList = new ArrayList<>();
private List<Location> getLocationsByIds(List<Long> locationIds) {
List<Location> 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<IBaseResource> 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<CareTeam> mapToCareTeams(List<IBaseResource> careTeams) {
List<CareTeam> 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<String> getOrganizationIdentifiers(Long practitionerId) {
Expand Down Expand Up @@ -266,16 +285,14 @@ private List<IBaseResource> getOrganizationsOfPractitioner(Long practitionerId)
: new ArrayList<>();
}

private List<FhirOrganizationExtension> mapToTeamExtensionsList(List<IBaseResource> teams) {
List<FhirOrganizationExtension> fhirOrganizationExtensions = new ArrayList<>();
private List<Organization> mapToTeams(List<IBaseResource> teams) {
List<Organization> 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<LocationHierarchy> getLocationsHierarchy(List<String> locationsIdentifiers) {
Expand All @@ -291,11 +308,10 @@ private List<LocationHierarchy> getLocationsHierarchy(List<String> locationsIden
return locationHierarchyList;
}

private List<String> getLocationIdentifiersByOrganizations(
List<FhirOrganizationExtension> teamExtensions) {
private List<String> getLocationIdentifiersByOrganizations(List<Organization> organizations) {
List<String> 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();
Expand Down

0 comments on commit 4820a99

Please sign in to comment.