Guest User

Untitled

a guest
Sep 14th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. private Provider getProvider(PV1 pv1) throws HL7Exception {
  2. XCN hl7Provider = pv1.getAttendingDoctor(0);
  3. Provider provider = null;
  4. String id = hl7Provider.getIDNumber().getValue();
  5. String assignAuth = hl7Provider.getAssigningAuthority().getUniversalID().getValue();
  6. String type = hl7Provider.getAssigningAuthority().getUniversalIDType().getValue();
  7. String errorMessage = "";
  8. if (StringUtils.hasText(id)) {
  9. String specificErrorMsg = "";
  10. if (OpenmrsUtil.nullSafeEquals("L", type)) {
  11. if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_ID.equalsIgnoreCase(assignAuth)) {
  12. try {
  13. provider = Context.getProviderService().getProvider(Integer.valueOf(id));
  14. }
  15. catch (NumberFormatException e) {
  16. // ignore
  17. }
  18. specificErrorMsg = "with provider Id";
  19. } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER.equalsIgnoreCase(assignAuth)) {
  20. provider = Context.getProviderService().getProviderByIdentifier(id);
  21. specificErrorMsg = "with provider identifier";
  22. } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID.equalsIgnoreCase(assignAuth)) {
  23. provider = Context.getProviderService().getProviderByUuid(id);
  24. specificErrorMsg = "with provider uuid";
  25. }
  26. } else {
  27. try {
  28. Person person = Context.getPersonService().getPerson(Integer.valueOf(id));
  29. Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
  30. if (!providers.isEmpty())
  31. provider = providers.iterator().next();
  32. }
  33. catch (NumberFormatException e) {
  34. // ignore
  35. }
  36. specificErrorMsg = "associated to a person with person id";
  37. }
  38.  
  39. errorMessage = "Could not resolve provider " + specificErrorMsg + ":" + id;
  40. } else {
  41. errorMessage = "No unique identifier was found for the provider";
  42. }
  43.  
  44. if (provider == null) {
  45. throw new HL7Exception(errorMessage);
  46. }
  47.  
  48. return provider;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment