<repo_name>armstj7/CAS757_AutomatedAdvagrafAdjustment<file_sep>/Test/File.swift
//
//  File.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-12.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

func getNow() -> String {
    let date = Date()
    let formatter = DateFormatter()
    formatter.dateFormat = "MMM d, yyyy"
    
    let now = formatter.string(from: date)
    return now
}

func getNowTimestamp() -> String {
    let date = Date()
    let formatter = DateFormatter()
    formatter.dateFormat = "MMM d, h:mm a"
    
    let now = formatter.string(from: date)
    return now
}
<file_sep>/Test/PatientListCell.swift
//
//  PatientListCell.swift
//  Test
//
//  Created by <NAME> on 2018-11-26.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class PatientListCell: UITableViewCell {


    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var patientDOBLabel: UILabel!
    
    
    func setPatient(_ patient: Patient){
        patientNameLabel.text = patient.getName()
        patientDOBLabel.text = patient.DOB
    }
}
<file_sep>/Test/PatientListScreenViewController.swift
//
//  PatientListScreenViewController.swift
//  Test
//
//  Created by <NAME> on 2018-11-26.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit
import FirebaseDatabase

class PatientListScreenViewController: UIViewController {

    @IBOutlet weak var patientTableView: UITableView!
    @IBOutlet weak var patientSearchBar: UISearchBar!
    
    var patients: [Patient] = []
    var allPatients: [Patient] = []
    var searching:Bool = false
    var filtering:Bool = false
    
    var ref:DatabaseReference?
    var databaseHandle:DatabaseHandle?
    
    var postData: [String] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        createPatientArray()
        
        /*
        var tempPatients: [Patient] = []
        let patient1 = Patient(firstName: "Harry", lastName:  "Potter", DOB: "June 05, 1980")
        let patient2 = Patient(firstName: "Hermione", lastName: "Granger", DOB: "Sept 19, 1979")
        let patient3 = Patient(firstName: "Ron", lastName: "Weasley", DOB: "Mar 1, 1980")
        let patient4 = Patient(firstName: "Albus", lastName: "Dumbledore", DOB: "August 8, 1881")
        let patient5 = Patient(firstName: "Minerva", lastName: "McGonagall", DOB: "c")
        
        tempPatients.append(patient1)
        tempPatients.append(patient2)
        tempPatients.append(patient3)
        tempPatients.append(patient4)
        tempPatients.append(patient5)
        
        self.allPatients = tempPatients
        self.patients = tempPatients
    */
        
    }

    func createPatientArray(){
        /*
        let patient1 = Patient(firstName: "Harry", lastName:  "Potter", DOB: "June 05, 1980")
         let patient2 = Patient(firstName: "Hermione", lastName: "Granger", DOB: "Sept 19, 1979")
         let patient3 = Patient(firstName: "Ron", lastName: "Weasley", DOB: "Mar 1, 1980")
         let patient4 = Patient(firstName: "Albus", lastName: "Dumbledore", DOB: "August 8, 1881")
         let patient5 = Patient(firstName: "Minerva", lastName: "McGonagall", DOB: "Oct 04, 1935")
         
         tempPatients.append(patient1)
         tempPatients.append(patient2)
         tempPatients.append(patient3)
         tempPatients.append(patient4)
         tempPatients.append(patient5)
         */
        
        ref = Database.database().reference()
        //get all patient data
        
        databaseHandle = ref?.child("Patients").observe(.value, with: {(snapshot) in
            var tempPatients: [Patient] = []
            
            for pat in snapshot.children.allObjects as! [DataSnapshot] {
                //getting values
                let patObject = pat.value as? [String: AnyObject]
                let tempPatient = setPatient(patObject: patObject!)
                tempPatients.append(tempPatient)
            }
            
            self.allPatients = tempPatients
            self.patients = tempPatients
            
            DispatchQueue.main.async {
                self.patientTableView.reloadData()
            }
            
        })
    }
    
    func filterPatientArray(allPatients: [Patient]) -> [Patient] {
        var tempPatients: [Patient] = []
        
        for patIndex in 0 ..< allPatients.count {
            if(allPatients[patIndex].getAlert()){
                tempPatients.append(allPatients[patIndex])
            }
        }
        
        /*
        let patient1 = Patient(firstName: "Harry", lastName:  "Potter", DOB: "June 05, 1980")
        let patient2 = Patient(firstName: "Hermione", lastName: "Granger", DOB: "Sept 19, 1979")
        let patient3 = Patient(firstName: "Ron", lastName: "Weasley", DOB: "Mar 1, 1980")
        
        tempPatients.append(patient1)
        tempPatients.append(patient2)
        tempPatients.append(patient3)
        */
        
        return tempPatients
    }

    @IBAction func switchViewAction(_ sender: UISegmentedControl) {
        switch sender.selectedSegmentIndex {
        case 0:
            filtering = false
            patients = allPatients
            
            if searching {
                patients = performPatientSearch()
            }
            
            UIView.transition(with: patientTableView, duration: 0.35, options: .transitionCrossDissolve , animations: {() -> Void in self.patientTableView.reloadData()}, completion: nil)
            //patientTableView.reloadData()
        default:
            filtering = true
            patients = filterPatientArray(allPatients: allPatients)
            
            if searching {
                patients = performPatientSearch()
            }
            UIView.transition(with: patientTableView, duration: 0.35, options: .transitionCrossDissolve , animations: {() -> Void in self.patientTableView.reloadData()}, completion: nil)
            //patientTableView.reloadData()
        }
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "PatientSegue" {
            let destVC = segue.destination as! TabBarController
            destVC.patient = sender as? Patient
        }
    }
}

