Search in sources :

Example 1 with ProgramWorkflowService

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());
        }
    }
}
Also used : ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) PatientProgram(org.openmrs.PatientProgram)

Example 2 with ProgramWorkflowService

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());
}
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 3 with ProgramWorkflowService

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"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with ProgramWorkflowService

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"));
}
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 5 with ProgramWorkflowService

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);
    }
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) ConceptService(org.openmrs.api.ConceptService) HashSet(java.util.HashSet)

Aggregations

ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)7 PatientProgram (org.openmrs.PatientProgram)6 Patient (org.openmrs.Patient)5 Test (org.junit.Test)4 ProgramWorkflow (org.openmrs.ProgramWorkflow)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 BindException (org.springframework.validation.BindException)4 Date (java.util.Date)3 PatientState (org.openmrs.PatientState)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PatientIdentifier (org.openmrs.PatientIdentifier)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Program (org.openmrs.Program)1 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)1 ConceptService (org.openmrs.api.ConceptService)1 PatientService (org.openmrs.api.PatientService)1