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"));
}
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"));
}
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"));
}
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()));
}
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());
}
Aggregations