/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAnyPatientStateHasAnEndDateBeforeItsStartDate() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); Calendar c = Calendar.getInstance(); patientState.setStartDate(c.getTime()); c.set(1970, 2, 1);//set to an old date patientState.setEndDate(c.getTime()); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
@Test public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() { Program program = Context.getProgramWorkflowService().getProgram(2); // program has at least one patient enrolled List<PatientProgram> patientPrograms = Context.getProgramWorkflowService().getPatientPrograms(null, program, null, null, null, null, true); assertTrue(patientPrograms.size() > 0); Context.getProgramWorkflowService().purgeProgram(program); // should cascade to patient programs for (PatientProgram patientProgram : patientPrograms) { assertNull(Context.getProgramWorkflowService().getPatientProgram(patientProgram.getId())); } // make sure that the program was deleted properly assertNull(Context.getProgramWorkflowService().getProgram(2)); } @Test
@Override public void testResults(SubmissionResults results) { results.assertNoErrors(); results.assertEncounterCreated(); List<PatientProgram> pps = pws.getPatientPrograms(ps.getPatient(patientId), pws.getProgram(programId), null, null, null, null, false); Assert.assertEquals(1, pps.size()); //the user selected date should have been ignored Assert.assertEquals(ymdToDate(dateAsString(initialEnrollmentDate)), ymdToDate(dateAsString(pps.get(0) .getDateEnrolled()))); //The patient is still enrolled in the same program Assert.assertEquals(1, pws.getPatientPrograms(patient, pws.getProgram(programId), null, null, null, null, false).size()); //the state id in the form should have been ignored Assert.assertEquals(originalState, pws.getPatientProgram(patientProgramId).getCurrentState(wf).getState()); };
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldPassForAValidProgram() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); patientState.getPatientProgram().transitionToState(patientState.getState().getProgramWorkflow().getState(4), new Date()); ValidateUtil.validate(program); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfPatientProgramEnrolledDateIsInFuture() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); Date date10DaysAfterSystemCurrentDate = new Date(System.currentTimeMillis() + 10 * 24 * 60 * 60 * 1000); program.setDateEnrolled(date10DaysAfterSystemCurrentDate); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("dateEnrolled")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfPatientProgramEndDateIsInFuture() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); Date date10DaysAfterSystemCurrentDate = new Date(System.currentTimeMillis() + 10 * 24 * 60 * 60 * 1000); program.setDateCompleted(date10DaysAfterSystemCurrentDate); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("dateCompleted")); }
/** * @throws InterruptedException * @see ProgramWorkflowService#triggerStateConversion(Patient,Concept,Date) */ @Test public void triggerStateConversion_shouldSkipPastPatientProgramsThatAreAlreadyCompleted() throws InterruptedException { Integer patientProgramId = 1; PatientProgram pp = pws.getPatientProgram(patientProgramId); Date originalDateCompleted = new Date(); pp.setDateCompleted(originalDateCompleted); pp = pws.savePatientProgram(pp); Concept diedConcept = cs.getConcept(16); //sanity check to ensure the patient died is a possible state in one of the work flows Assert.assertNotNull(pp.getProgram().getWorkflow(1).getState(diedConcept)); Thread.sleep(10);//delay so that we have a time difference pp = pws.getPatientProgram(patientProgramId); Assert.assertEquals(originalDateCompleted, pp.getDateCompleted()); }
/** * @throws ParseException * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfPatientProgramEndDateComesBeforeItsEnrolledDate() throws ParseException { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date dateEnrolled = sdf.parse("12/04/2014"); Date dateCompleted = sdf.parse("21/03/2014"); program.setDateEnrolled(dateEnrolled); program.setDateCompleted(dateCompleted); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("dateCompleted")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAnyPatientStateHasANullWorkFlowState() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); patientState.setState(null); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfThereIsMoreThanOnePatientStateWithTheSameStatesAndStartDates() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); Set<PatientState> states = program.getStates(); Assert.assertNotNull(states); PatientState patientState = states.iterator().next(); PatientState duplicate = patientState.copy(); states.add(duplicate); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfTheStartDateOfTheFirstPatientStateInTheWorkFlowIsNull() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); Assert.assertEquals(1, program.getStates().size());//sanity check PatientState patientState = program.getStates().iterator().next(); patientState.setStartDate(null); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertEquals(false, errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAPatientProgramHasDuplicateStatesInTheSameWorkFlow() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); Set<PatientState> states = program.getStates(); Assert.assertNotNull(states); PatientState patientState = states.iterator().next(); PatientState duplicate = patientState.copy(); states.add(duplicate); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfAPatientIsInMultipleStatesInDifferentWorkFlows() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); //Add another state to another work flow PatientState patientState2 = new PatientState(); patientState2.setStartDate(new Date()); patientState2.setState(Context.getProgramWorkflowService().getWorkflowByUuid("c66c8713-7df4-40de-96f6-dc4cce3432da") .getState(5)); program.getStates().add(patientState2); ValidateUtil.validate(program); }
/** * @throws InterruptedException * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAnyPatientStatesOverlapEachOtherInTheSameWorkFlow() throws InterruptedException { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); //Addition of new states to this program in the test data can make this test useless, so catch it her Assert.assertEquals(1, program.getStates().size()); PatientState patientState1 = program.getStates().iterator().next(); //Add a state that comes after patientState1 PatientState patientState2 = new PatientState(); patientState2.setStartDate(new Date()); patientState2.setState(Context.getProgramWorkflowService().getWorkflowByUuid("84f0effa-dd73-46cb-b931-7cd6be6c5f81") .getState(1)); //guarantees that startDate of patientState2 is atleast 10ms earlier Thread.sleep(10); patientState1.setEndDate(new Date()); program.getStates().add(patientState2); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertEquals(true, errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAPatientIsInMultipleStatesInTheSameWorkFlow() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); patientState.getPatientProgram().transitionToState(patientState.getState().getProgramWorkflow().getState(4), new Date()); //make the closed state active patientState.setEndDate(null); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfAPatientStateHasAnInvalidWorkFlowState() { executeDataSet("org/openmrs/api/include/ProgramWorkflowServiceTest-otherProgramWorkflows.xml"); PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); patientState.setState(Context.getProgramWorkflowService().getStateByUuid("31c82d66-245c-11e1-9cf0-00248140a5eb")); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("states")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfPatientProgramEnrollDateIsEmpty() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); program.setDateEnrolled(null); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertTrue(errors.hasFieldErrors("dateEnrolled")); }
/** * @see PatientProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldPassForPatientStatesThatHaveTheSameStartDatesInTheSameWorkFlow() { PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1); PatientState patientState = program.getStates().iterator().next(); //add a new state by moving the patient to a another one ProgramWorkflowState nextState = patientState.getState().getProgramWorkflow().getState(4); patientState.getPatientProgram().transitionToState(nextState, patientState.getStartDate()); BindException errors = new BindException(program, ""); new PatientProgramValidator().validate(program, errors); Assert.assertEquals(false, errors.hasFieldErrors("states")); }
PatientProgram patientProgram = pws.getPatientProgram(1); Date dateCompleted = patientProgram.getDateCompleted(); Date dateChanged = patientProgram.getDateChanged(); PatientProgram ptProg = pws.getPatientProgram(1); Date dateCompleted2 = patientProgram.getDateCompleted(); Date dateChanged2 = patientProgram.getDateChanged();
@Test @Verifies(value = "should return null if program enrollment date same as specified date", method = "getClosestFutureProgramEnrollment(Patient,Program,Date)") public void getClosestFutureProgramEnrollment_shouldReturnNullIfProgramEnrollmentSameAsSpecifiedDate() throws Exception { ProgramWorkflowService pws = Context.getProgramWorkflowService(); Patient patient = Context.getPatientService().getPatient(2); Program program = pws.getProgram(1); Date date = pws.getPatientProgram(1).getDateEnrolled(); Assert.assertNull(HtmlFormEntryUtil.getClosestFutureProgramEnrollment(patient, program, date)); }