Search in sources :

Example 11 with EncounterRole

use of org.openmrs.EncounterRole in project openmrs-module-coreapps by openmrs.

the class ParseEncounterToJson method createEncounterJSON.

public SimpleObject createEncounterJSON(User authenticatedUser, Encounter encounter) {
    boolean canDelete = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_ENCOUNTER);
    boolean canEdit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_EDIT_ENCOUNTER);
    SimpleObject simpleEncounter = SimpleObject.fromObject(new EncounterDomainWrapper(encounter), uiUtils, "encounterId", "location", "encounterDatetime", "encounterProviders.provider", "voided", "form");
    // UUID is not provided by EncounterDomainWrapper, adding it here.
    simpleEncounter.put("uuid", encounter.getUuid());
    // manually set the date and time components so we can control how we format them
    simpleEncounter.put("encounterDate", DateFormatUtils.format(encounter.getEncounterDatetime(), "dd MMM yyyy", Context.getLocale()));
    simpleEncounter.put("encounterTime", DateFormatUtils.format(encounter.getEncounterDatetime(), "hh:mm a", Context.getLocale()));
    // do the same for other date fields
    simpleEncounter.put("dateCreated", DateFormatUtils.format(encounter.getDateCreated(), "dd MMM yyyy", Context.getLocale()));
    simpleEncounter.put("creator", uiUtils.format(encounter.getCreator()));
    if (encounter.getDateChanged() != null) {
        simpleEncounter.put("dateChanged", DateFormatUtils.format(encounter.getDateChanged(), "dd MMM yyyy", Context.getLocale()));
    }
    if (encounter.getChangedBy() != null) {
        simpleEncounter.put("changedBy", uiUtils.format(encounter.getChangedBy()));
    }
    EncounterType encounterType = encounter.getEncounterType();
    simpleEncounter.put("encounterType", SimpleObject.create("uuid", encounterType.getUuid(), "name", uiUtils.format(encounterType)));
    // determine the provider
    Provider primaryProvider = null;
    // if a primary encounter role has been specified, get the provider for that role
    EncounterRole primaryEncounterRole = getPrimaryEncounterRoleForEncounter(encounter);
    if (primaryEncounterRole != null) {
        Set<Provider> providers = encounter.getProvidersByRole(primaryEncounterRole);
        if (providers != null && !providers.isEmpty()) {
            // for now, if there are multiple providers with this role, return an arbitrary one
            primaryProvider = providers.iterator().next();
        }
    }
    // otherwise, just pick an arbitrary (non-voided) provider
    if (primaryProvider == null) {
        primaryProvider = getFirstNonVoidedProvider(encounter);
    }
    simpleEncounter.put("primaryProvider", uiUtils.format(primaryProvider));
    if (verifyIfUserHasPermissionToDeleteAnEncounter(encounter, authenticatedUser, canDelete)) {
        simpleEncounter.put("canDelete", true);
    }
    if (verifyIfUserHasPermissionToEditAnEncounter(encounter, authenticatedUser, canEdit)) {
        simpleEncounter.put("canEdit", true);
    } else {
        simpleEncounter.put("canEdit", false);
    }
    if (encounter.getVisit() != null) {
        simpleEncounter.put("visitId", encounter.getVisit().getId());
    }
    return simpleEncounter;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) SimpleObject(org.openmrs.ui.framework.SimpleObject) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider)

Example 12 with EncounterRole

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

the class EncounterServiceTest method retireEncounterRole_shouldRetireTypeAndSetAttributes.

/**
 * @see EncounterService#retireEncounterRole(org.openmrs.EncounterRole, String)
 */
@Test
public void retireEncounterRole_shouldRetireTypeAndSetAttributes() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = encounterService.getEncounterRole(1);
    assertFalse(encounterRole.getRetired());
    assertNull(encounterRole.getRetiredBy());
    assertNull(encounterRole.getRetireReason());
    assertNull(encounterRole.getDateRetired());
    EncounterRole retiredEncounterRole = encounterService.retireEncounterRole(encounterRole, "Just Testing");
    assertEquals(retiredEncounterRole, encounterRole);
    assertTrue(retiredEncounterRole.getRetired());
    assertNotNull(retiredEncounterRole.getDateRetired());
    assertEquals(Context.getAuthenticatedUser(), retiredEncounterRole.getRetiredBy());
    assertEquals("Just Testing", retiredEncounterRole.getRetireReason());
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 13 with EncounterRole

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

the class EncounterServiceTest method saveEncounterRole_shouldSaveEncounterRoleWithBasicDetails.

/**
 * @see org.openmrs.api.EncounterService#saveEncounterRole(org.openmrs.EncounterRole)
 */
@Test
public void saveEncounterRole_shouldSaveEncounterRoleWithBasicDetails() {
    EncounterRole encounterRole = new EncounterRole();
    encounterRole.setName("Attending physician");
    encounterRole.setDescription("The person in charge");
    EncounterService encounterService = Context.getEncounterService();
    encounterService.saveEncounterRole(encounterRole);
    assertNotNull("The saved encounter role should have an encounter role id now", encounterRole.getEncounterRoleId());
    EncounterRole newSavedEncounterRole = encounterService.getEncounterRole(encounterRole.getEncounterRoleId());
    assertNotNull("We should get back an encounter role", newSavedEncounterRole);
    assertEquals(encounterRole, newSavedEncounterRole);
    assertTrue("The created encounter role needs to equal the pojo encounter role", encounterRole.equals(newSavedEncounterRole));
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 14 with EncounterRole

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

the class EncounterServiceTest method retireEncounterRole_shouldThrowErrorIfGivenNullReasonParameter.

/**
 * @see EncounterService#retireEncounterRole(org.openmrs.EncounterRole, String)
 */
@Test(expected = IllegalArgumentException.class)
public void retireEncounterRole_shouldThrowErrorIfGivenNullReasonParameter() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = encounterService.getEncounterRole(1);
    encounterService.retireEncounterRole(encounterRole, null);
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 15 with EncounterRole

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

the class EncounterServiceTest method filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull.

/**
 * @see EncounterService#filterEncountersByViewPermissions(List, User)
 */
@Test
public void filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull() {
    EncounterService encounterService = Context.getEncounterService();
    int beforeSize = encounterService.getEncountersByPatientId(3).size();
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(Context.getPatientService().getPatient(3));
    EncounterType encounterType = new EncounterType(1);
    // viewPrivilege on encounter type intentionally left null
    encounter.setEncounterType(encounterType);
    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);
    List<Encounter> patientEncounters = encounterService.getEncountersByPatientId(3);
    assertNotNull(patientEncounters);
    assertEquals(beforeSize + 1, patientEncounters.size());
}
Also used : Encounter(org.openmrs.Encounter) 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)

Aggregations

EncounterRole (org.openmrs.EncounterRole)22 Test (org.junit.Test)20 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 EncounterType (org.openmrs.EncounterType)7 Provider (org.openmrs.Provider)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Date (java.util.Date)6 Encounter (org.openmrs.Encounter)6 Location (org.openmrs.Location)6 Patient (org.openmrs.Patient)4 EncounterProvider (org.openmrs.EncounterProvider)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 AdministrationService (org.openmrs.api.AdministrationService)1 EncounterService (org.openmrs.api.EncounterService)1 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)1