extension PatientListScreenViewController: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return patients.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let patient = patients[(indexPath as NSIndexPath).row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "PatientListCell") as! PatientListCell
        
        cell.setPatient(patient)
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let patient = patients[(indexPath as NSIndexPath).row]
        performSegue(withIdentifier: "PatientSegue", sender: patient)
    }
}

extension PatientListScreenViewController: UISearchBarDelegate {
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        
        searching = true
        
        patients = performPatientSearch()
        
        patientTableView.reloadData()
    }
    
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        searching = false

        searchBar.text = ""
        
        if filtering {
            patients = filterPatientArray(allPatients: allPatients)
        } else {
            patients = allPatients
        }
        
        patientTableView.reloadData()
    }
    
    func performPatientSearch() -> [Patient] {
        var searchPatients: [Patient] = []

        if filtering {
            patients = filterPatientArray(allPatients: allPatients)
        } else {
            patients = allPatients
        }
        
        if(patientSearchBar.text!.isEmpty){
            searchPatients = patients
        } else {
            for rows in 0 ..< patients.count {
                if(patients[rows].getName().lowercased().contains(patientSearchBar.text!.lowercased())){
                    searchPatients.append(patients[rows])
                }
            }
        }
        
        return searchPatients
    }
}
<file_sep>/Test/PhysNotifScreen.swift
//
//  PhysNotifScreen.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit
import FirebaseDatabase

class PhysNotifScreen: UIViewController {
    
    @IBOutlet weak var notifTableView: UITableView!
    
    var ref:DatabaseReference?
    var databaseHandle:DatabaseHandle?
    
    
    var notifs: [Notification] = []
    var patient:Patient?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        createNotifArray()
        //notifs = createNotifArray()
        // Do any additional setup after loading the view.
    }

    func createNotifArray(){
        
        ref = Database.database().reference()
        
        databaseHandle = ref?.child("Notifications").child("1").observe(.value, with: {(snapshot) in
            var tempNotifs: [Notification] = []
            
            for notif in snapshot.children.allObjects as! [DataSnapshot] {
                //getting values
                let notifObject = notif.value as? [String: AnyObject]
                print(notifObject)
                
                if let doseObject = notifObject?["doseType"] as? [String: AnyObject] {
                    let notifText  = doseObject["text"]
                    let patientID  = doseObject["patientID"]
                    let dose = doseObject["dose"]
                    
                    let tempNotif = Notification(notifStr: notifText as! String, type: "dose", patientID: patientID as! String)
                    tempNotif.setDose(dose: Float(dose as! String)!)
                    tempNotifs.append(tempNotif)
                }
                
                if let rangeObject = notifObject?["rangeType"] as? [String: AnyObject] {
                    let notifText  = rangeObject["text"]
                    let patientID  = rangeObject["patientID"]
                    let rangeLow = rangeObject["rangeLow"]
                    let rangeHigh = rangeObject["rangeHigh"]
                    
                    let tempNotif = Notification(notifStr: notifText as! String, type: "range", patientID: patientID as! String)
                    tempNotif.setRange(rangeLow: Float(rangeLow as! String)!, rangeHigh: Float(rangeHigh as! String)!)
                    tempNotifs.append(tempNotif)
                }
                
            }
            
            self.notifs = tempNotifs
            
            DispatchQueue.main.async {
                self.notifTableView.reloadData()
            }
            
            //return tempNotifs
        })
    }
    
    func removeNotif(index:Int) {
        ref = Database.database().reference()
        
        ref?.child("Notifications").child("1").child(notifs[index].patientID).removeValue()
    }
    
    func updateValue(index:Int, attribute:String, value:String){
        ref = Database.database().reference()
        
        ref?.child("Patients").child(notifs[index].patientID).updateChildValues([attribute: value])
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "NotifSegue" {
            let destVC = segue.destination as! TabBarController
            destVC.patient = sender as? Patient
        }
    }

}

extension PhysNotifScreen: PhysNotifCellDelegate {
    func didTapAccept(_ cellIndex: Int){
        updateValue(index: cellIndex, attribute:"lastAdvagrafDose", value: String(notifs[cellIndex].dose))
        updateValue(index: cellIndex, attribute: "alert", value: "false")
        removeNotif(index: cellIndex)
        
        var ref:DatabaseReference?
        
        var tempString = "<NAME>"
        
        tempString += " changed the dose to "
        tempString += String(String(notifs[cellIndex].dose)) + "mg"
        tempString += " on " + getNow()
        
        let history = ["text": tempString]
        
        ref = Database.database().reference().child("History").child(notifs[cellIndex].patientID).childByAutoId()
        ref?.setValue(history)
        
        
        notifs.remove(at: cellIndex)
        notifTableView.reloadData()
        
    }
    
