Skip to content

Commit

Permalink
Improve error handling the create logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwanganto committed Jul 4, 2024
1 parent 193941a commit 0260579
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ private Map createLocationMap(Location l) {
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;
}
Expand All @@ -80,12 +92,13 @@ private Map createPatientMap(Patient p) {
Map map = new HashMap();
map.put("name", p.getPersonName().getFullName());
map.put("uuid", p.getUuid());
map.put("identifier", p.getPatientIdentifier().getIdentifier());
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ public ResponseEntity<Object> grantAccess(@Valid @RequestBody EntityBasisMap ent
&& basisDomain.equalsIgnoreCase("org.openmrs.Location")) {
basis = Context.getLocationService().getLocationByUuid(basisIdentifier);
}
if (entity == null) {
return new ResponseEntity<>("Data filter Entity is required!", HttpStatus.BAD_REQUEST);
}

if (entity != null && basis != null) {
dataFilterService.grantAccess(entity, basis);
return new ResponseEntity<>("Assignment done successfully", HttpStatus.OK);
if (basis == null) {
return new ResponseEntity<>("Data filter Basis is required!", HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>("There was an error saving the assignment", HttpStatus.INTERNAL_SERVER_ERROR);
dataFilterService.grantAccess(entity, basis);
return new ResponseEntity<>("Data filter mapping done successfully", HttpStatus.CREATED);

}
catch (Exception e) {
log.error("Runtime error while trying to create new appointment", e);
Expand Down

0 comments on commit 0260579

Please sign in to comment.