generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Prompts, Display Name, Date, and Summary Model (#13)
# Improve Prompts, Display Name, Date, and Summary Model ## ⚙️ Release Notes - Improve the summary and interpretation prompts - Better holistic to generate a display name that tries to inspect the resource for information - Best effort to determine the date of the FHIR resource - Improvement of the summary and interpretation models as `FHIRResourceProcesser` now has a generic `Content` type. ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
786cf34
commit d60882b
Showing
9 changed files
with
194 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Sources/SpeziFHIR/FHIRResource/ResourceProxy+DisplayName.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// 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 ModelsR4 | ||
|
||
|
||
extension ResourceProxy { | ||
/// Provides a best-effort human readable display name for the resource. | ||
public var displayName: String { | ||
switch self { | ||
case let .condition(condition): | ||
return condition.code?.text?.value?.string ?? resourceType | ||
case let .diagnosticReport(diagnosticReport): | ||
return diagnosticReport.code.coding?.first?.display?.value?.string ?? resourceType | ||
case let .encounter(encounter): | ||
return encounter.reasonCode?.first?.coding?.first?.display?.value?.string | ||
?? encounter.type?.first?.coding?.first?.display?.value?.string | ||
?? resourceType | ||
case let .immunization(immunization): | ||
return immunization.vaccineCode.text?.value?.string ?? resourceType | ||
case let .medicationRequest(medicationRequest): | ||
guard case let .codeableConcept(medicationCodeableConcept) = medicationRequest.medication else { | ||
return resourceType | ||
} | ||
return medicationCodeableConcept.text?.value?.string ?? resourceType | ||
case let .observation(observation): | ||
return observation.code.text?.value?.string ?? resourceType | ||
case let .procedure(procedure): | ||
return procedure.code?.text?.value?.string ?? resourceType | ||
case let .patient(patient): | ||
let name = (patient.name?.first?.given?.first?.value?.string ?? "") + (patient.name?.first?.family?.value?.string ?? "") | ||
guard !name.isEmpty else { | ||
return resourceType | ||
} | ||
return name | ||
default: | ||
return resourceType | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Sources/SpeziFHIRInterpretation/FHIRResourceProcesserError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// 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 Foundation | ||
|
||
|
||
enum FHIRResourceProcesserError: LocalizedError { | ||
case notParsableAsAString | ||
|
||
|
||
var errorDescription: String? { | ||
switch self { | ||
case .notParsableAsAString: | ||
String( | ||
localized: "Unable to parse result of the LLM prompt.", | ||
bundle: .module, | ||
comment: "Error thrown if the result can not be parsed in the underlying type." | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters