Search in sources :

Example 16 with Location

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

the class PatientValidatorTest method validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred.

@Test
public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    patient.setGender("male");
    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);
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setLocation(new Location(1));
    patientIdentifier1.setIdentifier("012345678");
    patientIdentifier1.setDateCreated(new Date());
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    Errors errors = new BindException(patient, "patient");
    validator.validate(patient, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 17 with Location

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

the class LocationServiceImpl method getDefaultLocation.

/**
 * @see org.openmrs.api.LocationService#getDefaultLocation()
 */
@Override
@Transactional(readOnly = true)
public Location getDefaultLocation() throws APIException {
    Location location = null;
    String locationGP = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME);
    if (StringUtils.hasText(locationGP)) {
        location = Context.getLocationService().getLocation(locationGP);
    }
    if (location == null) {
        location = getDefaultLocation(location, locationGP);
    }
    // If neither exist, get the first available location
    if (location == null) {
        location = Context.getLocationService().getLocation(1);
    }
    return location;
}
Also used : Location(org.openmrs.Location) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Location

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

the class EncounterServiceTest method saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs.

@Test
public void saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs() {
    executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
    ConceptService cs = Context.getConceptService();
    EncounterService es = Context.getEncounterService();
    ObsService os = Context.getObsService();
    Encounter enc = es.getEncounter(100);
    Obs o3 = new Obs();
    o3.setConcept(cs.getConcept(3));
    o3.setDateCreated(new Date());
    o3.setCreator(Context.getAuthenticatedUser());
    o3.setLocation(new Location(1));
    o3.setObsDatetime(new Date());
    o3.setPerson(Context.getPersonService().getPerson(3));
    o3.setValueText("third obs value text");
    o3.setEncounter(enc);
    Obs oParent = os.getObs(100);
    oParent.addGroupMember(o3);
    es.saveEncounter(enc);
    Context.flushSession();
    Context.clearSession();
    enc = es.getEncounter(100);
    Set<Obs> obsAtTopLevelUpdated = enc.getObsAtTopLevel(true);
    assertEquals(1, obsAtTopLevelUpdated.size());
    assertEquals(3, obsAtTopLevelUpdated.iterator().next().getGroupMembers(true).size());
    oParent = os.getObs(100);
    assertTrue(oParent.getGroupMembers(true).contains(os.getObs(101)));
    assertTrue(oParent.getGroupMembers(true).contains(os.getObs(102)));
    assertTrue(oParent.getGroupMembers(true).contains(os.getObs(o3.getObsId())));
}
Also used : Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 19 with Location

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

the class EncounterServiceTest method saveEncounter_shouldCascadeDeleteEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeDeleteEncounterProviders() {
    // given
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(3));
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = Context.getEncounterService().saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // when
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    encounter.setProvider(role, provider);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).contains(provider));
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 20 with Location

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

the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered() {
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(2));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(2));
    encounter.setCreator(new User(4));
    // We should have no visit
    assertNull(encounter.getVisit());
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
    gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(encounter.getEncounterDatetime());
    calendar.set(Calendar.YEAR, 1900);
    encounter.setEncounterDatetime(calendar.getTime());
    Context.getEncounterService().saveEncounter(encounter);
    // We should have a visit.
    assertNotNull(encounter.getVisit());
    // The visit should be persisted.
    assertNotNull(encounter.getVisit().getVisitId());
}
Also used : User(org.openmrs.User) Calendar(java.util.Calendar) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) 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