/** * @see org.openmrs.api.db.PersonDAO#getWinningPersonMergeLogs(org.openmrs.Person) */ @Override @SuppressWarnings("unchecked") public List<PersonMergeLog> getWinningPersonMergeLogs(Person person) throws DAOException { return (List<PersonMergeLog>) sessionFactory.getCurrentSession().createQuery( "from PersonMergeLog p where p.winner.id = :winnerId").setInteger("winnerId", person.getId()).list(); }
/** * @see org.openmrs.api.db.PersonDAO#getLosingPersonMergeLogs(org.openmrs.Person) */ @Override public PersonMergeLog getLosingPersonMergeLogs(Person person) throws DAOException { return (PersonMergeLog) sessionFactory.getCurrentSession().createQuery( "from PersonMergeLog p where p.loser.id = :loserId").setInteger("loserId", person.getId()).uniqueResult(); }
private void assertPeopleContainPersonID(List<Person> people, Integer personID) { for (Person person : people) { if (person.getId() == personID) { return; } } Assert.fail("list of people does not contain person with ID = " + personID); }
/** * @see org.openmrs.api.PersonService#savePersonMergeLog(PersonMergeLog) */ @Override public PersonMergeLog savePersonMergeLog(PersonMergeLog personMergeLog) throws SerializationException, APIException { //verify required fields if (Context.getSerializationService().getDefaultSerializer() == null) { throw new APIException("serializer.default.not.found", (Object[]) null); } log.debug("Auditing merging of non-preferred person " + personMergeLog.getLoser().getUuid() + " with preferred person " + personMergeLog.getWinner().getId()); //populate the mergedData XML from the PersonMergeLogData object String serialized = Context.getSerializationService().getDefaultSerializer() .serialize(personMergeLog.getPersonMergeLogData()); personMergeLog.setSerializedMergedData(serialized); log.debug(serialized); //save the bean to the database return dao.savePersonMergeLog(personMergeLog); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldChangeUserRecordsOfNonPreferredPersonToPreferredPerson() throws Exception { executeDataSet(USERS_WHO_ARE_PATIENTS_XML); Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); Context.getPatientService().mergePatients(patientService.getPatient(6), notPreferred); User user = Context.getUserService().getUser(2); Assert.assertEquals(6, user.getPerson().getId().intValue()); }
/** * @see PersonService#purgePerson(Person) */ @Test public void purgePerson_shouldDeletePersonFromTheDatabase() throws Exception { PersonService personService = Context.getPersonService(); User user = Context.getAuthenticatedUser(); Person person = new Person(); person.setPersonCreator(user); person.setPersonDateCreated(new Date()); person.setPersonChangedBy(user); person.setPersonDateChanged(new Date()); person.setGender("F"); Assert.assertNull(person.getId()); person.addName(new PersonName("givenName", "middleName", "familyName")); person = personService.savePerson(person); Assert.assertNotNull(person.getId()); personService.purgePerson(person); Person deletedPerson = personService.getPerson(person.getId()); Assert.assertNull(deletedPerson); }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldCreateNewObjectWhenPersonIdIsNull() throws Exception { User user = Context.getAuthenticatedUser(); Person person = new Person(); person.setPersonCreator(user); person.setPersonDateCreated(new Date()); person.setPersonChangedBy(user); person.setPersonDateChanged(new Date()); person.setGender("F"); Assert.assertNull(person.getId()); person.addName(new PersonName("givenName", "middleName", "familyName")); Person personSaved = Context.getPersonService().savePerson(person); Assert.assertNotNull(personSaved.getId()); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditCreatedRelationships() throws Exception { //create relationships and retrieve preferred and notPreferredPatient patient executeDataSet(PATIENT_RELATIONSHIPS_XML); Patient preferred = patientService.getPatient(7); Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); //merge the two patients and retrieve the audit object PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); //find the UUID of the created relationship as a result of the merge //note: since patient 2 is related to patient 1. patient 7 should now be related to patient 1 String createdRelationshipUuid = null; List<Relationship> relationships = personService.getRelationshipsByPerson(preferred); for (Relationship r : relationships) { if (r.getPersonB().getId().equals(1) || r.getPersonA().getId().equals(1)) { createdRelationshipUuid = r.getUuid(); } } Assert.assertNotNull("expected relationship was not found for the preferred patient after the merge", createdRelationshipUuid); Assert.assertTrue("relationship creation not audited", isValueInList(createdRelationshipUuid, audit.getPersonMergeLogData().getCreatedRelationships())); }
/** * @throws HL7Exception * @see HL7Service#resolvePersonFromIdentifiers(null) */ @Test public void resolvePersonFromIdentifiers_shouldFindAPersonBasedOnAPatientIdentifier() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); Message message = hl7service .parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||1234^^^Test Identifier Type^PT||||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212"); ORU_R01 oru = (ORU_R01) message; List<NK1> nk1List = new ORUR01Handler().getNK1List(oru); Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size()); Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers()); Assert.assertNotNull("should have found a person", result); Assert.assertEquals("found the wrong person", 2, result.getId().intValue()); }
/** * @throws HL7Exception * @see HL7Service#resolvePersonFromIdentifiers(null) */ @Test public void resolvePersonFromIdentifiers_shouldFindAPersonBasedOnAUUID() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); Message message = hl7service .parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220022^^^UUID^v4||||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212"); ORU_R01 oru = (ORU_R01) message; List<NK1> nk1List = new ORUR01Handler().getNK1List(oru); Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size()); Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers()); Assert.assertNotNull("should have found a person", result); Assert.assertEquals("found the wrong person", 2, result.getId().intValue()); }
/** * @throws HL7Exception * @see HL7Service#resolvePersonFromIdentifiers(null) */ @Test public void resolvePersonFromIdentifiers_shouldFindAPersonBasedOnTheInternalPersonID() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); Message message = hl7service .parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||2^^^L^PN||||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212"); ORU_R01 oru = (ORU_R01) message; List<NK1> nk1List = new ORUR01Handler().getNK1List(oru); Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size()); Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers()); Assert.assertNotNull("should have found a person", result); Assert.assertEquals("found the wrong person", 2, result.getId().intValue()); }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldUpdateExistingObjectWhenPersonIdIsNotNull() throws Exception { Person personSaved = Context.getPersonService().getPerson(1); Assert.assertNotNull(personSaved.getId()); personSaved.setGender("M"); Person personUpdated = Context.getPersonService().savePerson(personSaved); Assert.assertEquals("M", personUpdated.getGender()); }
for (Obs o : e.getAllObs(true)) { if (!originalUnvoidedObs.contains(o)) { assertThat(o.getPerson().getId(), is(v.getPatient().getId()));
/** * @see ProviderService#saveProvider(Provider) */ @Test public void saveProvider_shouldSaveAProviderWithPersonAlone() { Provider provider = new Provider(); provider.setIdentifier("unique"); Person person = Context.getPersonService().getPerson(999); provider.setPerson(person); service.saveProvider(provider); Assert.assertNotNull(provider.getId()); Assert.assertNotNull(provider.getUuid()); Assert.assertNotNull(provider.getCreator()); Assert.assertNotNull(provider.getDateCreated()); Assert.assertEquals(999, provider.getPerson().getId().intValue()); }
for (Person p : ps.getPeople(searchPhrase, null)) { if(!personId.contains(p.getId()))
/** * @see {@link HtmlFormEntryUtil#getPerson(String)} this is the username test */ @Test @Verifies(value = "should find a person by username", method = "getPerson(String)") public void getPerson_shouldFindAPersonByUsername() throws Exception { Assert.assertEquals("502", HtmlFormEntryUtil.getPerson("butch").getId().toString()); }
/** * Finds user by UserName * * @param userId User's unique Identifier ( email or MOTECH id ) * @return The User object, if found, else null. */ @Override public MRSUser getUserByUserName(String userId) { org.openmrs.User openMrsUser = getOpenMrsUserByUserName(userId); if (openMrsUser == null) { return null; } return (!isSystemAdmin(openMrsUser.getSystemId())) ? openMrsToMrsUser(openMrsUser) : new OpenMRSUser().systemId(openMrsUser.getSystemId()).id(Integer.toString(openMrsUser.getId())) .person(new OpenMRSPerson().id(Integer.toString(openMrsUser.getPerson().getId()))); }
public static OpenMRSPerson openMRSToMRSPerson(Person person) { Set<PersonName> personNames = person.getNames(); PersonName personName = getFirstName(personNames); final List<OpenMRSAttribute> attributes = project(person.getAttributes(), OpenMRSAttribute.class, on(PersonAttribute.class).getAttributeType().toString(), on(PersonAttribute.class).getValue()); List<MRSAttribute> personAttributes = new ArrayList<MRSAttribute>(); personAttributes.addAll(attributes); OpenMRSPerson mrsPerson = new OpenMRSPerson().firstName(personName.getGivenName()).middleName(personName.getMiddleName()) .lastName(personName.getFamilyName()).birthDateEstimated(person.getBirthdateEstimated()).gender(person.getGender()).age(person.getAge()) .address(getAddress(person)).attributes(personAttributes).dateOfBirth(new DateTime(person.getBirthdate())).dead(person.isDead()).deathDate(new DateTime(person.getDeathDate())); if (person.getId() != null) { mrsPerson.id(Integer.toString(person.getId())); } return mrsPerson; }
MRSEncounter openmrsToMrsEncounter(Encounter openMrsEncounter) { String id = Integer.toString(openMrsEncounter.getEncounterId()); String encounterType = openMrsEncounter.getEncounterType().getName(); Date date = openMrsEncounter.getEncounterDatetime(); MRSFacility facility = openMRSFacilityAdapter.convertLocationToFacility(openMrsEncounter.getLocation()); MRSPatient patient = openMRSPatientAdapter.getMrsPatient(openMrsEncounter.getPatient()); Set<? extends MRSObservation> observations = openMRSObservationAdapter.convertOpenMRSToMRSObservations(openMrsEncounter.getObs()); MRSUser creator = new OpenMRSUser().systemId(openMrsEncounter.getCreator().getSystemId()).id(openMrsEncounter.getCreator().getId().toString()); MRSPerson person = new OpenMRSPerson().id(String.valueOf(openMrsEncounter.getProvider().getId())); MRSProvider provider = new OpenMRSProvider(person); provider.setProviderId(String.valueOf(openMrsEncounter.getProvider().getId())); return new OpenMRSEncounter.MRSEncounterBuilder().withId(id).withProvider(provider).withCreator(creator).withFacility(facility) .withDate(date).withPatient(patient).withObservations(observations).withEncounterType(encounterType).build(); }
} else if (value instanceof Person) { Person person = (Person) value; obs.setValueText(person.getId().toString() + " - " + person.getPersonName().toString()); } else { obs.setValueText(value.toString());