private List<VisitType> getVisitTypesFromVisitTypeNames(String[] visitTypeNames) { List<VisitType> result = new ArrayList<>(); for (VisitType visitType : Context.getVisitService().getAllVisitTypes()) { if (ArrayUtils.contains(visitTypeNames, visitType.getName().toLowerCase())) { result.add(visitType); } } return result; }
return Context.getVisitService().getAllVisitTypes().get(0);
@Test public void getAllVisitTypes_shouldGetAllVisitTypes() { List<VisitType> visitTypes = visitService.getAllVisitTypes(); assertEquals(3, visitTypes.size()); }
/** * @see VisitService#getAllVisitTypes(boolean) */ @Test public void getAllVisitTypes_shouldGetAllVisitTypesBasedOnIncludeRetiredFlag() { VisitService visitService = Context.getVisitService(); List<VisitType> visitTypes = visitService.getAllVisitTypes(true); assertEquals("get all visit types including retired", 3, visitTypes.size()); visitTypes = visitService.getAllVisitTypes(false); assertEquals("get all visit types excluding retired", 2, visitTypes.size()); }
@Test public void saveVisitType_shouldSaveNewVisitType() { List<VisitType> visitTypes = visitService.getVisitTypes("Some Name"); assertEquals(0, visitTypes.size()); VisitType visitType = new VisitType("Some Name", "Description"); visitService.saveVisitType(visitType); visitTypes = visitService.getVisitTypes("Some Name"); assertEquals(1, visitTypes.size()); //Should create a new visit type row. assertEquals(4, visitService.getAllVisitTypes().size()); }
@Test public void purgeVisitType_shouldDeleteGivenVisitType() { VisitType visitType = visitService.getVisitType(3); assertNotNull(visitType); visitService.purgeVisitType(visitType); visitType = visitService.getVisitType(3); assertNull(visitType); //Should reduce the existing number of visit types. assertEquals(2, visitService.getAllVisitTypes().size()); }
/** * @see ExistingVisitAssignmentHandler#beforeCreateEncounter(Encounter) */ @Test public void beforeCreateEncounter_shouldAssignFirstVisitTypeIfMappingGlobalPropertyIsNotSet() { VisitType visitType = Context.getVisitService().getAllVisitTypes().get(0); Encounter encounter = Context.getEncounterService().getEncounter(1); Assert.assertNull(encounter.getVisit()); Calendar calendar = Calendar.getInstance(); calendar.setTime(encounter.getEncounterDatetime()); calendar.set(Calendar.YEAR, 1900); encounter.setEncounterDatetime(calendar.getTime()); new ExistingOrNewVisitAssignmentHandler().beforeCreateEncounter(encounter); Assert.assertNotNull(encounter.getVisit()); Assert.assertEquals(visitType, encounter.getVisit().getVisitType()); }
@Test public void unretireVisitType_shouldUnretireGivenVisitType() { VisitType visitType = visitService.getVisitType(3); assertNotNull(visitType); assertTrue(visitType.getRetired()); assertEquals("Some Retire Reason", visitType.getRetireReason()); visitService.unretireVisitType(visitType); visitType = visitService.getVisitType(3); assertNotNull(visitType); Assert.assertFalse(visitType.getRetired()); assertNull(visitType.getRetireReason()); //Should not change the number of visit types. assertEquals(3, visitService.getAllVisitTypes().size()); }
@Test public void retireVisitType_shouldRetireGivenVisitType() { VisitType visitType = visitService.getVisitType(1); assertNotNull(visitType); Assert.assertFalse(visitType.getRetired()); assertNull(visitType.getRetireReason()); visitService.retireVisitType(visitType, "retire reason"); visitType = visitService.getVisitType(1); assertNotNull(visitType); assertTrue(visitType.getRetired()); assertEquals("retire reason", visitType.getRetireReason()); //Should not change the number of visit types. assertEquals(3, visitService.getAllVisitTypes().size()); }
@Test public void saveVisitType_shouldSaveEditedVisitType() { VisitType visitType = visitService.getVisitType(1); assertNotNull(visitType); assertEquals("Initial HIV Clinic Visit", visitType.getName()); visitType.setName("Edited Name"); visitType.setDescription("Edited Description"); visitService.saveVisitType(visitType); visitType = visitService.getVisitType(1); assertNotNull(visitType); assertEquals("Edited Name", visitType.getName()); assertEquals("Edited Description", visitType.getDescription()); //Should not change the number of visit types. assertEquals(3, visitService.getAllVisitTypes().size()); }
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { int count = 0; for (VisitType type : service.getAllVisitTypes()) { if (!type.isRetired()) { count++; } } return count; }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<VisitType> doGetAll(RequestContext context) { //Apparently, in 1.9.0 this method returns all and has no argument for excluding retired ones List<VisitType> visitTypes = Context.getVisitService().getAllVisitTypes(); List<VisitType> filteredVisitTypes; if (context.getIncludeAll()) { filteredVisitTypes = visitTypes; } else { filteredVisitTypes = new ArrayList<VisitType>(); for (VisitType visitType : visitTypes) { if (!visitType.isRetired()) filteredVisitTypes.add(visitType); } } return new NeedsPaging<VisitType>(filteredVisitTypes, context); }
/** * Fetches a visitType by uuid, if no match is found, it tries to look up one with a matching * name with the assumption that the passed parameter is a visitType name * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public VisitType getByUniqueId(String uuid) { VisitType visitType = Context.getVisitService().getVisitTypeByUuid(uuid); //We assume the caller was fetching by name, 1.9.0 has no method to fetch by name if (visitType == null) { List<VisitType> visitTypes = Context.getVisitService().getAllVisitTypes(); for (VisitType possibleVisitType : visitTypes) { if (possibleVisitType.getName().equalsIgnoreCase(uuid)) return possibleVisitType; } } return visitType; }
@Test public void shouldCreateAVisitType() throws Exception { int originalCount = service.getAllVisitTypes().size(); String json = "{ \"name\":\"test visitType\", \"description\":\"description\" }"; Object newVisitType = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisitType, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisitTypes().size()); }
@Test public void shouldPurgeAVisitType() throws Exception { String uuid = "759799ab-c9a5-435e-b671-77773ada74e6"; Assert.assertNotNull(service.getVisitTypeByUuid(uuid)); int originalCount = service.getAllVisitTypes().size(); handle(newDeleteRequest(getURI() + "/" + uuid, new Parameter("purge", "true"))); Assert.assertNull(service.getVisitTypeByUuid(uuid)); Assert.assertEquals(originalCount - 1, service.getAllVisitTypes().size()); }