Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed procedure dates #14

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Sources/SpeziFHIR/Extensions/ConditionOnsetXR4+Date.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 Foundation
import ModelsR4


extension Condition.OnsetX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case let .period(period):
return period.date
case .age:
return nil
case .range:
return nil
case .string:
return nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 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
import ModelsR4


extension DiagnosticReport.EffectiveX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case let .period(period):
return period.date
}
}
}
22 changes: 22 additions & 0 deletions Sources/SpeziFHIR/Extensions/ImmunizationOccurrenceXR4+Date.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 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
import ModelsR4


extension Immunization.OccurrenceX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case .string:
return nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// 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
import ModelsR4


extension Period {
var date: Date? {
if let endDate = try? end?.value?.asNSDate() {
return endDate
}
if let startDate = try? start?.value?.asNSDate() {
return startDate
}
return nil
}
}
22 changes: 22 additions & 0 deletions Sources/SpeziFHIR/Extensions/PeriodR4+Date.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 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
import ModelsR4


extension MedicationAdministration.EffectiveX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case let .period(period):
return period.date
}
}
}
28 changes: 28 additions & 0 deletions Sources/SpeziFHIR/Extensions/ProcedurePerformedXR4+Date.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 Foundation
import ModelsR4


extension Procedure.PerformedX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case let .period(period):
return period.date
case .age:
return nil
case .range:
return nil
case .string:
return nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// 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
import ModelsR4


extension SupplyDelivery.OccurrenceX {
var date: Date? {
switch self {
case let .dateTime(date):
return try? date.value?.asNSDate()
case let .period(period):
return period.date
case .timing:
return nil
}
}
}
63 changes: 42 additions & 21 deletions Sources/SpeziFHIR/FHIRResource/FHIRResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,40 @@ public struct FHIRResource: Sendable, Identifiable, Hashable {
switch versionedResource {
case let .r4(resource):
switch resource {
case let carePlan as ModelsR4.CarePlan:
return carePlan.period?.date
case let careTeam as ModelsR4.CareTeam:
return careTeam.period?.date
case let claim as ModelsR4.Claim:
return try? claim.billablePeriod?.end?.value?.asNSDate()
case let condition as ModelsR4.Condition:
guard case let .dateTime(date) = condition.onset else {
return nil
}
return try? date.value?.asNSDate()
return condition.onset?.date
case let device as ModelsR4.Device:
return try? device.manufactureDate?.value?.asNSDate()
case let diagnosticReport as ModelsR4.DiagnosticReport:
guard case let .dateTime(date) = diagnosticReport.effective else {
return nil
}
return try? date.value?.asNSDate()
return diagnosticReport.effective?.date
case let documentReference as ModelsR4.DocumentReference:
return try? documentReference.date?.value?.asNSDate()
case let encounter as ModelsR4.Encounter:
return try? encounter.period?.end?.value?.asNSDate()
case let explanationOfBenefit as ModelsR4.ExplanationOfBenefit:
return try? explanationOfBenefit.billablePeriod?.end?.value?.asNSDate()
case let immunization as ModelsR4.Immunization:
guard case let .dateTime(date) = immunization.occurrence else {
return nil
}
return try? date.value?.asNSDate()
return immunization.occurrence.date
case let medicationRequest as ModelsR4.MedicationRequest:
return try? medicationRequest.authoredOn?.value?.asNSDate()
case let medicationAdministration as ModelsR4.MedicationAdministration:
return medicationAdministration.effective.date
case let observation as ModelsR4.Observation:
return try? observation.issued?.value?.asNSDate()
case let procedure as ModelsR4.Procedure:
guard case let .dateTime(date) = procedure.performed else {
return nil
}
return try? date.value?.asNSDate()
case is ModelsR4.Patient:
return .now
return procedure.performed?.date
case let patient as ModelsR4.Patient:
return try? patient.birthDate?.value?.asNSDate()
case let provenance as ModelsR4.Provenance:
return try? provenance.recorded.value?.asNSDate()
case let supplyDelivery as ModelsR4.SupplyDelivery:
return supplyDelivery.occurrence?.date
default:
return nil
}
Expand All @@ -92,16 +98,31 @@ public struct FHIRResource: Sendable, Identifiable, Hashable {
return try? observation.issued?.value?.asNSDate()
case let medicationOrder as ModelsDSTU2.MedicationOrder:
return try? medicationOrder.dateWritten?.value?.asNSDate()
case let medicationStatement as ModelsDSTU2.MedicationStatement:
guard case let .dateTime(date) = medicationStatement.effective else {
return nil
}
return try? date.value?.asNSDate()
case let condition as ModelsDSTU2.Condition:
guard case let .dateTime(date) = condition.onset else {
return nil
}
return try? date.value?.asNSDate()
case let procedure as ModelsDSTU2.Procedure:
guard case let .dateTime(date) = procedure.performed else {
return nil
switch procedure.performed {
case let .dateTime(date):
if let date = try? date.value?.asNSDate() {
return date
}
case let .period(period):
if let date = try? period.end?.value?.asNSDate() {
return date
}
default:
break
}
return try? date.value?.asNSDate()

return nil
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your task is to private a title and compact summary for an FHIR resource from the user's clinical record. You should provide the title and summary in the following locale: {{LOCALE}}.\n\nYour response should contain two lines without headings, markdown formatting, or any other structure beyond two lines. Directly provide the content without any additional structure or an introduction. Another computer program will parse the output.\n\n1. Line: A 1-5 Word summary of the FHIR resource that immediately identifies the resource and provides the essential information at a glance. Do NOT use a complete sentence; instead, use a formatting typically used for titles in computer systems.\n\n2. Line: Provide a short one-sentence summary of the resource in less than 40 words. Ensure that the summary only focuses on the essential information that a patient would need and, e.g., excludes the person who prescribed a medication or similar metadata. Ensure that all clinically relevant data is included, which allows us to use the summary in additional prompts where using the complete JSON might not be feasible.\n\nThe following JSON representation defines the FHIR resource that you should provide a title and summary for:\n\n{{FHIR_RESOURCE}}"
"value" : "Your task is to private a title and compact summary for an FHIR resource from the user's clinical record. You should provide the title and summary in the following locale: {{LOCALE}}.\n\nYour response should contain two lines without headings, markdown formatting, or any other structure beyond two lines. Directly provide the content without any additional structure or an introduction. Another computer program will parse the output.\n\n1. Line: A 1-5 Word summary of the FHIR resource that immediately identifies the resource and provides the essential information at a glance. Do NOT use a complete sentence; instead, use a formatting typically used for titles in computer systems.\n\n2. Line: Provide a short one-sentence summary of the resource in less than 100 words. Ensure that the summary only focuses on the essential information that a patient would need and, e.g., excludes the person who prescribed a medication or similar metadata. Ensure that all clinically relevant data is included, which allows us to use the summary in additional prompts where using the complete JSON might not be feasible.\n\nThe following JSON representation defines the FHIR resource that you should provide a title and summary for:\n\n{{FHIR_RESOURCE}}"
}
}
}
Expand Down