Search in sources :

Example 6 with EncounterType

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

the class ExistingOrNewVisitAssignmentHandler method beforeCreateEncounter.

/**
 * @see org.openmrs.api.handler.ExistingVisitAssignmentHandler#beforeCreateEncounter(org.openmrs.Encounter)
 * @should assign existing visit if match found
 * @should assign new visit if no match found
 * @should resolve encounter and visit type uuids as global property values
 */
@Override
public void beforeCreateEncounter(Encounter encounter) {
    // Do the default assignment to an existing visit.
    super.beforeCreateEncounter(encounter);
    // Do nothing if the encounter already belongs to a visit.
    if (encounter.getVisit() != null) {
        return;
    }
    Visit visit = new Visit();
    visit.setStartDatetime(encounter.getEncounterDatetime());
    visit.setLocation(encounter.getLocation());
    visit.setPatient(encounter.getPatient());
    if (encounterVisitMapping == null) {
        // initial one-time setup
        setEncounterVisitMapping(new HashMap<>());
        Context.getAdministrationService().addGlobalPropertyListener(this);
    }
    VisitType visitType = encounterVisitMapping.get(encounter.getEncounterType());
    if (visitType == null) {
        visitType = loadVisitType(encounter.getEncounterType());
        // replace reference instead of synchronizing
        Map<EncounterType, VisitType> newMap = new HashMap<>(encounterVisitMapping);
        newMap.put(encounter.getEncounterType(), visitType);
        setEncounterVisitMapping(newMap);
    }
    visit.setVisitType(visitType);
    // set stop date time to last millisecond of the encounter day.
    visit.setStopDatetime(OpenmrsUtil.getLastMomentOfDay(encounter.getEncounterDatetime()));
    encounter.setVisit(visit);
}
Also used : HashMap(java.util.HashMap) Visit(org.openmrs.Visit) VisitType(org.openmrs.VisitType) EncounterType(org.openmrs.EncounterType)

Example 7 with EncounterType

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

the class EncounterTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see EncounterTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    EncounterType type = new EncounterType();
    type.setName("name");
    type.setDescription("some descriptin not exceeding the limit");
    type.setRetireReason("retireReason");
    Errors errors = new BindException(type, "type");
    new EncounterTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) EncounterType(org.openmrs.EncounterType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with EncounterType

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

the class EncounterTypeValidatorTest method validate_shouldPassValidationWhenEditingAnExistingEncounterType.

/**
 * @see EncounterTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationWhenEditingAnExistingEncounterType() {
    EncounterType type = Context.getEncounterService().getEncounterType("Scheduled");
    Assert.assertNotNull(type);
    Errors errors = new BindException(type, "encounterType");
    new EncounterTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) EncounterType(org.openmrs.EncounterType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with EncounterType

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

the class EncounterServiceTest method getEncounterType_shouldReturnNullWithNullNameParameter.

/**
 * Make sure that we are not throwing an error with a null parameter to
 *
 * @see EncounterService#getEncounterType(String)
 */
@Test
public void getEncounterType_shouldReturnNullWithNullNameParameter() {
    EncounterService encounterService = Context.getEncounterService();
    // we should not get an error here...but silently return nothing
    EncounterType type = encounterService.getEncounterType((String) null);
    assertNull(type);
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 10 with EncounterType

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

the class EncounterServiceTest method saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited.

/**
 * @see EncounterService#saveEncounterType(EncounterType)
 */
@Test
public void saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited() {
    EncounterService es = Context.getEncounterService();
    // Create encounter type, ensure creator/dateCreated are set, and changedBy and dateChanged are not setDateCreated.
    EncounterType encounterType = es.saveEncounterType(new EncounterType("testing", "desc"));
    User creator = encounterType.getCreator();
    Date dateCreated = encounterType.getDateCreated();
    assertNotNull("creator should be set after saving", creator);
    assertNotNull("date creates should be set after saving", dateCreated);
    assertNull("changed by should not be set after creation", encounterType.getChangedBy());
    assertNull("date changed should not be set after creation", encounterType.getDateChanged());
    // Edit encounter type.
    encounterType.setDescription("This has been a test!");
    EncounterType editedEt = es.saveEncounterType(encounterType);
    Context.flushSession();
    // Ensure creator/dateCreated remain unchanged, and changedBy and dateChanged are set.
    assertTrue("creator should not change during edit", creator.equals(editedEt.getCreator()));
    assertTrue("date created should not changed during edit", dateCreated.equals(editedEt.getDateCreated()));
    assertNotNull("changed by should be set after edit", editedEt.getChangedBy());
    assertNotNull("date changed should be set after edit", editedEt.getDateChanged());
}
Also used : User(org.openmrs.User) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

EncounterType (org.openmrs.EncounterType)60 Test (org.junit.Test)44 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)42 Encounter (org.openmrs.Encounter)19 Date (java.util.Date)17 Location (org.openmrs.Location)12 Patient (org.openmrs.Patient)10 User (org.openmrs.User)10 EncounterRole (org.openmrs.EncounterRole)9 Provider (org.openmrs.Provider)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)5 GlobalProperty (org.openmrs.GlobalProperty)5 List (java.util.List)4 Privilege (org.openmrs.Privilege)4 Concept (org.openmrs.Concept)3 Visit (org.openmrs.Visit)3 HashMap (java.util.HashMap)2 SQLQuery (org.hibernate.SQLQuery)2