Search in sources :

Example 21 with EncounterType

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

the class EncounterServiceTest method getEncounterType_shouldNotGetRetiredTypes.

/**
 * @see EncounterService#getEncounterType(String)
 */
@Test
public void getEncounterType_shouldNotGetRetiredTypes() {
    EncounterService encounterService = Context.getEncounterService();
    // loop over all types to make sure
    // that the retired "Test Enc Type C" exists
    boolean foundRetired = false;
    for (EncounterType encType : encounterService.getAllEncounterTypes(true)) {
        if (encType.getName().equals("Test Enc Type C") && encType.getRetired()) {
            foundRetired = true;
        }
    }
    assertTrue(foundRetired);
    assertNull(encounterService.getEncounterType("Test Enc Type C"));
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 22 with EncounterType

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

the class EncounterServiceTest method saveEncounterType_shouldNotOverwriteCreatorOrDateCreated.

/**
 * @see EncounterService#saveEncounterType(EncounterType)
 */
@Test
public void saveEncounterType_shouldNotOverwriteCreatorOrDateCreated() {
    EncounterService encounterService = Context.getEncounterService();
    // the encounter to save without a dateCreated
    EncounterType encounterType = new EncounterType("testing", "desc");
    encounterType.setCreator(new User(4));
    // make sure we have a date that isn't "right now"
    Date date = new Date(System.currentTimeMillis() - 5000);
    encounterType.setDateCreated(date);
    // make sure the logged in user isn't the user we're testing with
    assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
    encounterService.saveEncounterType(encounterType);
    // make sure the encounter type creator is user 4 not user 1
    assertNotSame(encounterType.getCreator().getId(), Context.getAuthenticatedUser().getId());
    // make sure the encounter type date created wasn't overwritten
    assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
    // make sure we can fetch this new encounter type
    // from the database and its values are the same as the passed in ones
    EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId());
    assertNotNull(newEncounterType);
    assertEquals(4, encounterType.getCreator().getId().intValue());
    assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
    assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
}
Also used : User(org.openmrs.User) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 23 with EncounterType

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

the class EncounterServiceTest method voidEncounter_shouldNotVoidProviders.

/**
 * @see EncounterService#voidEncounter(Encounter, String)
 */
@Test
public void voidEncounter_shouldNotVoidProviders() {
    EncounterService encounterService = Context.getEncounterService();
    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 = encounterService.saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    encounter.addProvider(role, provider);
    encounterService.saveEncounter(encounter);
    assertEquals(1, encounter.getProvidersByRoles().size());
    encounterService.voidEncounter(encounter, "reason");
    encounter = encounterService.getEncounter(encounter.getEncounterId());
    assertEquals(1, encounter.getProvidersByRoles().size());
}
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 24 with EncounterType

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

the class EncounterServiceTest method saveEncounterType_shouldUpdateAnExistingEncounterTypeName.

/**
 * @see EncounterService#saveEncounterType(EncounterType)
 */
@Test
public void saveEncounterType_shouldUpdateAnExistingEncounterTypeName() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterTypeToChange = encounterService.getEncounterType(1);
    // change the name of the type
    encounterTypeToChange.setName("another test");
    // save the type to the database
    encounterService.saveEncounterType(encounterTypeToChange);
    // make sure the encounter type id didn't change
    assertEquals(1, encounterTypeToChange.getEncounterTypeId().intValue());
    // refetch the encounter type from the database
    EncounterType fetchedEncounterType = encounterService.getEncounterType(1);
    assertTrue(fetchedEncounterType.getName().equals("another test"));
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 25 with EncounterType

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

the class ORUR01Handler method createEncounter.

/**
 * This method does not call the database to create the encounter row. The encounter is only
 * created after all obs have been attached to it Creates an encounter pojo to be attached
 * later. This method does not create an encounterId
 *
 * @param msh
 * @param patient
 * @param pv1
 * @param orc
 * @return
 * @throws HL7Exception
 */
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
    // the encounter we will return
    Encounter encounter;
    // look for the encounter id in PV1-19
    CX visitNumber = pv1.getVisitNumber();
    Integer encounterId = null;
    try {
        encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
    } catch (NumberFormatException e) {
    // pass
    }
    // the database
    if (encounterId != null) {
        encounter = Context.getEncounterService().getEncounter(encounterId);
    } else {
        // if no encounter_id was passed in, this is a new
        // encounter, create the object
        encounter = new Encounter();
        Date encounterDate = getEncounterDate(pv1);
        Provider provider = getProvider(pv1);
        Location location = getLocation(pv1);
        Form form = getForm(msh);
        EncounterType encounterType = getEncounterType(msh, form);
        User enterer = getEnterer(orc);
        // Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
        encounter.setEncounterDatetime(encounterDate);
        if (unknownRole == null) {
            unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
        }
        encounter.setProvider(unknownRole, provider);
        encounter.setPatient(patient);
        encounter.setLocation(location);
        encounter.setForm(form);
        encounter.setEncounterType(encounterType);
        encounter.setCreator(enterer);
        encounter.setDateCreated(new Date());
    }
    return encounter;
}
Also used : User(org.openmrs.User) CX(ca.uhn.hl7v2.model.v25.datatype.CX) Form(org.openmrs.Form) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Provider(org.openmrs.Provider) Location(org.openmrs.Location)

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