@Test public void shouldAddNewPNCVisitDateToPNCVisitsDatesThatHappened() throws Exception { when(reportFieldsDefinition.get("pnc_visit")).thenReturn(asList("pncVisitDate")); Mother mother = new Mother("mother id 1", "ec id 1", "TC1") .withDetails( EasyMap.create("some-key", "some-value").put("pncVisitDates", "2013-01-01").map()); when(allMothers.findByCaseId("entity id 1")).thenReturn(mother); FormSubmission submission = create() .withFormName("pnc_visit") .addFormField("pncVisitDate", "2013-01-02") .withSubForm( new SubFormData("child_pnc_visit", Collections.<Map<String, String>>emptyList())) .build(); service.pncVisitHappened(submission); Mother updatedMother = new Mother("mother id 1", "ec id 1", "TC1") .withDetails( EasyMap.create("some-key", "some-value") .put("pncVisitDates", "2013-01-01 2013-01-02") .map()) .withPNCVisits( asList( new PNCVisit() .withDate("2013-01-02") .withChildrenDetails(Collections.<Map<String, String>>emptyList()))); verify(allMothers).update(updatedMother); }
@Test public void shouldUpdateMotherWithPNCVisitDetails() throws Exception { Mother mother = new Mother("mother id 1", "ec id 1", "TC1") .withDetails(EasyMap.mapOf("some-key", "some-value")); when(allMothers.findByCaseId("entity id 1")).thenReturn(mother); FormSubmission submission = create() .withFormName("pnc_visit") .addFormField("pncVisitDate", "2013-01-01") .addFormField("pncVisitPerson", "ASHA") .addFormField("pncVisitPlace", "phc") .addFormField("difficulties1", "difficulties 1") .addFormField("abdominalProblems", "abdominal Problems") .addFormField("vaginalProblems", "vaginal Problems") .addFormField("difficulties2", "difficulties 2") .addFormField("breastProblems", "breast Problems") .withSubForm( new SubFormData( "child_pnc_visit", asList( EasyMap.create("id", "child id 1") .put("urineStoolProblems", "vomiting diarrhea") .put("activityProblems", "convulsions") .put("breathingProblems", "breathing_too_fast") .put("skinProblems", "jaundice") .map()))) .build(); service.pncVisitHappened(submission); Mother updatedMother = new Mother("mother id 1", "ec id 1", "TC1") .withDetails( EasyMap.create("some-key", "some-value").put("pncVisitDates", "2013-01-01").map()) .withPNCVisits( asList( new PNCVisit() .withDate("2013-01-01") .withPerson("ASHA") .withPlace("phc") .withDifficulties("difficulties 1") .withAbdominalProblems("abdominal Problems") .withVaginalProblems("vaginal Problems") .withUrinalProblems("difficulties 2") .withBreastProblems("breast Problems") .withChildrenDetails( asList( EasyMap.create("id", "child id 1") .put("urineStoolProblems", "vomiting diarrhea") .put("activityProblems", "convulsions") .put("breathingProblems", "breathing_too_fast") .put("skinProblems", "jaundice") .map())))); verify(allMothers).update(updatedMother); }
@Test public void shouldUpdateMotherWithChildrenDetailsWhenPNCRegistrationOA() { when(allMothers.findByEcCaseId("ec id 1")) .thenReturn(asList(new Mother("mother id 1", "ec id 1", "tc 1"))); when(allEligibleCouples.findByCaseId("ec id 1")) .thenReturn(new EligibleCouple("ec id 1", "123")); FormSubmission submission = create() .withFormName("pnc_registration_oa") .withANMId("anm id 1") .withEntityId("ec id 1") .addFormField("referenceDate", "2012-01-01") .addFormField("didWomanSurvive", "yes") .withSubForm( new SubFormData( "child_registration_oa", asList( EasyMap.create("id", "child id 1") .put("gender", "male") .put("weight", "2") .map(), EasyMap.create("id", "child id 2") .put("gender", "female") .put("weight", "3") .map()))) .build(); service.pncRegistrationOA(submission); verify(allMothers) .update( new Mother("mother id 1", "ec id 1", "tc 1") .withAnm("anm id 1") .withChildrenDetails( asList( EasyMap.create("id", "child id 1") .put("gender", "male") .put("weight", "2") .put("immunizationsAtBirth", null) .map(), EasyMap.create("id", "child id 2") .put("gender", "female") .put("weight", "3") .put("immunizationsAtBirth", null) .map()))); }
@Test public void shouldUpdateMotherWithNewFamilyPlanningCondomWhenPPFPIsSubmitted() throws Exception { FormSubmission submission = create() .withFormName("postpartum_family_planning") .withEntityId("mother id 1") .addFormField("some-key", "value") .addFormField("currentMethod", "condom") .addFormField("familyPlanningMethodChangeDate", "2010-01-01") .addFormField("numberOfCondomsSupplied", "20") .build(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi card number 1"); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(new ArrayList<CondomFPDetails>()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()); when(allMothers.findByCaseId("mother id 1")).thenReturn(mother); when(allEligibleCouples.findByCaseId("ec id 1")).thenReturn(eligibleCouple); service.reportPPFamilyPlanning(submission); List<CondomFPDetails> condomFPDetails = new ArrayList<>(); condomFPDetails.add( new CondomFPDetails( "2010-01-01", asList(EasyMap.create("date", "2010-01-01").put("quantity", "20").map()))); EligibleCouple expectedEC = new EligibleCouple("ec id 1", "ec number 1") .withIUDFPDetails(Collections.<IUDFPDetails>emptyList()) .withCondomFPDetails(Collections.<CondomFPDetails>emptyList()) .withOCPFPDetails(Collections.<OCPFPDetails>emptyList()) .withMaleSterilizationFPDetails(Collections.<MaleSterilizationFPDetails>emptyList()) .withFemaleSterilizationFPDetails(Collections.<FemaleSterilizationFPDetails>emptyList()) .withCondomFPDetails(condomFPDetails); verify(allEligibleCouples).update(expectedEC); }
@Test public void shouldNotAddChildrenDetailsInTheCaseOfStillBirthDuringDeliveryOutcome() throws Exception { when(allMothers.findByCaseId("mother id 1")) .thenReturn(new Mother("mother id 1", "ec id 1", "tc 1")); FormSubmission submission = create() .withFormName("delivery_outcome") .withANMId("anm id 1") .withEntityId("mother id 1") .addFormField("referenceDate", "2012-01-01") .addFormField("deliveryOutcome", "still_birth") .addFormField("didWomanSurvive", "yes") .withSubForm( new SubFormData( "child_registration", asList(EasyMap.create("id", "child id 1").map()))) .build(); service.deliveryOutcome(submission); verify(allMothers).update(new Mother("mother id 1", "ec id 1", "tc 1")); }