    func didTapDecline(_ cellIndex: Int){
        updateValue(index: cellIndex, attribute: "alert", value: "false")
        removeNotif(index: cellIndex)
        
        var ref:DatabaseReference?
        var tempString = "<NAME>"
        
        tempString += " declined changing the dose"
        tempString += " on " + getNow()
        
        let history = ["text": tempString]
        
        ref = Database.database().reference().child("History").child(notifs[cellIndex].patientID).childByAutoId()
        ref?.setValue(history)
        
        notifs.remove(at: cellIndex)
        notifTableView.reloadData()
        
    }
    
    func didTapSeePat(_ cellIndex: Int) {
        
        ref = Database.database().reference()
        
        ref?.child("Patients").child(notifs[cellIndex].patientID).observeSingleEvent(of: .value, with: {(snapshot) in
            
            let patObject = snapshot.value as? [String: AnyObject]
            
            let tempPatient = setPatient(patObject: patObject!)
            
            self.patient = tempPatient
            
            DispatchQueue.main.async {
                self.performSegue(withIdentifier: "NotifSegue", sender: self.patient)
            }
            
        })
    }
}

extension PhysNotifScreen: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return notifs.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let notif = notifs[(indexPath as NSIndexPath).row]
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "PhysNotifCell") as! PhysNotifCell
        
        cell.setNotif(notif, cellIndex: (indexPath as NSIndexPath).row)
        cell.delegate = self
        
        return cell
    }
}

    
<file_sep>/Test/EnterResultVC.swift
//
//  EnterResultVC.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-05.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class EnterResultVC: UIViewController {

    @IBOutlet weak var resultTextField: UITextField!
    
    var patient:Patient?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    @IBAction func submitTapped(_ sender: Any) {
       if(resultTextField.text != ""){
            if let result = Float(resultTextField.text!) {
                
                patient?.addBloodResult(result, entryDate: getNow())
        
                _ = self.navigationController?.popViewController(animated: true)
            }
        
        }
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
<file_sep>/Test/PhysNotifCell.swift
//
//  PhysNotifCell.swift
//  Test
//
//  Created by <NAME> on 2018-11-26.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

protocol PhysNotifCellDelegate {
    func didTapAccept(_ cellIndex: Int)
    func didTapDecline(_ cellIndex: Int)
    func didTapSeePat(_ cellIndex: Int)
}

class PhysNotifCell: UITableViewCell {
    
    @IBOutlet weak var notifText: UILabel!
    @IBOutlet weak var acceptNotif: UIButton!
    @IBOutlet weak var declineNotif: UIButton!
    @IBOutlet weak var seePatient: UIButton!
    
    var delegate: PhysNotifCellDelegate?
    var notif: Notification!
    var index:Int = 0
    
    func setNotif(_ notification: Notification, cellIndex: Int){
        notif = notification
        self.index = cellIndex
        notifText.text = notification.notifStr
    }
    
    
    @IBAction func acceptTapped(_ sender: AnyObject) {
        delegate?.didTapAccept(index)
    }
    
    @IBAction func declineTapped(_ sender: AnyObject) {
        delegate?.didTapDecline(index)
    }
        //update patient values
    @IBAction func seePatientTapped(_ sender: AnyObject) {
        delegate?.didTapSeePat(index)
    }
        
        //add to history
        
        //update notification variable
        
        //remove notification cell
    
}
<file_sep>/Test/Clinic.swift
//
//  Clinic.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Clinic {
    var clinicName:String
    var nurses:[Nurse] = []
    var doctors:[Doctor] = []
    
    init(clinicName:String){
        self.clinicName = clinicName
    }
    
    func addNurse(_ firstName: String, lastName: String, employeeID: Int){
        let nurse = Nurse(firstName: firstName, lastName: lastName, employeeID: employeeID)
        self.nurses.append(nurse)
    }
    
    func addDoctor(_ firstName: String, lastName: String, employeeID: Int){
        let doctor = Doctor(firstName: firstName, lastName: lastName, employeeID: employeeID)
        self.doctors.append(doctor)
    }
}
<file_sep>/Test/PatHistCell.swift
//
//  PatHistCell.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class PatHistCell: UITableViewCell {

    @IBOutlet weak var patHistLabel: UILabel!
    
    func setHist(_ history:History){
        patHistLabel.text = history.histStr
    }

}
<file_sep>/Test/setPatient.swift
//
//  setPatient.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-12.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

