use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ObsServiceTest method saveObs_shouldAllowSettingPropertiesOnObs.
/**
* @see ObsService#saveObs(Obs,String)
*/
@Test
public void saveObs_shouldAllowSettingPropertiesOnObs() {
ObsService obsService = Context.getObsService();
Order order = null;
Concept concept = Context.getConceptService().getConcept(3);
Patient patient = new Patient(2);
Encounter encounter = new Encounter(3);
Date datetime = new Date();
Location location = new Location(1);
Integer valueGroupId = 7;
Date valueDatetime = new Date();
Concept valueCoded = new Concept(3);
Double valueNumeric = 2.0;
String valueModifier = "cc";
String valueText = "value text2";
String comment = "commenting2";
Obs obs = new Obs();
obs.setOrder(order);
obs.setConcept(concept);
obs.setPerson(patient);
obs.setEncounter(encounter);
obs.setObsDatetime(datetime);
obs.setLocation(location);
obs.setValueGroupId(valueGroupId);
obs.setValueDatetime(valueDatetime);
obs.setValueCoded(valueCoded);
obs.setValueNumeric(valueNumeric);
obs.setValueModifier(valueModifier);
obs.setValueText(valueText);
obs.setComment(comment);
Obs saved = obsService.saveObs(obs, null);
assertEquals(order, saved.getOrder());
assertEquals(patient, saved.getPerson());
assertEquals(comment, saved.getComment());
assertEquals(concept, saved.getConcept());
assertEquals(encounter, saved.getEncounter());
assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime());
assertEquals(location, saved.getLocation());
assertEquals(valueGroupId, saved.getValueGroupId());
assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime());
assertEquals(valueCoded, saved.getValueCoded());
assertEquals(valueNumeric, saved.getValueNumeric());
assertEquals(valueModifier, saved.getValueModifier());
assertEquals(valueText, saved.getValueText());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ObsServiceTest method getObservationsByPersonAndConcept_shouldGetObservationsMatchingPersonAndQuestion.
/**
* @see ObsService#getObservationsByPersonAndConcept(Person,Concept)
*/
@Test
public void getObservationsByPersonAndConcept_shouldGetObservationsMatchingPersonAndQuestion() {
ObsService obsService = Context.getObsService();
List<Obs> obss = obsService.getObservationsByPersonAndConcept(new Person(7), new Concept(5089));
Assert.assertEquals(3, obss.size());
Assert.assertEquals(16, obss.get(0).getObsId().intValue());
Assert.assertEquals(10, obss.get(1).getObsId().intValue());
Assert.assertEquals(7, obss.get(2).getObsId().intValue());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveTestOrderForTheSameConceptAndCareSettingExists() {
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
// sanity check that we have an active order for the same concept
TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
assertTrue(duplicateOrder.isActive());
assertEquals(cd4Count, duplicateOrder.getConcept());
Order order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(duplicateOrder.getCareSetting());
Order savedOrder = orderService.saveOrder(order, null);
assertNotNull(orderService.getOrder(savedOrder.getOrderId()));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADifferentCareSetting() {
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
TestOrder duplicateOrder = (TestOrder) orderService.getOrder(7);
final CareSetting inpatient = orderService.getCareSetting(2);
assertNotEquals(inpatient, duplicateOrder.getCareSetting());
assertTrue(duplicateOrder.isActive());
assertEquals(cd4Count, duplicateOrder.getConcept());
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(inpatient);
orderService.saveOrder(order, null);
List<Order> activeOrders = orderService.getActiveOrders(patient, null, null, null);
assertEquals(++initialActiveOrderCount, activeOrders.size());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase.
/**
* @see OrderService#saveOrderFrequency(OrderFrequency)
*/
@Test
public void saveOrderFrequency_shouldAddANewOrderFrequencyToTheDatabase() {
Concept concept = new Concept();
concept.addName(new ConceptName("new name", Context.getLocale()));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(conceptService.getConceptClassByName("Frequency"));
concept = conceptService.saveConcept(concept);
Integer originalSize = orderService.getOrderFrequencies(true).size();
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setFrequencyPerDay(2d);
orderFrequency = orderService.saveOrderFrequency(orderFrequency);
assertNotNull(orderFrequency.getId());
assertNotNull(orderFrequency.getUuid());
assertNotNull(orderFrequency.getCreator());
assertNotNull(orderFrequency.getDateCreated());
assertEquals(originalSize + 1, orderService.getOrderFrequencies(true).size());
}
Aggregations