MotherService { public void pncVisitHappened(FormSubmission submission) { allTimelines.add( forMotherPNCVisit( submission.entityId(), submission.getFieldValue(AllConstants.PNCVisitFields.PNC_VISIT_DAY), submission.getFieldValue(AllConstants.PNCVisitFields.PNC_VISIT_DATE), submission.getFieldValue(AllConstants.PNCVisitFields.BP_SYSTOLIC), submission.getFieldValue(AllConstants.PNCVisitFields.BP_DIASTOLIC), submission.getFieldValue(AllConstants.PNCVisitFields.TEMPERATURE), submission.getFieldValue(AllConstants.PNCVisitFields.HB_LEVEL))); serviceProvidedService.add( ServiceProvided.forMotherPNCVisit( submission.entityId(), submission.getFieldValue(AllConstants.PNCVisitFields.PNC_VISIT_DAY), submission.getFieldValue(AllConstants.PNCVisitFields.PNC_VISIT_DATE))); String numberOfIFATabletsGiven = submission.getFieldValue(AllConstants.PNCVisitFields.NUMBER_OF_IFA_TABLETS_GIVEN); if (tryParse(numberOfIFATabletsGiven, 0) > 0) { allTimelines.add(forIFATabletsGiven(submission.entityId(), numberOfIFATabletsGiven, submission.getFieldValue(SUBMISSION_DATE))); } } MotherService(AllBeneficiaries allBeneficiaries, AllEligibleCouples allEligibleCouples,
                         AllTimelineEvents allTimelineEvents, ServiceProvidedService serviceProvidedService); void registerANC(FormSubmission submission); void registerOutOfAreaANC(FormSubmission submission); void ancVisit(FormSubmission submission); void close(FormSubmission submission); void close(String entityId, String reason); void ttProvided(FormSubmission submission); void ifaTabletsGiven(FormSubmission submission); void hbTest(FormSubmission submission); void deliveryOutcome(FormSubmission submission); void pncVisitHappened(FormSubmission submission); void deliveryPlan(FormSubmission submission); static final String MOTHER_ID; static String submissionDate; }
@Test public void shouldAddPNCVisitTimelineEventWhenPNCVisitHappens() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("pncVisitDay")).thenReturn("2"); when(submission.getFieldValue("pncVisitDate")).thenReturn("2012-01-01"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("100"); when(submission.getFieldValue("bpSystolic")).thenReturn("120"); when(submission.getFieldValue("bpDiastolic")).thenReturn("80"); when(submission.getFieldValue("temperature")).thenReturn("98.1"); when(submission.getFieldValue("hbLevel")).thenReturn("10.0"); when(submission.getFieldValue("submissionDate")).thenReturn("2013-01-01"); service.pncVisitHappened(submission); verify(allTimelineEvents).add(TimelineEvent.forMotherPNCVisit("entity id 1", "2", "2012-01-01", "120", "80", "98.1", "10.0")); }
@Test public void shouldAddIFATabletsGivenTimelineEventWhenPNCVisitHappens() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("pncVisitDay")).thenReturn("2"); when(submission.getFieldValue("pncVisitDate")).thenReturn("2012-01-01"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("100"); when(submission.getFieldValue("bpSystolic")).thenReturn("120"); when(submission.getFieldValue("bpDiastolic")).thenReturn("80"); when(submission.getFieldValue("temperature")).thenReturn("98.1"); when(submission.getFieldValue("hbLevel")).thenReturn("10.0"); when(submission.getFieldValue("submissionDate")).thenReturn("2012-01-02"); service.pncVisitHappened(submission); verify(allTimelineEvents).add(forIFATabletsGiven("entity id 1", "100", "2012-01-02")); }
@Test public void shouldAddPNCVisitServiceProvidedWhenPNCVisitHappens() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("pncVisitDay")).thenReturn("2"); when(submission.getFieldValue("pncVisitDate")).thenReturn("2012-01-01"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("100"); when(submission.getFieldValue("bpSystolic")).thenReturn("120"); when(submission.getFieldValue("bpDiastolic")).thenReturn("80"); when(submission.getFieldValue("temperature")).thenReturn("98.1"); when(submission.getFieldValue("hbLevel")).thenReturn("10.0"); when(submission.getFieldValue("submissionDate")).thenReturn("2013-01-01"); service.pncVisitHappened(submission); verify(serviceProvidedService).add(new ServiceProvided("entity id 1", "PNC", "2012-01-01", mapOf("day", "2"))); }
@Test public void shouldNotAddIFATabletsGivenTimelineEventWhenPNCVisitHappensAndNoIFATabletsWereGiven() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("pncVisitDay")).thenReturn("2"); when(submission.getFieldValue("pncVisitDate")).thenReturn("2012-01-01"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn(""); when(submission.getFieldValue("ifaTabletsDate")).thenReturn(null); when(submission.getFieldValue("bpSystolic")).thenReturn("120"); when(submission.getFieldValue("bpDiastolic")).thenReturn("80"); when(submission.getFieldValue("temperature")).thenReturn("98.1"); when(submission.getFieldValue("hbLevel")).thenReturn("10.0"); service.pncVisitHappened(submission); verify(allTimelineEvents, times(0)).add(forIFATabletsGiven("entity id 1", "2012-01-01", "100")); }