func setPatient(patObject:[String: AnyObject]) -> Patient {
    
    let patFirstName  = patObject["firstName"]
    let patLastName  = patObject["lastName"]
    let patDOB  = patObject["DOB"]
    let patAlert = patObject["alert"]
    let patientID = patObject["userID"]
    
    let patDoctorID  = patObject["doctorID"]
    let patDoctorName  = patObject["doctorName"]
    //let patientID  = patObject?["userID"]
    
    let tempPatient = Patient(firstName: patFirstName as! String, lastName: patLastName as! String, DOB: patDOB as! String, doctorID: patDoctorID as! String, doctorName: patDoctorName as! String)
    
    tempPatient.setPatientID(patientID as! String)
    tempPatient.setAlert(state: Bool(patAlert as! String)!)
    
    if let patMRN  = patObject["MRN"] as? String {
        tempPatient.setMRN(patMRN)
    }
    
    if let patTransDate  = patObject["transDate"] as? String {
        tempPatient.setTransDate(patTransDate)
    }
    
    if let patlastBloodResult  = patObject["lastBloodResult"] as? String {
        if let patDateBloodResult  = patObject["dateOfBloodResult"] as? String {
            tempPatient.setBloodResult(Float(patlastBloodResult)!, entryDate: patDateBloodResult)
        }
    }
    
    if let patBloodLow  = patObject["bloodRangeLow"] as? String {
        if let patBloodHigh  = patObject["bloodRangeHigh"] as? String {
            tempPatient.setBloodWorkRange(Float(patBloodLow)!, bloodWorkHigher: Float(patBloodHigh)!)
        }
    }
    
    //THIS DATE IS WRONG, FIX ME!!!!!!!!!!
    if let patLastAdvagrafDose  = patObject["lastAdvagrafDose"] as? String {
        tempPatient.setAdvagrafDose(Float(patLastAdvagrafDose)!, entryDate: "")
    }
    
    return tempPatient
}
<file_sep>/Test/Patient.swift
//
//  Patient.swift
//  Test
//
//  Created by <NAME> on 2018-11-26.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

/*
import Foundation

class Patient {
    
    var name: String
    var DOB: String
    
    init(name:String, DOB:String){
        self.name = name
        self.DOB = DOB
    }
}
*/

import UIKit
import FirebaseDatabase

class Patient:Person{
    var DOB:String
    var MRN:String = ""
    var transplantDate:String = ""
    var doctorID:String
    var doctorName:String
    var bloodWorkLower:Float = 0
    var bloodWorkHigher:Float = 0
    
    var patientID = ""
    var alert:Bool = false
    
    var advagrafDoses:[Dose] = []
    var bloodWorkResults:[BloodWorkResult] = []
    var historyEvents:[HistoryEvent] = []
    var doctorNotifcations:[DoctorNotification] = []
    
    init(firstName: String, lastName:String, DOB: String, doctorID:String, doctorName:String){
        self.DOB = DOB
        self.doctorID = doctorID
        self.doctorName = doctorName
        super.init()
        self.setName(firstName, lastName: lastName)
    }
    
    func setMRN(_ MRN: String){
        self.MRN = MRN
    }
    
    func setPatientID(_ patientID: String){
        self.patientID = patientID
    }
    
    func setTransDate(_ transplantDate: String){
        self.transplantDate = transplantDate
    }
    
    func setBloodWorkRange(_ bloodWorkLower:Float, bloodWorkHigher: Float){
        self.bloodWorkLower = bloodWorkLower
        self.bloodWorkHigher = bloodWorkHigher
    }
    
    func setBloodWorkRange(_ bloodWorkBoundary:Float, high:Int){
        if(high==0){
            self.bloodWorkLower = bloodWorkBoundary
        }else{
            self.bloodWorkHigher = bloodWorkBoundary
        }
    }
    
    func setAdvagrafDose(_ doseInMG:Float, entryDate:String){
        let advagrafDose = Dose(doseInMG: doseInMG, entryDate: entryDate)
        self.advagrafDoses.insert(advagrafDose, at: 0)
    }
    
    func addAdvagrafDose(_ doseInMG:Float, entryDate:String){
        var ref:DatabaseReference?
        
        let advagrafDose = Dose(doseInMG: doseInMG, entryDate: entryDate)
        
        self.advagrafDoses.insert(advagrafDose, at: 0)
        
        self.updateValue(attribute:"lastAdvagrafDose", value: String(doseInMG))
        self.updateValue(attribute: "alert", value: "false")
        
        ref = Database.database().reference()
        ref?.child("Notifications").child(self.doctorID).child(self.patientID).removeValue()
        
        self.addHistoryEvent(doctorName, action: "changed dose", entryDate: getNowTimestamp())
    }
    
    func declineDoseChange(entryDate:String){
        var ref:DatabaseReference?
        
        self.updateValue(attribute: "alert", value: "false")
        
        ref = Database.database().reference()
        ref?.child("Notifications").child(self.doctorID).child(self.patientID).removeValue()
        
        self.addHistoryEvent(doctorName, action: "declined dose", entryDate: getNowTimestamp())
    }
    
    func setBloodResult(_ result:Float, entryDate:String){
        let bloodWorkResult = BloodWorkResult(result: result, entryDate: entryDate)
        self.bloodWorkResults.insert(bloodWorkResult, at: 0)
    }
    
    func addBloodResult(_ result:Float, entryDate:String){
        let bloodWorkResult = BloodWorkResult(result: result, entryDate: entryDate)
        self.bloodWorkResults.insert(bloodWorkResult, at: 0)
        self.updateValue(attribute: "lastBloodResult", value: String(result))
        self.updateValue(attribute: "dateOfBloodResult", value: entryDate)
        self.addHistoryEvent(doctorName, action: "changed result", entryDate: getNowTimestamp())
        
        if !self.inRange() {
            self.updateValue(attribute: "alert", value: "true")
            self.addDoseChangeNotif("The app", dateSuggested: getNow(), newDose: self.suggestedDose())
            self.addHistoryEvent("The app", action: "suggested dose", entryDate: getNowTimestamp())
        }
    }
    
