use of org.openmrs.Patient in project openmrs-core by openmrs.
the class OrderServiceTest method getActiveOrders_shouldReturnAllOrdersIfNoOrderTypeIsSpecified.
/**
* @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
* org.openmrs.CareSetting, java.util.Date)
*/
@Test
public void getActiveOrders_shouldReturnAllOrdersIfNoOrderTypeIsSpecified() {
Patient patient = Context.getPatientService().getPatient(2);
List<Order> orders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(5, orders.size());
Order[] expectedOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) };
assertThat(orders, hasItems(expectedOrders));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedNonCodedAllergen.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllergiesWithEditedNonCodedAllergen() {
// get a patient with some allergies
Patient patient = allergyService.getPatient(2);
Allergies allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
Assert.assertEquals(4, allergies.size());
Allergy editedAllergy = allergies.get(0);
// clear any cache for this object such that the next calls fetch it from the database
Context.evictFromSession(editedAllergy);
// edit non coded allergen
editedAllergy.getAllergen().setNonCodedAllergen("some non coded allergen");
Assert.assertTrue(allergies.contains(editedAllergy));
allergyService.setAllergies(patient, allergies);
// should remain with four unvoided allergies and status maintained as see list
allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
Assert.assertEquals(4, allergies.size());
// the edited allergy should have been voided
Assert.assertFalse(allergies.contains(editedAllergy));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified.
@Test
public void setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified() {
Patient patient = allergyService.getPatient(2);
Allergen allergen = new Allergen(AllergenType.DRUG, null, "Some allergy name");
Allergy allergy = new Allergy(patient, allergen, null, null, null);
Allergies allergies = allergyService.getAllergies(patient);
allergies.add(allergy);
allergyService.setAllergies(patient, allergies);
Assert.assertFalse(allergy.getAllergen().isCoded());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldSaveTheAllergyListAndStatus.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldSaveTheAllergyListAndStatus() {
// get a patient without any allergies
Patient patient = allergyService.getPatient(7);
Allergies allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.UNKNOWN, allergies.getAllergyStatus());
Assert.assertEquals(0, allergies.size());
// save some allergies for this patient
Allergen allergen = new Allergen(AllergenType.DRUG, new Concept(3), null);
Concept severity = new Concept(4);
Allergy allergy = new Allergy(patient, allergen, severity, "some comment", new ArrayList<>());
AllergyReaction reaction = new AllergyReaction(allergy, new Concept(21), null);
allergy.addReaction(reaction);
allergies = new Allergies();
allergies.add(allergy);
allergyService.setAllergies(patient, allergies);
// now the patient should have allergies and the correct allergy status
allergies = allergyService.getAllergies(patient);
Assert.assertEquals(Allergies.SEE_LIST, allergies.getAllergyStatus());
Assert.assertEquals(1, allergies.size());
Assert.assertEquals(1, allergies.get(0).getReactions().size());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PersonServiceTest method createTestPatient.
/*
* Helper to create patient that does not have any existing relationships. Returns created Patient.
*/
private Patient createTestPatient() {
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.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept(1));
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = ps.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 TreeSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
ps.savePatient(patient);
return patient;
}
Aggregations