use of org.motechproject.mots.domain.UnitProgress in project mots by motech-implementations.
the class ModuleProgressService method parseVotoModuleBlocks.
private boolean parseVotoModuleBlocks(VotoCallLogDto callLog, Iterator<VotoBlockDto> blockIterator, String moduleId, boolean callInterrupted) {
String chwIvrId = callLog.getChwIvrId();
ModuleProgress moduleProgress = moduleProgressRepository.findByCommunityHealthWorkerIvrIdAndCourseModuleIvrId(chwIvrId, moduleId).orElseThrow(() -> new CourseProgressException("No module progress found for" + " CHW with IVR Id: {0} and module with IVR Id: {1}", chwIvrId, moduleId));
if (ProgressStatus.COMPLETED.equals(moduleProgress.getStatus())) {
throw new CourseProgressException("Module already completed for CHW with IVR Id: {0} " + "and module with IVR Id: {1}", chwIvrId, moduleId);
}
if (!moduleProgress.getInterrupted()) {
VotoBlockDto blockDto = checkRunUnitBlock(blockIterator, moduleProgress);
moduleProgress.startModule(parseDate(blockDto.getEntryAt()));
}
while (!moduleProgress.isCompleted()) {
UnitProgress unitProgress = moduleProgress.getCurrentUnitProgress();
if (parseVotoUnitBlocks(unitProgress, blockIterator, callInterrupted) || !blockIterator.hasNext()) {
moduleProgress.setInterrupted(true);
moduleProgressRepository.save(moduleProgress);
return true;
}
moduleProgress.setInterrupted(false);
if (parseUnitContinuationQuestion(blockIterator, moduleProgress, unitProgress)) {
moduleProgressRepository.save(moduleProgress);
return true;
}
}
moduleProgressRepository.save(moduleProgress);
return false;
}
use of org.motechproject.mots.domain.UnitProgress in project mots by motech-implementations.
the class ModuleProgressService method checkRunUnitBlock.
private VotoBlockDto checkRunUnitBlock(Iterator<VotoBlockDto> blockIterator, ModuleProgress moduleProgress) {
VotoBlockDto blockDto = getVotoBlock(blockIterator);
if (blockDto == null || !RUN_ANOTHER_TREE_BLOCK_TYPE.equals(blockDto.getBlockType())) {
throw new CourseProgressException("Unexpected block in module: {0}", moduleProgress.getCourseModule().getModule().getName());
}
UnitProgress unitProgress = moduleProgress.getCurrentUnitProgress();
if (!blockDto.getBlockId().equals(unitProgress.getUnit().getIvrId())) {
throw new CourseProgressException("IVR Block Id: {0} did not match current Unit IVR Id", blockDto.getBlockId());
}
return blockDto;
}
Aggregations