use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientValidatorTest method validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred.
@Test
public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() {
PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
patient.setGender("male");
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
PatientIdentifier patientIdentifier1 = new PatientIdentifier();
patientIdentifier1.setLocation(new Location(1));
patientIdentifier1.setIdentifier("012345678");
patientIdentifier1.setDateCreated(new Date());
patientIdentifier1.setIdentifierType(patientIdentifierType);
patient.addIdentifier(patientIdentifier1);
Errors errors = new BindException(patient, "patient");
validator.validate(patient, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceImpl method getDefaultLocation.
/**
* @see org.openmrs.api.LocationService#getDefaultLocation()
*/
@Override
@Transactional(readOnly = true)
public Location getDefaultLocation() throws APIException {
Location location = null;
String locationGP = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME);
if (StringUtils.hasText(locationGP)) {
location = Context.getLocationService().getLocation(locationGP);
}
if (location == null) {
location = getDefaultLocation(location, locationGP);
}
// If neither exist, get the first available location
if (location == null) {
location = Context.getLocationService().getLocation(1);
}
return location;
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs.
@Test
public void saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs() {
executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
ConceptService cs = Context.getConceptService();
EncounterService es = Context.getEncounterService();
ObsService os = Context.getObsService();
Encounter enc = es.getEncounter(100);
Obs o3 = new Obs();
o3.setConcept(cs.getConcept(3));
o3.setDateCreated(new Date());
o3.setCreator(Context.getAuthenticatedUser());
o3.setLocation(new Location(1));
o3.setObsDatetime(new Date());
o3.setPerson(Context.getPersonService().getPerson(3));
o3.setValueText("third obs value text");
o3.setEncounter(enc);
Obs oParent = os.getObs(100);
oParent.addGroupMember(o3);
es.saveEncounter(enc);
Context.flushSession();
Context.clearSession();
enc = es.getEncounter(100);
Set<Obs> obsAtTopLevelUpdated = enc.getObsAtTopLevel(true);
assertEquals(1, obsAtTopLevelUpdated.size());
assertEquals(3, obsAtTopLevelUpdated.iterator().next().getGroupMembers(true).size());
oParent = os.getObs(100);
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(101)));
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(102)));
assertTrue(oParent.getGroupMembers(true).contains(os.getObs(o3.getObsId())));
}
use of org.openmrs.Location 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.Location in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered() {
Encounter encounter = new Encounter();
encounter.setLocation(new Location(2));
encounter.setEncounterType(new EncounterType(1));
encounter.setEncounterDatetime(new Date());
encounter.setPatient(new Patient(2));
encounter.setCreator(new User(4));
// We should have no visit
assertNull(encounter.getVisit());
GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
Context.getAdministrationService().saveGlobalProperty(gp);
Calendar calendar = Calendar.getInstance();
calendar.setTime(encounter.getEncounterDatetime());
calendar.set(Calendar.YEAR, 1900);
encounter.setEncounterDatetime(calendar.getTime());
Context.getEncounterService().saveEncounter(encounter);
// We should have a visit.
assertNotNull(encounter.getVisit());
// The visit should be persisted.
assertNotNull(encounter.getVisit().getVisitId());
}
Aggregations