state.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import 'dart:collection';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vnoteapp/architecture/defines.dart';
  5. import 'package:vnoteapp/architecture/types/index.dart';
  6. import 'package:vnoteapp/architecture/utils/datetime.dart';
  7. import 'package:vnoteapp/pages/controllers/crowd_labels.dart';
  8. import 'package:vnoteapp/store/store.dart';
  9. class CreatePatientState {
  10. final RxBool _isCreateOnly = RxBool(false);
  11. final RxString _name = RxString("");
  12. final RxString _personalNo = RxString("");
  13. final RxString _phoneNo = RxString("");
  14. final Rx<CardTypeEnum> _cardType = Rx<CardTypeEnum>(CardTypeEnum.Identity);
  15. final RxString _cardNo = RxString("");
  16. final RxString _nation = RxString("");
  17. final Rx<GenderEnum> _gender = Rx<GenderEnum>(GenderEnum.Male);
  18. final Rx<DateTime?> _birthday = Rx<DateTime?>(null);
  19. final RxString _age = RxString("");
  20. final RxString _censusRegister = RxString("");
  21. final RxString _address = RxString("");
  22. final RxString _villageCode = RxString("");
  23. final RxList<String> _crowdLabelCodes = RxList();
  24. final RxBool _isSyncAddresses = RxBool(true);
  25. void reset() {
  26. var crowdLabelController = Get.find<CrowdLabelsController>();
  27. crowdLabelController.state.selectedNormalCodes = [];
  28. crowdLabelController.state.selectedDiseaseCodes = [];
  29. crowdLabelController.state.selectedSpecialCareCodes = [];
  30. name = "";
  31. personalNo = "";
  32. cardType = CardTypeEnum.Identity;
  33. cardNo = "";
  34. nation = "";
  35. gender = GenderEnum.Male;
  36. birthday = null;
  37. censusRegister = "";
  38. address = "";
  39. villageCode = "";
  40. phoneNo = "";
  41. crowdLabelCodes = [];
  42. isSyncAddresses = true;
  43. }
  44. /// 机构名称
  45. String get organizationName => Store.user.organizationName;
  46. /// 村选项集合
  47. List<StringKVModel> get villageOptions => Store.user.residence;
  48. /// 是否只创建档案
  49. bool get isCreateOnly => _isCreateOnly.value;
  50. set isCreateOnly(bool val) => _isCreateOnly.updateValue(val);
  51. /// 姓名
  52. String get name => _name.value;
  53. set name(String val) => _name.updateValue(val);
  54. /// 个人编号
  55. String get personalNo => _personalNo.value;
  56. set personalNo(String val) => _personalNo.updateValue(val);
  57. /// 手机号
  58. String get phoneNo => _phoneNo.value;
  59. set phoneNo(String val) => _phoneNo.updateValue(val);
  60. /// 证件类型
  61. CardTypeEnum get cardType => _cardType.value;
  62. set cardType(CardTypeEnum val) => _cardType.updateValue(val);
  63. /// 证件号
  64. String get cardNo => _cardNo.value;
  65. set cardNo(String val) {
  66. _cardNo.updateValue(val);
  67. if (cardType == CardTypeEnum.Identity) {
  68. birthday = extractBirthDateFromIDCard(val);
  69. }
  70. }
  71. DateTime extractBirthDateFromIDCard(String idCardNumber) {
  72. final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$');
  73. final match = idCardRegex.firstMatch(idCardNumber);
  74. if (match != null) {
  75. final year = int.parse(match.group(2)!);
  76. final month = int.parse(match.group(3)!);
  77. final day = int.parse(match.group(4)!);
  78. final birthDate = DateTime(year, month, day);
  79. return birthDate;
  80. }
  81. return DateTime(1970, 1, 1); // 返回一个默认值,表示无法提取出生日期
  82. }
  83. /// 民族
  84. String get nation => _nation.value;
  85. set nation(String val) => _nation.updateValue(val);
  86. /// 性别
  87. GenderEnum get gender => _gender.value;
  88. set gender(GenderEnum val) => _gender.updateValue(val);
  89. /// 户籍地址
  90. String get censusRegister => _censusRegister.value;
  91. set censusRegister(String val) => _censusRegister.updateValue(val);
  92. /// 现住址
  93. String get address => _address.value;
  94. set address(String val) => _address.updateValue(val);
  95. /// 村/居委会 编号
  96. String get villageCode => _villageCode.value;
  97. set villageCode(String val) => _villageCode.updateValue(val);
  98. /// 村/居委会 名称
  99. String get villageName {
  100. String name = "";
  101. if (villageCode.isNotEmpty) {
  102. final dto = villageOptions.firstWhereOrNull((e) => e.key == villageCode);
  103. if (dto != null) {
  104. name = dto.value;
  105. }
  106. }
  107. return name;
  108. }
  109. /// 人群分类集合
  110. List<String> get crowdLabelCodes =>
  111. UnmodifiableListView(_crowdLabelCodes.toList());
  112. set crowdLabelCodes(List<String> val) => _crowdLabelCodes.value = val;
  113. /// 生日
  114. DateTime? get birthday => _birthday.value;
  115. set birthday(DateTime? val) {
  116. if (val != _birthday.value) {
  117. _birthday.value = val;
  118. if (val != null) {
  119. _age.value = DataTimeUtils.calculateAge(val);
  120. } else if (val == null) {
  121. _age.value = "";
  122. }
  123. }
  124. }
  125. /// 年龄
  126. String get age => _age.value;
  127. /// 是否开启地址同步
  128. bool get isSyncAddresses => _isSyncAddresses.value;
  129. set isSyncAddresses(bool val) => _isSyncAddresses.updateValue(val);
  130. }