Няма описание

EncuestaMarle.swift 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Encuesta_MARLE.swift
  3. // Created by Tatiana Castro on 1/18/19.
  4. // Copyright © 2019 Tatiana Castro. All rights reserved.
  5. //
  6. import UIKit
  7. import ResearchKit
  8. import Foundation
  9. public var EncuestaMarle: ORKOrderedTask {
  10. var steps = [ORKStep]()
  11. let instruccion = ORKInstructionStep(identifier: "Instrucción")
  12. instruccion.title = "Proyecto TANIA"
  13. instruccion.text = descripcion
  14. steps += [instruccion]
  15. for i in 0..<cantidad_preguntas{
  16. switch tipo_preg[i] {
  17. case "3":
  18. let escala1Formato = ORKAnswerFormat.scale(withMaximumValue: Int(max_values[i]) ?? 0, minimumValue: 1, defaultValue: NSIntegerMax, step: 1, vertical: false, maximumValueDescription: "Máximo", minimumValueDescription: "Mínimo")
  19. let escala1Pregunta = ORKQuestionStep(identifier: id_preg[i] , title: "Pregunta \(i+1)", question: preguntas[i], answer: escala1Formato)
  20. steps += [escala1Pregunta]
  21. case "2":
  22. let respuestaFormato = ORKAnswerFormat.textAnswerFormat()
  23. let respuestaStep = ORKQuestionStep(identifier: id_preg[i], title: NSLocalizedString("Pregunta \(i+1)", comment: ""), question: preguntas[i], answer: respuestaFormato);
  24. steps += [respuestaStep]
  25. case "1":
  26. var textChoices = [ORKTextChoice]()
  27. for j in 1...(Int(max_values[i]) ?? 0){
  28. if j==1{
  29. textChoices.append(ORKTextChoice(text: String(j)+" "+min_text[i], value: String(j) as NSCoding & NSCopying & NSObjectProtocol))
  30. }
  31. else if j==(Int(max_values[i])){
  32. textChoices.append(ORKTextChoice(text: String(j)+" "+max_text[i], value: String(j) as NSCoding & NSCopying & NSObjectProtocol))
  33. }
  34. else{
  35. textChoices.append(ORKTextChoice(text: String(j), value: String(j) as NSCoding & NSCopying & NSObjectProtocol))
  36. }
  37. }
  38. let answerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)
  39. let questionStep = ORKQuestionStep(identifier: id_preg[i], title: NSLocalizedString("Pregunta \(i+1)", comment: ""), question: preguntas[i], answer: answerFormat)
  40. steps += [questionStep]
  41. default:
  42. let respuestaFormato = ORKAnswerFormat.textAnswerFormat()
  43. let respuestaStep = ORKQuestionStep(identifier: id_preg[i], title: NSLocalizedString("Pregunta \(i+1)", comment: ""), question: preguntas[i], answer: respuestaFormato);
  44. steps += [respuestaStep]
  45. }
  46. }
  47. let completionStep = ORKCompletionStep(identifier: "CompletionStep")
  48. completionStep.title = "Thank you for answering."
  49. completionStep.text = "Your answers have been recorded."
  50. steps += [completionStep]
  51. getJsonFromUrl()
  52. return ORKOrderedTask(identifier: id_questionario, steps: steps)
  53. }