|
@@ -8,6 +8,7 @@ import 'package:vitalapp/architecture/utils/prompt_box.dart';
|
|
|
import 'package:vitalapp/architecture/values/features.dart';
|
|
|
import 'package:vitalapp/components/alert_dialog.dart';
|
|
|
import 'package:vitalapp/global.dart';
|
|
|
+import 'package:vitalapp/helper/id_card_helper.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/device.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/models/device.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/patient.dart';
|
|
@@ -501,28 +502,6 @@ class CreatePatientController extends FControllerBase
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- bool validateIDCard(String idCard) {
|
|
|
- // 校验身份证号码长度
|
|
|
- if (idCard.length != 18) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 校验前17位是否为数字
|
|
|
- String idCard17 = idCard.substring(0, 17);
|
|
|
- if (!isNumeric(idCard17)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 校验最后一位校验码
|
|
|
- String checkCode = getCheckCode(idCard17);
|
|
|
- if (idCard[17].toUpperCase() != checkCode) {
|
|
|
- print("checkCode: $checkCode");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
bool isNumeric(String str) {
|
|
|
if (str.isEmpty) {
|
|
|
return false;
|
|
@@ -541,50 +520,6 @@ class CreatePatientController extends FControllerBase
|
|
|
return alphaNumericChineseWithSpaceRegExp.hasMatch(str);
|
|
|
}
|
|
|
|
|
|
- String getCheckCode(String idCard17) {
|
|
|
- List<int> coefficients = [
|
|
|
- 7,
|
|
|
- 9,
|
|
|
- 10,
|
|
|
- 5,
|
|
|
- 8,
|
|
|
- 4,
|
|
|
- 2,
|
|
|
- 1,
|
|
|
- 6,
|
|
|
- 3,
|
|
|
- 7,
|
|
|
- 9,
|
|
|
- 10,
|
|
|
- 5,
|
|
|
- 8,
|
|
|
- 4,
|
|
|
- 2
|
|
|
- ];
|
|
|
- List<String> checkCodes = [
|
|
|
- '1',
|
|
|
- '0',
|
|
|
- 'X',
|
|
|
- '9',
|
|
|
- '8',
|
|
|
- '7',
|
|
|
- '6',
|
|
|
- '5',
|
|
|
- '4',
|
|
|
- '3',
|
|
|
- '2'
|
|
|
- ];
|
|
|
-
|
|
|
- int sum = 0;
|
|
|
- for (int i = 0; i < idCard17.length; i++) {
|
|
|
- int digit = int.parse(idCard17[i]);
|
|
|
- sum += digit * coefficients[i];
|
|
|
- }
|
|
|
-
|
|
|
- int remainder = sum % 11;
|
|
|
- return checkCodes[remainder];
|
|
|
- }
|
|
|
-
|
|
|
Future<String?> _validateForm() async {
|
|
|
if (state.name.isEmpty) {
|
|
|
return "请填写姓名";
|
|
@@ -611,7 +546,7 @@ class CreatePatientController extends FControllerBase
|
|
|
}
|
|
|
}
|
|
|
if (state.cardType == CardTypeEnum.Identity) {
|
|
|
- bool isNotIDCard = validateIDCard(state.cardNo);
|
|
|
+ bool isNotIDCard = IdCardHelper.validateIDCard(state.cardNo);
|
|
|
if (!isNotIDCard) {
|
|
|
return "请填写正确的证件号";
|
|
|
}
|