2020-05-08 17:49:14 +10:00
|
|
|
//
|
|
|
|
// Encounter+EncounterRecord.swift
|
|
|
|
// CovidSafe
|
|
|
|
//
|
|
|
|
// Copyright © 2020 Australian Government. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import CoreData
|
|
|
|
|
|
|
|
extension EncounterRecord {
|
|
|
|
|
|
|
|
func saveToCoreData() {
|
|
|
|
DispatchQueue.main.async {
|
2020-05-26 17:10:41 +10:00
|
|
|
guard let persistentContainer = EncounterDB.shared.persistentContainer else {
|
|
|
|
return
|
2020-05-08 17:49:14 +10:00
|
|
|
}
|
|
|
|
let managedContext = appDelegate.persistentContainer.viewContext
|
|
|
|
let entity = NSEntityDescription.entity(forEntityName: "Encounter", in: managedContext)!
|
|
|
|
let encounter = Encounter(entity: entity, insertInto: managedContext)
|
|
|
|
encounter.set(encounterStruct: self)
|
|
|
|
do {
|
|
|
|
try managedContext.save()
|
|
|
|
} catch {
|
|
|
|
print("Could not save. \(error)")
|
|
|
|
}
|
2020-05-18 12:43:53 +10:00
|
|
|
NotificationCenter.default.post(name: .encounterRecorded, object: nil)
|
2020-05-08 17:49:14 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|