use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceUnitTest method purgePatientProgram_shouldFailGivenNonEmptyStatesAndTrueCascade.
@Test
public void purgePatientProgram_shouldFailGivenNonEmptyStatesAndTrueCascade() {
exception.expect(APIException.class);
exception.expectMessage("Cascade purging of PatientPrograms is not implemented yet");
PatientProgram patientProgram = new PatientProgram();
PatientState patientState = new PatientState();
patientProgram.getStates().add(patientState);
pws.purgePatientProgram(patientProgram, true);
}
use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceImpl method triggerStateConversion.
/**
* @see org.openmrs.api.ProgramWorkflowService#triggerStateConversion(org.openmrs.Patient,
* org.openmrs.Concept, java.util.Date)
*/
public void triggerStateConversion(Patient patient, Concept trigger, Date dateConverted) {
// Check input parameters
if (patient == null) {
throw new APIException("convert.state.invalid.patient", (Object[]) null);
}
if (trigger == null) {
throw new APIException("convert.state.patient.without.valid.trigger", (Object[]) null);
}
if (dateConverted == null) {
throw new APIException("convert.state.invalid.date", (Object[]) null);
}
for (PatientProgram patientProgram : getPatientPrograms(patient, null, null, null, null, null, false)) {
// skip past patient programs that already completed
if (patientProgram.getDateCompleted() == null) {
Set<ProgramWorkflow> workflows = patientProgram.getProgram().getWorkflows();
for (ProgramWorkflow workflow : workflows) {
// (getWorkflows() is only returning over nonretired workflows)
PatientState patientState = patientProgram.getCurrentState(workflow);
// #1080 cannot exit patient from care
// Should allow a transition from a null state to a terminal state
// Or we should require a user to ALWAYS add an initial workflow/state when a patient is added to a program
ProgramWorkflowState currentState = (patientState != null) ? patientState.getState() : null;
ProgramWorkflowState transitionState = workflow.getState(trigger);
log.debug("Transitioning from current state [" + currentState + "]");
log.debug("|---> Transitioning to final state [" + transitionState + "]");
if (transitionState != null && workflow.isLegalTransition(currentState, transitionState)) {
patientProgram.transitionToState(transitionState, dateConverted);
log.debug("State Conversion Triggered: patientProgram=" + patientProgram + " transition from " + currentState + " to " + transitionState + " on " + dateConverted);
}
}
// #1068 - Exiting a patient from care causes "not-null property references
// a null or transient value: org.openmrs.PatientState.dateCreated". Explicitly
// calling the savePatientProgram() method will populate the metadata properties.
//
// #1067 - We should explicitly save the patient program rather than let
// Hibernate do so when it flushes the session.
Context.getProgramWorkflowService().savePatientProgram(patientProgram);
}
}
}
use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldFailIfThereIsMoreThanOnePatientStateWithTheSameStatesAndStartDates.
/**
* @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"));
}
use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldFailIfAPatientProgramHasDuplicateStatesInTheSameWorkFlow.
/**
* @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"));
}
use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldNotFailIfPatientStateIsInRetiredWorkflow.
/**
* @see PatientProgramValidator#validate(Object,Errors)
* this test is to specifically validate fix for https://tickets.openmrs.org/browse/TRUNK-3670
*/
@Test
public void validate_shouldNotFailIfPatientStateIsInRetiredWorkflow() {
ProgramWorkflowService pws = Context.getProgramWorkflowService();
Patient patient = Context.getPatientService().getPatient(6);
// create a patient program
PatientProgram pp = new PatientProgram();
pp.setPatient(patient);
pp.setProgram(pws.getProgram(1));
// add a test workflow, and put the patient in a state in that workflow
ProgramWorkflow testWorkflow = pp.getProgram().getWorkflow(1);
PatientState newPatientState = new PatientState();
newPatientState.setState(testWorkflow.getState(1));
pp.getStates().add(newPatientState);
// now retire the workflow
testWorkflow.setRetired(true);
testWorkflow.setRetiredBy(Context.getAuthenticatedUser());
testWorkflow.setRetireReason("test");
BindException errors = new BindException(pp, "");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(false, errors.hasFieldErrors("states"));
}
Aggregations