Search in sources :

Example 1 with ModuleProgress

use of org.motechproject.mots.domain.ModuleProgress 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 ModuleProgress

use of org.motechproject.mots.domain.ModuleProgress in project mots by motech-implementations.

the class ModuleProgressService method updateModuleProgressWithNewCourseModules.

/**
 * Update ModuleProgresses with new Course Modules when Module is reused in newly released Course.
 * @param courseModules list of new Course Modules with reused Modules
 */
public void updateModuleProgressWithNewCourseModules(List<CourseModule> courseModules) {
    courseModules.forEach(courseModule -> {
        UUID courseModuleId = courseModule.getPreviousVersion().getId();
        List<ModuleProgress> moduleProgresses = moduleProgressRepository.findByCourseModuleId(courseModuleId);
        if (moduleProgresses != null && !moduleProgresses.isEmpty()) {
            moduleProgresses.forEach(moduleProgress -> moduleProgress.setCourseModule(courseModule));
            moduleProgressRepository.save(moduleProgresses);
        }
    });
}
Also used : ModuleProgress(org.motechproject.mots.domain.ModuleProgress) UUID(java.util.UUID)

Example 3 with ModuleProgress

use of org.motechproject.mots.domain.ModuleProgress in project mots by motech-implementations.

the class ModuleProgressDataBuilder method buildAsNew.

/**
 * Builds instance of {@link ModuleProgress} without id.
 */
public ModuleProgress buildAsNew() {
    ModuleProgress moduleProgress = new ModuleProgress();
    moduleProgress.setStatus(status);
    moduleProgress.setCourseModule(courseModule);
    moduleProgress.setCommunityHealthWorker(chw);
    return moduleProgress;
}
Also used : ModuleProgress(org.motechproject.mots.domain.ModuleProgress)

Example 4 with ModuleProgress

use of org.motechproject.mots.domain.ModuleProgress in project mots by motech-implementations.

the class ModuleProgressDataBuilder method build.

/**
 * Builds instance of {@link ModuleProgress}.
 */
public ModuleProgress build() {
    ModuleProgress moduleProgress = buildAsNew();
    moduleProgress.setId(id);
    return moduleProgress;
}
Also used : ModuleProgress(org.motechproject.mots.domain.ModuleProgress)

Example 5 with ModuleProgress

use of org.motechproject.mots.domain.ModuleProgress in project mots by motech-implementations.

the class ModuleProgressService method createModuleProgress.

private void createModuleProgress(CommunityHealthWorker chw, Module module) {
    Course course = moduleService.getReleasedCourse();
    if (!moduleProgressRepository.findByCommunityHealthWorkerIdAndCourseModuleModuleIdAndCourseModuleCourseId(chw.getId(), module.getId(), course.getId()).isPresent()) {
        CourseModule courseModule = moduleService.findReleasedCourseModuleByModuleId(module.getId());
        ModuleProgress moduleProgress = new ModuleProgress(chw, courseModule);
        moduleProgressRepository.save(moduleProgress);
    }
}
Also used : ModuleProgress(org.motechproject.mots.domain.ModuleProgress) CourseModule(org.motechproject.mots.domain.CourseModule) Course(org.motechproject.mots.domain.Course)

Aggregations

ModuleProgress (org.motechproject.mots.domain.ModuleProgress)6 VotoBlockDto (org.motechproject.mots.dto.VotoBlockDto)2 UUID (java.util.UUID)1 Course (org.motechproject.mots.domain.Course)1 CourseModule (org.motechproject.mots.domain.CourseModule)1 UnitProgress (org.motechproject.mots.domain.UnitProgress)1 CourseProgressException (org.motechproject.mots.exception.CourseProgressException)1 MotsException (org.motechproject.mots.exception.MotsException)1