import 'package:fis_jsonrpc/rpc.dart';

class PatientModelDTO extends PatientDTO {
  bool? isExistLocalData;
  PatientModelDTO({
    super.recordNo,
    // String? recordNo,
    super.patientName,
    super.phone,
    super.cardNo,
    super.nationality,
    super.birthday,
    super.crowdLabels,
    super.cardType = CardTypeEnum.Identity,
    super.patientGender = GenderEnum.Unknown,
    super.patientAddress,
    super.permanentResidenceAddress,
    super.teamRegionCode,
    super.createdDoctor,
    super.contractedDoctor,
    super.labelNames,
    super.createdDoctorName,
    super.createdOrgName,
    super.createdTeamName,
    super.status = PatientStatusEnum.Created,
    super.createdOrgCode,
    super.createdTeamCode,
    super.contractedDoctorName,
    super.contractState = ContractStateEnum.Unsigned,
    super.code,
    super.createTime,
    super.updateTime,
    this.isExistLocalData = false,
  });

  factory PatientModelDTO.fromJson(Map<String, dynamic> map) {
    return PatientModelDTO(
      recordNo: map['RecordNo'],
      patientName: map['PatientName'],
      phone: map['Phone'],
      cardNo: map['CardNo'],
      nationality: map['Nationality'],
      birthday:
          map['Birthday'] != null ? DateTime.parse(map['Birthday']) : null,
      crowdLabels: map['CrowdLabels']?.cast<String>().toList(),
      cardType:
          CardTypeEnum.values.firstWhere((e) => e.index == map['CardType']),
      patientGender:
          GenderEnum.values.firstWhere((e) => e.index == map['PatientGender']),
      patientAddress: map['PatientAddress'],
      permanentResidenceAddress: map['PermanentResidenceAddress'],
      teamRegionCode: map['TeamRegionCode'],
      createdDoctor: map['CreatedDoctor'],
      contractedDoctor: map['ContractedDoctor'],
      labelNames: map['LabelNames']?.cast<String>().toList(),
      createdDoctorName: map['CreatedDoctorName'],
      createdOrgName: map['CreatedOrgName'],
      createdTeamName: map['CreatedTeamName'],
      status:
          PatientStatusEnum.values.firstWhere((e) => e.index == map['Status']),
      createdOrgCode: map['CreatedOrgCode'],
      createdTeamCode: map['CreatedTeamCode'],
      contractedDoctorName: map['ContractedDoctorName'],
      contractState: ContractStateEnum.values
          .firstWhere((e) => e.index == map['ContractState']),
      code: map['Code'],
      createTime:
          map['CreateTime'] != null ? DateTime.parse(map['CreateTime']) : null,
      updateTime:
          map['UpdateTime'] != null ? DateTime.parse(map['UpdateTime']) : null,
    );
  }
}
