-
Notifications
You must be signed in to change notification settings - Fork 13
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
Initial work to support CRUD through REST #26
Draft
ojwanganto
wants to merge
4
commits into
openmrs:master
Choose a base branch
from
palladiumkenya:feat/add-rest-endpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
api/src/main/java/org/openmrs/module/datafilter/impl/api/DataFilterDefaultResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.datafilter.impl.api; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
public class DataFilterDefaultResponse { | ||
|
||
private String uuid; | ||
|
||
private Date dateCreated; | ||
|
||
private Map entity; | ||
|
||
private Map basis; | ||
|
||
private Map creator; | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public Date getDateCreated() { | ||
return dateCreated; | ||
} | ||
|
||
public void setDateCreated(Date dateCreated) { | ||
this.dateCreated = dateCreated; | ||
} | ||
|
||
public Map getEntity() { | ||
return entity; | ||
} | ||
|
||
public void setEntity(Map entity) { | ||
this.entity = entity; | ||
} | ||
|
||
public Map getBasis() { | ||
return basis; | ||
} | ||
|
||
public void setBasis(Map basis) { | ||
this.basis = basis; | ||
} | ||
|
||
public Map getCreator() { | ||
return creator; | ||
} | ||
|
||
public void setCreator(Map creator) { | ||
this.creator = creator; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
api/src/main/java/org/openmrs/module/datafilter/impl/api/EntityBasisMapResponseMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.datafilter.impl.api; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Person; | ||
import org.openmrs.User; | ||
import org.openmrs.api.LocationService; | ||
import org.openmrs.api.PatientService; | ||
import org.openmrs.api.UserService; | ||
import org.openmrs.module.datafilter.impl.EntityBasisMap; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like I said earlier, build on top of the REST API instead of creating this logic from scratch. |
||
public class EntityBasisMapResponseMapper { | ||
|
||
@Autowired | ||
LocationService locationService; | ||
|
||
@Autowired | ||
UserService userService; | ||
|
||
@Autowired | ||
PatientService patientService; | ||
|
||
/** | ||
* Handles only User, Patient, and Location objects TODO: Make this implementation generic to handle | ||
* other OpenMRS objects | ||
* | ||
* @param a | ||
* @param response | ||
* @return | ||
*/ | ||
private DataFilterDefaultResponse mapToDefaultResponse(EntityBasisMap a, DataFilterDefaultResponse response) { | ||
response.setUuid(a.getUuid()); | ||
response.setDateCreated(a.getDateCreated()); | ||
response.setCreator(createUserMap(a.getCreator())); | ||
if (a.getEntityType().equals("org.openmrs.User")) { | ||
response.setEntity(createUserMap(userService.getUser(Integer.valueOf(a.getEntityIdentifier())))); | ||
} else if (a.getEntityType().equals("org.openmrs.Patient")) { | ||
response.setEntity(createPatientMap(patientService.getPatient(Integer.valueOf(a.getEntityIdentifier())))); | ||
} | ||
|
||
if (a.getBasisType().equals("org.openmrs.Location")) { | ||
response.setBasis(createLocationMap(locationService.getLocation(Integer.valueOf(a.getBasisIdentifier())))); | ||
} | ||
return response; | ||
} | ||
|
||
public List<DataFilterDefaultResponse> constructResponse(List<EntityBasisMap> entityBasisMaps) { | ||
return entityBasisMaps.stream().map(as -> this.mapToDefaultResponse(as, new DataFilterDefaultResponse())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private Map createLocationMap(Location l) { | ||
Map locationMap = null; | ||
if (l != null) { | ||
locationMap = new HashMap(); | ||
locationMap.put("name", l.getName()); | ||
locationMap.put("uuid", l.getUuid()); | ||
locationMap.put("country", l.getCountry() != null ? l.getCountry() : ""); | ||
locationMap.put("countyDistrict", l.getCountyDistrict() != null ? l.getCountyDistrict() : ""); | ||
locationMap.put("cityVillage", l.getCityVillage() != null ? l.getCityVillage() : ""); | ||
locationMap.put("country", l.getCountry() != null ? l.getCountry() : ""); | ||
locationMap.put("address1", l.getAddress1() != null ? l.getAddress1() : ""); | ||
locationMap.put("address2", l.getAddress2() != null ? l.getAddress2() : ""); | ||
locationMap.put("address3", l.getAddress3() != null ? l.getAddress3() : ""); | ||
locationMap.put("address4", l.getAddress4() != null ? l.getAddress4() : ""); | ||
locationMap.put("address5", l.getAddress5() != null ? l.getAddress5() : ""); | ||
locationMap.put("address6", l.getAddress6() != null ? l.getAddress6() : ""); | ||
locationMap.putAll(l.getActiveAttributes().stream().filter(e -> e.getAttributeType() != null).collect( | ||
Collectors.toMap(e -> e.getAttributeType().getName(), e -> e.getValue(), (e1, e2) -> e1 + "," + e2))); | ||
} | ||
return locationMap; | ||
} | ||
|
||
private Map createPatientMap(Patient p) { | ||
Map map = new HashMap(); | ||
map.put("name", p.getPersonName().getFullName()); | ||
map.put("uuid", p.getUuid()); | ||
map.put("age", p.getAge()); | ||
map.put("gender", p.getGender()); | ||
map.putAll(p.getActiveIdentifiers().stream().filter(e -> e.getIdentifierType() != null) | ||
.collect(Collectors.toMap(e -> e.getIdentifierType().toString().replaceAll("[- ]", ""), | ||
e -> e.getIdentifier(), (e1, e2) -> e1 + "," + e2))); | ||
map.putAll(p.getActiveAttributes().stream().filter(e -> e.getValue() != null).collect( | ||
Collectors.toMap(e -> e.getAttributeType().getName(), e -> e.getValue(), (e1, e2) -> e1 + "," + e2))); | ||
return map; | ||
} | ||
|
||
private Map createUserMap(User u) { | ||
Person p = u.getPerson(); | ||
Map map = new HashMap(); | ||
map.put("name", p.getPersonName().getFullName()); | ||
map.put("uuid", p.getUuid()); | ||
return map; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
api/src/main/java/org/openmrs/module/datafilter/impl/api/EntityBasisMapSearchRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.datafilter.impl.api; | ||
|
||
/** | ||
* A model for search | ||
*/ | ||
public class EntityBasisMapSearchRequest { | ||
|
||
private String entityIdentifier; | ||
|
||
private String entityType; | ||
|
||
private String basisIdentifier; | ||
|
||
private String basisType; | ||
|
||
public String getEntityIdentifier() { | ||
return entityIdentifier; | ||
} | ||
|
||
public void setEntityIdentifier(String entityIdentifier) { | ||
this.entityIdentifier = entityIdentifier; | ||
} | ||
|
||
public String getEntityType() { | ||
return entityType; | ||
} | ||
|
||
public void setEntityType(String entityType) { | ||
this.entityType = entityType; | ||
} | ||
|
||
public String getBasisIdentifier() { | ||
return basisIdentifier; | ||
} | ||
|
||
public void setBasisIdentifier(String basisIdentifier) { | ||
this.basisIdentifier = basisIdentifier; | ||
} | ||
|
||
public String getBasisType() { | ||
return basisType; | ||
} | ||
|
||
public void setBasisType(String basisType) { | ||
this.basisType = basisType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please build atop the REST web services module’s API to maintain uniformity from a client perspective.