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);
}
}
}*/
}
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());
}
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));
}
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));
}
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));
}
Aggregations