use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerRepositoryIntegrationTest method shouldFindChw.
@Test
public void shouldFindChw() {
// when
Page<CommunityHealthWorker> result = repository.searchCommunityHealthWorkers(chw1.getChwId(), chw1.getFirstName(), chw1.getSecondName(), chw1.getOtherName(), chw1.getPhoneNumber(), chw1.getEducationLevel().toString(), community.getName(), facility.getName(), chiefdom.getName(), district.getName(), null, false, null);
// then
assertThat(result.getTotalElements(), is(1L));
CommunityHealthWorker foundWorker = result.getContent().get(0);
assertThat(foundWorker.getId(), is(chw1.getId()));
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class ModuleAssignmentServiceTest method assignModulesShouldThrowIfIvrIdIsNotSet.
@Test(expected = ModuleAssignmentException.class)
public void assignModulesShouldThrowIfIvrIdIsNotSet() {
final CommunityHealthWorker chw = new CommunityHealthWorkerDataBuilder().withIvrId(null).build();
final AssignedModules assignedModules = new AssignedModulesDataBuilder().withChw(chw).build();
when(assignedModulesRepository.findByHealthWorkerId(eq(chw.getId()))).thenReturn(Optional.of(assignedModules));
moduleAssignmentService.assignModules(assignedModules);
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerDataBuilder method buildAsNew.
/**
* Builds instance of {@link CommunityHealthWorker} without id.
*/
public CommunityHealthWorker buildAsNew() {
CommunityHealthWorker chw = new CommunityHealthWorker();
chw.setChwId(chwId);
chw.setFirstName(firstName);
chw.setSecondName(secondName);
chw.setGender(gender);
chw.setPhoneNumber(phoneNumber);
chw.setCommunity(community);
chw.setPreferredLanguage(preferredLanguage);
chw.setEducationLevel(educationLevel);
chw.setIvrId(ivrId);
return chw;
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerRepositoryImpl method searchCommunityHealthWorkers.
/**
* Finds CommunityHealthWorkers matching all of the provided parameters.
* If there are no parameters, return all CommunityHealthWorkers.
*/
@Override
public Page<CommunityHealthWorker> searchCommunityHealthWorkers(String chwId, String firstName, String secondName, String otherName, String phoneNumber, String educationLevel, String communityName, String facilityName, String chiefdomName, String districtName, String phuSupervisor, Boolean selected, Pageable pageable) throws IllegalArgumentException {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<CommunityHealthWorker> query = builder.createQuery(CommunityHealthWorker.class);
query = prepareQuery(query, chwId, firstName, secondName, otherName, phoneNumber, educationLevel, communityName, facilityName, chiefdomName, districtName, phuSupervisor, selected, false, pageable);
CriteriaQuery<Long> countQuery = builder.createQuery(Long.class);
countQuery = prepareQuery(countQuery, chwId, firstName, secondName, otherName, phoneNumber, educationLevel, communityName, facilityName, chiefdomName, districtName, phuSupervisor, selected, true, pageable);
Long count = entityManager.createQuery(countQuery).getSingleResult();
int pageSize = getPageSize(pageable);
int firstResult = getFirstResult(pageable, pageSize);
List<CommunityHealthWorker> communityHealthWorkers = entityManager.createQuery(query).setMaxResults(pageSize).setFirstResult(firstResult).getResultList();
return new PageImpl<>(communityHealthWorkers, pageable, count);
}
use of org.motechproject.mots.domain.CommunityHealthWorker in project mots by motech-implementations.
the class CommunityHealthWorkerService method processChwCsv.
/**
*.
* Processes CSV file which contains CHW list and returns list of errors
* @param chwCsvFile CSV file with CHW list
* @return map with row numbers as keys and errors as values.
* @throws IOException in case of file issues
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
@PreAuthorize(RoleNames.HAS_UPLOAD_CSV_ROLE)
public Map<Integer, String> processChwCsv(MultipartFile chwCsvFile, Boolean selected) throws IOException {
ICsvMapReader csvMapReader;
csvMapReader = new CsvMapReader(new InputStreamReader(chwCsvFile.getInputStream()), CsvPreference.STANDARD_PREFERENCE);
final String[] header = csvMapReader.getHeader(true);
final CellProcessor[] processors = getProcessors();
Map<String, Object> csvRow;
Set<String> phoneNumberSet = new HashSet<>();
Set<String> chwIdSet = new HashSet<>();
Map<Integer, String> errorMap = new HashMap<>();
while ((csvRow = csvMapReader.read(header, processors)) != null) {
LOGGER.debug(String.format("lineNo=%s, rowNo=%s, chw=%s", csvMapReader.getLineNumber(), csvMapReader.getRowNumber(), csvRow));
String phoneNumber = Objects.toString(csvRow.get("Mobile"), null);
String chwId = Objects.toString(csvRow.get("CHW ID"), null);
// Validate
if (phoneNumberSet.contains(phoneNumber)) {
errorMap.put(csvMapReader.getLineNumber(), "Phone number is duplicated in CSV");
continue;
}
if (chwIdSet.contains(chwId)) {
errorMap.put(csvMapReader.getLineNumber(), "CHW ID is duplicated in CSV");
continue;
}
if (validateBlankFieldsInCsv(csvMapReader.getLineNumber(), csvRow, errorMap)) {
continue;
}
// Add to collections
if (phoneNumber != null) {
phoneNumberSet.add(phoneNumber);
}
if (chwId != null) {
chwIdSet.add(chwId);
}
String community = Objects.toString(csvRow.get("Community"), null);
String facility = Objects.toString(csvRow.get("PHU"), null);
Community chwCommunity = communityRepository.findByNameAndFacilityName(community, facility);
if (chwCommunity == null) {
errorMap.put(csvMapReader.getLineNumber(), String.format("There is no community %s in facility %s in MOTS", community, facility));
continue;
}
Optional<CommunityHealthWorker> existingHealthWorker = healthWorkerRepository.findByChwId(csvRow.get("CHW ID").toString());
CommunityHealthWorker communityHealthWorker;
if (existingHealthWorker.isPresent()) {
communityHealthWorker = existingHealthWorker.get();
} else {
communityHealthWorker = new CommunityHealthWorker();
communityHealthWorker.setPreferredLanguage(Language.ENGLISH);
communityHealthWorker.setSelected(false);
}
if ((selected || communityHealthWorker.getSelected()) && StringUtils.isBlank(phoneNumber)) {
errorMap.put(csvMapReader.getLineNumber(), "Phone number is empty");
continue;
}
communityHealthWorker.setChwId(csvRow.get("CHW ID").toString());
communityHealthWorker.setFirstName(csvRow.get("First_Name").toString());
communityHealthWorker.setSecondName(csvRow.get("Second_Name").toString());
communityHealthWorker.setOtherName(Objects.toString(csvRow.get("Other_Name"), null));
communityHealthWorker.setYearOfBirth(csvRow.get("Age") != null ? LocalDate.now().getYear() - Integer.valueOf(Objects.toString(csvRow.get("Age"), null)) : null);
communityHealthWorker.setGender(Gender.getByDisplayName(csvRow.get("Gender").toString()));
communityHealthWorker.setLiteracy(Literacy.getByDisplayName(csvRow.get("Read_Write").toString()));
communityHealthWorker.setEducationLevel(EducationLevel.getByDisplayName(csvRow.get("Education").toString()));
communityHealthWorker.setPhoneNumber(phoneNumber);
communityHealthWorker.setCommunity(chwCommunity);
communityHealthWorker.setHasPeerSupervisor(csvRow.get("Peer_Supervisor").equals("Yes"));
communityHealthWorker.setWorking(csvRow.get("Working").equals("Yes"));
if (selected && !communityHealthWorker.getSelected()) {
selectHealthWorker(communityHealthWorker);
} else {
healthWorkerRepository.save(communityHealthWorker);
}
}
return errorMap;
}
Aggregations