struct Treatment: Identifiable {
    let id = UUID()
    let treatmentId: Int
    let chandoan: String
    let chandoanICD10: String
    let chandoanKemTheo: String?
    let chandoanKemTheoICD10: String?
    let dmTreatmentTypeID: Int
    let dmTreatmentStatusID: Int
    let linhThuocTreatmentID: Int
    let masterTreatmentID: Int
    let userID: Int
    let userIDDieuDuong: Int?
    let treatmentUseDate: Date
    let treatmentCode: String
    let departmentID: Int
    let serviceDatas: [ServiceData]
    
    enum CodingKeys: String, CodingKey {
        case idtreatmentId = "treatmentid"
        case chandoan
        case chandoanICD10 = "chandoan_icd10"
        case chandoanKemTheo = "chandoan_kemtheo"
        case chandoanKemTheoICD10 = "chandoan_kemtheo_icd10"
        case dmTreatmentTypeID = "dm_treatmenttypeid"
        case dmTreatmentStatusID = "dm_treatmentstatusid"
        case linhThuocTreatmentID = "linhthuoc_treatmentid"
        case masterTreatmentID = "master_treatmentid"
        case userID = "userid"
        case userIDDieuDuong = "userid_dieuduong"
        case treatmentUseDate = "treatmentusedate"
        case treatmentCode = "treatmentcode"
        case departmentID = "departmentid"
        case serviceDatas = "servicedatas"
    }
}

struct ServiceData: Identifiable, Codable {
    var id = UUID()
    let servicedataid: Int
    let dmServicedataStatusID: Int?
    let dmServiceobjectidBHYT: Int?
    let dmServiceobjectid: Int?
    let departmentid: Int?
    let servicedatausedate: Date?
    let userid: Int?
    let servicedatanote: String?
    let tiepnhanUserid: Int?
    let tiepnhanServicedatadate: Date?
    let doUserid: Int?
    let doServicedatadate: Date?
    let endDate: Date?
    let dataSoluong: Double?
    let dataValue: String?
    let dataValueTbgpb: String?
    let dataValueLh: String?
    let servicename: String?
    let serviceunit: String?
    let serviceresultunit: String?
    let datareference: String?
    let dmServicegroupid: Int?
    let dmServicesubgroupid: Int?
    let dmServicedetailgroupid: Int?
    let dmReportGroupid: Int?
    let soLuong: Double?
    let donGia: Double?
    let donGiaBh: Double?
    let tyleTt: Double?
    let thanhTien: Double?
    let mucHuong: Double?
    let tNguonkhac: Double?
    let tBntt: Double?
    let tBhtt: Double?
    let tBncct: Double?
    let tNgoaids: Double?
    let traiTuyen: Double?
    let mediboxdocumentidChidinh: Int?
    let mediboxdocumentidKetqua: Int?
    let isStorefile: Int?
    let storefile1: String?
    let storefile2: String?
    let serviceDatas: [ServiceData]?
    
    var foreceColor: Color {
        switch dataValueLh {
        case "H":
            return .red
        case "L":
            return .blue
        default:
            return .secondary
        }
    }
    
    enum CodingKeys: String, CodingKey {
        case servicedataid
        case dmServicedataStatusID = "dm_servicedatastatusid"
        case dmServiceobjectidBHYT = "dm_serviceobjectid_bhyt"
        case dmServiceobjectid = "dm_serviceobjectid"
        case departmentid
        case servicedatausedate
        case userid
        case servicedatanote
        case tiepnhanUserid = "tiepnhan_userid"
        case tiepnhanServicedatadate = "tiepnhan_servicedatadate"
        case doUserid = "do_userid"
        case doServicedatadate = "do_servicedatadate"
        case endDate = "end_date"
        case dataSoluong = "data_soluong"
        case dataValue = "data_value"
        case dataValueTbgpb = "data_value_tbgpb"
        case dataValueLh = "data_value_lh"
        case servicename
        case serviceunit
        case serviceresultunit
        case datareference
        case dmServicegroupid = "dm_servicegroupid"
        case dmServicesubgroupid = "dm_servicesubgroupid"
        case dmServicedetailgroupid = "dm_servicedetailgroupid"
        case dmReportGroupid = "dm_report_groupid"
        case soLuong = "so_luong"
        case donGia = "don_gia"
        case donGiaBh = "don_gia_bh"
        case tyleTt = "tyle_tt"
        case thanhTien = "thanh_tien"
        case mucHuong = "muc_huong"
        case tNguonkhac = "t_nguonkhac"
        case tBntt = "t_bntt"
        case tBhtt = "t_bhtt"
        case tBncct = "t_bncct"
        case tNgoaids = "t_ngoaids"
        case traiTuyen = "trai_tuyen"
        case mediboxdocumentidChidinh = "mediboxdocumentid_chidinh"
        case mediboxdocumentidKetqua = "mediboxdocumentid_ketqua"
        case isStorefile = "is_storefile"
        case storefile1 = "storefile_1"
        case storefile2 = "storefile_2"
        case serviceDatas = "servicedatas"
    }
}