use of org.openmrs.ProgramWorkflowState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceImpl method unretireProgram.
/**
* @see org.openmrs.api.ProgramWorkflowService#retireProgram(org.openmrs.Program)
*/
@Override
public Program unretireProgram(Program program) throws APIException {
Date lastModifiedDate = program.getDateChanged();
program.setRetired(false);
for (ProgramWorkflow workflow : program.getAllWorkflows()) {
if (lastModifiedDate != null && lastModifiedDate.equals(workflow.getDateChanged())) {
workflow.setRetired(false);
for (ProgramWorkflowState state : workflow.getStates()) {
if (lastModifiedDate.equals(state.getDateChanged())) {
state.setRetired(false);
}
}
}
}
return saveProgram(program);
}
use of org.openmrs.ProgramWorkflowState 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.ProgramWorkflowState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getStateByUuid_shouldFindObjectGivenValidUuid.
/**
* @see ProgramWorkflowService#getStateByUuid(String)
*/
@Test
public void getStateByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "92584cdc-6a20-4c84-a659-e035e45d36b0";
ProgramWorkflowState state = Context.getProgramWorkflowService().getStateByUuid(uuid);
Assert.assertEquals(1, (int) state.getProgramWorkflowStateId());
}
use of org.openmrs.ProgramWorkflowState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method retireProgram_shouldSaveTheRetiredProgramWithReason.
@Test
public void retireProgram_shouldSaveTheRetiredProgramWithReason() throws APIException {
String reason = "Feeling well.";
String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0";
Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid);
Program retireProgram = pws.retireProgram(program, reason);
assertTrue(retireProgram.getRetired());
assertEquals(reason, retireProgram.getRetireReason());
for (ProgramWorkflow programWorkflow : program.getAllWorkflows()) {
assertTrue(programWorkflow.getRetired());
for (ProgramWorkflowState programWorkflowState : programWorkflow.getStates()) {
assertTrue(programWorkflowState.getRetired());
}
}
}
use of org.openmrs.ProgramWorkflowState in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getSortedStates_shouldSortNamesContainingNumbersIntelligently.
/**
* THIS TEST SHOULD BE IN THE CLASS 'PROGRAMWORKFLOWTEST.JAVA' BUT IT REQUIRES ACCESS TO THE DAO
* LAYER
*
* @see ProgramWorkflow#getSortedStates()
*/
@Test
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {
ProgramWorkflow program = new ProgramWorkflow();
ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
Concept state1Concept = new Concept();
state1Concept.addName(state1ConceptName);
ProgramWorkflowState state1 = new ProgramWorkflowState();
state1.setConcept(state1Concept);
program.addState(state1);
ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
Concept state2Concept = new Concept();
state2Concept.addName(state2ConceptName);
ProgramWorkflowState state2 = new ProgramWorkflowState();
state2.setConcept(state2Concept);
program.addState(state2);
Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
int x = 1;
for (ProgramWorkflowState state : sortedStates) {
if (x == 1) {
Assert.assertEquals("Group 2", state.getConcept().getName(Context.getLocale()).getName());
} else if (x == 2) {
Assert.assertEquals("Group 10", state.getConcept().getName(Context.getLocale()).getName());
} else {
Assert.fail("Wha?!");
}
x++;
}
}
Aggregations