Awesome
<!-- This source file is part of the ResearchKitOnFHIR open source project SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) SPDX-License-Identifier: MIT -->ResearchKitOnFHIR
ResearchKitOnFHIR is a framework that allows you to use FHIR Questionnaires with ResearchKit to create healthcare surveys on iOS based on the HL7 Structured Data Capture Implementation Guide
For more information, please refer to the API documentation.
Features
- Converts FHIR Questionnaires into ResearchKit tasks
- Serializes results into FHIR QuestionnaireResponses
- Supports survey skip-logic by converting FHIR
enableWhen
conditions into ResearchKit navigation rules - Supports answer validation during entry
- Supports contained FHIR ValueSets as answer options
FHIR <-> ResearchKit Conversion
FHIR R4 QuestionnaireItemType | ResearchKit Type | FHIR Response Type |
---|---|---|
attachment | ORKImageCaptureStep | valueAttachment |
boolean | ORKBooleanAnswerFormat | valueBoolean |
choice | ORKTextChoice | valueCoding |
date | ORKDateAnswerFormat(style: ORKDateAnswerStyle.date) | valueDate |
dateTime | ORKDateAnswerFormat(style: ORKDateAnswerStyle.dateAndTime) | valueDateTime |
decimal | ORKNumericAnswerFormat.decimalAnswerFormat | valueDecimal |
display | ORKInstructionStep | none |
group | ORKFormStep | none |
integer | ORKNumericAnswerFormat.integerAnswerFormat | valueInteger |
quantity | ORKNumericAnswerFormat.decimalAnswerFormat(withUnit: quantityUnit) | valueQuantity |
string | ORKTextAnswerFormat | valueString |
text | ORKTextAnswerFormat | valueString |
time | ORKTimeOfDayAnswerFormat | valueTime |
Navigation Rules
The following table describes how the FHIR enableWhen is converted to a ResearchKit ORKSkipStepNavigationRule for each supported type and operator. (The conversion is performed by constructing an ORKResultPredicate from the enableWhen expression and negating it.)
Multiple enableWhen expressions are supported, using the enableBehavior element to determine if any or all of the expressions should be applied. If enableBehavior is not defined, all expressions will be applied.
FHIR R4 QuestionnaireItemType | Supported QuestionnaireItemOperators | ResearchKit ORKResultPredicate |
---|---|---|
boolean | =, != | .predicateForBooleanQuestionResult |
integer | =, !=, <=, >= | .predicateForNumericQuestionResult |
decimal | =, !=, <=, >= | .predicateForNumericQuestionResult |
date | >, < | .predicateForDateQuestionResult |
coding | =, != | .predicateForChoiceQuestionResult |
Installation
ResearchKitOnFHIR can be installed into your Xcode project using Swift Package Manager.
- In Xcode 14 and newer (requires Swift 5.7), go to “File” » “Add Packages...”
- Enter the URL to this GitHub repository, then select the
ResearchKitOnFhir
package to install.
Usage
The Example
directory contains an Xcode project that demonstrates how to create a ResearchKit task from an FHIR Questionnaire and extract the results in the form of an FHIR QuestionnaireResponse.
Converting from FHIR to ResearchKit
1. Instantiate an FHIR Questionnaire from JSON
let data = <FHIR JSON data>
var questionnaire: Questionnaire?
do {
questionnaire = try JSONDecoder().decode(Questionnaire.self, from: data)
} catch {
print("Could not decode the FHIR questionnaire": \(error)")
}
2. Create a ResearchKit Navigable Task from the FHIR Questionnaire
var task: ORKNavigableOrderedTask?
do {
task = try ORKNavigableOrderedTask(questionnaire: questionnaire)
} catch {
print("Error creating task: \(error)")
}
Now you can present the task as described in the ResearchKit documentation.
Converting ResearchKit Task Results to FHIR QuestionnaireResponse
In your class that implements the ORKTaskViewControllerDelegateProtocol
, you can extract an FHIR QuestionnaireResponse from the task's results as shown below.
func taskViewController(
_ taskViewController: ORKTaskViewController,
didFinishWith reason: ORKTaskViewControllerFinishReason,
error: Error?
) {
switch reason {
case .completed:
let fhirResponse = taskViewController.result.fhirResponse
// ...
}
}
License
This project is licensed under the MIT License. See Licenses for more information.
Contributors
This project is developed as part of the Stanford University projects at Stanford. See CONTRIBUTORS.md for a full list of all ResearchKitOnFHIR contributors.
Notices
ResearchKit is a registered trademark of Apple, Inc. FHIR is a registered trademark of Health Level Seven International.