    func addHistoryEvent(_ actor:String, action:String, entryDate:String){
        var ref:DatabaseReference?
        
        //create text
        var tempString = actor
        switch action {
        case "suggested dose":
            tempString += " suggested changing the dose to "
            tempString += String(self.suggestedDose()) + "mg"
        break
        
        case "changed dose":
            tempString += " changed the dose to "
            tempString += String(self.advagrafDoses[0].doseInMG) + "mg"
        break
        
        case "declined dose":
            tempString += " declined changing the dose"
        break
        
        case "changed range":
            tempString += " changed the blood test range to "
            tempString += String(self.bloodWorkLower) + "-"
            tempString += String(self.bloodWorkHigher) + "ng/L"
        break
        
        case "changed result":
            tempString += " entered the new blood test result of "
            tempString += String(self.bloodWorkResults[0].result) + "ng/L"
        break
            
        default:
        break
        }
        
        tempString += " on " + getNow()
        
        let history = ["text": tempString]
        
        ref = Database.database().reference().child("History").child(self.patientID).childByAutoId()
        ref?.setValue(history)
    }
    
    func addDoseChangeNotif(_ suggester:String, dateSuggested:String, newDose:Float){
        var ref:DatabaseReference?
        
        //create text
        var tempString = suggester
        tempString += " suggested changing the Advagraf dose for "
        tempString += String(self.getName())
        tempString += " from " + String(self.advagrafDoses[0].doseInMG)
        tempString += " to " +  String(newDose)
        tempString += " on " + getNow()
        
        let notification = [
            "text": tempString,
            "dose": String(newDose),
            "patientID": self.patientID
        ]
        
        ref = Database.database().reference().child("Notifications").child(self.doctorID).child(self.patientID).child("doseType")
        ref?.setValue(notification)
        
    }
    
    func addRangeUpdateNotif(_ suggester:String, suggestType:Character, dateSuggested:String, newRangeLow:Float, newRangeHigh:Float){
        let doctorNotification = DoctorNotification(suggester: suggester, suggestType: suggestType, dateSuggested: dateSuggested, newRangeLow: newRangeLow, newRangeHigh: newRangeHigh)
        self.doctorNotifcations.insert(doctorNotification, at: 0)
    }
    
    func inRange() -> Bool {
        if(bloodWorkResults.isEmpty){
            return true
        } else {
            if(bloodWorkResults[0].result>=bloodWorkLower && bloodWorkResults[0].result<=bloodWorkHigher){
                return true
            } else {
                return false
            }
        }
    }
    
    func setAlert(state:Bool){
        self.alert = state
    }
    
    func getAlert() -> Bool {
        return self.alert
    }
    
    func suggestedDose() -> Float {
        let midRange = (bloodWorkLower + bloodWorkHigher)/2
        let adjustment:Float = (midRange/bloodWorkResults[0].result)
        
        var suggestedDose = round(adjustment*advagrafDoses[0].doseInMG*2)/2
        
        if (suggestedDose>25){
           suggestedDose = 25
        }
        
        
        return suggestedDose
    }
    
    func hasDoctorNotification() -> Bool {
        if (doctorNotifcations.isEmpty) {
            return false
        } else {
            for rows in 0 ..< doctorNotifcations.count {
                if(!doctorNotifcations[rows].approved){
                    return true
                }
            }
            return false
        }
    }
    
    //change to returning only indices??
    func getDoctorNotification() -> [DoctorNotification] {
        var tempNotification:[DoctorNotification] = []
        
        if !(doctorNotifcations.isEmpty) {
            for rows in 0 ..< doctorNotifcations.count {
                if(!doctorNotifcations[rows].approved){
                    tempNotification.append(doctorNotifcations[rows])
                }
            }
        }
        
        return tempNotification
    }
    
    func getPatientHistory() -> [String] {
        var tempStringArr:[String] = []
        
        for rows in 0..<historyEvents.count{
            tempStringArr.append(historyEvents[rows].getHistory())
        }
        
        return tempStringArr
    }
    
    func updateValue(attribute:String, value:String){
        var ref:DatabaseReference?
        
        ref = Database.database().reference()
        ref?.child("Patients").child(self.patientID).updateChildValues([attribute: value])
    }
}

class Dose {
    var doseInMG:Float
    var entryDate:String
    
    init(doseInMG:Float, entryDate:String){
        self.doseInMG = doseInMG
        self.entryDate = entryDate
    }
}

class BloodWorkResult {
    var result:Float
    var entryDate:String
    
    init(result:Float, entryDate:String){
        self.result = result
        self.entryDate = entryDate
    }
}

class HistoryEvent {
    var actor:String
    var actorType:Character
    var action:String
    var entryDate:String
    
    init(actor:String, actorType:Character, action:String, entryDate:String){
        self.actor = actor
        self.actorType = actorType
        self.action = action
        self.entryDate = entryDate
    }
    
    func getHistory () -> String {
        return (actor +  " " + action + " on " + entryDate)
    }
}

