Search in sources :

Example 11 with PatientProgram

use of org.openmrs.PatientProgram in project openmrs-core by openmrs.

the class PatientProgramValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(6);
    PatientProgram pp = new PatientProgram();
    pp.setPatient(patient);
    pp.setProgram(pws.getProgram(1));
    pp.setDateEnrolled(new Date());
    pp.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    BindException errors = new BindException(pp, "program");
    new PatientProgramValidator().validate(pp, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("voidReason"));
}
Also used : ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with PatientProgram

use of org.openmrs.PatientProgram in project openmrs-core by openmrs.

the class PatientProgramValidatorTest method validate_shouldPassIfTheStartDateOfTheFirstPatientStateInTheWorkFlowIsNull.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfTheStartDateOfTheFirstPatientStateInTheWorkFlowIsNull() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    // sanity check
    Assert.assertEquals(1, program.getStates().size());
    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"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with PatientProgram

use of org.openmrs.PatientProgram in project openmrs-core by openmrs.

the class PatientProgramValidatorTest method validate_shouldFailIfThePatientFieldIsBlank.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfThePatientFieldIsBlank() {
    PatientProgram program = new PatientProgram();
    BindException errors = new BindException(program, "program");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("patient"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with PatientProgram

use of org.openmrs.PatientProgram in project openmrs-core by openmrs.

the class PatientServiceTest method mergePatients_shouldAuditCreatedPatientPrograms.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldAuditCreatedPatientPrograms() throws Exception {
    // retrieve preferred  and notPreferredPatient patient
    Patient preferred = patientService.getPatient(999);
    Patient notPreferred = patientService.getPatient(2);
    voidOrders(Collections.singleton(notPreferred));
    // retrieve program for notProferred patient
    PatientProgram program = Context.getProgramWorkflowService().getPatientPrograms(notPreferred, null, null, null, null, null, false).get(0);
    // merge the two patients and retrieve the audit object
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    // find the UUID of the program to which the preferred patient was enrolled as a result of the merge
    String enrolledProgramUuid = null;
    List<PatientProgram> programs = Context.getProgramWorkflowService().getPatientPrograms(preferred, null, null, null, null, null, false);
    for (PatientProgram p : programs) {
        if (p.getDateCreated().equals(program.getDateCreated())) {
            enrolledProgramUuid = p.getUuid();
        }
    }
    Assert.assertNotNull("expected enrolled program was not found for the preferred patient after the merge", enrolledProgramUuid);
    Assert.assertTrue("program enrollment not audited", isValueInList(enrolledProgramUuid, audit.getPersonMergeLogData().getCreatedPrograms()));
}
Also used : Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientProgram(org.openmrs.PatientProgram) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 15 with PatientProgram

use of org.openmrs.PatientProgram in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method savePatientProgram_shouldUpdatePatientProgram.

/**
 * Tests fetching a PatientProgram, updating and saving it, and subsequently fetching the
 * updated value. To use in MySQL database: Uncomment method useInMemoryDatabase() and comment
 * out call to initializeInMemoryDatabase() and executeDataSet() within onSetupTransaction() .
 *
 * @see ProgramWorkflowService#savePatientProgram(PatientProgram)
 */
@Test
public void savePatientProgram_shouldUpdatePatientProgram() {
    Date today = new Date();
    PatientProgram patientProgram = pws.getPatientProgram(1);
    Date dateCompleted = patientProgram.getDateCompleted();
    Date dateChanged = patientProgram.getDateChanged();
    User changedBy = patientProgram.getChangedBy();
    if (null != dateCompleted) {
    // System.out.println("Date Completed: " + dateCompleted);
    }
    if (null != dateChanged) {
    // System.out.println("Date Changed: " + dateChanged);
    }
    if (null != changedBy) {
    // System.out.println("Changed By: " + changedBy.toString());
    }
    patientProgram.setDateCompleted(today);
    patientProgram.setChangedBy(Context.getAuthenticatedUser());
    patientProgram.setDateChanged(today);
    pws.savePatientProgram(patientProgram);
    // Uncomment to commit to database
    // setComplete( );
    PatientProgram ptProg = pws.getPatientProgram(1);
    Date dateCompleted2 = patientProgram.getDateCompleted();
    Date dateChanged2 = patientProgram.getDateChanged();
    User changedBy2 = patientProgram.getChangedBy();
    if (null != dateCompleted2) {
    // System.out.println("Date Completed: " + dateCompleted2);
    }
    if (null != dateChanged2) {
    // System.out.println("Date Changed: " + dateChanged2);
    }
    if (null != changedBy2) {
    // System.out.println("Changed By: " + changedBy2.toString());
    }
    assertNotNull(ptProg.getDateCompleted());
    assertEquals(today, ptProg.getDateCompleted());
}
Also used : User(org.openmrs.User) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PatientProgram (org.openmrs.PatientProgram)37 Test (org.junit.Test)30 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)27 BindException (org.springframework.validation.BindException)18 PatientState (org.openmrs.PatientState)17 Date (java.util.Date)14 Patient (org.openmrs.Patient)11 ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)7 Program (org.openmrs.Program)6 ProgramWorkflow (org.openmrs.ProgramWorkflow)5 ArrayList (java.util.ArrayList)3 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)3 MissingPropertyException (groovy.lang.MissingPropertyException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 DateTime (org.joda.time.DateTime)1