/** * @see VisitService#getAllVisits() */ @Test public void getAllVisits_shouldReturnAllUnvoidedVisits() { assertEquals(5, visitService.getAllVisits().size()); }
/** * @see VisitService#saveVisit(Visit) */ @Test public void saveVisit_shouldAddANewVisitToTheDatabase() { Integer originalSize = visitService.getAllVisits().size(); Visit visit = new Visit(new Patient(2), new VisitType(1), new Date()); visit = visitService.saveVisit(visit); assertNotNull(visit.getId()); assertNotNull(visit.getUuid()); assertNotNull(visit.getCreator()); assertNotNull(visit.getDateCreated()); assertEquals(originalSize + 1, visitService.getAllVisits().size()); }
public void saveVisit_shouldSaveNewVisitWithEncountersSuccessfully() { Integer originalSize = visitService.getAllVisits().size(); Visit visit = new Visit(new Patient(2), new VisitType(1), new Date()); assertNotNull(visit.getCreator()); assertNotNull(visit.getDateCreated()); assertEquals(originalSize + 1, visitService.getAllVisits().size()); assertEquals(1, visit.getEncounters().size()); assertEquals(Integer.valueOf(4), ((Encounter) visit.getEncounters().toArray()[0]).getEncounterId());
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getAllVisits().size(); }
/** * Get all the visits * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<Visit> doGetAll(RequestContext context) { return new NeedsPaging<Visit>(Context.getVisitService().getAllVisits(), context); }
@Test public void shouldCreateAVisitWithAttributes() throws Exception { int originalCount = service.getAllVisits().size(); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\"," + "\"attributes\":[{\"attributeType\":\"" + RestTestConstants1_9.VISIT_ATTRIBUTE_TYPE_UUID + "\",\"value\":\"2012-12-01\"}]}"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); }
@Test public void shouldCreateAVisit() throws Exception { int originalCount = service.getAllVisits().size(); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\"}"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); }
@Test public void shouldCreateVisitWithoutStartDatetime() throws Exception { int originalCount = service.getAllVisits().size(); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\"}"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); }
@Test public void shouldCreateAVisitWithEncounters() throws Exception { int originalCount = service.getAllVisits().size(); final String patientUuid = "5946f880-b197-400b-9caa-a3c661d23041"; Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); Assert.assertEquals(0, service.getVisitsByPatient(patient).size()); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\", \"encounters\": [\"6519d653-393b-4118-9c83-a3715b82d4ac\", \"eec646cb-c847-45a7-98bc-91c8c4f70add\"] }"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); Assert.assertEquals(2, service.getVisitsByPatient(patient).get(0).getEncounters().size()); }
@Test public void shouldPurgeAVisit() throws Exception { Assert.assertNotNull(service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID)); int originalCount = service.getAllVisits().size(); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("purge", "true"))); Assert.assertNull(service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID)); Assert.assertEquals(originalCount - 1, service.getAllVisits().size()); }
@Test public void shouldCreateAVisitWithEncounterAndObs() throws Exception { int originalCount = service.getAllVisits().size(); final String patientUuid = "5946f880-b197-400b-9caa-a3c661d23041"; Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); Assert.assertEquals(0, service.getVisitsByPatient(patient).size()); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\", \"encounters\": [{\"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"obs\": [{\"concept\":\"89ca642a-dab6-4f20-b712-e12ca4fc6d36\", \"value\":\"b055abd8-a420-4a11-8b98-02ee170a7b54\"}]}] }}] }"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); Assert.assertEquals(1, service.getVisitsByPatient(patient).get(0).getEncounters().size()); Iterator<Encounter> encouters = service.getVisitsByPatient(patient).get(0).getEncounters().iterator(); Assert.assertEquals(1, encouters.next().getObs().size()); }