Search in sources :

Example 1 with VisitService

use of org.openmrs.api.VisitService in project openmrs-core by openmrs.

the class VisitValidatorTest method validate_shouldFailIfPatientIsNotSet.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfPatientIsNotSet() {
    VisitService vs = Context.getVisitService();
    Visit visit = new Visit();
    visit.setVisitType(vs.getVisitType(1));
    visit.setStartDatetime(new Date());
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertTrue(errors.hasFieldErrors("patient"));
}
Also used : Errors(org.springframework.validation.Errors) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with VisitService

use of org.openmrs.api.VisitService in project openmrs-core by openmrs.

the class VisitValidatorTest method validate_shouldFailIfStartDatetimeIsNotSet.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfStartDatetimeIsNotSet() {
    VisitService vs = Context.getVisitService();
    Visit visit = new Visit();
    visit.setVisitType(vs.getVisitType(1));
    visit.setPatient(Context.getPatientService().getPatient(2));
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertTrue(errors.hasFieldErrors("startDatetime"));
}
Also used : Errors(org.springframework.validation.Errors) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with VisitService

use of org.openmrs.api.VisitService in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getOrderedVisitTypes.

/**
 * Returns a list of ordered visit types, provided by a global property
 * If a visit type is present in the visitTypes argument, but not found in the global property string,
 * it will be returned unordered, at the end of the visitTypesOrdered list
 *
 * @param visitTypes
 * @return visitTypesOrdered
 */
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes) {
    AdministrationService adminService = Context.getAdministrationService();
    String propertyValue = adminService.getGlobalProperty(CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY);
    VisitService vs = Context.getVisitService();
    return getOrderedVisitTypes(visitTypes, propertyValue, vs);
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) VisitService(org.openmrs.api.VisitService)

Example 4 with VisitService

use of org.openmrs.api.VisitService in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getUnRetiredVisitTypes.

public List<VisitType> getUnRetiredVisitTypes() {
    VisitService visitService = Context.getVisitService();
    List<VisitType> visitTypes = new ArrayList<VisitType>();
    for (VisitType visitType : visitService.getAllVisitTypes()) {
        if (visitType.getRetired() == false) {
            visitTypes.add(visitType);
        }
    }
    return visitTypes;
}
Also used : VisitService(org.openmrs.api.VisitService) ArrayList(java.util.ArrayList) VisitType(org.openmrs.VisitType)

Example 5 with VisitService

use of org.openmrs.api.VisitService in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method setEncounterBasedOnVisitType.

/**
 * Create encounters based on visit type
 *
 * @param visit
 * @param loginLocation
 * @param previousType
 */
public void setEncounterBasedOnVisitType(Visit visit, Location loginLocation, VisitType previousType) {
    // all types are transfer type
    boolean isTransferType = true;
    if (visit.getVisitType() == previousType) {
        // visit type is not changed: do nothing
        return;
    }
    EncounterService es = Context.getEncounterService();
    VisitService vs = Context.getVisitService();
    Patient patient = visit.getPatient();
    Person person = Context.getUserContext().getAuthenticatedUser().getPerson();
    Encounter encounter = new Encounter();
    setTransferEncounter(visit, vs, es, encounter, patient, person, loginLocation, previousType, isTransferType);
}
Also used : VisitService(org.openmrs.api.VisitService) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Person(org.openmrs.Person) EncounterService(org.openmrs.api.EncounterService)

Aggregations

VisitService (org.openmrs.api.VisitService)9 Visit (org.openmrs.Visit)4 Test (org.junit.Test)2 VisitType (org.openmrs.VisitType)2 EncounterService (org.openmrs.api.EncounterService)2 LocationService (org.openmrs.api.LocationService)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Encounter (org.openmrs.Encounter)1 Location (org.openmrs.Location)1 LocationTag (org.openmrs.LocationTag)1 Patient (org.openmrs.Patient)1 Person (org.openmrs.Person)1 APIException (org.openmrs.api.APIException)1 AdministrationService (org.openmrs.api.AdministrationService)1 ConceptService (org.openmrs.api.ConceptService)1 FormService (org.openmrs.api.FormService)1