use of org.openmrs.api.ProgramWorkflowService in project openmrs-core by openmrs.
the class PatientServiceImpl method mergeProgramEnrolments.
private void mergeProgramEnrolments(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
// copy all program enrollments
ProgramWorkflowService programService = Context.getProgramWorkflowService();
for (PatientProgram pp : programService.getPatientPrograms(notPreferred, null, null, null, null, null, false)) {
if (!pp.getVoided()) {
PatientProgram enroll = pp.copy();
enroll.setPatient(preferred);
log.debug("Copying patientProgram " + pp.getPatientProgramId() + " to " + preferred.getPatientId());
PatientProgram persisted = programService.savePatientProgram(enroll);
mergedData.addCreatedProgram(persisted.getUuid());
}
}
}
use of org.openmrs.api.ProgramWorkflowService in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
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("voidReason");
BindException errors = new BindException(pp, "program");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(false, errors.hasErrors());
}
use of org.openmrs.api.ProgramWorkflowService 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"));
}
use of org.openmrs.api.ProgramWorkflowService 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.api.ProgramWorkflowService in project openmrs-core by openmrs.
the class WorkflowCollectionEditor method setAsText.
/**
* Takes a "program_id:list" where program_id is the id of the program that this collection is
* for (or not present, if it's a new program) and list is a space-separated list of concept
* ids. This class is a bit of a hack, because I don't know a better way to do this. -DJ The
* purpose is to retire and un-retire workflows where possible rather than deleting and creating
* them.
*
* @should update workflows in program
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasText(text)) {
ConceptService cs = Context.getConceptService();
ProgramWorkflowService pws = Context.getProgramWorkflowService();
try {
int ind = text.indexOf(":");
String progIdStr = text.substring(0, ind);
text = text.substring(ind + 1);
if (program == null) {
// if a program wasn't passed in, try to look it up now
program = pws.getProgram(Integer.valueOf(progIdStr));
}
} catch (Exception ex) {
}
String[] conceptIds = text.split(" ");
Set<ProgramWorkflow> oldSet = program == null ? new HashSet<>() : program.getAllWorkflows();
Set<Integer> newConceptIds = new HashSet<>();
for (String id : conceptIds) {
if (id.trim().length() == 0) {
continue;
}
log.debug("trying " + id);
newConceptIds.add(Integer.valueOf(id.trim()));
}
// go through oldSet and see what we need to keep and what we need to unvoid
Set<Integer> alreadyDone = new HashSet<>();
for (ProgramWorkflow pw : oldSet) {
if (!newConceptIds.contains(pw.getConcept().getConceptId())) {
pw.setRetired(true);
} else if (newConceptIds.contains(pw.getConcept().getConceptId()) && pw.getRetired()) {
pw.setRetired(false);
}
alreadyDone.add(pw.getConcept().getConceptId());
}
// now add any new ones
newConceptIds.removeAll(alreadyDone);
for (Integer conceptId : newConceptIds) {
ProgramWorkflow pw = new ProgramWorkflow();
pw.setProgram(program);
pw.setConcept(cs.getConcept(conceptId));
oldSet.add(pw);
}
setValue(oldSet);
} else {
setValue(null);
}
}
Aggregations