use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerController method saveHealthWorker.
/**
* Update community health worker.
* @param id id of CHW to update
* @param healthWorkerDto DTO of CHW to update
* @return updated CHW
*/
@RequestMapping(value = "/chw/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public CommunityHealthWorkerDto saveHealthWorker(@PathVariable("id") UUID id, @RequestBody @Valid CommunityHealthWorkerDto healthWorkerDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
CommunityHealthWorker existingHealthWorker = healthWorkerService.getHealthWorker(id);
healthWorkerMapper.updateFromDto(healthWorkerDto, existingHealthWorker);
return healthWorkerMapper.toDto(healthWorkerService.saveHealthWorker(existingHealthWorker));
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerController method selectHealthWorker.
/**
* Select community health worker.
* @param id id of CHW to select
* @param healthWorkerDto DTO of community health worker to be selected
* @return selected community health worker
*/
@RequestMapping(value = "/chw/{id}/select", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public CommunityHealthWorkerDto selectHealthWorker(@PathVariable("id") UUID id, @RequestBody @Valid CommunityHealthWorkerDto healthWorkerDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
CommunityHealthWorker existingHealthWorker = healthWorkerService.getHealthWorker(id);
healthWorkerMapper.updateFromDto(healthWorkerDto, existingHealthWorker);
return healthWorkerMapper.toDto(healthWorkerService.selectHealthWorker(existingHealthWorker));
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerRepositoryImpl method prepareQuery.
private <T> CriteriaQuery<T> prepareQuery(CriteriaQuery<T> query, String chwId, String firstName, String secondName, String otherName, String phoneNumber, String educationLevel, String communityName, String facilityName, String chiefdomName, String districtName, String phuSupervisor, Boolean selected, boolean count, Pageable pageable) throws IllegalArgumentException {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
Root<CommunityHealthWorker> root = query.from(CommunityHealthWorker.class);
if (count) {
CriteriaQuery<Long> countQuery = (CriteriaQuery<Long>) query;
query = (CriteriaQuery<T>) countQuery.select(builder.count(root));
}
Predicate predicate = builder.conjunction();
if (chwId != null) {
predicate = builder.and(predicate, builder.like(root.get(CHW_ID), '%' + chwId + '%'));
}
if (firstName != null) {
predicate = builder.and(predicate, builder.like(root.get(FIRST_NAME), '%' + firstName + '%'));
}
if (secondName != null) {
predicate = builder.and(predicate, builder.like(root.get(SECOND_NAME), '%' + secondName + '%'));
}
if (otherName != null) {
predicate = builder.and(predicate, builder.like(root.get(OTHER_NAME), '%' + otherName + '%'));
}
if (phoneNumber != null) {
predicate = builder.and(predicate, builder.like(root.get(PHONE_NUMBER), '%' + phoneNumber + '%'));
}
if (educationLevel != null) {
EducationLevel validLevel = EducationLevel.valueOf(educationLevel.toUpperCase());
predicate = builder.and(predicate, builder.equal(root.get(EDUCATION_LEVEL), validLevel));
}
if (communityName != null) {
predicate = builder.and(predicate, builder.like(root.get(COMMUNITY).get(NAME), '%' + communityName + '%'));
}
if (facilityName != null) {
predicate = builder.and(predicate, builder.like(root.get(COMMUNITY).get(FACILITY).get(NAME), '%' + facilityName + '%'));
}
if (chiefdomName != null) {
predicate = builder.and(predicate, builder.like(root.get(COMMUNITY).get(FACILITY).get(CHIEFDOM).get(NAME), '%' + chiefdomName + '%'));
}
if (districtName != null) {
predicate = builder.and(predicate, builder.like(root.get(COMMUNITY).get(FACILITY).get(CHIEFDOM).get(DISTRICT).get(NAME), '%' + districtName + '%'));
}
if (phuSupervisor != null) {
Predicate localPredicate = builder.like(root.get(COMMUNITY).get(FACILITY).get(INCHARGE).get(FIRST_NAME), '%' + phuSupervisor + '%');
localPredicate = builder.or(localPredicate, builder.like(root.get(COMMUNITY).get(FACILITY).get(INCHARGE).get(SECOND_NAME), '%' + phuSupervisor + '%'));
localPredicate = builder.or(localPredicate, builder.like(root.get(COMMUNITY).get(FACILITY).get(INCHARGE).get(OTHER_NAME), '%' + phuSupervisor + '%'));
predicate = builder.and(predicate, localPredicate);
}
if (selected != null) {
predicate = builder.and(predicate, builder.equal(root.get(SELECTED), selected));
}
query.where(predicate);
if (!count && pageable != null && pageable.getSort() != null) {
query = addSortProperties(query, root, pageable);
}
return query;
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerRepositoryIntegrationTest method shouldFindChwByFirstName.
@Test
public void shouldFindChwByFirstName() {
// when
Page<CommunityHealthWorker> result = repository.searchCommunityHealthWorkers(null, chw2.getFirstName(), null, null, null, null, null, null, null, null, null, false, null);
// then
assertThat(result.getTotalElements(), is(1L));
CommunityHealthWorker foundWorker = result.getContent().get(0);
assertThat(foundWorker.getFirstName(), is(chw2.getFirstName()));
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class ModuleAssignmentServiceTest method assignModulesToDistrictShouldThrowIfIvrIdIsNotSet.
@Test(expected = ModuleAssignmentException.class)
public void assignModulesToDistrictShouldThrowIfIvrIdIsNotSet() {
CommunityHealthWorker chw = new CommunityHealthWorkerDataBuilder().withIvrId(null).build();
AssignedModules assignedModules = new AssignedModulesDataBuilder().withChw(chw).build();
when(communityHealthWorkerRepository.findByCommunityFacilityChiefdomDistrictIdAndSelected(any(), any())).thenReturn(Collections.singletonList(chw));
when(assignedModulesRepository.findByHealthWorkerId(eq(chw.getId()))).thenReturn(Optional.of(assignedModules));
moduleAssignmentService.assignModulesToDistrict(districtAssignmentDto);
}
Aggregations