<commit_before>import { Injectable } from '@angular/core'

import { KafkaService } from '../../../core/services/kafka/kafka.service'
import { ScheduleService } from '../../../core/services/schedule/schedule.service'
import { SchemaType } from '../../../shared/models/kafka'
import { TaskType, getTaskType } from '../../../shared/utilities/task-type'
import { PrepareDataService } from './prepare-data.service'

@Injectable()
export class FinishTaskService {
  constructor(
    private schedule: ScheduleService,
    private prepare: PrepareDataService,
    private kafka: KafkaService
  ) {}

  updateTaskToComplete(task): Promise<any> {
    return Promise.all([
      this.schedule.updateTaskToComplete(task),
      this.schedule.updateTaskToReportedCompletion(task),
      getTaskType(task) == TaskType.NON_CLINICAL
        ? this.schedule.addToCompletedTasks(task)
        : Promise.resolve()
    ])
  }

  processDataAndSend(data, task) {
    return this.sendAnswersToKafka(
      this.prepare.processQuestionnaireData(data),
      task
    )
  }

  sendAnswersToKafka(processedAnswers, task): Promise<any> {
    // NOTE: Submit data to kafka
    return Promise.all([
      this.kafka.prepareKafkaObjectAndSend(SchemaType.TIMEZONE, {}),
      this.kafka.prepareKafkaObjectAndSend(SchemaType.ASSESSMENT, {
        task: task,
        data: processedAnswers
      })
    ])
  }

  evalClinicalFollowUpTask(assessment): Promise<any> {
    console.log('evaluating')
    return this.schedule.generateClinicalSchedule(assessment, Date.now())
    // TODO: Fix notification scheduling right after generating clinic schedule
  }
}<commit_msg>fix(finishTaskService): add back rescheduling notifs after clinical task is generated<commit_after>import { Injectable } from '@angular/core'

import { ConfigService } from '../../../core/services/config/config.service'
import { KafkaService } from '../../../core/services/kafka/kafka.service'
import { ScheduleService } from '../../../core/services/schedule/schedule.service'
import { SchemaType } from '../../../shared/models/kafka'
import { TaskType, getTaskType } from '../../../shared/utilities/task-type'
import { PrepareDataService } from './prepare-data.service'

@Injectable()
export class FinishTaskService {
  constructor(
    private schedule: ScheduleService,
    private prepare: PrepareDataService,
    private kafka: KafkaService,
    private config: ConfigService
  ) {}

  updateTaskToComplete(task): Promise<any> {
    return Promise.all([
      this.schedule.updateTaskToComplete(task),
      this.schedule.updateTaskToReportedCompletion(task),
      getTaskType(task) == TaskType.NON_CLINICAL
        ? this.schedule.addToCompletedTasks(task)
        : Promise.resolve()
    ])
  }

  processDataAndSend(data, task) {
    return this.sendAnswersToKafka(
      this.prepare.processQuestionnaireData(data),
      task
    )
  }

  sendAnswersToKafka(processedAnswers, task): Promise<any> {
    // NOTE: Submit data to kafka
    return Promise.all([
      this.kafka.prepareKafkaObjectAndSend(SchemaType.TIMEZONE, {}),
      this.kafka.prepareKafkaObjectAndSend(SchemaType.ASSESSMENT, {
        task: task,
        data: processedAnswers
      })
    ])
  }

  evalClinicalFollowUpTask(assessment): Promise<any> {
    console.log('evaluating')
    return this.schedule
      .generateClinicalSchedule(assessment, Date.now())
      .then(() => this.config.rescheduleNotifications())
  }
}
{'fraction_non_alphanumeric': 0.12783265543288785, 'fraction_numerical': 0.0, 'mean_word_length': 3.548216644649934, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '131158', 'n_tokens_mistral': 1019, 'n_tokens_neox': 999, 'n_words': 182}