private static String getPatientIdentifier(Person person) throws Exception { try { Patient patient = Context.getPatientService().getPatient(person.getPersonId()); if (getPersonId(patient) == person.getPersonId()) { return patient.getPatientIdentifier().getIdentifier(); } } catch (Exception ex) { log.error(ex.getMessage(), ex); } return ""; }
/** * This method exists to allow us to quickly support providers as introduce in OpenMRS 1.9.x, * without having to branch the module. We should remove this method when do a proper * implementation. * * @return personIds of all providers that are attached to persons */ private Set<Integer> getAllProviderPersonIds() { try { Set<Integer> ret = new HashSet<Integer>(); for (Object candidate : getAllProvidersThatArePersons()) { Person person = (Person) PropertyUtils.getProperty(candidate, "person"); if (person != null) ret.add(person.getPersonId()); } return ret; } catch (Exception ex) { throw new RuntimeException( "Programming error in HTML Form Entry module. This method should be safe!", ex); } }
public static Integer getProviderId(String userName) { User userProvider; Person personProvider; // assume its a normal user-name or systemId formatted with a dash userProvider = Context.getUserService().getUserByUsername(userName); if (userProvider != null) { return userProvider.getPerson().getPersonId(); } // next assume it is a internal providerId (Note this is a person_id // not a user_id) and try again try { personProvider = Context.getPersonService().getPerson(Integer.parseInt(userName)); if (personProvider != null) { return personProvider.getPersonId(); } } catch (NumberFormatException e) { e.printStackTrace(); } // now assume its a systemId without a dash: fix the dash and try again if (userName != null && userName.trim() != "") { if (userName.indexOf("-") == -1 && userName.length() > 1) { userName = userName.substring(0, userName.length() - 1) + "-" + userName.substring(userName.length() - 1); userProvider = Context.getUserService().getUserByUsername(userName); if (userProvider != null) { return userProvider.getPerson().getPersonId(); } } } return null; }