Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed Nov 22, 2023
1 parent 67c73bd commit a44ac0a
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
.package(url: "https://github.com/StanfordBDHG/HealthKitOnFHIR", .upToNextMinor(from: "0.2.4")),
.package(url: "https://github.com/StanfordSpezi/Spezi", .upToNextMinor(from: "0.8.0")),
.package(url: "https://github.com/StanfordSpezi/SpeziHealthKit.git", .upToNextMinor(from: "0.4.0")),
.package(url: "https://github.com/StanfordSpezi/SpeziML.git", .upToNextMinor(from: "0.3.0"))
.package(url: "https://github.com/StanfordSpezi/SpeziML.git", branch: "publicModel")// .upToNextMinor(from: "0.3.0"))
],
targets: [
.target(
Expand Down
7 changes: 5 additions & 2 deletions Sources/SpeziFHIRInterpretation/FHIRResourceInterpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public class FHIRResourceInterpreter {
private let resourceProcesser: FHIRResourceProcesser


init(localStorage: LocalStorage, openAIComponent: OpenAIModel) {
/// - Parameters:
/// - localStorage: Local storage module that needs to be passed to the ``FHIRResourceInterpreter`` to allow it to cache interpretations.
/// - openAIModel: OpenAI module that needs to be passed to the ``FHIRResourceInterpreter`` to allow it to retrieve interpretations.
public init(localStorage: LocalStorage, openAIModel: OpenAIModel) {
self.resourceProcesser = FHIRResourceProcesser(
localStorage: localStorage,
openAIComponent: openAIComponent,
openAIModel: openAIModel,
storageKey: "FHIRResourceInterpreter.Interpretations",
prompt: FHIRPrompt.interpretation
)
Expand Down
8 changes: 4 additions & 4 deletions Sources/SpeziFHIRInterpretation/FHIRResourceProcesser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FHIRResourceProcesser {


private let localStorage: LocalStorage
private let openAIComponent: OpenAIModel
private let openAIModel: OpenAIModel
private let storageKey: String
private let prompt: FHIRPrompt

Expand All @@ -36,12 +36,12 @@ class FHIRResourceProcesser {

init(
localStorage: LocalStorage,
openAIComponent: OpenAIModel,
openAIModel: OpenAIModel,
storageKey: String,
prompt: FHIRPrompt
) {
self.localStorage = localStorage
self.openAIComponent = openAIComponent
self.openAIModel = openAIModel
self.storageKey = storageKey
self.prompt = prompt
self.results = (try? localStorage.read(storageKey: storageKey)) ?? [:]
Expand All @@ -54,7 +54,7 @@ class FHIRResourceProcesser {
return result
}

let chatStreamResults = try await openAIComponent.queryAPI(withChat: [systemPrompt(forResource: resource)])
let chatStreamResults = try await openAIModel.queryAPI(withChat: [systemPrompt(forResource: resource)])
var result = ""

for try await chatStreamResult in chatStreamResults {
Expand Down
7 changes: 5 additions & 2 deletions Sources/SpeziFHIRInterpretation/FHIRResourceSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public class FHIRResourceSummary {
private let resourceProcesser: FHIRResourceProcesser


init(localStorage: LocalStorage, openAIComponent: OpenAIModel) {
/// - Parameters:
/// - localStorage: Local storage module that needs to be passed to the ``FHIRResourceSummary`` to allow it to cache summaries.
/// - openAIModel: OpenAI module that needs to be passed to the ``FHIRResourceSummary`` to allow it to retrieve summaries.
public init(localStorage: LocalStorage, openAIModel: OpenAIModel) {
self.resourceProcesser = FHIRResourceProcesser(
localStorage: localStorage,
openAIComponent: openAIComponent,
openAIModel: openAIModel,
storageKey: "FHIRResourceSummary.Summaries",
prompt: FHIRPrompt.summary
)
Expand Down
28 changes: 28 additions & 0 deletions Tests/UITests/TestApp/ExampleModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// This source file is part of the Stanford Spezi open-source project
//
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

import Spezi
import SpeziFHIRInterpretation
import SpeziLocalStorage
import class SpeziOpenAI.OpenAIModule
import class SpeziOpenAI.OpenAIModel


class ExampleModule: Module {
@Dependency private var localStorage: LocalStorage
@Dependency private var openAI: OpenAIModule

@Model private var resourceSummary: FHIRResourceSummary
@Model private var resourceInterpreter: FHIRResourceInterpreter


func configure() {
resourceSummary = FHIRResourceSummary(localStorage: localStorage, openAIModel: openAI.model)
resourceInterpreter = FHIRResourceInterpreter(localStorage: localStorage, openAIModel: openAI.model)
}
}
4 changes: 3 additions & 1 deletion Tests/UITests/TestApp/TestAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import SwiftUI

class TestAppDelegate: SpeziAppDelegate {
override var configuration: Configuration {
Configuration(standard: FHIR()) { }
Configuration(standard: FHIR()) {
ExampleModule()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,77 @@ import XCTest


final class SpeziFHIRTests: XCTestCase {
func testSpeziFHIR() throws {
func testSpeziFHIRMockPatients() throws {
let app = XCUIApplication()
app.launch()

XCTAssert(app.staticTexts["Allergy Intolerances: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Conditions: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Diagnostics: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Encounters: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Immunizations: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Medications: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Observations: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Other Resources: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Procedures: 0"].waitForExistence(timeout: 2))

app.buttons["Select Mock Patient"].tap()

XCTAssert(app.buttons["Jamison785 Denesik803"].waitForExistence(timeout: 20))
app.buttons["Jamison785 Denesik803"].tap()

sleep(3)

app.navigationBars["Select Mock Patient"].buttons["Dismiss"].tap()

XCTAssert(app.staticTexts["Allergy Intolerances: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Conditions: 70"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Diagnostics: 205"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Encounters: 82"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Immunizations: 12"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Medications: 31"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Observations: 769"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Other Resources: 302"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Procedures: 106"].waitForExistence(timeout: 2))

app.buttons["Select Mock Patient"].tap()

XCTAssert(app.buttons["Maye976 Dickinson688"].waitForExistence(timeout: 20))
app.buttons["Maye976 Dickinson688"].tap()

sleep(3)

app.navigationBars["Select Mock Patient"].buttons["Dismiss"].tap()

XCTAssert(app.staticTexts["Allergy Intolerances: 0"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Conditions: 37"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Diagnostics: 113"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Encounters: 86"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Immunizations: 11"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Medications: 55"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Observations: 169"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Other Resources: 322"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Procedures: 225"].waitForExistence(timeout: 2))
}


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

XCTAssert(app.buttons["Settings"].waitForExistence(timeout: 2))
app.buttons["Settings"].tap()

XCTAssert(app.buttons["Summary Prompt"].waitForExistence(timeout: 2))
app.buttons["Summary Prompt"].tap()

XCTAssert(app.buttons["Save Prompt"].waitForExistence(timeout: 2))
app.buttons["Save Prompt"].tap()
app.navigationBars["Summary Prompt"].buttons["Prompt Settings"].tap()

XCTAssert(app.buttons["Interpretation Prompt"].waitForExistence(timeout: 2))
app.buttons["Interpretation Prompt"].tap()
app.navigationBars["Interpretation Prompt"].buttons["Prompt Settings"].tap()
app.navigationBars["Prompt Settings"].buttons["Dismiss"].tap()
}
}
15 changes: 15 additions & 0 deletions Tests/UITests/UITests.xcodeproj/TestApp.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
"containerPath" : "container:..\/..",
"identifier" : "SpeziFHIR",
"name" : "SpeziFHIR"
},
{
"containerPath" : "container:..\/..",
"identifier" : "SpeziFHIRHealthKit",
"name" : "SpeziFHIRHealthKit"
},
{
"containerPath" : "container:..\/..",
"identifier" : "SpeziFHIRInterpretation",
"name" : "SpeziFHIRInterpretation"
},
{
"containerPath" : "container:..\/..",
"identifier" : "SpeziFHIRMockPatients",
"name" : "SpeziFHIRMockPatients"
}
]
},
Expand Down
8 changes: 6 additions & 2 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
2F34D14E2B0CF1F1009300C1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F34D14D2B0CF1F1009300C1 /* ContentView.swift */; };
2F34D1502B0CF42F009300C1 /* PromptSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F34D14F2B0CF42F009300C1 /* PromptSettings.swift */; };
2F34D1522B0CF59A009300C1 /* MockPatientSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F34D1512B0CF59A009300C1 /* MockPatientSelection.swift */; };
2F34D1542B0D833F009300C1 /* ExampleModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F34D1532B0D833F009300C1 /* ExampleModule.swift */; };
2F35E9D62B015EB200CB89FF /* SpeziFHIRInterpretation in Frameworks */ = {isa = PBXBuildFile; productRef = 2F35E9D52B015EB200CB89FF /* SpeziFHIRInterpretation */; };
2F36AD33299DB72400B1077C /* FHIRMockDataStorageProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F36AD32299DB72400B1077C /* FHIRMockDataStorageProviderTests.swift */; };
2F6D139A28F5F386007C25D6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F6D139928F5F386007C25D6 /* Assets.xcassets */; };
Expand All @@ -34,6 +35,7 @@
2F34D14D2B0CF1F1009300C1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
2F34D14F2B0CF42F009300C1 /* PromptSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptSettings.swift; sourceTree = "<group>"; };
2F34D1512B0CF59A009300C1 /* MockPatientSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPatientSelection.swift; sourceTree = "<group>"; };
2F34D1532B0D833F009300C1 /* ExampleModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleModule.swift; sourceTree = "<group>"; };
2F36AD32299DB72400B1077C /* FHIRMockDataStorageProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FHIRMockDataStorageProviderTests.swift; sourceTree = "<group>"; };
2F6D139228F5F384007C25D6 /* TestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
2F6D139928F5F386007C25D6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -90,11 +92,12 @@
2F6D139428F5F384007C25D6 /* TestApp */ = {
isa = PBXGroup;
children = (
2FA7382B290ADFAA007ACEB9 /* TestApp.swift */,
2FD021DC299E0F2900E5B91B /* TestAppDelegate.swift */,
2F34D1532B0D833F009300C1 /* ExampleModule.swift */,
2F34D14D2B0CF1F1009300C1 /* ContentView.swift */,
2F34D1512B0CF59A009300C1 /* MockPatientSelection.swift */,
2F34D14F2B0CF42F009300C1 /* PromptSettings.swift */,
2FA7382B290ADFAA007ACEB9 /* TestApp.swift */,
2FD021DC299E0F2900E5B91B /* TestAppDelegate.swift */,
2F6D139928F5F386007C25D6 /* Assets.xcassets */,
);
path = TestApp;
Expand Down Expand Up @@ -248,6 +251,7 @@
files = (
2FA7382C290ADFAA007ACEB9 /* TestApp.swift in Sources */,
2FD021DD299E0F2900E5B91B /* TestAppDelegate.swift in Sources */,
2F34D1542B0D833F009300C1 /* ExampleModule.swift in Sources */,
2F34D1502B0CF42F009300C1 /* PromptSettings.swift in Sources */,
2F34D1522B0CF59A009300C1 /* MockPatientSelection.swift in Sources */,
2F34D14E2B0CF1F1009300C1 /* ContentView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziML.git",
"state" : {
"revision" : "b71b4a38ebfa066872435e44c09ff618da840ebe",
"version" : "0.3.0"
"branch" : "publicModel",
"revision" : "50dbb5f61fa88d200e80136040ddf021e40f4b8b"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D139128F5F384007C25D6"
BuildableName = "TestApp.app"
BlueprintName = "TestApp"
ReferencedContainer = "container:UITests.xcodeproj">
BlueprintIdentifier = "SpeziFHIR"
BuildableName = "SpeziFHIR"
BlueprintName = "SpeziFHIR"
ReferencedContainer = "container:../..">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
Expand All @@ -28,12 +28,54 @@
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SpeziFHIR"
BuildableName = "SpeziFHIR"
BlueprintName = "SpeziFHIR"
BlueprintIdentifier = "SpeziFHIRHealthKit"
BuildableName = "SpeziFHIRHealthKit"
BlueprintName = "SpeziFHIRHealthKit"
ReferencedContainer = "container:../..">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SpeziFHIRInterpretation"
BuildableName = "SpeziFHIRInterpretation"
BlueprintName = "SpeziFHIRInterpretation"
ReferencedContainer = "container:../..">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SpeziFHIRMockPatients"
BuildableName = "SpeziFHIRMockPatients"
BlueprintName = "SpeziFHIRMockPatients"
ReferencedContainer = "container:../..">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D139128F5F384007C25D6"
BuildableName = "TestApp.app"
BlueprintName = "TestApp"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down

0 comments on commit a44ac0a

Please sign in to comment.