# -*- coding: utf-8 -*-

# from lxml import etree
from bs4 import BeautifulSoup


from django.db import models
from django.utils.text import slugify

# Create your models here.

class MHCT_PAYITEM_NEW_2(models.Model):
    Q2ID      = models.CharField(max_length=12, primary_key=True)
    Number    = models.IntegerField(null=True)
    StartDate = models.IntegerField(null=True)
    EndDate   = models.IntegerField(null=True)
    EngName   = models.TextField   (null=True)
    ChtName   = models.TextField   (null=True)
    Memo      = models.TextField   (null=True)

    categories= models.ManyToManyField('categories.Category')
    
    def __unicode__(self):
        return '%s %s' % (self.Q2ID, self.ChtName)

class DischargeNote(models.Model):
    ChartNo           = models.CharField(max_length=10, null=True, db_index=True)

    HospName          = models.CharField(max_length=10, null=True)
    DeptName          = models.CharField(max_length=10, null=True)
    InDate            = models.DateField(null=True)
    OutDate           = models.DateField(null=True)
    WardName          = models.CharField(max_length=10, null=True)
    RoomName          = models.CharField(max_length=10, null=True)
    BedName           = models.CharField(max_length=10, null=True)
    MainDrName        = models.CharField(max_length=10, null=True)
    MainDiagnosisName = models.CharField(max_length=200, null=True)
    StatusName        = models.CharField(max_length=10, null=True)
#    ShowDischargeNote = models.CharField(max_length=100, null=True)
    
    AccountIDSE       = models.CharField(max_length=20, primary_key=True)
    Func              = models.CharField(max_length=20, null=True)
    KeyCodeList       = models.TextField(               null=True)
    KeyNameList       = models.TextField(               null=True)
    HTML              = models.TextField(               null=True)

    Created           = models.DateTimeField(auto_now_add = True)
    Saved             = models.DateTimeField(auto_now = True)



class Inpatient(models.Model):
    Ward         = models.CharField(max_length=10, null=True)
    Room         = models.CharField(max_length=10, null=True)
    Bed          = models.CharField(max_length=10, null=True)
    Name         = models.CharField(max_length=50, null=True)
    ChartNo      = models.CharField(max_length=10, primary_key=True)
    Sex          = models.CharField(max_length=10, null=True)
    Birthday     = models.DateField(null=True)
    Age          = models.CharField(max_length=10, null=True)
    HospitalDays = models.IntegerField(null=True)
    Enter        = models.DateField(null=True)

    Created      = models.DateTimeField(auto_now_add = True)
    Saved        = models.DateTimeField(auto_now = True)
            


#姓名：蕭輔仁　員工ID：004552　手機：0972651905　手機簡碼：51905　科部：外科部　成本中心：12140(腦神經外科)

class Physician(models.Model):
    Name            = models.CharField(max_length=10)
    EmployeeID      = models.CharField(max_length=10, primary_key=True)
    Phone           = models.CharField(max_length=10)
    MobileShortCode = models.CharField(max_length=10)
    BranchOf        = models.CharField(max_length=10)
    CostCenter      = models.CharField(max_length=20)
       

class Holiday(models.Model):
    date     = models.DateField(primary_key=True)
    name     = models.CharField(max_length=10, null=True)
    worktill = models.TimeField(blank=True,    null=True)

    def __unicode__(self):
        return '%s %s %s' % (self.date, self.name, self.worktill)
    

class PathologyReport(models.Model):
    ChartNo         = models.IntegerField(             null=True, verbose_name='病歷號', db_index=True)
    ReportKey       = models.CharField(max_length=50,  null=True)
    ReportCode      = models.CharField(max_length=20,  null=True)
    PersonID        = models.CharField(max_length=10,  null=True,                      db_index=True)

    PathCode        = models.CharField(max_length=10,             verbose_name='病理號', primary_key=True) 
    SpecimenGetDate = models.DateField(                null=True, verbose_name='收件日')
    ReportDate      = models.DateTimeField(            null=True, verbose_name='報告日')
    url             = models.TextField(                null=True)
    html            = models.TextField(                null=True)

