Browse Source

Merge branch 'master' of http://git.shengws.com/csx/XT_New

XMLWAN 3 years ago
parent
commit
3f22630e0b
1 changed files with 59 additions and 9 deletions
  1. 59 9
      controllers/patient_api_controller.go

+ 59 - 9
controllers/patient_api_controller.go View File

@@ -6,7 +6,6 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
-	"log"
10 9
 	"math/rand"
11 10
 	"reflect"
12 11
 	"regexp"
@@ -3561,10 +3560,17 @@ func (c *PatientApiController) ExportPatients() {
3561 3560
 						continue
3562 3561
 					}
3563 3562
 					patient.IdCardNo = id_card_no
3564
-					patient.Birthday = GetBirthDay(id_card_no).Unix()
3563
+					//patient.Birthday = GetBirthDay(id_card_no).Unix()
3564
+					if GetBirthDay(id_card_no) == nil {
3565
+						patient.Birthday = 0
3566
+					} else {
3567
+						patient.Birthday = GetBirthDay(id_card_no).Unix()
3568
+
3569
+					}
3565 3570
 				}
3566 3571
 			}
3567 3572
 
3573
+			fmt.Println("111112222")
3568 3574
 			if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
3569 3575
 				first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
3570 3576
 				timeLayout := "2006/01/02"
@@ -3846,13 +3852,12 @@ func (c *PatientApiController) ExportPatients() {
3846 3852
 }
3847 3853
 
3848 3854
 func GetBirthDay(IDCardNo string) *time.Time {
3849
-	dayStr := IDCardNo[6:14] + "000001"
3850
-	birthDay, err := time.Parse("20060102150405", dayStr)
3855
+	dayStr := IDCardNo[6:14]
3856
+	birthDay, err := time.Parse("20060102", dayStr)
3851 3857
 	if err != nil {
3852
-		log.Fatal(err)
3858
+		fmt.Println(err)
3853 3859
 		return nil
3854 3860
 	}
3855
-
3856 3861
 	return &birthDay
3857 3862
 }
3858 3863
 
@@ -3863,9 +3868,54 @@ func VerifyMobileFormat(mobileNum string) bool {
3863 3868
 	return reg.MatchString(mobileNum)
3864 3869
 }
3865 3870
 
3866
-func IsIdCard(idCard string) (res bool) {
3867
-	res, _ = regexp.Match("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$", []byte(idCard))
3868
-	return
3871
+func IsIdCard(id string) (res bool) {
3872
+	id = strings.ToUpper(id)
3873
+	if len(id) != 15 && len(id) != 18 {
3874
+		fmt.Println("11111")
3875
+		return false
3876
+	}
3877
+	r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
3878
+	if !r.MatchString(id) {
3879
+		fmt.Println("2222222")
3880
+
3881
+		return false
3882
+	}
3883
+	if len(id) == 15 {
3884
+		tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
3885
+		if tm2.Unix() <= 0 {
3886
+			fmt.Println("33333333")
3887
+
3888
+			return false
3889
+		}
3890
+		return true
3891
+	} else {
3892
+		tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
3893
+		if tm2.Unix() <= 0 {
3894
+			fmt.Println("fdfgdgfdgfd")
3895
+
3896
+			return false
3897
+		}
3898
+		//检验18位身份证的校验码是否正确。
3899
+		//校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
3900
+		arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
3901
+		arr_ch := []string{",", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
3902
+		sign := 0
3903
+		for k, v := range arr_int {
3904
+
3905
+			int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
3906
+
3907
+			sign += int_temp * v
3908
+
3909
+		}
3910
+		n := sign % 11
3911
+		val_num := arr_ch[n]
3912
+		if val_num != string([]byte(id)[17:18]) {
3913
+			fmt.Println("555555555555")
3914
+
3915
+			return false
3916
+		}
3917
+		return true
3918
+	}
3869 3919
 }
3870 3920
 
3871 3921
 func (c *PatientApiController) SaveEditAdvices() {