/** * @see ProgramWorkflowService#getPatientProgramByUuid(String) */ @Test public void getPatientProgramByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getProgramWorkflowService().getPatientProgramByUuid("some invalid uuid")); }
/** * @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()); }
@Override public PatientProgram getByUniqueId(String uniqueId) { return Context.getProgramWorkflowService().getPatientProgramByUuid(uniqueId); }
@Override public PatientProgram newObject() { return Context.getProgramWorkflowService().getPatientProgramByUuid(getUuidProperty()); }
@Test public void shouldUpdateTheDatesOfAProgramEnrollment() throws Exception { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleObject params = new SimpleObject(); String date = dateFormat.format(new Date()); params.add("dateEnrolled", date); MockHttpServletRequest req = newPostRequest(getURI() + "/" + getUuid(), params); SimpleObject result = deserialize(handle(req)); PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(dateFormat.format(patientProgram.getDateEnrolled()), date); }
@Test public void shouldPurgeAPatientProgram() throws Exception { Assert.assertNotNull(service.getPatientProgramByUuid(getUuid())); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("purge", "true"))); Assert.assertNull(service.getPatientProgramByUuid(getUuid())); }
@Test public void shouldUpdateExistingState() throws Exception { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String existingStartDate = "2008-08-08"; String stateStartDate = "2015-08-04"; PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Set<PatientState> existingStates = patientProgram.getStates(); Assert.assertEquals(1, existingStates.size()); PatientState existingPatientState = existingStates.iterator().next(); Assert.assertEquals(existingStartDate, dateFormat.format(existingPatientState.getStartDate())); String json = "{ \"states\": [{ \"uuid\": \"" + existingPatientState.getUuid() + "\", \"startDate\": \"" + stateStartDate + "\"}]}"; MockHttpServletRequest req = newPostRequest(getURI() + "/" + getUuid(), SimpleObject.parseJson(json)); SimpleObject result = deserialize(handle(req)); patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); Set<PatientState> actualPatientStates = patientProgram.getStates(); Assert.assertEquals(1, actualPatientStates.size()); Assert.assertEquals(stateStartDate, dateFormat.format(actualPatientStates.iterator().next().getStartDate())); }
@Test public void shouldGetAPatientProgramByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(patientProgram.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(patientProgram.getPatient().getUuid(), ((Map) PropertyUtils.getProperty(result, "patient")).get("uuid")); Assert.assertEquals(patientProgram.getProgram().getUuid(), ((Map) PropertyUtils.getProperty(result, "program")).get("uuid")); }
@SuppressWarnings("deprecation") @Override public void testResults(SubmissionResults results) { // do all the basic assertions to make sure the program was processed correctly results.assertNoErrors(); results.assertEncounterCreated(); results.assertProvider(502); results.assertLocation(2); // confirm that that patient is no longer in the program Patient patient = Context.getPatientService().getPatient(2); Program program = Context.getProgramWorkflowService().getProgram(1); Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null)); // but confirm that the patient was in the program in the past Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date())); // confirm that the proper program has been closed PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("32296060-03aa-102d-b0e3-001ec94a0cc5"); Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted())); };
@SuppressWarnings("deprecation") @Override public void testResults(SubmissionResults results) { // do all the basic assertions to make sure the program was processed correctly results.assertNoErrors(); results.assertEncounterCreated(); results.assertProvider(502); results.assertLocation(2); // confirm that that patient is no longer in the program Patient patient = Context.getPatientService().getPatient(2); Program program = Context.getProgramWorkflowService().getProgram(1); Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null)); // but confirm that the patient was in the program in the past Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date())); // confirm that the proper program has been closed PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("32296060-03aa-102d-b0e3-001ec94a0cc5"); Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted())); };
@Test public void shouldTransitPatientState() throws Exception { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String stateStartDate = "2015-08-04"; String json = "{ \"states\": [{ \"state\": {\"uuid\" : \"" + RestTestConstants1_8.STATE_UUID + "\"}, \"startDate\": \"" + stateStartDate + "\"}]}"; PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertEquals(1, patientProgram.getStates().size()); MockHttpServletRequest req = newPostRequest(getURI() + "/" + getUuid(), SimpleObject.parseJson(json)); SimpleObject result = deserialize(handle(req)); patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); List<PatientState> states = new ArrayList<PatientState>(patientProgram.getStates()); Assert.assertEquals(2, states.size()); sortPatientStatesBasedOnStartDate(states); Assert.assertEquals(RestTestConstants1_8.STATE_UUID, states.get(1).getState().getUuid()); String existingStateEndDate = dateFormat.format(states.get(0).getEndDate()); Assert.assertEquals(stateStartDate, existingStateEndDate); }
@SuppressWarnings("deprecation") @Override public void testEditedResults(SubmissionResults results) { // do all the basic assertions to make sure the program was processed correctly results.assertNoErrors(); results.assertEncounterCreated(); results.assertProvider(502); results.assertLocation(2); // confirm that that patient is no longer in the program Patient patient = Context.getPatientService().getPatient(2); Program program = Context.getProgramWorkflowService().getProgram(1); Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null)); // but confirm that the patient was in the program in the past Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date())); // confirm that the proper program has been closed PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("32296060-03aa-102d-b0e3-001ec94a0cc5"); Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted())); };
@SuppressWarnings("deprecation") @Override public void testResults(SubmissionResults results) { // do all the basic assertions to make sure the program was processed correctly results.assertNoErrors(); results.assertEncounterCreated(); results.assertProvider(502); results.assertLocation(2); // confirm that that patient is no longer in the program Patient patient = Context.getPatientService().getPatient(8); Program program = Context.getProgramWorkflowService().getProgram(10); Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null)); // but confirm that the patient was in the program in the past Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date())); // confirm that the proper program has been closed PatientProgram pp = Context.getProgramWorkflowService().getPatientProgramByUuid("31396060-03aa-102d-b0e3-001ec94a0cc5"); Assert.assertTrue("Program completion date should be current date", TestUtil.dateEquals(new Date(), pp.getDateCompleted())); // Confirm that the patient program has the right outcome Assert.assertEquals("Program should have recorded outcome", Context.getConceptService().getConcept(4202), pp.getOutcome()); };
@Test public void shouldVoidAPatientProgram() throws Exception { PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertTrue(!patientProgram.isVoided()); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("!purge", "random reason"))); patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertTrue(patientProgram.isVoided()); }
@Test public void shouldUnenrollAPatientFromAProgram() throws Exception { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleObject params = new SimpleObject(); String dateString = dateFormat.format(new Date()); params.add("dateCompleted", dateString); MockHttpServletRequest req = newPostRequest(getURI() + "/" + getUuid(), params); SimpleObject result = deserialize(handle(req)); PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(dateFormat.format(patientProgram.getDateCompleted()), dateString); params.add("dateEnrolled", dateString); MockHttpServletRequest req1 = newPostRequest(getURI() + "/" + getUuid(), params); SimpleObject result1 = deserialize(handle(req)); PatientProgram patientProgram1 = service.getPatientProgramByUuid(getUuid()); Assert.assertNotEquals(dateFormat.format(patientProgram.getDateEnrolled()), dateString); }
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); PatientProgram patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertEquals(1, patientProgram.getStates().size()); SimpleObject result = deserialize(handle(req)); patientProgram = service.getPatientProgramByUuid(getUuid()); Assert.assertNotNull(result); List<PatientState> states = new ArrayList<PatientState>(patientProgram.getStates()); handle(req); patientProgram = service.getPatientProgramByUuid(getUuid());