Search in sources :

Example 36 with Location

use of org.openmrs.Location 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 37 with Location

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

the class PatientServiceTest method getPatients_shouldSupportSimpleRegex.

/**
 * @see PatientService#getPatients(String, String, java.util.List, boolean)
 */
@Test
public void getPatients_shouldSupportSimpleRegex() throws Exception {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, "^0*@SEARCH@([A-Z]+-[0-9])?$"));
    PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
    identifier.setCreator(new User(1));
    identifier.setDateCreated(new Date());
    Patient patient = Context.getPatientService().getPatient(2);
    patient.addIdentifier(identifier);
    Context.getPatientService().savePatient(patient);
    updateSearchIndex();
    assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
Also used : User(org.openmrs.User) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 38 with Location

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

the class PatientServiceTest method savePatientIdentifier_shouldCreateNewPatientIndentifier.

@Test
public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception {
    PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1));
    Patient associatedPatient = patientService.getPatient(2);
    patientIdentifier.setPatient(associatedPatient);
    PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
    Assert.assertNotNull(createdPatientIdentifier);
    Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId());
}
Also used : Patient(org.openmrs.Patient) 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 39 with Location

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

the class PatientServiceTest method shouldCreatePatient.

@Test
public void shouldCreatePatient() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    // patient.removeAddress(pAddress);
    patient.setBirthdateEstimated(true);
    patient.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept());
    patient.setGender("male");
    List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
    assertNotNull(patientIdTypes);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("123-0");
    patientIdentifier.setIdentifierType(patientIdTypes.get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setPreferred(true);
    Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
    patientIdentifiers.add(patientIdentifier);
    patient.setIdentifiers(patientIdentifiers);
    patientService.savePatient(patient);
    Patient createdPatient = patientService.getPatient(patient.getPatientId());
    assertNotNull(createdPatient);
    assertNotNull(createdPatient.getPatientId());
    Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
    assertNotNull(createdPatientById);
}
Also used : Concept(org.openmrs.Concept) LinkedHashSet(java.util.LinkedHashSet) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 40 with Location

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

the class PatientServiceTest method checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test(expected = DuplicateIdentifierException.class)
public void checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers() throws Exception {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    // Identifier #1
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setIdentifier("123456789");
    patientIdentifier1.setLocation(new Location(2));
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    // Identifier #2
    PatientIdentifier patientIdentifier2 = new PatientIdentifier();
    patientIdentifier2.setIdentifier("123456789");
    patientIdentifier2.setIdentifierType(patientIdentifierType);
    patientIdentifier2.setLocation(new Location(2));
    patient.addIdentifier(patientIdentifier2);
    patientService.checkPatientIdentifiers(patient);
}
Also used : Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15