class DoctorNotification {
    var approved:Bool = false
    var suggester:String
    var suggestType:Character
    var dateSuggested:String
    
    var rangeChange:Bool = false
    var newRangeLow:Float = 0
    var newRangeHigh:Float = 0
    
    var doseChange:Bool = false
    var newDose:Float = 0
    
    init(suggester:String, suggestType:Character, dateSuggested:String, newRangeLow:Float, newRangeHigh:Float){
        self.suggester = suggester
        self.suggestType = suggestType
        self.dateSuggested = dateSuggested
        self.rangeChange = true
        self.newRangeLow = newRangeLow
        self.newRangeHigh = newRangeHigh
    }
    
    init(suggester:String, suggestType:Character, dateSuggested:String, newDose:Float){
        self.suggester = suggester
        self.suggestType = suggestType
        self.dateSuggested = dateSuggested
        self.doseChange = true
        self.newDose = newDose
    }
    
    func getNotification (_ patient:Patient) -> String {
        var tempString:String = ""
        
        tempString += suggester + " "
        
        if(doseChange){
            tempString += "changed the Advagraf dose for "
            tempString += patient.getName()
            tempString += " from " + (newRangeLow).description
            tempString += " to " + (newRangeHigh).description
        } else if (rangeChange) {
            
        }
        
        tempString += "on " + dateSuggested
        
        return tempString
    }
}


<file_sep>/Test/LoginScreen.swift
//
//  LoginScreen.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit
import FirebaseDatabase

class LoginScreen: UIViewController {

    @IBOutlet weak var usernameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    
    //var ref:DatabaseReference?
    
    override func viewDidLoad() {
        
        super.viewDidLoad()

        
        //ref = Database.database().reference()
        
        //ref?.child("Patients")
        //.setValue(["username": username])

        /*
        let postRef = ref?.child("Patients").childByAutoId()

        
         let patient = [
         "firstName":"Ginny",
         "lastName":"Weasley",
         "DOB":"-",
         "MRN":"9876543214RT",
         "transDate":"Nov 9, 2018",
         "lastBloodResult": "2",
         "dateOfBloodResult": "Nov 26, 2018",
         "bloodRangeLow": "3",
         "bloodRangeHigh": "6",
         "lastAdvagrafDose": "9",
         "doctorID": "2",
         "doctorName": "-",
         //"doctorName": "<NAME>",
         "userID": postRef?.key]
         
         postRef?.setValue(patient)
        
        */
        
        // Do any additional setup after loading the view.
    }

    @IBAction func loginTapped(_ sender: AnyObject) {
       // let username = usernameTextField.text
        //let password = passwordTextField.text
    }
    
}
<file_sep>/Test/Doctor.swift
//
//  Doctor.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Doctor:Provider{
    var patients:[Patient] = []
    
    init(firstName: String, lastName: String, employeeID: Int){
        super.init()
        self.setName(firstName, lastName: lastName)
        self.setID(employeeID)
    }
    
    
    func addPatient(_ firstName: String, lastName: String, DOB: String, MRN: String, transplantDate: String, bloodWorkLower:Float, bloodWorkHigher: Float){
        /*let patient = Patient(firstName: firstName, lastName: lastName, DOB: DOB, doctorID: String(self.employeeID))
        
        patient.setMRN(MRN)
        patient.setTransDate(transplantDate)
        patient.setBloodWorkRange(bloodWorkLower, bloodWorkHigher: bloodWorkHigher)
        
        self.patients.append(patient)*/
    }
}
<file_sep>/Test/PatientDetailScreen.swift
//
//  PatientDetailScreen.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit
import FirebaseDatabase

class PatientDetailScreen: UIViewController {

    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var patientDOBLabel: UILabel!
    @IBOutlet weak var patientMRNLabel: UILabel!
    @IBOutlet weak var patientDateofTransLabel: UILabel!
    
    @IBOutlet weak var resultDateLabel: UILabel!
    @IBOutlet weak var resultCurrentLabel: UILabel!
    @IBOutlet weak var resultRangeLabel: UILabel!
    
    @IBOutlet weak var advagrafDoseLabel: UILabel!
    @IBOutlet weak var doseAlertLabel: UILabel!
    @IBOutlet weak var doseSuggestionLabel: UILabel!
    
    @IBOutlet weak var acceptDoseButton: UIButton!
    @IBOutlet weak var declineDoseButton: UIButton!
    
    var patient: Patient?
    
    var ref:DatabaseReference?
    var databaseHandle:DatabaseHandle?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = tabBarController as! TabBarController
        self.patient = tabBar.patient
        
