ResearchKitOnFHIR

0.1.5

HL7 FHIR Structured Data Capture with ResearchKit on iOS
StanfordBDHG/ResearchKitOnFHIR

What's New

0.1.5

2023-01-16T23:58:39Z

What's Changed

Full Changelog: 0.1.3...0.1.5

ResearchKitOnFHIR

Build and Test codecov DOI

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

FHIR <-> ResearchKit Conversion

FHIR R4 QuestionnaireItemType ResearchKit Type FHIR Response Type
display ORKInstructionStep none
group ORKFormStep none
boolean ORKBooleanAnswerFormat valueBoolean
choice ORKTextChoice valueCoding
date ORKDateAnswerFormat(style: ORKDateAnswerStyle.date valueDate
dateTime ORKDateAnswerFormat(style: ORKDateAnswerStyle.dateAndTime valueDateTime
time ORKTimeOfDayAnswerFormat valueTime
decimal ORKNumericAnswerFormat.decimalAnswerFormat valueDecimal
quantity ORKNumericAnswerFormat.decimalAnswerFormat(withUnit: quantityUnit) valueQuantity
integer ORKNumericAnswerFormat.integerAnswerFormat valueInteger
text ORKTextAnswerFormat valueString
string ORKTextAnswerFormat valueString

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.

  1. In Xcode 14 and newer (requires Swift 5.7), go to “File” » “Add Packages...”
  2. 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 a FHIR Questionnaire, and extract the results in the form of a FHIR QuestionnaireResponse.

Converting from FHIR to ResearchKit

1. Instantiate a 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 a 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 Biodesign for Digital Health 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.

Stanford Byers Center for Biodesign Logo Stanford Byers Center for Biodesign Logo

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Thu Feb 02 2023 22:35:32 GMT-0500 (GMT-05:00)