@Test public void shouldSaveNewDrugOrdersInTheSequenceOfOrderingToAnEncounterWithExistingOrders() throws ParseException { EmrOrderServiceImpl_1_10 emrOrderService = new EmrOrderServiceImpl_1_10(openMRSDrugOrderMapper, encounterService, openMRSOrderMapper); EncounterTransaction.DrugOrder drugOrder3 = new DrugOrderBuilder().withDrugUuid("drug-uuid3").build(); EncounterTransaction.DrugOrder drugOrder4 = new DrugOrderBuilder().withDrugUuid("drug-uuid4").build(); DrugOrder existingDrugOrder1 = new DrugOrder(); DrugOrder existingDrugOrder2 = new DrugOrder(); DrugOrder mappedDrugOrder3 = new DrugOrder(); DrugOrder mappedDrugOrder4 = new DrugOrder(); Encounter encounter = new Encounter(); encounter.addOrder(existingDrugOrder1); encounter.addOrder(existingDrugOrder2); when(openMRSDrugOrderMapper.map(drugOrder3, encounter)).thenReturn(mappedDrugOrder3); when(openMRSDrugOrderMapper.map(drugOrder4, encounter)).thenReturn(mappedDrugOrder4); emrOrderService.save(Arrays.asList(drugOrder3, drugOrder4), encounter); ArgumentCaptor<Encounter> encounterArgumentCaptor = ArgumentCaptor.forClass(Encounter.class); verify(encounterService).saveEncounter(encounterArgumentCaptor.capture()); Encounter savedEncounter = encounterArgumentCaptor.getValue(); ArrayList<org.openmrs.Order> savedOrders = new ArrayList<org.openmrs.Order>(savedEncounter.getOrders()); assertThat(savedOrders.size(), is(4)); assertThat((DrugOrder) savedOrders.get(2), is(sameInstance(mappedDrugOrder3))); assertThat((DrugOrder) savedOrders.get(3), is(sameInstance(mappedDrugOrder4))); }
@Test public void shouldSaveOrdersToEncounterWithExistingOrders() throws ParseException { EmrOrderServiceImpl_1_10 emrOrderService = new EmrOrderServiceImpl_1_10(openMRSDrugOrderMapper, encounterService, openMRSOrderMapper); EncounterTransaction.Order order1 = new OrderBuilder().withConceptUuid("concept-uuid1").withComment("Comment").build(); EncounterTransaction.Order order2 = new OrderBuilder().withConceptUuid("concept-uuid2").withComment("Comment").build(); Order mappedOrder1 = new Order(); Concept concept = new Concept(); concept.setUuid("concept-uuid1"); mappedOrder1.setConcept(concept); mappedOrder1.setCommentToFulfiller("Comment"); Order mappedOrder2 = new Order(); concept = new Concept(); concept.setUuid("concept-uuid2"); mappedOrder2.setConcept(concept); mappedOrder2.setCommentToFulfiller("Comment"); Order existingOrder1 = new Order(); Order existingOrder2 = new Order(); Encounter encounter = new Encounter(); encounter.addOrder(existingOrder1); encounter.addOrder(existingOrder2); when(openMRSOrderMapper.map(order1, encounter)).thenReturn(mappedOrder1); when(openMRSOrderMapper.map(order2, encounter)).thenReturn(mappedOrder2); emrOrderService.saveOrders(Arrays.asList(order1, order2), encounter); ArgumentCaptor<Encounter> encounterArgumentCaptor = ArgumentCaptor.forClass(Encounter.class); verify(encounterService).saveEncounter(encounterArgumentCaptor.capture()); Encounter savedEncounter = encounterArgumentCaptor.getValue(); ArrayList<org.openmrs.Order> savedOrders = new ArrayList<org.openmrs.Order>(savedEncounter.getOrders()); assertThat(savedOrders.size(), is(4)); assertTrue(existsInOrdersList(mappedOrder1, savedOrders)); assertTrue(existsInOrdersList(mappedOrder2, savedOrders)); }