Search in sources :

Example 6 with Location

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

the class ObsServiceTest method saveObs_shouldAllowSettingPropertiesOnObs.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldAllowSettingPropertiesOnObs() {
    ObsService obsService = Context.getObsService();
    Order order = null;
    Concept concept = Context.getConceptService().getConcept(3);
    Patient patient = new Patient(2);
    Encounter encounter = new Encounter(3);
    Date datetime = new Date();
    Location location = new Location(1);
    Integer valueGroupId = 7;
    Date valueDatetime = new Date();
    Concept valueCoded = new Concept(3);
    Double valueNumeric = 2.0;
    String valueModifier = "cc";
    String valueText = "value text2";
    String comment = "commenting2";
    Obs obs = new Obs();
    obs.setOrder(order);
    obs.setConcept(concept);
    obs.setPerson(patient);
    obs.setEncounter(encounter);
    obs.setObsDatetime(datetime);
    obs.setLocation(location);
    obs.setValueGroupId(valueGroupId);
    obs.setValueDatetime(valueDatetime);
    obs.setValueCoded(valueCoded);
    obs.setValueNumeric(valueNumeric);
    obs.setValueModifier(valueModifier);
    obs.setValueText(valueText);
    obs.setComment(comment);
    Obs saved = obsService.saveObs(obs, null);
    assertEquals(order, saved.getOrder());
    assertEquals(patient, saved.getPerson());
    assertEquals(comment, saved.getComment());
    assertEquals(concept, saved.getConcept());
    assertEquals(encounter, saved.getEncounter());
    assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime());
    assertEquals(location, saved.getLocation());
    assertEquals(valueGroupId, saved.getValueGroupId());
    assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime());
    assertEquals(valueCoded, saved.getValueCoded());
    assertEquals(valueNumeric, saved.getValueNumeric());
    assertEquals(valueModifier, saved.getValueModifier());
    assertEquals(valueText, saved.getValueText());
}
Also used : Order(org.openmrs.Order) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 7 with Location

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

the class ObsServiceTest method saveObs_shouldCascadeSaveToChildObsGroups.

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldCascadeSaveToChildObsGroups() {
    ObsService obsService = Context.getObsService();
    Obs parentObs = new Obs();
    parentObs.setConcept(Context.getConceptService().getConcept(3));
    parentObs.setObsDatetime(new Date());
    parentObs.setPerson(new Patient(2));
    parentObs.setLocation(new Location(1));
    Obs groupMember = new Obs();
    groupMember.setConcept(Context.getConceptService().getConcept(3));
    groupMember.setValueNumeric(1.0);
    groupMember.setObsDatetime(new Date());
    groupMember.setPerson(new Patient(2));
    groupMember.setLocation(new Location(1));
    parentObs.addGroupMember(groupMember);
    obsService.saveObs(parentObs, null);
    // make sure the child obs was saved
    Assert.assertNotNull(groupMember.getObsId());
}
Also used : Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 8 with Location

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

the class PersonServiceTest method createTestPatient.

/*
	 * Helper to create patient that does not have any existing relationships. Returns created Patient.
	 */
private Patient createTestPatient() {
    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.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept(1));
    patient.setGender("male");
    List<PatientIdentifierType> patientIdTypes = ps.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 TreeSet<>();
    patientIdentifiers.add(patientIdentifier);
    patient.setIdentifiers(patientIdentifiers);
    ps.savePatient(patient);
    return patient;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) TreeSet(java.util.TreeSet) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location)

Example 9 with Location

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

the class LocationValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if name is null or empty
 * @should fail validation if retired and retireReason is null or empty
 * @should set retired to false if retireReason is null or empty
 * @should pass validation if all fields are correct
 * @should pass validation if retired location is given retired reason
 * @should fail validation if parent location creates a loop
 * @should fail validation if name is exist in non retired locations
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    Location location = (Location) obj;
    if (location == null) {
        errors.rejectValue("location", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
        if (location.getRetired() && !StringUtils.hasLength(location.getRetireReason())) {
            // so that the jsp page displays
            location.setRetired(false);
            // properly again
            errors.rejectValue("retireReason", "error.null");
        }
        Location exist = Context.getLocationService().getLocation(location.getName());
        if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(location.getUuid(), exist.getUuid())) {
            errors.rejectValue("name", "location.duplicate.name");
        }
        // Traverse all the way up (down?) to the root and check if it
        // equals the root.
        Location root = location;
        while (root.getParentLocation() != null) {
            root = root.getParentLocation();
            if (root.equals(location)) {
                // Have gone in a circle
                errors.rejectValue("parentLocation", "Location.parentLocation.error");
                break;
            }
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "address1", "address2", "cityVillage", "stateProvince", "country", "postalCode", "latitude", "longitude", "countyDistrict", "address3", "address4", "address5", "address6", "address7", "address8", "address9", "address10", "address11", "address12", "address13", "address14", "address15", "retireReason");
        super.validateAttributes(location, errors, Context.getLocationService().getAllLocationAttributeTypes());
    }
}
Also used : Location(org.openmrs.Location)

Example 10 with Location

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

the class LocationValidatorTest method validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason.

/**
 * @see LocationValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason() {
    Location location = new Location();
    location.setName("County General");
    location.setDescription("desc");
    location.setRetired(true);
    location.setRetireReason("Because I don't like County General");
    Errors errors = new BindException(location, "location");
    new LocationValidator().validate(location, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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