Skip to content

Commit

Permalink
Update to ResearchKit 3.0 (#81)
Browse files Browse the repository at this point in the history
# Update to ResearchKit 3.0

## ♻️ Current situation & Problem
- ResearchKit 3.0 was released

## ⚙️ Release Notes 
- Updates ResearchKitOnFHIR to ResearchKit 3.0
- Move UI tests in the Tests folder to be consistent with all
@StanfordSpezi & @StanfordBDHG packages.


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Vishnu Ravi <[email protected]>
  • Loading branch information
PSchmiedmayer and vishnuravi authored May 21, 2024
1 parent cdb24dd commit dcd5f95
Show file tree
Hide file tree
Showing 28 changed files with 84 additions and 271 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
name: Build and Test UI Tests
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
artifactname: Example.xcresult
artifactname: TestApp.xcresult
runsonlabels: '["macOS", "self-hosted"]'
path: 'Example'
scheme: Example
path: 'Tests/UITests'
scheme: TestApp
uploadcoveragereport:
name: Upload Coverage Report
needs: [buildandtest, buildandtestuitests]
uses: StanfordBDHG/.github/.github/workflows/create-and-upload-coverage-report.yml@v2
with:
coveragereports: ResearchKitOnFHIR-Package.xcresult Example.xcresult
coveragereports: ResearchKitOnFHIR-Package.xcresult TestApp.xcresult
secrets:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ xcuserdata/
docs/

# Example Project
!Example.xcodeproj
!UITests.xcodeproj
106 changes: 0 additions & 106 deletions Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme

This file was deleted.

8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import PackageDescription
let package = Package(
name: "ResearchKitOnFHIR",
platforms: [
.iOS(.v15),
.watchOS(.v8),
.iOS(.v17),
.watchOS(.v10),
.visionOS(.v1),
.macOS(.v12)
.macOS(.v14)
],
products: [
.library(name: "ResearchKitOnFHIR", targets: ["ResearchKitOnFHIR"]),
.library(name: "FHIRQuestionnaires", targets: ["FHIRQuestionnaires"])
],
dependencies: [
.package(url: "https://github.com/StanfordBDHG/ResearchKit", .upToNextMinor(from: "2.2.25")),
.package(url: "https://github.com/StanfordBDHG/ResearchKit", .upToNextMinor(from: "3.0.1")),
.package(url: "https://github.com/apple/FHIRModels.git", .upToNextMinor(from: "0.5.0")),
.package(url: "https://github.com/antlr/antlr4", from: "4.13.1")
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ extension QuestionnaireItem {
/// Converts FHIR text answer choices to ResearchKit `ORKTextChoice`.
/// - Parameter - valueSets: An array of `ValueSet` items containing sets of answer choices
/// - Returns: An array of `ORKTextChoice` objects, each representing a textual answer option.
private func toORKTextChoice(valueSets: [ValueSet], openChoice: Bool) -> [ORKTextChoice] { // swiftlint:disable:this function_body_length
private func toORKTextChoice(valueSets: [ValueSet], openChoice: Bool) -> [ORKTextChoice] {
var choices: [ORKTextChoice] = []

// If the `QuestionnaireItem` has an `answerValueSet` defined which is a reference to a contained `ValueSet`,
Expand Down Expand Up @@ -303,14 +303,14 @@ extension QuestionnaireItem {
if openChoice {
// If the `QuestionnaireItemType` is `open-choice`, allow user to enter in their own free-text answer.
let otherChoiceText = NSLocalizedString("Other", comment: "")
let otherChoiceResult = ValueCoding(code: "other", system: "other", display: otherChoiceText)
let otherChoice = ORKTextChoiceOther.choice(
withText: otherChoiceText,
detailText: nil,
value: otherChoiceResult.rawValue as NSSecureCoding & NSCopying & NSObjectProtocol,
value: otherChoiceText as NSSecureCoding & NSCopying & NSObjectProtocol,
exclusive: true,
textViewPlaceholderText: ""
)

choices.append(otherChoice)
}
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ final class ExampleUITests: XCTestCase {

// Select the "other" option and fill in a free-text answer
app.tables.staticTexts["Other"].tap()
// This is currently broken because of an issue in ResearchKit
// let otherField = app.textViews.element(boundBy: 0)
// otherField.tap()
// otherField.typeText("Cookie Dough")

let otherField = app.textViews.element(boundBy: 0)
otherField.tap()
otherField.typeText("Cookie Dough")

app.buttons["Next"].tap()

// Enter in a date on the next screen
Expand Down Expand Up @@ -426,118 +427,6 @@ final class ExampleUITests: XCTestCase {
}
}

// MARK: UI Tests for Clinical Questionnaires

func testPHQ9Example() throws {
let app = XCUIApplication()
app.launch()

let phq9ExampleButton = app.collectionViews.buttons["Patient Health Questionnaire - 9 Item"]

// Open questionnaire
phq9ExampleButton.tap()

// Answer all 9 questions
let options = ["Not at all", "Several days", "More than half the days", "Nearly every day"]

for question in 0...8 {
let buttonQuery = app.tables.staticTexts.matching(identifier: options.randomElement() ?? options[0]).element(boundBy: question)
buttonQuery.tap()
}

// Finish survey
app.buttons["Next"].tap()

// Close the completion step
app.buttons["Done"].tap()

// Open context menu and view results
phq9ExampleButton.press(forDuration: 1.0)
app.collectionViews.buttons["View Responses"].tap()

// Check results
let buttonsInResultView = app.collectionViews.allElementsBoundByIndex[1].buttons
XCTAssertEqual(buttonsInResultView.count, 1)
buttonsInResultView.allElementsBoundByIndex[0].tap()
app.navigationBars.buttons["Back"].tap()

// Dismiss results view
app.swipeDown(velocity: XCUIGestureVelocity.fast)
}

func testGAD7Example() throws {
let app = XCUIApplication()
app.launch()

let gad7ExampleButton = app.collectionViews.buttons["Generalized Anxiety Disorder - 7"]

// Open questionnaire
gad7ExampleButton.tap()

// Answer all 7 questions
let options = ["Not at all", "Several days", "More than half the days", "Nearly every day"]

for question in 0...6 {
let buttonQuery = app.tables.staticTexts.matching(identifier: options.randomElement() ?? options[0]).element(boundBy: question)
buttonQuery.tap()
}

// Finish survey
app.buttons["Next"].tap()

// Close the completion step
app.buttons["Done"].tap()

// Open context menu and view results
gad7ExampleButton.press(forDuration: 1.0)
app.collectionViews.buttons["View Responses"].tap()

// Check results
let buttonsInResultView = app.collectionViews.allElementsBoundByIndex[1].buttons
XCTAssertEqual(buttonsInResultView.count, 1)
buttonsInResultView.allElementsBoundByIndex[0].tap()
app.navigationBars.buttons["Back"].tap()

// Dismiss results view
app.swipeDown(velocity: XCUIGestureVelocity.fast)
}

func testGCSExample() throws {
let app = XCUIApplication()
app.launch()

let gcsExampleButton = app.collectionViews.buttons["Glasgow Coma Score"]

// Open questionnaire
gcsExampleButton.tap()

// Answer questions
app.tables.staticTexts["Oriented"].tap()
app.buttons["Next"].tap()

app.tables.staticTexts["Obeys commands"].tap()
app.buttons["Next"].tap()

app.tables.staticTexts["Eyes open spontaneously"].tap()
app.buttons["Next"].tap()

// Close the completion step
app.buttons["Done"].tap()

// Open context menu and view results
gcsExampleButton.press(forDuration: 1.0)
app.collectionViews.buttons["View Responses"].tap()

// Check results
let buttonsInResultView = app.collectionViews.allElementsBoundByIndex[1].buttons
XCTAssertEqual(buttonsInResultView.count, 1)
buttonsInResultView.allElementsBoundByIndex[0].tap()
app.navigationBars.buttons["Back"].tap()

// Dismiss results view
app.swipeDown(velocity: XCUIGestureVelocity.fast)
}

func testMultipleEnableWhenExampleWithAllAnswersCorrect() throws {
let app = XCUIApplication()
app.launch()
Expand Down
Loading

0 comments on commit dcd5f95

Please sign in to comment.