Search in sources :

Example 26 with Provider

use of org.openmrs.Provider in project openmrs-module-pihcore by PIH.

the class UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts method execute.

@Override
public void execute() {
    UserService userService = Context.getUserService();
    ProviderService providerService = Context.getProviderService();
    Set<Person> personsToIncludeWhenRetiringProviderAccts = new HashSet<Person>();
    Set<Person> personsToExcludeWhenRetiringProviderAccts = new HashSet<Person>();
    for (User user : userService.getUsers(null, null, true)) {
        // the user account has been retired over a month ago
        if (user.isRetired() && user.getDateRetired() != null && user.getDateRetired().before(new DateTime().minusMonths(1).toDate())) {
            personsToIncludeWhenRetiringProviderAccts.add(user.getPerson());
        } else {
            personsToExcludeWhenRetiringProviderAccts.add(user.getPerson());
        /* if (!user.isRetired()) {
                    personsToMakeSureHaveActiveProviderAcct.add(user.getPerson());
                }*/
        }
    }
    personsToIncludeWhenRetiringProviderAccts.removeAll(personsToExcludeWhenRetiringProviderAccts);
    // retire all provider accts associated with persons with retired user accts
    for (Person person : personsToIncludeWhenRetiringProviderAccts) {
        for (Provider provider : providerService.getProvidersByPerson(person)) {
            if (!provider.isRetired()) {
                providerService.retireProvider(provider, "user account retired over 1 month ago");
            }
        }
    }
/*   // check all persons to include and make sure, if they have provider accts, that at least one is unretired
        for (Person person : personsToMakeSureHaveActiveProviderAcct) {

            Collection<Provider> providers = providerService.getProvidersByPerson(person);

            if (providers.size() == 1 && providers.iterator().next().isRetired()) {
                providerService.unretireProvider(providers.iterator().next());
            }
            else if (providers.size() > 1) {

                Provider mostRecentlyRetiredProvider = null;
                Boolean noUnretiredProviders = true;
                Iterator<Provider> i = providers.iterator();

                while (i.hasNext()) {
                    Provider provider = i.next();
                    if (!provider.isRetired()) {
                        noUnretiredProviders = false;
                        break;
                    }
                    else if (mostRecentlyRetiredProvider == null || mostRecentlyRetiredProvider.getDateRetired().before(provider.getDateRetired())) {
                        mostRecentlyRetiredProvider = provider;
                    }
                }

                if (noUnretiredProviders) {
                    providerService.unretireProvider(mostRecentlyRetiredProvider);
                }
            }
        }*/
}
Also used : ProviderService(org.openmrs.api.ProviderService) User(org.openmrs.User) UserService(org.openmrs.api.UserService) Person(org.openmrs.Person) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Provider(org.openmrs.Provider)

Example 27 with Provider

use of org.openmrs.Provider 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)

Example 28 with Provider

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

the class EncounterServiceTest method saveEncounter_shouldCascadeSaveEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeSaveEncounterProviders() {
    // given
    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 = Context.getEncounterService().saveEncounterRole(role);
    EncounterRole role2 = new EncounterRole();
    role2.setName("role2");
    role2 = Context.getEncounterService().saveEncounterRole(role2);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name1"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    encounter.addProvider(role2, provider2);
    // when
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(2, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).containsAll(Arrays.asList(provider, provider2)));
    Assert.assertEquals(1, encounter.getProvidersByRole(role2).size());
    Assert.assertTrue("Role2", encounter.getProvidersByRole(role2).contains(provider2));
}
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 29 with Provider

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

the class ProviderServiceTest method isProviderIdentifierUnique_shouldReturnFalseIfTheIdentifierIsADuplicate.

/**
 * @see ProviderService#isProviderIdentifierUnique(Provider)
 */
@Test
public void isProviderIdentifierUnique_shouldReturnFalseIfTheIdentifierIsADuplicate() {
    executeDataSet(OTHERS_PROVIDERS_XML);
    Provider duplicateProvider = service.getProvider(200);
    Provider existingProviderToEdit = service.getProvider(1);
    existingProviderToEdit.setIdentifier(duplicateProvider.getIdentifier());
    Assert.assertFalse(service.isProviderIdentifierUnique(existingProviderToEdit));
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 30 with Provider

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

the class ProviderServiceTest method isProviderIdentifierUnique_shouldReturnTrueIfTheIdentifierIsABlankString.

/**
 * @see ProviderService#isProviderIdentifierUnique(Provider)
 */
@Test
public void isProviderIdentifierUnique_shouldReturnTrueIfTheIdentifierIsABlankString() {
    Provider provider = new Provider();
    provider.setIdentifier("");
    Assert.assertTrue(service.isProviderIdentifierUnique(provider));
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Provider (org.openmrs.Provider)49 Test (org.junit.Test)40 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 Encounter (org.openmrs.Encounter)16 Date (java.util.Date)12 Person (org.openmrs.Person)10 Patient (org.openmrs.Patient)9 EncounterType (org.openmrs.EncounterType)8 EncounterRole (org.openmrs.EncounterRole)7 Location (org.openmrs.Location)7 PersonName (org.openmrs.PersonName)6 TestOrder (org.openmrs.TestOrder)5 Message (ca.uhn.hl7v2.model.Message)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 DrugOrder (org.openmrs.DrugOrder)4 Order (org.openmrs.Order)4 OrderUtilTest (org.openmrs.order.OrderUtilTest)4 Criteria (org.hibernate.Criteria)3 Concept (org.openmrs.Concept)3 User (org.openmrs.User)3