        updateView()
        //self.patient = setPatient(patObje)(tabBar.patient?.patientID)

        
        // Do any additional setup after loading the view.
    }
    
    func updateView(){
        ref = Database.database().reference()
        
        ref?.child("Patients").child((self.patient?.patientID)!).observe(.value, with: {(snapshot) in
            
            let patObject = snapshot.value as? [String: AnyObject]
            
            let tempPatient = setPatient(patObject: patObject!)
            
            self.patient = tempPatient
            
            DispatchQueue.main.async {
                self.setUI()
            }
            
        })
    }
    
    func setUI(){
        patientNameLabel.text = patient?.getName()
        patientDOBLabel.text = "Date of Birth: " + patient!.DOB
        patientMRNLabel.text = "OHIP: " + patient!.MRN
        patientDateofTransLabel.text = "Date of Transplant: " + patient!.transplantDate
        
        if(!patient!.bloodWorkResults.isEmpty){
            resultDateLabel.text = patient!.bloodWorkResults[0].entryDate
            resultCurrentLabel.text = (NSString(format: "%.1f",patient!.bloodWorkResults[0].result) as String) + "ng/mL"
        } else {
            resultDateLabel.text = ""
            resultCurrentLabel.text = "__ ng/L"
        }
        
        if(patient!.bloodWorkLower==0 && patient!.bloodWorkHigher==0){
            resultRangeLabel.text = "__ - __ ng/L"
        } else {
            resultRangeLabel.text = (NSString(format: "%.1f",patient!.bloodWorkLower) as String) + " - " + (NSString(format: "%.1f",patient!.bloodWorkHigher) as String) + "ng/mL"
        }
        
        if(!patient!.advagrafDoses.isEmpty){
            advagrafDoseLabel.text = (NSString(format: "%.1f",patient!.advagrafDoses[0].doseInMG) as String) + "mg"
        } else {
            advagrafDoseLabel.text = "__ mg"
        }
        
        if(!((patient?.getAlert())!)){
            self.hideAlert()
        } else {
            self.showAlert()
        }
    }
    
    @IBAction func acceptTapped(_ sender: Any) {
        patient?.addAdvagrafDose((patient?.suggestedDose())!, entryDate: getNow())
        updateView()
    }

    @IBAction func declineTapped(_ sender: Any) {
        patient?.declineDoseChange(entryDate: getNow())
        updateView()
    }
    
    @IBAction func enterResultTapped(_ sender: Any) {
        self.performSegue(withIdentifier: "ResultSegue", sender: self.patient)
    }
    
    @IBAction func updateRangeTapped(_ sender: Any) {
        self.performSegue(withIdentifier: "RangeSegue", sender: self.patient)
    }
    
    @IBAction func adjustDoseTapped(_ sender: Any) {
        self.performSegue(withIdentifier: "DoseSegue", sender: self.patient)
    }
    
    func hideAlert(){
        acceptDoseButton.isHidden = true
        declineDoseButton.isHidden = true
        doseAlertLabel.text = ""
        doseSuggestionLabel.text = ""
    }
    
    func showAlert(){
        acceptDoseButton.isHidden = false
        declineDoseButton.isHidden = false
        doseAlertLabel.text = "ALERT!"
        doseSuggestionLabel.text = "Suggestion: Change dose to " + (NSString(format: "%.1f",(patient?.suggestedDose())!) as String) + "mg"
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "ResultSegue" {
            let destVC = segue.destination as! EnterResultVC
            destVC.patient = sender as? Patient
        } else if segue.identifier == "DoseSegue" {
            let destVC = segue.destination as! EnterDoseVC
            destVC.patient = sender as? Patient
        } else if segue.identifier == "RangeSegue" {
            let destVC = segue.destination as! EnterRangeVC
            destVC.patient = sender as? Patient
        }
        
    }
    
    
    
}
<file_sep>/Test/History.swift
//
//  History.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class History {
    var histStr: String
    
    init(histStr:String){
        self.histStr = histStr
    }
}<file_sep>/Test/EnterRangeVC.swift
//
//  EnterRangeVC.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-11.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class EnterRangeVC: UIViewController {

    var patient:Patient?
    
    @IBOutlet weak var rangeLowTF: UITextField!
    @IBOutlet weak var rangeHighTF: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    @IBAction func submitTapped(_ sender: Any) {
        var updated = false
        
        if(rangeLowTF.text != ""){
            if let rangeLow = Float(rangeLowTF.text!) {
                patient?.updateValue(attribute: "bloodRangeLow", value: String(rangeLow))
                patient?.setBloodWorkRange(rangeLow, high: 0)
                updated = true
            }
        }
        
        if(rangeHighTF.text != ""){
            if let rangeHigh = Float(rangeHighTF.text!) {
                patient?.updateValue(attribute: "bloodRangeHigh", value: String(rangeHigh))
                patient?.setBloodWorkRange(rangeHigh, high: 1)
                updated = true
            }
            
        }
        
        if(updated){
            patient?.addHistoryEvent((patient?.doctorName)!, action: "changed range", entryDate: getNowTimestamp())
            _ = self.navigationController?.popViewController(animated: true)
            
        }
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
<file_sep>/Test/Nurse.swift
//
//  Nurse.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Nurse:Provider{
    
    init(firstName: String, lastName: String, employeeID: Int){
        super.init()
        self.setName(firstName, lastName: lastName)
        self.setID(employeeID)
    }
}<file_sep>/Test/Provider.swift
//
//  Provider.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Provider:Person{
    var employeeID:Int = 0
    
    func setID(_ employeeID:Int){
        self.employeeID = employeeID
    }
}
<file_sep>/Test/Notification.swift
//
//  Notification.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Notification{
    var notifStr: String
    var type:String
    var patientID:String
    var dose:Float = 0
    var rangeLow:Float = 0
    var rangeHigh:Float = 0
    
    init(notifStr:String, type:String, patientID:String){
        self.notifStr = notifStr
        self.type = type
        self.patientID = patientID
    }
    
    func setDose(dose:Float){
        self.dose = dose
    }
    
    func setRange(rangeLow:Float, rangeHigh:Float){
        self.rangeLow = rangeLow
        self.rangeHigh = rangeHigh
    }
    
    func acceptNotif(patient: Patient){
        //update patient values
        if(type=="dose"){
            patient.addAdvagrafDose(dose, entryDate: "")
        } else {
            patient.setBloodWorkRange(rangeLow, bloodWorkHigher: rangeHigh)
        }
        
        //remove warning
        
        //add to patient history
        
    }
    
    func declineNotif(){
        //remove warning
        
        //add to patient history
        
    }
    
    func addNotif(patient: Patient, rangeLow:Float, rangeHigh:Float){
        //create text
        
        //write to database
        
    }

    func addNotif(patient: Patient, dose:Float){
        //create text
        
        //write to database
        
    }
    
}
<file_sep>/Test/PatientHistoryScreen.swift
//
//  PatientHistoryScreen.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit
import FirebaseDatabase

