Contents

HKVerifiableClinicalRecordQueryDescriptor

A query interface that provides one-time access to a SMART Health Card or EU Digital COVID Certificate using Swift concurrency.

Declaration

struct HKVerifiableClinicalRecordQueryDescriptor

Overview

Use HKVerifiableClinicalRecordQueryDescriptor to read verifiable clinical records.

// Calculate the start and end dates.
var sixMonthsAgo = DateComponents()
sixMonthsAgo.month = -6

let end = Date()
guard let start = Calendar.current.date(byAdding: sixMonthsAgo, to: end) else {
    fatalError("*** Unable to calculate a date using \(end) and \(sixMonthsAgo) ***")
}

// Create the predicate.
let lastSixMonthsPredicate =
HKQuery.predicateForVerifiableClinicalRecords(withRelevantDateWithin: DateInterval(start: start, end: end))

// Create the descriptor.
let healthRecordDescriptor = HKVerifiableClinicalRecordQueryDescriptor(
    recordTypes: [.covid19, .immunization],
    sourceTypes: [.smartHealthCard, .euDigitalCOVIDCertificate],
    predicate: lastSixMonthsPredicate)

// Asynchronously read the records.
let records = try await healthRecordDescriptor.result(for: store)

// Use the records here.
for record in records {
    print(record.recordTypes)
    print(record.itemNames)
    print(record.issuedDate)
    print(record.expirationDate ?? "No expiration date.")
}

When you call the descriptor’s result(for:) method, it creates and executes an HKVerifiableClinicalRecordQuery in the background, passing the results as an array of HKVerifiableClinicalRecord instances.

Unlike other HealthKit queries, you don’t need to request permission to read verifiable health records before using this descriptor. HealthKit prompts the user for permission to read the records each time your app runs the underlying query.

Topics

Creating Query Descriptors

Running Queries

Accessing Query Properties

Default Implementations

See Also

Clinical record queries