class XrayTextReport(models.Model):
    ChartNo         = models.CharField(max_length=7,  null=True, verbose_name='病歷號', db_index=True)
    ReportKey       = models.CharField(max_length=50,                                  primary_key=True)
    ReportCode      = models.CharField(max_length=20,  null=True)
    PersonID        = models.CharField(max_length=10,  null=True,                      db_index=True)

    OrderDesc       = models.TextField(                           verbose_name='報告類別')
    ExamDate        = models.DateField(                null=True, verbose_name='檢查日期')
    ReportDate      = models.DateField(                null=True, verbose_name='報告日期')

    Exam            = models.TextField(                null=True)
    Impression      = models.TextField(                null=True)

    url             = models.TextField(                null=True)
    html            = models.TextField(                null=True)


class OPNote(models.Model):
#    patient     = models.ForeignKey(Patient)
    # PatChartNo   = models.IntegerField(null=True)
    PatChartNo   = models.CharField(max_length=7, db_index=True)
    KeyCode     = models.CharField(max_length=200,            primary_key=True)
    KeyName     = models.CharField(max_length=200, null=True)
    department  = models.CharField(max_length=200, null=True, verbose_name='手術科部')
    date        = models.DateField(                null=True, verbose_name='手術日期')
    content     = models.TextField(                null=True, verbose_name='手術紀錄')


    def get_metadata(self):
        # html = etree.HTML(self.content)
        # result = html.xpath('//*[@id="TableScheduleBasicInfo"]/tbody/tr[1]/td')
        # print(result)
        # print(type(result))

        soup = BeautifulSoup(self.content)

        TD = soup.find_all('td')

        TDTEXT = []

        for td in TD:
            TDTEXT.append(td.text)

        # print(TD)

        r = {'info': TDTEXT[0]}
        for i in range(len(TDTEXT)-1):
            if len(TDTEXT[i]) < 99:
                r[slugify(TDTEXT[i], allow_unicode=True)] = TDTEXT[i+1]

        # print(r)

        return r





class OPSchedule(models.Model):
#日期    房    序    姓名    病房    病    性    齡    診斷    術式    DR    類    帳    麻    起    費
    id = models.CharField(max_length=50, primary_key=True)
    
    OPDate          = models.DateField(null=True)
    OpRoomNo        = models.CharField(max_length=10, null=True)
    OpSeqNo         = models.IntegerField(null=True)
    PatName         = models.CharField(max_length=50, null=True)
    PatWard         = models.CharField(max_length=50, null=True)
    # PatChartNo      = models.IntegerField(null=True)
    PatChartNo      = models.CharField(max_length=7, db_index=True)
    PatSex          = models.CharField(max_length=50, null=True)
    PatAge          = models.CharField(max_length=50, null=True)
    PatDignosis     = models.CharField(max_length=200, null=True)
    MainOpModeTitle = models.CharField(max_length=200, null=True)
    MainOpMode      = models.CharField(max_length=200, null=True)
    OpDoctorName    = models.CharField(max_length=50, null=True)
    OpTypeName      = models.CharField(max_length=50, null=True)
    Complete        = models.CharField(max_length=50, null=True)
    Anes            = models.CharField(max_length=50, null=True)
    StartTime       = models.TimeField(max_length=50, null=True)
    SpendTime       = models.IntegerField(null=True)
    
    category  = models.ForeignKey('categories.Category', null=True, on_delete=models.CASCADE)
    Memo      = models.CharField(max_length=50, null=True)
    Morbidity = models.CharField(max_length=50, null=True)
    Mortality = models.CharField(max_length=50, null=True)
   
    Remark    = models.CharField(max_length=200, null=True)

#class Picture(models.Model):
#
#    # This is a small demo using just two fields. The slug field is really not
#    # necessary, but makes the code simpler. ImageField depends on PIL or
#    # pillow (where Pillow is easily installable in a virtualenv. If you have
#    # problems installing pillow, use a more generic FileField instead.
#
#    #file = models.FileField(upload_to="pictures")
#    file = models.ImageField(upload_to="pictures")
#    slug = models.SlugField(max_length=50, blank=True)
#
#    OPDate          = models.DateField(null=True)
#    PatChartNo      = models.IntegerField(null=True)
#
#    def __unicode__(self):
#        return self.file
#
#    @models.permalink
#    def get_absolute_url(self):
#        return ('upload-new', )
#
#    def save(self, *args, **kwargs):
#        self.slug = self.file.name
#        super(Picture, self).save(*args, **kwargs)
#
#    def delete(self, *args, **kwargs):
#        self.file.delete(False)
#        super(Picture, self).delete(*args, **kwargs)


