Skip to content

Commit

Permalink
Replace ORKOrderedTaskView with new ResearchKit one (#23)
Browse files Browse the repository at this point in the history
# Replace ORKOrderedTaskView with new ResearchKit one

## ♻️ Current situation & Problem

This PR updates to our latest version of ResearchKit and replaces the
internal `ORKOrderedTaskView` implementation with the new one available
in `ResearchKitSwiftUI`.

## ⚙️ Release Notes 
* Updated to new ResearchKit version

## 📚 Documentation

--
## ✅ Testing

--

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Feb 24, 2024
1 parent fac0bb0 commit f25580e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 98 deletions.
7 changes: 4 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.0.0"),
.package(url: "https://github.com/apple/FHIRModels", .upToNextMinor(from: "0.5.0")),
.package(url: "https://github.com/StanfordBDHG/ResearchKit", from: "2.2.21"),
.package(url: "https://github.com/StanfordBDHG/ResearchKitOnFHIR", from: "1.0.0")
.package(url: "https://github.com/StanfordBDHG/ResearchKit", from: "2.2.25"),
.package(url: "https://github.com/StanfordBDHG/ResearchKitOnFHIR", from: "1.1.0")
],
targets: [
.target(
Expand All @@ -33,7 +33,8 @@ let package = Package(
.product(name: "ModelsR4", package: "FHIRModels"),
.product(name: "ResearchKitOnFHIR", package: "ResearchKitOnFHIR"),
.product(name: "FHIRQuestionnaires", package: "ResearchKitOnFHIR"),
.product(name: "ResearchKit", package: "ResearchKit")
.product(name: "ResearchKit", package: "ResearchKit"),
.product(name: "ResearchKitSwiftUI", package: "ResearchKit")
]
),
.testTarget(
Expand Down
89 changes: 0 additions & 89 deletions Sources/SpeziQuestionnaire/ORKOrderedTaskView.swift

This file was deleted.

24 changes: 18 additions & 6 deletions Sources/SpeziQuestionnaire/QuestionnaireView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ModelsR4
import OSLog
import ResearchKit
import ResearchKitOnFHIR
import ResearchKitSwiftUI
import SwiftUI


Expand Down Expand Up @@ -45,11 +46,7 @@ public struct QuestionnaireView: View {

public var body: some View {
if let task = createTask(questionnaire: questionnaire) {
ORKOrderedTaskView(
tasks: task,
result: questionnaireResult,
tintColor: .accentColor
)
ORKOrderedTaskView(tasks: task, tintColor: .accentColor, result: handleResult)
.ignoresSafeArea(.container, edges: .bottom)
.ignoresSafeArea(.keyboard, edges: .bottom)
.interactiveDismissDisabled()
Expand All @@ -72,7 +69,22 @@ public struct QuestionnaireView: View {
self.completionStepMessage = completionStepMessage
self.questionnaireResult = questionnaireResult
}


private func handleResult(_ result: TaskResult) async {
let questionnaireResult: QuestionnaireResult
switch result {
case let .completed(result):
let fhirResponse = result.fhirResponse
questionnaireResult = .completed(result.fhirResponse)
case .cancelled:
questionnaireResult = .cancelled
case .failed:
questionnaireResult = .failed
}

await self.questionnaireResult(questionnaireResult)
}


/// Creates a ResearchKit navigable task from a questionnaire
/// - Parameter questionnaire: a questionnaire
Expand Down

0 comments on commit f25580e

Please sign in to comment.