Skip to content

Instantly share code, notes, and snippets.

struct Person:Codable {
let display: String?
let reference: String
}
struct CodeableConcept:Codable {
let text:String
let coding:[[String:String]]
}
// MARK: VitalSign
struct VitalSign:Codable {
let id: String
let resourceType:String
let category:CodeableConcept
let code:CodeableConcept
let status:String
let encounter:[String: String]
// MARK: Procedure
struct Procedure:Codable {
let id: String
let resourceType:String
let code:CodeableConcept
let status:String
let encounter:[String: String]
let performedDateTime:String
// MARK: Medication
struct DosageInstruction: Codable {
let text:String?
let timing:[String:[String:String?]?]?
}
struct Medication:Codable {
let dateWritten:String
let status: String
// MARK: LabResult
struct ReferenceRange:Codable {
let low:ValueQuantity
let high:ValueQuantity
let text:String
}
struct ValueQuantity:Codable {
// MARK: Immunization
struct Immunization:Codable {
let id: String
let resourceType:String
let vaccineCode:CodeableConcept
let encounter:[String: String]
let requester:[String: String]
let date: String
// MARK: Condition
struct Condition:Codable {
let id: String
let resourceType:String
let asserter:Person
let category:[String: [[String: String]]]
let clinicalStatus: String
let code: CodeableConcept
// MARK: Allergy
struct Reaction:Codable {
let onset:String?
let manifestation:[[String: String]]
let severity:String
}
struct Allergy: Codable {
let id: String
func getRecordForType(type: HKClinicalTypeIdentifier, recordReadCompletionHandler:@escaping ([HKClinicalRecord]?) -> Void) {
guard let healthRecordType = HKObjectType.clinicalType(forIdentifier: type) else {
fatalError("*** Unable to create the record type ***")
}
let healthRecordQuery = HKSampleQuery(sampleType: healthRecordType, predicate: nil, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in
guard let actualSamples = samples else {
func getRecordUsingPredicateForAllergyType(recordReadCompletionHandler:@escaping ([HKClinicalRecord]?) -> Void) {
guard let healthRecordAllergyType = HKObjectType.clinicalType(forIdentifier: .allergyRecord) else {
fatalError("*** Unable to create the Allergy type ***")
}
let healthRecordPredicate = HKQuery.predicateForClinicalRecords(withFHIRResourceType: .allergyIntolerance)