Search in sources :

Example 46 with Patient

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));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 47 with Patient

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));
}
Also used : Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 48 with Patient

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());
}
Also used : Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 49 with Patient

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());
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Patient(org.openmrs.Patient) AllergyReaction(org.openmrs.AllergyReaction) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 50 with Patient

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;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) TreeSet(java.util.TreeSet) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28