use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject() throws Exception {
// sanity check, make sure there isn't a 501 patient already
Patient oldPatient = patientService.getPatient(501);
Assert.assertNull(oldPatient);
// fetch Bruno from the database
Person existingPerson = Context.getPersonService().getPerson(501);
Context.clearSession();
Patient patient = new Patient(existingPerson);
PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2), new Location(1));
patientIdentifier.setPreferred(true);
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
Assert.assertEquals(501, patient.getPatientId().intValue());
// make sure a new row with a patient id WAS created
Assert.assertNotNull(patientService.getPatient(501));
// make sure a new row with a new person id WASN'T created
Assert.assertNull(patientService.getPatient(503));
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientServiceTest method getPatients_shouldSupportSimpleRegex.
/**
* @see PatientService#getPatients(String, String, java.util.List, boolean)
*/
@Test
public void getPatients_shouldSupportSimpleRegex() throws Exception {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, "^0*@SEARCH@([A-Z]+-[0-9])?$"));
PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
identifier.setCreator(new User(1));
identifier.setDateCreated(new Date());
Patient patient = Context.getPatientService().getPatient(2);
patient.addIdentifier(identifier);
Context.getPatientService().savePatient(patient);
updateSearchIndex();
assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldCreateNewPatientIndentifier.
@Test
public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception {
PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1));
Patient associatedPatient = patientService.getPatient(2);
patientIdentifier.setPatient(associatedPatient);
PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
Assert.assertNotNull(createdPatientIdentifier);
Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientServiceTest method shouldCreatePatient.
@Test
public void shouldCreatePatient() throws Exception {
executeDataSet(CREATE_PATIENT_XML);
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
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);
// patient.removeAddress(pAddress);
patient.setBirthdateEstimated(true);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept());
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
assertNotNull(patientIdTypes);
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientIdTypes.get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setPreferred(true);
Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
patientService.savePatient(patient);
Patient createdPatient = patientService.getPatient(patient.getPatientId());
assertNotNull(createdPatient);
assertNotNull(createdPatient.getPatientId());
Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
assertNotNull(createdPatientById);
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test(expected = DuplicateIdentifierException.class)
public void checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers() throws Exception {
PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
Patient patient = new Patient();
// Identifier #1
PatientIdentifier patientIdentifier1 = new PatientIdentifier();
patientIdentifier1.setIdentifier("123456789");
patientIdentifier1.setLocation(new Location(2));
patientIdentifier1.setIdentifierType(patientIdentifierType);
patient.addIdentifier(patientIdentifier1);
// Identifier #2
PatientIdentifier patientIdentifier2 = new PatientIdentifier();
patientIdentifier2.setIdentifier("123456789");
patientIdentifier2.setIdentifierType(patientIdentifierType);
patientIdentifier2.setLocation(new Location(2));
patient.addIdentifier(patientIdentifier2);
patientService.checkPatientIdentifiers(patient);
}
Aggregations