use of org.openmrs.PatientProgram in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method triggerStateConversion_shouldSkipPastPatientProgramsThatAreAlreadyCompleted.
/**
* @throws InterruptedException
* @see ProgramWorkflowService#triggerStateConversion(Patient,Concept,Date)
*/
@Test
public void triggerStateConversion_shouldSkipPastPatientProgramsThatAreAlreadyCompleted() throws InterruptedException {
Integer patientProgramId = 1;
PatientProgram pp = pws.getPatientProgram(patientProgramId);
Date originalDateCompleted = new Date();
pp.setDateCompleted(originalDateCompleted);
pp = pws.savePatientProgram(pp);
Concept diedConcept = cs.getConcept(16);
// sanity check to ensure the patient died is a possible state in one of the work flows
Assert.assertNotNull(pp.getProgram().getWorkflow(1).getState(diedConcept));
// delay so that we have a time difference
Thread.sleep(10);
pp = pws.getPatientProgram(patientProgramId);
Assert.assertEquals(originalDateCompleted, pp.getDateCompleted());
}
use of org.openmrs.PatientProgram in project openmrs-module-pihcore by PIH.
the class ProgramDashboardPageController method controller.
public Redirect controller(@RequestParam(value = "patientId") Patient patient) {
String providerName = "coreapps";
String pageName = "clinicianfacing/patient";
String queryString = "patientId=" + patient.getUuid();
List<PatientProgram> activeEnrollments = new ArrayList<>();
ProgramWorkflowService pws = Context.getProgramWorkflowService();
for (PatientProgram pp : pws.getPatientPrograms(patient, null, null, null, null, null, false)) {
if (pp.getActive()) {
activeEnrollments.add(pp);
}
}
if (activeEnrollments.size() == 1) {
// TODO: Once we have legitimate dashboards for all programs, remove this constraint on HIV program?
String programUuid = activeEnrollments.get(0).getProgram().getUuid();
if (programUuid.equals(PihEmrConfigConstants.PROGRAM_HIV_UUID)) {
queryString += "&dashboard=" + programUuid;
}
}
return new Redirect(providerName, pageName, queryString);
}
use of org.openmrs.PatientProgram in project openmrs-module-coreapps by openmrs.
the class ProgramHistoryFragmentController method controller.
public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("programWorkflowService") ProgramWorkflowService programWorkflowService) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object patient = null;
patient = config.get("patient");
if (patient == null) {
patient = config.get("patientId");
}
if (patient == null) {
config.require("patient");
}
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else if (patient instanceof Integer) {
// assume we have patientId
patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
ObjectNode appConfig = app.getConfig();
appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
if (appConfig.get("program") == null || StringUtils.isEmpty(appConfig.get("program").getTextValue())) {
throw new MissingPropertyException("Program must be specified");
}
Program program = programWorkflowService.getProgramByUuid(appConfig.get("program").getTextValue());
if (program == null) {
throw new MissingPropertyException("Invalid program");
}
List<PatientProgram> patientPrograms = programWorkflowService.getPatientPrograms(patientWrapper.getPatient(), program, null, null, null, null, false);
// TODO: assumption here is that "getPatientPrograms" returns results in chronological order--need to confirm?
Collections.reverse(patientPrograms);
List<String> programJson = new ArrayList<String>();
Boolean includeActive = appConfig.get("includeActive") != null ? appConfig.get("includeActive").getBooleanValue() : true;
Boolean includeInactive = appConfig.get("includeInactive") != null ? appConfig.get("includeInactive").getBooleanValue() : true;
for (PatientProgram patientProgram : patientPrograms) {
if ((patientProgram.getDateCompleted() == null && includeActive) || (patientProgram.getDateCompleted() != null && includeInactive)) {
appConfig.put("patientProgram", patientProgram.getUuid());
programJson.add(appConfig.toString().replace('\"', '\''));
}
}
Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
config.merge(appConfigMap);
config.addAttribute("programJson", programJson);
}
use of org.openmrs.PatientProgram in project openmrs-core by openmrs.
the class OpenmrsServiceTest method shouldCheckThatAMethodIsNotRolledBackInCaseOfAnErrorInAnotherInvokedInsideIt.
/**
* Tests that if two service methods are called (one from inside the other) the first one will
* be rolled back if an exception is thrown inside the second one. <pre>
* We are testing with the merge patient method since it is transactional and calls multiple other
* transactional methods
* </pre>
*
* @throws SerializationException
*/
@Test
@Ignore
public void shouldCheckThatAMethodIsNotRolledBackInCaseOfAnErrorInAnotherInvokedInsideIt() throws SerializationException {
// TODO FIx why this test fails when run with other tests
PatientService patientService = Context.getPatientService();
EncounterService encounterService = Context.getEncounterService();
ProgramWorkflowService programService = Context.getProgramWorkflowService();
Patient prefPatient = patientService.getPatient(6);
Patient notPrefPatient = patientService.getPatient(7);
Collection<Program> programs = programService.getAllPrograms(false);
int originalPrefEncounterCount = encounterService.getEncountersByPatient(prefPatient).size();
int originalNotPrefEncounterCount = encounterService.getEncountersByPatient(notPrefPatient).size();
Assert.assertTrue(originalNotPrefEncounterCount > 0);
Cohort notPreferredCohort = new Cohort(notPrefPatient.getPatientId().toString());
List<PatientProgram> notPrefPrograms = programService.getPatientPrograms(notPreferredCohort, programs);
Assert.assertTrue(notPrefPrograms.size() > 0);
// Set the program to null so that the patient program is rejected on validation with
// an APIException, since it is a RuntimeException, all transactions should be rolled back
notPrefPrograms.get(0).setProgram(null);
boolean failed = false;
try {
patientService.mergePatients(prefPatient, notPrefPatient);
} catch (APIException e) {
// should have failed to force a rollback
failed = true;
}
Assert.assertTrue(failed);
// Since the encounters are moved first, that logic should have been rolled back
Assert.assertEquals(originalPrefEncounterCount, encounterService.getEncountersByPatient(prefPatient).size());
}
use of org.openmrs.PatientProgram in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getPatientProgramByUuid_shouldFindObjectGivenValidUuid.
/**
* @see ProgramWorkflowService#getPatientProgramByUuid(String)
*/
@Test
public void getPatientProgramByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "2edf272c-bf05-4208-9f93-2fa213ed0415";
PatientProgram patientProgram = Context.getProgramWorkflowService().getPatientProgramByUuid(uuid);
Assert.assertEquals(2, (int) patientProgram.getPatientProgramId());
}
Aggregations