use of org.motechproject.mots.dto.VotoBlockDto in project mots by motech-implementations.
the class ModuleProgressService method parseUnitContinuationQuestion.
private boolean parseUnitContinuationQuestion(Iterator<VotoBlockDto> blockIterator, ModuleProgress moduleProgress, UnitProgress unitProgress) {
// unit continuation question block
VotoBlockDto blockDto = blockIterator.next();
Integer choiceId = getChoiceId(blockDto);
// no response was chosen - should end the call
if (choiceId == null) {
return true;
}
switch(choiceId) {
case QUIT_RESPONSE:
moduleProgress.nextUnit(parseDate(blockDto.getExitAt()));
return true;
case CONTINUE_RESPONSE:
moduleProgress.nextUnit(parseDate(blockDto.getExitAt()));
if (!moduleProgress.isCompleted()) {
checkRunUnitBlock(blockIterator, moduleProgress);
}
return false;
case REPEAT_RESPONSE:
if (!unitProgress.getUnit().getAllowReplay()) {
throw new CourseProgressException("Unit with IVR Id: {0} cannot be replayed", unitProgress.getUnit().getIvrId());
}
unitProgress.resetProgressForUnitRepeat();
return false;
default:
throw new CourseProgressException("Unexpected unit continuation question response for Unit " + "with IVR Id: {0}", unitProgress.getUnit().getIvrId());
}
}
use of org.motechproject.mots.dto.VotoBlockDto 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.dto.VotoBlockDto in project mots by motech-implementations.
the class ModuleProgressService method parseVotoMainMenuBlocks.
@SuppressWarnings("PMD.CyclomaticComplexity")
private void parseVotoMainMenuBlocks(VotoCallLogDto callLog, Iterator<VotoBlockDto> blockIterator, boolean callInterrupted) {
while (blockIterator.hasNext()) {
VotoBlockDto blockDto = getVotoBlock(blockIterator);
// main menu on Voto should start with a tree that checks if any module is available for CHW
if (blockDto == null || !RUN_ANOTHER_TREE_BLOCK_TYPE.equals(blockDto.getBlockType())) {
throw new CourseProgressException("Invalid first main menu block");
}
// skip the check modules availability logic blocks
blockDto = getVotoBlock(blockIterator);
// skip the "No modules available" or "Choose module" message
if (blockDto == null || !MESSAGE_BLOCK_TYPE.equals(blockDto.getBlockType())) {
throw new CourseProgressException("Invalid main menu block");
}
String chwIvrId = callLog.getChwIvrId();
if (!blockIterator.hasNext()) {
LOGGER.debug("No modules available for CHW with IVR Id: ", chwIvrId);
return;
}
// skip all choose module questions
while (blockIterator.hasNext()) {
blockDto = getVotoBlock(blockIterator);
if (blockDto == null) {
LOGGER.debug("No module chosen by CHW with IVR Id: ", chwIvrId);
return;
}
if (RUN_ANOTHER_TREE_BLOCK_TYPE.equals(blockDto.getBlockType())) {
break;
}
// skip all "start module" questions, if main menu was repeated skip "choose module" message
if (!QUESTION_BLOCK_TYPE.equals(blockDto.getBlockType()) && !MESSAGE_BLOCK_TYPE.equals(blockDto.getBlockType())) {
throw new CourseProgressException("Unexpected block type: \"{0}\" in main menu", blockDto.getBlockType());
}
}
if (!blockIterator.hasNext()) {
LOGGER.debug("No module chosen by CHW with IVR Id: ", chwIvrId);
return;
}
String moduleIvrId = blockDto.getBlockId();
if (parseVotoModuleBlocks(callLog, blockIterator, moduleIvrId, callInterrupted)) {
return;
}
}
}
use of org.motechproject.mots.dto.VotoBlockDto in project mots by motech-implementations.
the class ModuleProgressService method parseVotoUnitBlocks.
/**
* Parse Voto Unit blocks.
* @return returns true if call was interrupted
*/
private boolean parseVotoUnitBlocks(UnitProgress unitProgress, Iterator<VotoBlockDto> blockIterator, boolean callInterrupted) {
unitProgress.startUnit();
List<CallFlowElement> callFlowElements = unitProgress.getNotProcessedCallFlowElements();
for (CallFlowElement callFlowElement : callFlowElements) {
if (blockIterator.hasNext()) {
VotoBlockDto blockDto = blockIterator.next();
if (!callFlowElement.getIvrId().equals(blockDto.getBlockId())) {
throw new CourseProgressException("IVR Block Id: {0} did not match CallFlowElement IVRId", blockDto.getBlockId());
}
LocalDateTime startDate = parseDate(blockDto.getEntryAt());
LocalDateTime endDate = parseDate(blockDto.getExitAt());
if (CallFlowElementType.QUESTION.equals(callFlowElement.getType())) {
Integer choiceId = getChoiceId(blockDto);
Integer numberOfAttempts = getNumberOfAttempts(blockDto);
unitProgress.addMultipleChoiceQuestionLog(startDate, endDate, callFlowElement, choiceId, numberOfAttempts);
} else {
unitProgress.addMessageLog(startDate, endDate, callFlowElement);
}
unitProgress.nextElement();
} else {
if (callInterrupted) {
unitProgress.previousElement();
return true;
}
throw new CourseProgressException("Unexpected end of IVR Call Log");
}
}
return false;
}
use of org.motechproject.mots.dto.VotoBlockDto 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