use of org.openmrs.Concept in project openmrs-core by openmrs.
the class ConceptAnswersEditorTest method setAsText_shouldSetTheSortWeightsWithTheLeastPossibleChanges.
/**
* @see ConceptAnswersEditor#setAsText(String)
*/
@Test
public void setAsText_shouldSetTheSortWeightsWithTheLeastPossibleChanges() {
ConceptService service = Context.getConceptService();
Concept c = service.getConcept(21);
ConceptAnswersEditor editor = new ConceptAnswersEditor(c.getAnswers(true));
editor.setAsText("22 7 8");
// conceptId=7
ConceptAnswer ca1 = service.getConceptAnswer(1);
// conceptId=8
ConceptAnswer ca2 = service.getConceptAnswer(2);
// conceptId=22
ConceptAnswer ca3 = service.getConceptAnswer(3);
Concept cafter = service.getConcept(21);
Assert.assertEquals(3, cafter.getAnswers(true).size());
Assert.assertTrue(ca3.getSortWeight() < ca1.getSortWeight());
Assert.assertTrue(ca1.getSortWeight() < ca2.getSortWeight());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class HibernateConceptDAO method getParents.
/**
* returns a list of n-generations of parents of a concept in a concept set
*
* @param Concept current
* @return List<Concept>
* @throws DAOException
*/
@SuppressWarnings("unchecked")
private List<Concept> getParents(Concept current) throws DAOException {
List<Concept> parents = new ArrayList<>();
if (current != null) {
Query query = sessionFactory.getCurrentSession().createQuery("from Concept c join c.conceptSets sets where sets.concept = ?").setEntity(0, current);
List<Concept> immedParents = query.list();
for (Concept c : immedParents) {
parents.addAll(getParents(c));
}
parents.add(current);
if (log.isDebugEnabled()) {
log.debug("parents found: ");
for (Concept c : parents) {
log.debug("id: " + c.getConceptId());
}
}
}
return parents;
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndDrugNonCodedAndCareSettingExists.
/**
* @see OrderService#saveOrder(Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndDrugNonCodedAndCareSettingExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
final Concept nonCodedConcept = orderService.getNonCodedDrugConcept();
// sanity check that we have an active order for the same concept
DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(584);
assertTrue(duplicateOrder.isActive());
assertEquals(nonCodedConcept, duplicateOrder.getConcept());
DrugOrder drugOrder = duplicateOrder.copy();
drugOrder.setDrugNonCoded("non coded drug crocine");
expectedException.expect(AmbiguousOrderException.class);
expectedException.expectMessage("Order.cannot.have.more.than.one");
orderService.saveOrder(drugOrder, null);
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method getOrderFrequencyByConcept_shouldReturnTheOrderFrequencyThatMatchesTheSpecifiedConcept.
/**
* @see OrderService#getOrderFrequencyByConcept(org.openmrs.Concept)
*/
@Test
public void getOrderFrequencyByConcept_shouldReturnTheOrderFrequencyThatMatchesTheSpecifiedConcept() {
Concept concept = conceptService.getConcept(4);
assertEquals(3, orderService.getOrderFrequencyByConcept(concept).getOrderFrequencyId().intValue());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldSaveRevisionOrderScheduledOnDateNotOverlappingWithAnActiveOrderForTheSameConceptAndCareSetting() {
// sanity check that we have an active order
final Patient patient = patientService.getPatient(2);
final Concept cd4Count = conceptService.getConcept(5497);
TestOrder activeOrder = new TestOrder();
activeOrder.setPatient(patient);
activeOrder.setConcept(cd4Count);
activeOrder.setEncounter(encounterService.getEncounter(6));
activeOrder.setOrderer(providerService.getProvider(1));
activeOrder.setCareSetting(orderService.getCareSetting(2));
activeOrder.setDateActivated(new Date());
activeOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
orderService.saveOrder(activeOrder, null);
// New Drug order in future for same concept
TestOrder secondOrder = new TestOrder();
secondOrder.setPatient(activeOrder.getPatient());
secondOrder.setConcept(activeOrder.getConcept());
secondOrder.setEncounter(encounterService.getEncounter(6));
secondOrder.setOrderer(providerService.getProvider(1));
secondOrder.setCareSetting(activeOrder.getCareSetting());
secondOrder.setDateActivated(new Date());
secondOrder.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 1));
secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
orderService.saveOrder(secondOrder, null);
// Revise Second Order to have scheduled date not overlapping with active order
TestOrder revision = secondOrder.cloneForRevision();
revision.setScheduledDate(DateUtils.addDays(activeOrder.getEffectiveStopDate(), 2));
revision.setEncounter(encounterService.getEncounter(6));
revision.setOrderer(providerService.getProvider(1));
Order savedRevisionOrder = orderService.saveOrder(revision, null);
assertNotNull(orderService.getOrder(savedRevisionOrder.getOrderId()));
}
Aggregations