# 上/下午 -> On_afternoon
class On_afternoon(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    On_afternoon = models.CharField(max_length=50, db_column=u"上/下午", verbose_name=u"上/下午")
    class Meta:
        db_table = u'上/下午'

# 主治醫師 -> Doctor_in_charge
class Doctor_in_charge(models.Model):
    Doctor_in_charge_numbers = models.AutoField(primary_key=True, db_column=u"主治醫師編號", verbose_name=u"主治醫師編號")
    Name = models.CharField(max_length=50, db_column=u"名字", verbose_name=u"名字")
    Rank = models.IntegerField(db_column=u"等級", verbose_name=u"等級")
    Abbreviation = models.CharField(max_length=50, db_column=u"簡稱", verbose_name=u"簡稱")
    ID = models.CharField(max_length=50, db_column=u"ID", verbose_name=u"ID")
    House_telephone = models.CharField(max_length=30, db_column=u"住家電話", verbose_name=u"住家電話")
    Work_extension_telephone = models.CharField(max_length=20, db_column=u"工作分機", verbose_name=u"工作分機")
    Callmaker = models.CharField(max_length=50, db_column=u"呼叫器", verbose_name=u"呼叫器")
    Mobile_phone = models.CharField(max_length=30, db_column=u"行動電話", verbose_name=u"行動電話")
    Date_of_birth = models.DateTimeField(db_column=u"出生日期", verbose_name=u"出生日期")
    Picture = models.TextField(db_column=u"照片", verbose_name=u"照片")
    The_second_telephone = models.CharField(max_length=30, db_column=u"第二支電話", verbose_name=u"第二支電話")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    Identification_card_number = models.CharField(max_length=50, db_column=u"身分證號碼", verbose_name=u"身分證號碼")
    Doctor_s_license = models.CharField(max_length=50, db_column=u"醫師執照", verbose_name=u"醫師執照")
    Outside_god_specially = models.CharField(max_length=50, db_column=u"神外專", verbose_name=u"神外專")
    class Meta:
        db_table = u'主治醫師'

# 主治醫師及其他 -> Doctor_in_charge_and_other
class Doctor_in_charge_and_other(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Name = models.CharField(max_length=50, db_column=u"名字", verbose_name=u"名字")
    Rank = models.IntegerField(db_column=u"等級", verbose_name=u"等級")
    Abbreviation = models.CharField(max_length=50, db_column=u"簡稱", verbose_name=u"簡稱")
    ID = models.CharField(max_length=50, db_column=u"ID", verbose_name=u"ID")
    House_telephone = models.CharField(max_length=30, db_column=u"住家電話", verbose_name=u"住家電話")
    Work_extension_telephone = models.CharField(max_length=20, db_column=u"工作分機", verbose_name=u"工作分機")
    Callmaker = models.CharField(max_length=50, db_column=u"呼叫器", verbose_name=u"呼叫器")
    Mobile_phone = models.CharField(max_length=30, db_column=u"行動電話", verbose_name=u"行動電話")
    Date_of_birth = models.DateTimeField(db_column=u"出生日期", verbose_name=u"出生日期")
    Picture = models.TextField(db_column=u"照片", verbose_name=u"照片")
    The_second_telephone = models.CharField(max_length=30, db_column=u"第二支電話", verbose_name=u"第二支電話")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'主治醫師及其他'

# 主治醫師等級 -> Doctor_in_charge_rank
class Doctor_in_charge_rank(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Rank = models.CharField(max_length=50, db_column=u"等級", verbose_name=u"等級")
    Branch_expense = models.IntegerField(db_column=u"科費", verbose_name=u"科費")
    The_receipt_gains_ground = models.CharField(max_length=50, db_column=u"收據抬頭", verbose_name=u"收據抬頭")
    class Meta:
        db_table = u'主治醫師等級'

# 主治醫師請假記錄 -> Doctor_in_charge_asks_for_leave
class Doctor_in_charge_asks_for_leave(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Doctor_in_charge_numbers_1 = models.IntegerField(db_column=u"主治醫師編號1", verbose_name=u"主治醫師編號1")
    Doctor_in_charge_numbers_2 = models.IntegerField(db_column=u"主治醫師編號2", verbose_name=u"主治醫師編號2")
    Destination = models.CharField(max_length=50, db_column=u"目的地", verbose_name=u"目的地")
    Gets_up_the_date = models.DateTimeField(db_column=u"起日", verbose_name=u"起日")
    Up_to_date = models.DateTimeField(db_column=u"迄日", verbose_name=u"迄日")
    The_generation_examines_the_date = models.CharField(max_length=50, db_column=u"代診日", verbose_name=u"代診日")
    Stops_the_knife_date = models.CharField(max_length=50, db_column=u"停刀日", verbose_name=u"停刀日")
    Prepares_forgets = models.TextField(db_column=u"備忘", verbose_name=u"備忘")
    class Meta:
        db_table = u'主治醫師請假記錄'

# 住院醫師 -> Resident
class Resident(models.Model):
    Resident_numbers = models.AutoField(primary_key=True, db_column=u"住院醫師編號", verbose_name=u"住院醫師編號")
    Name = models.CharField(max_length=255, db_column=u"名字", verbose_name=u"名字")
    Rank = models.IntegerField(db_column=u"等級", verbose_name=u"等級")
    ID = models.CharField(max_length=255, db_column=u"ID", verbose_name=u"ID")
    This_month_attends_the_surgery = models.IntegerField(db_column=u"本月參加手術", verbose_name=u"本月參加手術")
    Abbreviation = models.CharField(max_length=255, db_column=u"簡稱", verbose_name=u"簡稱")
    Home_use_telephone = models.CharField(max_length=255, db_column=u"家用電話", verbose_name=u"家用電話")
    PHS_Jan_Ma = models.CharField(max_length=255, db_column=u"PHS簡碼", verbose_name=u"PHS簡碼")
    Callmaker = models.CharField(max_length=255, db_column=u"呼叫器", verbose_name=u"呼叫器")
    Mobile_phone = models.CharField(max_length=255, db_column=u"行動電話", verbose_name=u"行動電話")
    Date_of_birth = models.CharField(max_length=255, db_column=u"出生日期", verbose_name=u"出生日期")
    Picture = models.CharField(max_length=255, db_column=u"照片", verbose_name=u"照片")
    The_second_telephone = models.CharField(max_length=255, db_column=u"第二支電話", verbose_name=u"第二支電話")
    Note = models.CharField(max_length=255, db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'住院醫師'

# 住院醫師2001 -> Resident_2001
class Resident_2001(models.Model):
    Resident_numbers = models.AutoField(primary_key=True, db_column=u"住院醫師編號", verbose_name=u"住院醫師編號")
    Name = models.CharField(max_length=50, db_column=u"名字", verbose_name=u"名字")
    Rank = models.IntegerField(db_column=u"等級", verbose_name=u"等級")
    ID = models.CharField(max_length=50, db_column=u"ID", verbose_name=u"ID")
    This_month_attends_the_surgery = models.IntegerField(db_column=u"本月參加手術", verbose_name=u"本月參加手術")
    Abbreviation = models.CharField(max_length=50, db_column=u"簡稱", verbose_name=u"簡稱")
    Home_use_telephone = models.CharField(max_length=50, db_column=u"家用電話", verbose_name=u"家用電話")
    Work_extension_telephone = models.CharField(max_length=30, db_column=u"工作分機", verbose_name=u"工作分機")
    Callmaker = models.CharField(max_length=50, db_column=u"呼叫器", verbose_name=u"呼叫器")
    Mobile_phone = models.CharField(max_length=50, db_column=u"行動電話", verbose_name=u"行動電話")
    Date_of_birth = models.DateTimeField(db_column=u"出生日期", verbose_name=u"出生日期")
    Picture = models.TextField(db_column=u"照片", verbose_name=u"照片")
    The_second_telephone = models.CharField(max_length=50, db_column=u"第二支電話", verbose_name=u"第二支電話")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'住院醫師2001'

# 住院醫師床位分配 -> Resident_bed_assignment
class Resident_bed_assignment(models.Model):
    Serial_number = models.IntegerField(db_column=u"編號", verbose_name=u"編號")
    Resident_numbers = models.IntegerField(db_column=u"住院醫師編號", verbose_name=u"住院醫師編號")
    Doctor_in_charge_numbers = models.IntegerField(db_column=u"主治醫師編號", verbose_name=u"主治醫師編號")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'住院醫師床位分配'

# 住院醫師床位分配v2 -> Resident_the_bed_assigns_v2
class Resident_the_bed_assigns_v2(models.Model):
    Serial_number = models.IntegerField(db_column=u"編號", verbose_name=u"編號")
    Resident_numbers_1 = models.IntegerField(db_column=u"住院醫師編號1", verbose_name=u"住院醫師編號1")
    Resident_numbers_2 = models.IntegerField(db_column=u"住院醫師編號2", verbose_name=u"住院醫師編號2")
    Doctor_in_charge_numbers = models.IntegerField(db_column=u"主治醫師編號", verbose_name=u"主治醫師編號")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'住院醫師床位分配v2'

# 住院醫師等級 -> Resident_rank
class Resident_rank(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Rank = models.CharField(max_length=50, db_column=u"等級", verbose_name=u"等級")
    class Meta:
        db_table = u'住院醫師等級'

# 備血 -> Prepares_the_blood
class Prepares_the_blood(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    WB = models.IntegerField(db_column=u"WB", verbose_name=u"WB")
    pRBC = models.IntegerField(db_column=u"pRBC", verbose_name=u"pRBC")
    FFP = models.IntegerField(db_column=u"FFP", verbose_name=u"FFP")
    PLT = models.IntegerField(db_column=u"PLT", verbose_name=u"PLT")
    Others = models.CharField(max_length=50, db_column=u"Others", verbose_name=u"Others")
    Remark = models.TextField(db_column=u"Remark", verbose_name=u"Remark")
    class Meta:
        db_table = u'備血'

# 分類 -> Classification
class Classification(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Classification = models.CharField(max_length=255, db_column=u"分類", verbose_name=u"分類")
    class Meta:
        db_table = u'分類'

# 實習醫師 -> Interne
class Interne(models.Model):
    Serial_number = models.IntegerField(db_column=u"編號", verbose_name=u"編號")
    Chinese_name = models.AutoField(primary_key=True, db_column=u"中文姓名", verbose_name=u"中文姓名")
    class Meta:
        db_table = u'實習醫師'

# 手術排程 -> Surgery_row_of_regulation
class Surgery_row_of_regulation(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Surgery_date = models.DateTimeField(db_column=u"手術日期", verbose_name=u"手術日期")
    Operation_room = models.IntegerField(db_column=u"手術房", verbose_name=u"手術房")
    In_turn = models.IntegerField(db_column=u"順序", verbose_name=u"順序")
    Scheduled_time = models.CharField(max_length=50, db_column=u"預定時間", verbose_name=u"預定時間")
    Basic_document = models.IntegerField(db_column=u"基本資料", verbose_name=u"基本資料")
    Intensive_care_unit = models.IntegerField(db_column=u"加護病房", verbose_name=u"加護病房")
    Emergency_surgery = models.IntegerField(db_column=u"急診手術", verbose_name=u"急診手術")
    Special_instrument = models.CharField(max_length=50, db_column=u"特殊器械", verbose_name=u"特殊器械")
    Prepares_the_blood = models.IntegerField(db_column=u"備血", verbose_name=u"備血")
    Anaesthesia = models.IntegerField(db_column=u"麻醉", verbose_name=u"麻醉")
    Monitoring_device_1 = models.IntegerField(db_column=u"監視器1", verbose_name=u"監視器1")
    Monitoring_device_2 = models.IntegerField(db_column=u"監視器2", verbose_name=u"監視器2")
    Surgery_code = models.IntegerField(db_column=u"手術代碼", verbose_name=u"手術代碼")
    Death = models.IntegerField(db_column=u"死亡", verbose_name=u"死亡")
    Complications = models.IntegerField(db_column=u"合併症", verbose_name=u"合併症")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    Resident_1 = models.IntegerField(db_column=u"住院醫師1", verbose_name=u"住院醫師1")
    Resident_2 = models.IntegerField(db_column=u"住院醫師2", verbose_name=u"住院醫師2")
    class Meta:
        db_table = u'手術排程'

# 星期 -> Week
class Week(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Week = models.CharField(max_length=50, db_column=u"星期", verbose_name=u"星期")
    class Meta:
        db_table = u'星期'

# 時間表 -> Timetable
class Timetable(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Activity = models.CharField(max_length=50, db_column=u"活動", verbose_name=u"活動")
    Doctor_in_charge = models.IntegerField(db_column=u"主治醫師", verbose_name=u"主治醫師")
    Week = models.IntegerField(db_column=u"星期", verbose_name=u"星期")
    On_afternoon = models.IntegerField(db_column=u"上/下午", verbose_name=u"上/下午")
    Examines_a_place = models.CharField(max_length=50, db_column=u"診次/地點", verbose_name=u"診次/地點")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    class Meta:
        db_table = u'時間表'

# 病床 -> Hospital_bed
class Hospital_bed(models.Model):
    Hospital_bed_serial_number = models.AutoField(primary_key=True, db_column=u"病床編號", verbose_name=u"病床編號")
    Bed_number = models.CharField(max_length=50, db_column=u"床號", verbose_name=u"床號")
    Hospital_ward_serial_number = models.IntegerField(db_column=u"病房編號", verbose_name=u"病房編號")
    Hospital_ward_rank_serial_number = models.IntegerField(db_column=u"病房等級編號", verbose_name=u"病房等級編號")
    class Meta:
        db_table = u'病床'

# 病床等級 -> Hospital_bed_rank
class Hospital_bed_rank(models.Model):
    Hospital_ward_rank_serial_number = models.AutoField(primary_key=True, db_column=u"病房等級編號", verbose_name=u"病房等級編號")
    Hospital_ward_rank = models.CharField(max_length=20, db_column=u"病房等級", verbose_name=u"病房等級")
    class Meta:
        db_table = u'病床等級'

# 病房 -> Hospital_ward
class Hospital_ward(models.Model):
    Hospital_ward_serial_number = models.AutoField(primary_key=True, db_column=u"病房編號", verbose_name=u"病房編號")
    Hospital_ward = models.CharField(max_length=50, db_column=u"病房", verbose_name=u"病房")
    Classification = models.CharField(max_length=50, db_column=u"分類", verbose_name=u"分類")
    class Meta:
        db_table = u'病房'

# 監視器 -> Monitoring_device
class Monitoring_device(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Project = models.CharField(max_length=50, db_column=u"項目", verbose_name=u"項目")
    Explanation = models.TextField(db_column=u"說明", verbose_name=u"說明")
    class Meta:
        db_table = u'監視器'

# 術式代碼 -> Technique_type_code
class Technique_type_code(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Code = models.CharField(max_length=255, db_column=u"代碼", verbose_name=u"代碼")
    The_technique_type_assigns_instrument_to_use = models.CharField(max_length=255, db_column=u"術式(指定器械用)", verbose_name=u"術式(指定器械用)")
    class Meta:
        db_table = u'術式代碼'

# 診斷 -> Diagnosis
class Diagnosis(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Classification = models.IntegerField(db_column=u"分類", verbose_name=u"分類")
    Monthly_statement_project = models.CharField(max_length=255, db_column=u"月報表項目", verbose_name=u"月報表項目")
    Diagnosis = models.CharField(max_length=50, db_column=u"診斷", verbose_name=u"診斷")
    Technique_type = models.CharField(max_length=100, db_column=u"術式", verbose_name=u"術式")
    class Meta:
        db_table = u'診斷'

# 麻醉 -> Anaesthesia
class Anaesthesia(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Anaesthesia = models.CharField(max_length=50, db_column=u"麻醉", verbose_name=u"麻醉")
    Abbreviation = models.CharField(max_length=50, db_column=u"簡稱", verbose_name=u"簡稱")
    Hemp_according_to_list = models.IntegerField(db_column=u"麻照單", verbose_name=u"麻照單")
    class Meta:
        db_table = u'麻醉'

# X事前審查代碼 -> X_examined_the_code_in_anticipation
class X_examined_the_code_in_anticipation(models.Model):
    Identification_code = models.IntegerField(db_column=u"識別碼", verbose_name=u"識別碼")
    Examination_condition = models.CharField(max_length=50, db_column=u"審查狀況", verbose_name=u"審查狀況")
    class Meta:
        db_table = u'X事前審查代碼'

# X再入院資料表 -> X_is_hospitalized_again_the_material
class X_is_hospitalized_again_the_material(models.Model):
    Medical_record_number = models.AutoField(primary_key=True, db_column=u"病歷號碼", verbose_name=u"病歷號碼")
    class Meta:
        db_table = u'X再入院資料表'

# X廠商資料 -> X_manufacturer_material
class X_manufacturer_material(models.Model):
    ID = models.AutoField(primary_key=True, db_column=u"ID", verbose_name=u"ID")
    category = models.IntegerField(db_column=u"category", verbose_name=u"category")
    name = models.CharField(max_length=50, db_column=u"name", verbose_name=u"name")
    contact = models.CharField(max_length=50, db_column=u"contact", verbose_name=u"contact")
    phone = models.CharField(max_length=50, db_column=u"phone", verbose_name=u"phone")
    product = models.CharField(max_length=50, db_column=u"product", verbose_name=u"product")
    class Meta:
        db_table = u'X廠商資料'

# X手術排程 -> X_surgery_row_of_regulation
class X_surgery_row_of_regulation(models.Model):
    Serial_number = models.AutoField(primary_key=True, db_column=u"編號", verbose_name=u"編號")
    Surgery_date = models.DateTimeField(db_column=u"手術日期", verbose_name=u"手術日期")
    Operation_room = models.IntegerField(db_column=u"手術房", verbose_name=u"手術房")
    In_turn = models.IntegerField(db_column=u"順序", verbose_name=u"順序")
    Scheduled_time = models.CharField(max_length=50, db_column=u"預定時間", verbose_name=u"預定時間")
    Basic_document = models.IntegerField(db_column=u"基本資料", verbose_name=u"基本資料")
    Intensive_care_unit = models.IntegerField(db_column=u"加護病房", verbose_name=u"加護病房")
    Emergency_surgery = models.IntegerField(db_column=u"急診手術", verbose_name=u"急診手術")
    Special_instrument = models.CharField(max_length=50, db_column=u"特殊器械", verbose_name=u"特殊器械")
    Prepares_the_blood = models.IntegerField(db_column=u"備血", verbose_name=u"備血")
    Anaesthesia = models.IntegerField(db_column=u"麻醉", verbose_name=u"麻醉")
    Monitoring_device_1 = models.IntegerField(db_column=u"監視器1", verbose_name=u"監視器1")
    Monitoring_device_2 = models.IntegerField(db_column=u"監視器2", verbose_name=u"監視器2")
    Technique_type = models.IntegerField(db_column=u"術式", verbose_name=u"術式")
    Surgery_code = models.IntegerField(db_column=u"手術代碼", verbose_name=u"手術代碼")
    Death = models.IntegerField(db_column=u"死亡", verbose_name=u"死亡")
    Complications = models.IntegerField(db_column=u"合併症", verbose_name=u"合併症")
    Note = models.TextField(db_column=u"備註", verbose_name=u"備註")
    Resident_1 = models.IntegerField(db_column=u"住院醫師1", verbose_name=u"住院醫師1")
    Resident_2 = models.IntegerField(db_column=u"住院醫師2", verbose_name=u"住院醫師2")
    class Meta:
        db_table = u'X手術排程'

# X手術歷史資料 -> X_surgery_historic_information
class X_surgery_historic_information(models.Model):
    Identification_code = models.AutoField(primary_key=True, db_column=u"識別碼", verbose_name=u"識別碼")
    Surgery_date = models.DateTimeField(db_column=u"手術日期", verbose_name=u"手術日期")
    Room = models.IntegerField(db_column=u"房間", verbose_name=u"房間")
    Sequence = models.IntegerField(db_column=u"序列", verbose_name=u"序列")
    Hospital_bed_number = models.CharField(max_length=50, db_column=u"病床號", verbose_name=u"病床號")
    Medical_record_number = models.IntegerField(db_column=u"病歷號", verbose_name=u"病歷號", db_index=True)
    Name = models.CharField(max_length=50, db_column=u"姓名", verbose_name=u"姓名")
    Diagnosis = models.IntegerField(db_column=u"診斷", verbose_name=u"診斷")
    Prepares_forgets = models.CharField(max_length=50, db_column=u"備忘", verbose_name=u"備忘")
    Doctor_in_charge = models.CharField(max_length=50, db_column=u"主治醫師", verbose_name=u"主治醫師")
    class Meta:
        db_table = u'X手術歷史資料'

# X狀況代碼 -> X_condition_code
class X_condition_code(models.Model):
    Identification_code = models.AutoField(primary_key=True, db_column=u"識別碼", verbose_name=u"識別碼")
    Condition = models.CharField(max_length=50, db_column=u"狀況", verbose_name=u"狀況")
    class Meta:
        db_table = u'X狀況代碼'

# X病人資料 -> X_patient_material
class X_patient_material(models.Model):
    Medical_record_number = models.AutoField(primary_key=True, db_column=u"病歷號", verbose_name=u"病歷號")
    Hospital_bed_number = models.CharField(max_length=50, db_column=u"病床號", verbose_name=u"病床號")
    Name = models.CharField(max_length=50, db_column=u"姓名", verbose_name=u"姓名")
    Sex = models.CharField(max_length=50, db_column=u"性別", verbose_name=u"性別")
    Age = models.IntegerField(db_column=u"年齡", verbose_name=u"年齡")
    Diagnosis = models.IntegerField(db_column=u"診斷", verbose_name=u"診斷")
    Prepares_forgets = models.CharField(max_length=50, db_column=u"備忘", verbose_name=u"備忘")
    Doctor_in_charge = models.CharField(max_length=50, db_column=u"主治醫師", verbose_name=u"主治醫師")
    Resident = models.CharField(max_length=50, db_column=u"住院醫師", verbose_name=u"住院醫師")
    Interne = models.CharField(max_length=50, db_column=u"實習醫師", verbose_name=u"實習醫師")
    Hospital_ward_rank_serial_number = models.IntegerField(db_column=u"病房等級編號", verbose_name=u"病房等級編號")
    House_telephone = models.CharField(max_length=50, db_column=u"住家電話", verbose_name=u"住家電話")
    Mobile_phone = models.CharField(max_length=50, db_column=u"行動電話", verbose_name=u"行動電話")
    Office_telephone = models.CharField(max_length=50, db_column=u"辦公室電話", verbose_name=u"辦公室電話")
    The_second_telephone = models.CharField(max_length=50, db_column=u"第二支電話", verbose_name=u"第二支電話")
    Condition = models.IntegerField(db_column=u"狀況", verbose_name=u"狀況")
    In_hospital_date = models.CharField(max_length=50, db_column=u"住院日期", verbose_name=u"住院日期")
    Surgery_date = models.DateTimeField(db_column=u"手術日期", verbose_name=u"手術日期")
    Room = models.IntegerField(db_column=u"房間", verbose_name=u"房間")
    Sequence = models.IntegerField(db_column=u"序列", verbose_name=u"序列")
    In_hospital_number_of_days = models.IntegerField(db_column=u"住院天數", verbose_name=u"住院天數")
    Family_member_name = models.CharField(max_length=50, db_column=u"家人名字", verbose_name=u"家人名字")
    Last_modified_time = models.DateTimeField(db_column=u"最後更新時間", verbose_name=u"最後更新時間")
    Birthday = models.DateTimeField(db_column=u"生日", verbose_name=u"生日")
    Address = models.CharField(max_length=50, db_column=u"地址", verbose_name=u"地址")
    Identification_card_number = models.CharField(max_length=50, db_column=u"身分證號", verbose_name=u"身分證號")
    Doctor_team = models.CharField(max_length=50, db_column=u"醫師團隊", verbose_name=u"醫師團隊")
    class Meta:
        db_table = u'X病人資料'

# X醫師團隊資料表 -> X_doctor_team_material_table
class X_doctor_team_material_table(models.Model):
    Identification_code = models.AutoField(primary_key=True, db_column=u"識別碼", verbose_name=u"識別碼")
    Doctor_in_charge = models.CharField(max_length=50, db_column=u"主治醫師", verbose_name=u"主治醫師")
    Resident = models.CharField(max_length=50, db_column=u"住院醫師", verbose_name=u"住院醫師")
    Interne = models.CharField(max_length=50, db_column=u"實習醫師", verbose_name=u"實習醫師")
    class Meta:
        db_table = u'X醫師團隊資料表'

# XDisBedNo -> XDisBedNo
class XDisBedNo(models.Model):
    Hospital_bed_number = models.CharField(max_length=255, db_column=u"病床號", verbose_name=u"病床號")
    Name = models.CharField(max_length=255, db_column=u"姓名", verbose_name=u"姓名")
    Medical_record_number = models.IntegerField(db_column=u"病歷號", verbose_name=u"病歷號")
    Sex = models.CharField(max_length=255, db_column=u"性別", verbose_name=u"性別")
    Birthday = models.DateTimeField(db_column=u"生日", verbose_name=u"生日")
    VS_Name = models.CharField(max_length=255, db_column=u"VS Name", verbose_name=u"VS Name")
    In_hospital_date = models.DateTimeField(db_column=u"住院日期", verbose_name=u"住院日期")
    hospitalid = models.CharField(max_length=50, db_column=u"hospitalid", verbose_name=u"hospitalid")
    ioe = models.CharField(max_length=50, db_column=u"ioe", verbose_name=u"ioe")
    CaseNo = models.AutoField(primary_key=True, db_column=u"CaseNo", verbose_name=u"CaseNo")
    Location = models.CharField(max_length=50, db_column=u"Location", verbose_name=u"Location")
    BedNo = models.CharField(max_length=50, db_column=u"BedNo", verbose_name=u"BedNo")
    class Meta:
        db_table = u'XDisBedNo'
