Search in sources :

Example 6 with CommunityHealthWorker

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));
}
Also used : CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with CommunityHealthWorker

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));
}
Also used : CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with CommunityHealthWorker

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) EducationLevel(org.motechproject.mots.domain.enums.EducationLevel) Predicate(javax.persistence.criteria.Predicate)

Example 9 with CommunityHealthWorker

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()));
}
Also used : CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) Test(org.junit.Test)

Example 10 with CommunityHealthWorker

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);
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) AssignedModulesDataBuilder(org.motechproject.mots.testbuilder.AssignedModulesDataBuilder) CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) CommunityHealthWorkerDataBuilder(org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CommunityHealthWorker (org.motechproject.mots.domain.CommunityHealthWorker)13 Test (org.junit.Test)4 AssignedModules (org.motechproject.mots.domain.AssignedModules)4 HashSet (java.util.HashSet)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 CourseModule (org.motechproject.mots.domain.CourseModule)2 Module (org.motechproject.mots.domain.Module)2 IvrException (org.motechproject.mots.exception.IvrException)2 ModuleAssignmentException (org.motechproject.mots.exception.ModuleAssignmentException)2 AssignedModulesDataBuilder (org.motechproject.mots.testbuilder.AssignedModulesDataBuilder)2 CommunityHealthWorkerDataBuilder (org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1