use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept() {
Order previousOrder = orderService.getOrder(7);
assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
Order order = previousOrder.cloneForDiscontinuing();
order.setDateActivated(new Date());
order.setOrderReasonNonCoded("Discontinue this");
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
Concept newConcept = conceptService.getConcept(5089);
assertFalse(previousOrder.getConcept().equals(newConcept));
order.setConcept(newConcept);
expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
orderService.saveOrder(order, null);
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithAddedReactions.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllergiesWithAddedReactions() {
// 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);
// add a reaction
AllergyReaction reaction = new AllergyReaction(null, new Concept(22), null);
editedAllergy.addReaction(reaction);
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.Concept in project openmrs-core by openmrs.
the class PatientServiceAllergyTest method setAllergies_shouldVoidAllergiesWithEditedSeverity.
/**
* @see PatientService#setAllergies(Patient,Allergies)
*/
@Test
public void setAllergies_shouldVoidAllergiesWithEditedSeverity() {
// 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 severity
editedAllergy.setSeverity(new Concept(24));
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.Concept in project openmrs-core by openmrs.
the class ObsServiceTest method getObservations_shouldGetAllObsWithAnswerConceptInGivenAnswersParameter.
/**
* @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean)
* @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String)
*/
@Test
public void getObservations_shouldGetAllObsWithAnswerConceptInGivenAnswersParameter() {
executeDataSet(INITIAL_OBS_XML);
ObsService obsService = Context.getObsService();
List<Obs> obss = obsService.getObservations(null, null, null, Collections.singletonList(new Concept(7)), null, null, null, null, null, null, null, false, null);
// obs 11 in INITIAL_OBS_XML and obs 13 in standardTestDataset
Assert.assertEquals(3, obss.size());
Set<Integer> ids = new HashSet<>();
for (Obs o : obss) {
ids.add(o.getObsId());
}
Assert.assertTrue(ids.contains(11));
Assert.assertTrue(ids.contains(13));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldCreateNewFileFromComplexDataForNewObs.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldCreateNewFileFromComplexDataForNewObs() {
executeDataSet(COMPLEX_OBS_XML);
ObsService os = Context.getObsService();
ConceptService cs = Context.getConceptService();
AdministrationService as = Context.getAdministrationService();
// make sure the file isn't there to begin with
File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(as.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR));
File createdFile = new File(complexObsDir, "nameOfFile.txt");
if (createdFile.exists())
createdFile.delete();
// the complex data to put onto an obs that will be saved
Reader input = new CharArrayReader("This is a string to save to a file".toCharArray());
ComplexData complexData = new ComplexData("nameOfFile.txt", input);
// must fetch the concept instead of just new Concept(8473) because the attributes on concept are checked
// this is a concept mapped to the text handler
Concept questionConcept = cs.getConcept(8474);
Obs obsToSave = new Obs(new Person(1), questionConcept, new Date(), new Location(1));
obsToSave.setComplexData(complexData);
try {
os.saveObs(obsToSave, null);
// make sure the file appears now after the save
Assert.assertTrue(createdFile.exists());
} finally {
// we always have to delete this inside the same unit test because it is outside the
// database and hence can't be "rolled back" like everything else
createdFile.delete();
}
}
Aggregations