Guest User

Untitled

a guest
Jul 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1.  
  2.  
  3. private String getPatientLocation (Patient patient) {
  4.  
  5. String patientLocation = null;
  6.  
  7. EncounterService encounterService = Context.getEncounterService();
  8. List<Encounter> encounters = encounterService.getEncountersByPatient(patient);
  9.  
  10. if (!encounters.isEmpty()) {
  11. Encounter lastEncounter = encounters.get(0);
  12. Location lastLocation = lastEncounter.getLocation();
  13. if (lastLocation.getName().startsWith("MTRH Module"))
  14. patientLocation = lastLocation.getName().replace("MTRH Module", "").trim();
  15. }
  16.  
  17. if (patientLocation == null) {
  18. for (PatientIdentifier identifier : patient.getActiveIdentifiers()) {
  19. Location identifierLocation = identifier.getLocation();
  20. if (identifierLocation.getName().startsWith("MTRH Module")) {
  21. patientLocation = identifierLocation.getName().replace("MTRH Module", "").trim();
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. if (patientLocation == null) {
  28. String attributeName = "Health Center";
  29. PersonAttribute attribute = patient.getAttribute(attributeName);
  30. Location healthCenterLocation = (Location) attribute.getHydratedObject();
  31. if (healthCenterLocation.getName() != null &&
  32. healthCenterLocation.getName().startsWith("MTRH Module"))
  33. patientLocation = healthCenterLocation.getName().replace("MTRH Module", "").trim();
  34. }
  35.  
  36. return patientLocation;
  37. }
Add Comment
Please, Sign In to add comment