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.
- 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 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 |
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 |
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.
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.
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)")
}
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.
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
// ...
}
}
This project is licensed under the MIT License. See Licenses for more information.
This project is developed as part of the Stanford University projects at Stanford. See CONTRIBUTORS.md for a full list of all ResearchKitOnFHIR contributors.
ResearchKit is a registered trademark of Apple, Inc. FHIR is a registered trademark of Health Level Seven International.