123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import 'dart:collection';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:get/get.dart';
- import 'package:vnoteapp/architecture/defines.dart';
- import 'package:vnoteapp/architecture/types/index.dart';
- import 'package:vnoteapp/architecture/utils/datetime.dart';
- import 'package:vnoteapp/pages/controllers/crowd_labels.dart';
- import 'package:vnoteapp/store/store.dart';
- class CreatePatientState {
- final RxBool _isCreateOnly = RxBool(false);
- final RxString _name = RxString("");
- final RxString _personalNo = RxString("");
- final RxString _phoneNo = RxString("");
- final Rx<CardTypeEnum> _cardType = Rx<CardTypeEnum>(CardTypeEnum.Identity);
- final RxString _cardNo = RxString("");
- final RxString _nation = RxString("");
- final Rx<GenderEnum> _gender = Rx<GenderEnum>(GenderEnum.Male);
- final Rx<DateTime?> _birthday = Rx<DateTime?>(null);
- final RxString _age = RxString("");
- final RxString _censusRegister = RxString("");
- final RxString _address = RxString("");
- final RxString _villageCode = RxString("");
- final RxList<String> _crowdLabelCodes = RxList();
- final RxBool _isSyncAddresses = RxBool(true);
- void reset() {
- var crowdLabelController = Get.find<CrowdLabelsController>();
- crowdLabelController.state.selectedNormalCodes = [];
- crowdLabelController.state.selectedDiseaseCodes = [];
- crowdLabelController.state.selectedSpecialCareCodes = [];
- name = "";
- personalNo = "";
- cardType = CardTypeEnum.Identity;
- cardNo = "";
- nation = "";
- gender = GenderEnum.Male;
- birthday = null;
- censusRegister = "";
- address = "";
- villageCode = "";
- phoneNo = "";
- crowdLabelCodes = [];
- isSyncAddresses = true;
- }
- /// 机构名称
- String get organizationName => Store.user.organizationName;
- /// 村选项集合
- List<StringKVModel> get villageOptions => Store.user.residence;
- /// 是否只创建档案
- bool get isCreateOnly => _isCreateOnly.value;
- set isCreateOnly(bool val) => _isCreateOnly.updateValue(val);
- /// 姓名
- String get name => _name.value;
- set name(String val) => _name.updateValue(val);
- /// 个人编号
- String get personalNo => _personalNo.value;
- set personalNo(String val) => _personalNo.updateValue(val);
- /// 手机号
- String get phoneNo => _phoneNo.value;
- set phoneNo(String val) => _phoneNo.updateValue(val);
- /// 证件类型
- CardTypeEnum get cardType => _cardType.value;
- set cardType(CardTypeEnum val) => _cardType.updateValue(val);
- /// 证件号
- String get cardNo => _cardNo.value;
- set cardNo(String val) {
- _cardNo.updateValue(val);
- if (cardType == CardTypeEnum.Identity) {
- birthday = extractBirthDateFromIDCard(val);
- }
- }
- 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); // 返回一个默认值,表示无法提取出生日期
- }
- /// 民族
- String get nation => _nation.value;
- set nation(String val) => _nation.updateValue(val);
- /// 性别
- GenderEnum get gender => _gender.value;
- set gender(GenderEnum val) => _gender.updateValue(val);
- /// 户籍地址
- String get censusRegister => _censusRegister.value;
- set censusRegister(String val) => _censusRegister.updateValue(val);
- /// 现住址
- String get address => _address.value;
- set address(String val) => _address.updateValue(val);
- /// 村/居委会 编号
- String get villageCode => _villageCode.value;
- set villageCode(String val) => _villageCode.updateValue(val);
- /// 村/居委会 名称
- String get villageName {
- String name = "";
- if (villageCode.isNotEmpty) {
- final dto = villageOptions.firstWhereOrNull((e) => e.key == villageCode);
- if (dto != null) {
- name = dto.value;
- }
- }
- return name;
- }
- /// 人群分类集合
- List<String> get crowdLabelCodes =>
- UnmodifiableListView(_crowdLabelCodes.toList());
- set crowdLabelCodes(List<String> val) => _crowdLabelCodes.value = val;
- /// 生日
- DateTime? get birthday => _birthday.value;
- set birthday(DateTime? val) {
- if (val != _birthday.value) {
- _birthday.value = val;
- if (val != null) {
- _age.value = DataTimeUtils.calculateAge(val);
- } else if (val == null) {
- _age.value = "";
- }
- }
- }
- /// 年龄
- String get age => _age.value;
- /// 是否开启地址同步
- bool get isSyncAddresses => _isSyncAddresses.value;
- set isSyncAddresses(bool val) => _isSyncAddresses.updateValue(val);
- }
|