class PatientHistoryScreen: UIViewController {
    
    @IBOutlet weak var patHistTableView: UITableView!
    
    @IBOutlet weak var patientDOBLabel: UILabel!
    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var patientMRNLabel: UILabel!
    @IBOutlet weak var patientDateofTransLabel: UILabel!
    
    var ref:DatabaseReference?
    var databaseHandle:DatabaseHandle?
    
    var histories: [History] = []
    var patient:Patient!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = tabBarController as! TabBarController
        self.patient = tabBar.patient
        
        setUI()
        
        createHistArray()
        
        // Do any additional setup after loading the view.
    }
    
    func setUI(){
        patientNameLabel.text = patient?.getName()
        patientDOBLabel.text = "Date of Birth: " + patient!.DOB
        patientMRNLabel.text = "OHIP: " + patient!.MRN
        patientDateofTransLabel.text = "Date of Transplant: " + patient!.transplantDate
        
    }
    
    func createHistArray() {
        
        ref = Database.database().reference()
        
        ref?.child("History").child(patient.patientID).observe(.value, with: { (snapshot) in
            var tempHists: [History] = []
            
            for history in snapshot.children.allObjects as! [DataSnapshot] {
                //getting values
                let historyObject = history.value as? [String: AnyObject]
                let text = historyObject?["text"]
                
                let tempHist = History(histStr: text as! String)
                tempHists.append(tempHist)
            }
            
            self.histories = tempHists
            
            DispatchQueue.main.async {
                self.patHistTableView.reloadData()
            }
        })
    }
}


extension PatientHistoryScreen: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return histories.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let history = histories[(indexPath as NSIndexPath).row]
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "PatHistCell") as! PatHistCell
        
        cell.setHist(history)
        
        return cell
    }
}


<file_sep>/Test/PatientStatsScreen.swift
//
//  PatientStatsScreen.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-06.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class PatientStatsScreen: UIViewController {

    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var patientDOBLabel: UILabel!
    @IBOutlet weak var patientMRNLabel: UILabel!
    @IBOutlet weak var patientDateofTransLabel: UILabel!
    
    var patient:Patient!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = tabBarController as! TabBarController
        self.patient = tabBar.patient
        
        setUI()
        
        // Do any additional setup after loading the view.
    }
    
    func setUI(){
        patientNameLabel.text = patient?.getName()
        patientDOBLabel.text = "Date of Birth: " + patient!.DOB
        patientMRNLabel.text = "OHIP: " + patient!.MRN
        patientDateofTransLabel.text = "Date of Transplant: " + patient!.transplantDate
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
<file_sep>/Test/TabBarController.swift
//
//  TabBarController.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class TabBarController: UITabBarController {

    var patient:Patient?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

}
<file_sep>/Test/EnterDoseVC.swift
//
//  EnterDoseVC.swift
//  AdvagrafApp
//
//  Created by <NAME> on 2018-12-11.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import UIKit

class EnterDoseVC: UIViewController {

    var patient:Patient?
    
    @IBOutlet weak var doseTextField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    @IBAction func submitTapped(_ sender: Any) {
        if(doseTextField.text != ""){
            if let dose = Float(doseTextField.text!) {
                /*let date = Date()
                let formatter = DateFormatter()
                formatter.dateFormat = "MMM d, yyyy"
                
                let now = formatter.string(from: date)*/
                
                patient?.addAdvagrafDose(dose, entryDate: getNow())
                _ = self.navigationController?.popViewController(animated: true)
            }
        }
    }
    
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
<file_sep>/Test/Person.swift
//
//  Person.swift
//  Test
//
//  Created by <NAME> on 2018-11-27.
//  Copyright © 2018 CAS757_Group6. All rights reserved.
//

import Foundation

class Person{
    var firstName:String = ""
    var lastName:String = ""
    
    init(){
        
    }
    
    func setName(_ firstName: String, lastName: String){
        self.firstName = firstName
        self.lastName = lastName
    }
    
    func getName() -> String {
        return (firstName + " " + lastName)
    }
}
