import 'package:fis_jsonrpc/rpc.dart';

/// 检查数据结构
class ConsultationsRecordData {
  String? recordCode;
  RecordStatusEnum recordStatus;
  ReferralTypeEnum referralType;
  String? patientCode;
  String? patientName;
  String? age;
  String? sex;
  String? devicePatientID;
  String? deviceCode;
  String? deviceName;
  String? rootOrganizationCode;
  String? rootOrganizationName;
  String? languge;
  DateTime? createTime;
  bool isCanCreateReport;
  bool canCollcetImg;
  bool isCollecting;
  bool canScreenshot;
  List<DiagnosisInfoDTO> diagnosisInfos;
  double? score;

  ConsultationsRecordData({
    this.recordCode,
    this.recordStatus = RecordStatusEnum.NotScanned,
    this.referralType = ReferralTypeEnum.Normal,
    this.patientCode,
    this.patientName,
    this.age,
    this.sex,
    this.devicePatientID,
    this.deviceCode,
    this.deviceName,
    this.rootOrganizationCode,
    this.rootOrganizationName,
    this.languge,
    this.createTime,
    this.isCanCreateReport = false,
    this.canCollcetImg = false,
    this.isCollecting = false,
    this.canScreenshot = false,
    this.diagnosisInfos = const [],
    this.score,
  });

  factory ConsultationsRecordData.fromJson(Map<String, dynamic> map) {
    return ConsultationsRecordData(
      recordCode: map['RecordCode'],
      recordStatus: RecordStatusEnum.values
          .firstWhere((e) => e.index == map['RecordStatus']),
      referralType: ReferralTypeEnum.values
          .firstWhere((e) => e.index == map['ReferralType']),
      patientCode: map['PatientCode'],
      patientName: map['PatientName'],
      age: map['Age'],
      sex: map['Sex'],
      devicePatientID: map['DevicePatientID'],
      deviceCode: map['DeviceCode'],
      deviceName: map['DeviceName'],
      rootOrganizationCode: map['RootOrganizationCode'],
      rootOrganizationName: map['RootOrganizationName'],
      languge: map['Languge'],
      isCanCreateReport: map['CanCreateReport'] ?? false,
      canCollcetImg: map['CanCollcetImg'] ?? false,
      isCollecting: map['IsCollecting'] ?? false,
      canScreenshot: map['CanScreenshot'] ?? false,
      createTime:
          map['CreateTime'] != null ? DateTime.parse(map['CreateTime']) : null,
      score: map['Score'],
    );
  }

  Map<String, dynamic> toJson() {
    final map = Map<String, dynamic>();
    if (recordCode != null) map['RecordCode'] = recordCode;
    map['RecordStatus'] = recordStatus.index;
    map['ReferralType'] = referralType.index;
    map['CanCreateReport'] = isCanCreateReport;
    if (patientCode != null) map['PatientCode'] = patientCode;
    if (patientName != null) map['PatientName'] = patientName;
    if (age != null) map['Age'] = age;
    if (sex != null) map['Sex'] = sex;
    if (devicePatientID != null) map['DevicePatientID'] = devicePatientID;
    if (deviceCode != null) map['DeviceCode'] = deviceCode;
    if (deviceName != null) map['DeviceName'] = deviceName;
    map['IsCollecting'] = isCollecting;
    map['CanCollcetImg'] = canCollcetImg;
    if (rootOrganizationCode != null)
      map['RootOrganizationCode'] = rootOrganizationCode;
    if (rootOrganizationName != null)
      map['RootOrganizationName'] = rootOrganizationName;
    if (languge != null) map['Languge'] = languge;
    return map;
  }
}

class UserDoctorModel {
  UserDoctorModel({
    required this.name,
    required this.code,
    this.roleCodes,
    this.fieldList,
    this.headImageUrl,
    this.roleName,
  });
  final String name;
  final String code;
  final List<String>? roleCodes;
  final List<String>? fieldList;
  final String? roleName;
  // final List<String>? fieldList;
  final String? headImageUrl;
}

class ReferralHistoryDetailData {
  String? referralOutOrganizationName;
  String? referralOutUserName;
  String? referralInOrganizationName;
  String? referralInUserName;
  String? code;
  String? recordCode;
  String? referralOutUserCode;
  String? referralOutOrganizationCode;
  String? referralInUserCode;
  String? referralInOrganizationCode;
  RecordReferralStatusEnum? referralStatus =
      RecordReferralStatusEnum.ReferralIn;
  DateTime? referralTime;
  String? subjectMatter;
  DateTime? createTime;
  DateTime? updateTime;
  String? patientName;

  ReferralHistoryDetailData({
    this.referralOutOrganizationName,
    this.referralOutUserName,
    this.referralInOrganizationName,
    this.referralInUserName,
    this.code,
    this.recordCode,
    this.referralOutUserCode,
    this.referralOutOrganizationCode,
    this.referralInUserCode,
    this.referralInOrganizationCode,
    this.referralStatus,
    this.referralTime,
    this.subjectMatter,
    this.createTime,
    this.updateTime,
    this.patientName,
  }) : super();

  factory ReferralHistoryDetailData.fromJson(Map<String, dynamic> map) {
    return ReferralHistoryDetailData(
      referralOutOrganizationName: map['ReferralOutOrganizationName'],
      referralOutUserName: map['ReferralOutUserName'],
      referralInOrganizationName: map['ReferralInOrganizationName'],
      referralInUserName: map['ReferralInUserName'],
      code: map['Code'],
      recordCode: map['RecordCode'],
      referralOutUserCode: map['ReferralOutUserCode'],
      referralOutOrganizationCode: map['ReferralOutOrganizationCode'],
      referralInUserCode: map['ReferralInUserCode'],
      referralInOrganizationCode: map['ReferralInOrganizationCode'],
      referralStatus: RecordReferralStatusEnum.values
          .firstWhere((e) => e.index == map['ReferralStatus']),
      referralTime: map['ReferralTime'] != null
          ? DateTime.parse(map['ReferralTime'])
          : null,
      subjectMatter: map['SubjectMatter'],
      createTime:
          map['CreateTime'] != null ? DateTime.parse(map['CreateTime']) : null,
      updateTime:
          map['UpdateTime'] != null ? DateTime.parse(map['UpdateTime']) : null,
      patientName: map['PatientName'],
    );
  }
}
