state.dart 2.8 KB

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