use of org.openmrs.Provider in project openmrs-core by openmrs.
the class ProviderValidatorTest method validate_shouldAcceptDuplicateIdentifierIfTheExistingProviderIsRetired.
/**
* @see ProviderValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldAcceptDuplicateIdentifierIfTheExistingProviderIsRetired() {
executeDataSet(OTHERS_PROVIDERS_XML);
Provider duplicateRetiredProvider = providerService.getProvider(201);
Assert.assertTrue(duplicateRetiredProvider.getRetired());
Provider provider = providerService.getProvider(1);
provider.setIdentifier(duplicateRetiredProvider.getIdentifier());
providerValidator.validate(provider, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class ProviderValidatorTest method setup.
@Before
public void setup() {
provider = new Provider();
errors = new BindException(provider, "provider");
providerValidator = new ProviderValidator();
providerService = Context.getProviderService();
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson.
@Test
public void compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson() {
Provider provider1 = new Provider();
Person person2 = new Person();
person2.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider2 = new Provider();
provider2.setPerson(person2);
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected a positive value but it was: " + actualValue, actualValue > 0);
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldCascadeDeleteEncounterProviders.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldCascadeDeleteEncounterProviders() {
// 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);
Provider provider = new Provider();
provider.setIdentifier("id1");
provider.setPerson(newPerson("name"));
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);
EncounterService es = Context.getEncounterService();
es.saveEncounter(encounter);
Context.flushSession();
Context.clearSession();
// when
encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
encounter.setProvider(role, provider);
es.saveEncounter(encounter);
Context.flushSession();
Context.clearSession();
// then
encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
Assert.assertTrue("Role", encounter.getProvidersByRole(role).contains(provider));
}
use of org.openmrs.Provider in project openmrs-core by openmrs.
the class EncounterServiceTest method filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters.
/**
* @see EncounterService#filterEncountersByViewPermissions(List, User)
*/
@Test
public void filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters() {
EncounterService encounterService = Context.getEncounterService();
int expectedSize = 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);
encounterType.setViewPrivilege(Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"));
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);
assertEquals(expectedSize + 1, patientEncounters.size());
if (Context.isAuthenticated()) {
Context.logout();
}
Context.authenticate("test_user", "test");
Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
patientEncounters = encounterService.getEncountersByPatientId(3);
int actualSize = patientEncounters.size();
Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
Context.logout();
assertEquals(actualSize, expectedSize);
assertTrue(!patientEncounters.contains(encounter));
}
Aggregations