Search in sources :

Example 1 with UnitProgress

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;
}
Also used : UnitProgress(org.motechproject.mots.domain.UnitProgress) VotoBlockDto(org.motechproject.mots.dto.VotoBlockDto) ModuleProgress(org.motechproject.mots.domain.ModuleProgress) CourseProgressException(org.motechproject.mots.exception.CourseProgressException)

Example 2 with UnitProgress

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;
}
Also used : UnitProgress(org.motechproject.mots.domain.UnitProgress) VotoBlockDto(org.motechproject.mots.dto.VotoBlockDto) CourseProgressException(org.motechproject.mots.exception.CourseProgressException)

Aggregations

UnitProgress (org.motechproject.mots.domain.UnitProgress)2 VotoBlockDto (org.motechproject.mots.dto.VotoBlockDto)2 CourseProgressException (org.motechproject.mots.exception.CourseProgressException)2 ModuleProgress (org.motechproject.mots.domain.ModuleProgress)1