import 'dart:convert'; import 'package:fis_jsonrpc/rpc.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; import 'package:vitalapp/architecture/defines.dart'; import 'package:vitalapp/architecture/utils/datetime.dart'; import 'package:vitalapp/components/dialog_profile_time_input.dart'; import 'package:vitalapp/consts/rpc_enum_labels.dart'; import 'widgets/ext_model.dart'; class HealthModel { final List? historyDrugAllergies; final List? historyExposure; final List? historyPreviousDisease; final String? historyPreviousDiseaseOther; ///既往疾病史-职业病 final String? historyPreviousDiseaseOccupationalDisease; ///既往疾病史-恶性肿瘤 final String? historyPreviousDiseaseMalignancy; final String? operation; final String? trauma; final String? transfusion; final List? father; final String? fatherOther; final List? mother; final String? motherOther; final List? sibling; final String? siblingOther; final List? children; final String? childrenOther; final String? historyGenetic; final String? historyGeneticName; final List? disabilitySituation; final String? disabilitySituationOther; final String? kitchenExhaustFacilities; final String? fuel; final String? fuelOther; final String? drinkingWater; final String? drinkingWaterOther; final String? toilet; final String? animalPen; final String? historyDrugAllergiesOther; final VProfileTimeInputModel? operationOne; final VProfileTimeInputModel? operationTwo; final VProfileTimeInputModel? traumaOne; final VProfileTimeInputModel? traumaTwo; final VProfileTimeInputModel? transfusionOne; final VProfileTimeInputModel? transfusionTwo; final Map diseaseDiagnosisTime; ///详细信息 final String? workUnit; //工作单位 final String? contactName; //联系人姓名 final String? contactPhone; //联系人电话 final String? permanentlyResideType; //常住类型 final String? bloodType; //血型 final String? rh; //RH final String? educationLevel; //文化程度 final String? career; //职业 final String? maritalStatus; //婚姻状况 final String? providerPayments; //医疗费用支付方式 final String? providerPaymentsOther; //医疗费用支付方式 HealthModel({ required this.historyDrugAllergies, required this.historyExposure, required this.historyPreviousDisease, required this.historyPreviousDiseaseOther, required this.historyPreviousDiseaseOccupationalDisease, required this.historyPreviousDiseaseMalignancy, required this.operation, required this.trauma, required this.transfusion, required this.father, required this.fatherOther, required this.mother, required this.motherOther, required this.sibling, required this.siblingOther, required this.children, required this.childrenOther, required this.historyGenetic, required this.historyGeneticName, required this.disabilitySituation, required this.disabilitySituationOther, required this.kitchenExhaustFacilities, required this.fuel, required this.fuelOther, required this.drinkingWater, required this.drinkingWaterOther, required this.toilet, required this.animalPen, required this.historyDrugAllergiesOther, required this.operationOne, required this.operationTwo, required this.traumaOne, required this.traumaTwo, required this.transfusionOne, required this.transfusionTwo, required this.diseaseDiagnosisTime, required this.workUnit, required this.contactName, required this.contactPhone, required this.permanentlyResideType, required this.bloodType, required this.rh, required this.educationLevel, required this.career, required this.maritalStatus, required this.providerPayments, required this.providerPaymentsOther, }); factory HealthModel.fromJson(Map jsonMap) { return HealthModel( historyDrugAllergies: jsonMap["historyDrugAllergies"]?.cast().toList(), historyExposure: jsonMap["historyExposure"]?.cast().toList(), historyPreviousDisease: jsonMap["historyPreviousDisease"]?.cast().toList(), historyPreviousDiseaseOther: jsonMap["historyPreviousDiseaseOther"], historyPreviousDiseaseOccupationalDisease: jsonMap["historyPreviousDiseaseOccupationalDisease"], historyPreviousDiseaseMalignancy: jsonMap["historyPreviousDiseaseMalignancy"], operation: jsonMap["operation"], trauma: jsonMap["trauma"], transfusion: jsonMap["transfusion"], father: jsonMap["father"]?.cast().toList(), fatherOther: jsonMap["fatherOther"], mother: jsonMap["mother"]?.cast().toList(), motherOther: jsonMap["motherOther"], sibling: jsonMap["sibling"]?.cast().toList(), siblingOther: jsonMap["siblingOther"], children: jsonMap["children"]?.cast().toList(), childrenOther: jsonMap["childrenOther"], historyGenetic: jsonMap["historyGenetic"], historyGeneticName: jsonMap["historyGeneticName"], disabilitySituation: jsonMap["disabilitySituation"]?.cast().toList(), disabilitySituationOther: jsonMap["disabilitySituationOther"], kitchenExhaustFacilities: jsonMap["kitchenExhaustFacilities"], fuel: jsonMap["fuel"], fuelOther: jsonMap["fuelOther"], drinkingWater: jsonMap["drinkingWater"], drinkingWaterOther: jsonMap["drinkingWaterOther"], toilet: jsonMap["toilet"], animalPen: jsonMap["animalPen"], historyDrugAllergiesOther: jsonMap["historyDrugAllergiesOther"], operationOne: jsonMap["operationOne"] != null && jsonMap["operationOne"] != "{}" ? VProfileTimeInputModel.fromJson(jsonDecode(jsonMap["operationOne"])) : null, operationTwo: jsonMap["operationTwo"] != null && jsonMap["operationTwo"] != "{}" ? VProfileTimeInputModel.fromJson(jsonDecode(jsonMap["operationTwo"])) : null, traumaOne: jsonMap["traumaOne"] != null && jsonMap["traumaOne"] != "{}" ? VProfileTimeInputModel.fromJson(jsonDecode(jsonMap["traumaOne"])) : null, traumaTwo: jsonMap["traumaTwo"] != null && jsonMap["traumaTwo"] != "{}" ? VProfileTimeInputModel.fromJson(jsonDecode(jsonMap["traumaTwo"])) : null, transfusionOne: jsonMap["transfusionOne"] != null && jsonMap["transfusionOne"] != "{}" ? VProfileTimeInputModel.fromJson( jsonDecode(jsonMap["transfusionOne"])) : null, transfusionTwo: jsonMap["transfusionTwo"] != null && jsonMap["transfusionTwo"] != "{}" ? VProfileTimeInputModel.fromJson( jsonDecode(jsonMap["transfusionTwo"])) : null, diseaseDiagnosisTime: Map.from(jsonDecode(jsonMap["diseaseDiagnosisTime"])) .map((key, value) { return MapEntry(key, DateTime.parse(value)); }), workUnit: jsonMap["workUnit"], contactName: jsonMap["contactName"], contactPhone: jsonMap["contactPhone"], permanentlyResideType: jsonMap["permanentlyResideType"], bloodType: jsonMap["bloodType"], rh: jsonMap["rh"], educationLevel: jsonMap["educationLevel"], career: jsonMap["career"], maritalStatus: jsonMap["maritalStatus"], providerPayments: jsonMap["providerPayments"], providerPaymentsOther: jsonMap["providerPaymentsOther"], ); } Map toJson() { Map jsonMap = {}; { if (historyDrugAllergies != null) { jsonMap["historyDrugAllergies"] = historyDrugAllergies; } if (historyExposure != null) jsonMap["historyExposure"] = historyExposure; if (historyPreviousDisease != null) { jsonMap["historyPreviousDisease"] = historyPreviousDisease; } if (historyPreviousDiseaseOther != null) { jsonMap["historyPreviousDiseaseOther"] = historyPreviousDiseaseOther; } if (historyPreviousDiseaseOccupationalDisease != null) { jsonMap["historyPreviousDiseaseOccupationalDisease"] = historyPreviousDiseaseOccupationalDisease; } if (historyPreviousDiseaseMalignancy != null) { jsonMap["historyPreviousDiseaseMalignancy"] = historyPreviousDiseaseMalignancy; } if (operation != null) jsonMap["operation"] = operation; if (trauma != null) jsonMap["trauma"] = trauma; if (transfusion != null) jsonMap["transfusion"] = transfusion; if (father != null) jsonMap["father"] = father; if (fatherOther != null) jsonMap["fatherOther"] = fatherOther; if (mother != null) jsonMap["mother"] = mother; if (motherOther != null) jsonMap["motherOther"] = motherOther; if (sibling != null) jsonMap["sibling"] = sibling; if (siblingOther != null) jsonMap["siblingOther"] = siblingOther; if (children != null) jsonMap["children"] = children; if (childrenOther != null) jsonMap["childrenOther"] = childrenOther; if (historyGenetic != null) jsonMap["historyGenetic"] = historyGenetic; if (historyGeneticName != null) { jsonMap["historyGeneticName"] = historyGeneticName; } if (disabilitySituation != null) { jsonMap["disabilitySituation"] = disabilitySituation; } if (disabilitySituationOther != null) { jsonMap["disabilitySituationOther"] = disabilitySituationOther; } if (kitchenExhaustFacilities != null) { jsonMap["kitchenExhaustFacilities"] = kitchenExhaustFacilities; } if (fuel != null) jsonMap["fuel"] = fuel; if (fuelOther != null) jsonMap["fuelOther"] = fuelOther; if (drinkingWater != null) jsonMap["drinkingWater"] = drinkingWater; if (drinkingWaterOther != null) { jsonMap["drinkingWaterOther"] = drinkingWaterOther; } if (toilet != null) jsonMap["toilet"] = toilet; if (animalPen != null) jsonMap["animalPen"] = animalPen; if (historyDrugAllergiesOther != null) { jsonMap["historyDrugAllergiesOther"] = historyDrugAllergiesOther; } if (operationOne != null) { jsonMap["operationOne"] = jsonEncode(operationOne?.toJson()); } if (operationTwo != null) { jsonMap["operationTwo"] = jsonEncode(operationTwo?.toJson()); } if (traumaOne != null) { jsonMap["traumaOne"] = jsonEncode(traumaOne?.toJson()); } if (traumaTwo != null) { jsonMap["traumaTwo"] = jsonEncode(traumaTwo?.toJson()); } if (transfusionOne != null) { jsonMap["transfusionOne"] = jsonEncode(transfusionOne?.toJson()); } if (transfusionTwo != null) { jsonMap["transfusionTwo"] = jsonEncode(transfusionTwo?.toJson()); } jsonMap["diseaseDiagnosisTime"] = jsonEncode(diseaseDiagnosisTime .map((key, value) => MapEntry(key, value.toIso8601String()))); if (workUnit != null) { jsonMap["workUnit"] = workUnit; } if (contactName != null) { jsonMap["contactName"] = contactName; } if (contactPhone != null) { jsonMap["contactPhone"] = contactPhone; } if (permanentlyResideType != null) { jsonMap["permanentlyResideType"] = permanentlyResideType; } if (bloodType != null) { jsonMap["bloodType"] = bloodType; } if (rh != null) { jsonMap["rh"] = rh; } if (educationLevel != null) { jsonMap["educationLevel"] = educationLevel; } if (career != null) { jsonMap["career"] = career; } if (maritalStatus != null) { jsonMap["maritalStatus"] = maritalStatus; } if (providerPayments != null) { jsonMap["providerPayments"] = providerPayments; } if (providerPaymentsOther != null) { jsonMap["providerPaymentsOther"] = providerPaymentsOther; } return jsonMap; } } } class PatientInfoState { final Rx _anchor = NavAnchorType.base.obs; /// 导航锚点 NavAnchorType get anchor => _anchor.value; set anchor(NavAnchorType val) => _anchor.updateValue(val); final Rx _dto = Rx( PatientDTO(), ); String healthCode = ""; DateTime extractBirthDateFromIDCard(String idCardNumber) { final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$'); final match = idCardRegex.firstMatch(idCardNumber); if (match != null) { final year = int.parse(match.group(2)!); final month = int.parse(match.group(3)!); final day = int.parse(match.group(4)!); final birthDate = DateTime(year, month, day); return birthDate; } return DateTime(1970, 1, 1); // 返回一个默认值,表示无法提取出生日期 } } enum NavAnchorType { base, detail, health, }