Search in sources :

Example 66 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processNK1_shouldCreateAPersonIfTheRelativeIsNotFound.

/**
 * @see ORUR01Handler#processNK1(Patient,NK1)
 */
@Test
public void processNK1_shouldCreateAPersonIfTheRelativeIsNotFound() throws Exception {
    // process a message with an invalid relative identifier
    PersonService personService = Context.getPersonService();
    // the patient that is the focus of
    Patient patient = new Patient(3);
    // this hl7 message
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220029^^^UUID^v4\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
    ORUR01Handler oruHandler = new ORUR01Handler();
    Message hl7message = parser.parse(hl7String);
    ORU_R01 oru = (ORU_R01) hl7message;
    List<NK1> nk1List = oruHandler.getNK1List(oru);
    for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1);
    // find the relative in the database
    Person relative = personService.getPersonByUuid("2178037d-f86b-4f12-8d8b-be3ebc220029");
    Assert.assertNotNull("a new person was not created", relative);
    // see if the relative made it into the relationship properly
    List<Relationship> rels = personService.getRelationships(relative, patient, new RelationshipType(3));
    Assert.assertTrue("new relationship was not created", !rels.isEmpty() && rels.size() == 1);
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) NK1(ca.uhn.hl7v2.model.v25.segment.NK1) PersonService(org.openmrs.api.PersonService) Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Patient(org.openmrs.Patient) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 67 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric() throws Exception {
    ObsService os = Context.getObsService();
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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";
    // the expected question for the obs in the hl7 message has to be
    // numeric
    Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && !newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals(450, newObservation.getValueNumeric().intValue());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) ObsService(org.openmrs.api.ObsService) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 68 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientServiceTest method savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject.

/**
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject() throws Exception {
    // sanity check, make sure there isn't a 501 patient already
    Patient oldPatient = patientService.getPatient(501);
    Assert.assertNull(oldPatient);
    // fetch Bruno from the database
    Person existingPerson = Context.getPersonService().getPerson(501);
    Context.clearSession();
    Patient patient = new Patient(existingPerson);
    PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2), new Location(1));
    patientIdentifier.setPreferred(true);
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    Assert.assertEquals(501, patient.getPatientId().intValue());
    // make sure a new row with a patient id WAS created
    Assert.assertNotNull(patientService.getPatient(501));
    // make sure a new row with a new person id WASN'T created
    Assert.assertNull(patientService.getPatient(503));
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 69 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldReturnOnlyPatients.

@Test
public void getPatients_shouldReturnOnlyPatients() {
    Person person = personService.getPerson(501);
    assertThat(person.getIsPatient(), is(false));
    List<Patient> patients = patientService.getPatients(person.getGivenName());
    assertThat(patients, is(empty()));
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 70 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientServiceTest method mergePatients_shouldNotCreateDuplicateRelationships.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldNotCreateDuplicateRelationships() throws Exception {
    executeDataSet(PATIENT_RELATIONSHIPS_XML);
    Patient preferred = patientService.getPatient(999);
    Patient notPreferred = patientService.getPatient(2);
    voidOrders(Collections.singleton(notPreferred));
    // expected relationships before merge:
    // * 2->1 (type 2)
    // * 999->2 (type 5)
    // * 999->1 (type 2)
    // * 7->999 (type 4)
    // * 502->2 (type 1)
    // * 7->2 (type 1)
    patientService.mergePatients(preferred, notPreferred);
    // expected relationships after merge:
    // * 999->1 (type 2)
    // * 7->999 (type 4)
    // * 502->999 (type 1)
    // * 7->999 (type 1)
    // check for a relationship that should not be duplicated: 2->1 and
    // 999->1
    List<Relationship> rels = personService.getRelationships(preferred, new Person(1), new RelationshipType(2));
    assertEquals("duplicate relationships were not removed", 1, rels.size());
}
Also used : Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Patient(org.openmrs.Patient) Person(org.openmrs.Person) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

Person (org.openmrs.Person)172 Test (org.junit.Test)140 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)107 PersonName (org.openmrs.PersonName)41 User (org.openmrs.User)36 Date (java.util.Date)33 Relationship (org.openmrs.Relationship)19 Obs (org.openmrs.Obs)16 Patient (org.openmrs.Patient)15 BindException (org.springframework.validation.BindException)15 Message (ca.uhn.hl7v2.model.Message)14 Concept (org.openmrs.Concept)14 Provider (org.openmrs.Provider)14 Voidable (org.openmrs.Voidable)14 Errors (org.springframework.validation.Errors)14 ArrayList (java.util.ArrayList)10 PersonMergeLog (org.openmrs.person.PersonMergeLog)9 RelationshipType (org.openmrs.RelationshipType)8 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)7 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)7