state.dart 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'dart:collection';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/architecture/defines.dart';
  5. import 'package:vitalapp/architecture/types/index.dart';
  6. import 'package:vitalapp/architecture/utils/datetime.dart';
  7. import 'package:vitalapp/pages/controllers/crowd_labels.dart';
  8. import 'package:vitalapp/pages/patient/info/widgets/ext_model.dart';
  9. import 'package:vitalapp/pages/patient_info/controller.dart';
  10. import 'package:vitalapp/pages/patient_info/state.dart';
  11. import 'package:vitalapp/store/store.dart';
  12. class CreatePatientState {
  13. final RxBool _isCreateOnly = RxBool(false);
  14. final RxList<String> _crowdLabelCodes = RxList();
  15. final patientInfomationController = Get.find<PatientInfomationController>();
  16. PatientInfomationState get patientInfomationState =>
  17. patientInfomationController.state;
  18. void reset() {
  19. var crowdLabelController = Get.find<CrowdLabelsController>();
  20. crowdLabelController.state.selectedNormalCodes = [];
  21. crowdLabelController.state.selectedDiseaseCodes = [];
  22. crowdLabelController.state.selectedSpecialCareCodes = [];
  23. patientInfomationState.name = "";
  24. patientInfomationState.cardType = CardTypeEnum.Identity;
  25. patientInfomationState.cardNo = "";
  26. patientInfomationState.nation = "";
  27. patientInfomationState.gender = null;
  28. patientInfomationState.birthday = null;
  29. patientInfomationState.permanentResidenceAddress = "";
  30. patientInfomationState.address = "";
  31. patientInfomationState.villageCode = "";
  32. patientInfomationState.phoneNo = "";
  33. patientInfomationState.emergencyPhone = "";
  34. crowdLabelCodes = [];
  35. patientInfomationState.isSyncAddresses = true;
  36. patientInfomationState.detailInfo = PatientDetailInfoModel();
  37. patientInfomationState.healthInfo = PatientHealthInfoModel();
  38. }
  39. ///头像(用于人脸识别没有识别到时新增档案后自动绑定头像)
  40. String headImage = '';
  41. //用于识别是否是家医
  42. bool isVital = true;
  43. /// 机构名称
  44. String get organizationName => Store.user.organizationName;
  45. /// 村选项集合
  46. List<StringKVModel> get villageOptions => Store.user.residence;
  47. /// 是否只创建档案
  48. bool get isCreateOnly => _isCreateOnly.value;
  49. set isCreateOnly(bool val) => _isCreateOnly.updateValue(val);
  50. DateTime extractBirthDateFromIDCard(String idCardNumber) {
  51. if (idCardNumber.isEmpty) return DateTime(1970, 1, 1);
  52. final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$');
  53. final match = idCardRegex.firstMatch(idCardNumber);
  54. if (match != null) {
  55. final year = int.parse(match.group(2)!);
  56. final month = int.parse(match.group(3)!);
  57. final day = int.parse(match.group(4)!);
  58. final birthDate = DateTime(year, month, day);
  59. return birthDate;
  60. }
  61. return DateTime(1970, 1, 1); // 返回一个默认值,表示无法提取出生日期
  62. }
  63. /// 人群分类集合
  64. List<String> get crowdLabelCodes =>
  65. UnmodifiableListView(_crowdLabelCodes.toList());
  66. set crowdLabelCodes(List<String> val) => _crowdLabelCodes.value = val;
  67. }