class FormObject {
  String? label;
  dynamic defaultValue;
  int? span;
  String? key;
  String? type;
  bool? border;
  dynamic disabledValue;
  List<Option>? options;
  List<FormObject>? children;
  String? append;
  String? placeholder;
  bool? required;
  bool? showLimit;
  String? parentKey;
  String? buttonName;
  List? childrenKey;
  List? groupKeys;

  FormObject({
    this.label,
    this.defaultValue,
    this.span,
    this.key,
    this.type,
    this.border,
    this.disabledValue,
    this.options,
    this.children,
    this.append,
    this.placeholder,
    this.required,
    this.showLimit,
    this.parentKey,
    this.buttonName,
    this.childrenKey,
    this.groupKeys,
  });

  factory FormObject.fromJson(Map<String, dynamic> json) {
    var optionsList = json['options'] == null ? null : json['options'] as List;
    List<Option>? options =
        optionsList?.map((item) => Option.fromJson(item)).toList();

    return FormObject(
      label: json['label'],
      defaultValue: json['defaultValue'],
      span: json['span'],
      key: json['key'],
      type: json['type'],
      border: json['border'],
      disabledValue: json['disabledValue'],
      options: options,
      children: json['children'] != null
          ? List<FormObject>.from(json['children'])
          : null,
      append: json['append'],
      placeholder: json['placeholder'],
      required: json['required'],
      showLimit: json['show-limit'],
      parentKey: json['parentKey'],
      buttonName: json['buttonName'],
      childrenKey:
          json['childrenKey'] == null ? null : json['childrenKey'] as List,
      groupKeys: json['groupKeys'] == null ? null : json['groupKeys'] as List,
    );
  }

  Map<String, dynamic> toJson() {
    List<Map<String, dynamic>> optionsList =
        options != null ? options!.map((item) => item.toJson()).toList() : [];

    return {
      'label': label,
      'defaultValue': defaultValue,
      'span': span,
      'key': key,
      'type': type,
      'border': border,
      'disabledValue': disabledValue,
      'options': optionsList,
      'children': children,
      'append': append,
      'placeholder': placeholder,
      'required': required,
      'show-limit': showLimit,
      'parentKey': parentKey,
      'buttonName': buttonName,
      'childrenKey': childrenKey,
      'groupKeys': groupKeys,
    };
  }
}

class Option {
  String? label;
  String? value;

  Option({this.label, this.value});

  factory Option.fromJson(Map<String, dynamic> json) {
    return Option(
      label: json['label'],
      value: json['value'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'label': label,
      'value': value,
    };
  }
}

class ToxicSubstance {
  String? label;
  Map? value;

  ToxicSubstance({this.label, this.value});

  factory ToxicSubstance.fromJson(Map<String, dynamic> json) {
    return ToxicSubstance(
      label: json['label'],
      value: json['value'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'label': label,
      'value': value,
    };
  }
}

class MenuItem {
  // 显示的文本
  String label;
  // 选中的值
  dynamic value;
  // 是否选中
  bool checked;

  MenuItem({this.label = '', this.value, this.checked = false});
}

/// 住院史表单数据类型
class Admission {
  String? id;
  String? admissionDate;
  String? dischargeDate;
  String? reason;
  String? nameOfMedicalInstitution;
  String? patientNumber;

  Admission({
    this.id,
    this.admissionDate,
    this.dischargeDate,
    this.reason,
    this.nameOfMedicalInstitution,
    this.patientNumber,
  });

  factory Admission.fromJson(Map<String, dynamic> json) {
    return Admission(
      id: json['id'],
      admissionDate: json['Admission_Date'],
      dischargeDate: json['Discharge_Date'],
      reason: json['Reason'],
      nameOfMedicalInstitution: json['Name_Of_Medical_Institution'],
      patientNumber: json['Patient_Number'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id ?? '',
      'Admission_Date': admissionDate ?? '',
      'Discharge_Date': dischargeDate ?? '',
      'Reason': reason ?? '',
      'Name_Of_Medical_Institution': nameOfMedicalInstitution ?? '',
      'Patient_Number': patientNumber ?? '',
    };
  }
}

/// 家庭病床史
class BedConstruction {
  String? id;
  String? bedConstructionDate;
  String? dischargeDate;
  String? reason;
  String? nameOfMedicalInstitution;
  String? patientNumber;

  BedConstruction({
    this.id,
    this.bedConstructionDate,
    this.dischargeDate,
    this.reason,
    this.nameOfMedicalInstitution,
    this.patientNumber,
  });

  factory BedConstruction.fromJson(Map<String, dynamic> json) {
    return BedConstruction(
      id: json['id'],
      bedConstructionDate: json['Bed_Construction_Date'],
      dischargeDate: json['Discharge_Date'],
      reason: json['Reason'],
      nameOfMedicalInstitution: json['Name_Of_Medical_Institution'],
      patientNumber: json['Patient_Number'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id ?? '',
      'Admission_Date': bedConstructionDate ?? '',
      'Discharge_Date': dischargeDate ?? '',
      'Reason': reason ?? '',
      'Name_Of_Medical_Institution': nameOfMedicalInstitution ?? '',
      'Patient_Number': patientNumber ?? '',
    };
  }
}

/// 主要用药情况
class MainMedication {
  String? id;
  String? medicineName;
  String? medicineUsage;
  String? medicineDosage;
  String? medicineTime;
  String? medicineCompliance;

  MainMedication({
    this.id,
    this.medicineName,
    this.medicineUsage,
    this.medicineDosage,
    this.medicineTime,
    this.medicineCompliance,
  });

  factory MainMedication.fromJson(Map<String, dynamic> json) {
    return MainMedication(
      id: json['id'],
      medicineName: json['Medicine_Name'],
      medicineUsage: json['Medicine_Usage'],
      medicineDosage: json['Medicine_Dosage'],
      medicineTime: json['Medicine_Time'],
      medicineCompliance: json['Medicine_Compliance'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id ?? '',
      'Medicine_Name': medicineName ?? '',
      'Medicine_Usage': medicineUsage ?? '',
      'Medicine_Dosage': medicineDosage ?? '',
      'Medicine_Time': medicineTime ?? '',
      'Medicine_Compliance': medicineCompliance ?? '',
    };
  }
}

/// 预防接种史
class VaccinationHistory {
  String? id;
  String? vaccinationDate;
  String? vaccinationFacility;
  String? vaccineName;

  VaccinationHistory({
    this.id,
    this.vaccinationDate,
    this.vaccinationFacility,
    this.vaccineName,
  });

  factory VaccinationHistory.fromJson(Map<String, dynamic> json) {
    return VaccinationHistory(
      id: json['id'],
      vaccinationDate: json['Vaccination_Date'],
      vaccinationFacility: json['Vaccination_Facility'],
      vaccineName: json['Vaccine_Name'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id ?? '',
      'Vaccination_Date': vaccinationDate ?? '',
      'Vaccination_Facility': vaccinationFacility ?? '',
      'Vaccine_Name': vaccineName ?? '',
    };
  }
}

class EditTableValue {
  int? id;
  Map<String, dynamic>? value;

  EditTableValue({
    this.id,
    this.value,
  });
}
