张保健 il y a 2 ans
Parent
révision
2b571c2d78
8 fichiers modifiés avec 526 ajouts et 6 suppressions
  1. 8 0
      controllers/lis.go
  2. 38 0
      models/lis_model.go
  3. 11 5
      service/bl_service.go
  4. 20 0
      service/db.go
  5. 1 1
      service/ms_db.go
  6. 52 0
      service/ms_two_db.go
  7. 363 0
      service/sh_service.go
  8. 33 0
      service/ystx_service.go

+ 8 - 0
controllers/lis.go Voir le fichier

@@ -427,3 +427,11 @@ func (c *LisController) SyncBlResultLis() {
427 427
 		"resultList": "同步成功",
428 428
 	})
429 429
 }
430
+
431
+//肇庆三鹤
432
+func (c *LisController) SyncZQSHResultLis() {
433
+	service.GetResultDataInsertDB(10215)
434
+	c.ServeSuccessJSON(map[string]interface{}{
435
+		"resultList": "同步成功",
436
+	})
437
+}

+ 38 - 0
models/lis_model.go Voir le fichier

@@ -381,3 +381,41 @@ type UserAdminRole struct {
381 381
 func (UserAdminRole) TableName() string {
382 382
 	return "sgj_user_admin_role"
383 383
 }
384
+
385
+type VMHisProjectTeam struct {
386
+	ID                int64                `gorm:"column:id" json:"id" form:"id"`
387
+	ProjectTeam       string               `gorm:"column:project_team" json:"project_team" form:"project_team"`
388
+	Price             float64              `gorm:"column:price" json:"price" form:"price"`
389
+	Pinyin            string               `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
390
+	Wubi              string               `gorm:"column:wubi" json:"wubi" form:"wubi"`
391
+	TubeColor         int64                `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
392
+	TeamType          int64                `gorm:"column:team_type" json:"team_type" form:"team_type"`
393
+	Remark            string               `gorm:"column:remark" json:"remark" form:"remark"`
394
+	UserOrgId         int64                `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
395
+	Status            int64                `gorm:"column:status" json:"status" form:"status"`
396
+	CreatedTime       int64                `gorm:"column:created_time" json:"created_time" form:"created_time"`
397
+	UpdatedTime       int64                `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
398
+	ProjectId         string               `gorm:"column:project_id" json:"project_id" form:"project_id"`
399
+	VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
400
+	ItemId            string               `gorm:"column:item_id" json:"item_id" form:"item_id"`
401
+}
402
+
403
+func (VMHisProjectTeam) TableName() string {
404
+	return "xt_his_project_team"
405
+}
406
+
407
+type VMItemProjectList struct {
408
+	ID          int64 `gorm:"column:id" json:"id" form:"id"`
409
+	Number      int64 `gorm:"column:number" json:"number" form:"number"`
410
+	UserOrgId   int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
411
+	ProjectId   int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
412
+	Status      int64 `gorm:"column:status" json:"status" form:"status"`
413
+	CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
414
+	UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
415
+	TeamId      int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
416
+	Type        int64 `gorm:"column:type" json:"type" form:"type"`
417
+}
418
+
419
+func (VMItemProjectList) TableName() string {
420
+	return "xt_his_project_list"
421
+}

+ 11 - 5
service/bl_service.go Voir le fichier

@@ -166,6 +166,7 @@ type HisLabelPrintInfo struct {
166 166
 	PrescriptionId         int64                  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
167 167
 	HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
168 168
 	Patient                models.Patients        `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
169
+	VMHisProjectTeam       VMHisProjectTeam       `gorm:"ForeignKey:ID;AssociationForeignKey:ItemId" json:"team"`
169 170
 }
170 171
 
171 172
 func (HisLabelPrintInfo) TableName() string {
@@ -270,7 +271,7 @@ func GetLisDataById(org_id int64, last_id int64) (list []*HisLabelPrintInfo, err
270 271
 }
271 272
 
272 273
 func GetAllLisData(org_id int64) (list []*HisLabelPrintInfo, err error) {
273
-	err = readDb.Model(&HisLabelPrintInfo{}).Preload("Patient", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
274
+	err = readDb.Model(&HisLabelPrintInfo{}).Preload("Patient", "status = 1").Preload("VMHisProjectTeam", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
274 275
 		return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
275 276
 			return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
276 277
 				return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
@@ -343,7 +344,7 @@ func GetDataInsertDB(org_id int64) {
343 344
 				cms.Diagnosis = name
344 345
 				cms.Stype = ""
345 346
 				cms.Samstate = ""
346
-				cms.Desccode = strconv.FormatInt(item.ID, 10)
347
+				cms.Desccode = strconv.FormatInt(item.ItemId, 10)
347 348
 				cms.Descr = item.ProjectName
348 349
 
349 350
 				data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
@@ -389,7 +390,7 @@ func GetDataInsertDB(org_id int64) {
389 390
 				cms.Diagnosis = name
390 391
 				cms.Stype = ""
391 392
 				cms.Samstate = ""
392
-				cms.Desccode = strconv.FormatInt(item.ID, 10)
393
+				cms.Desccode = strconv.FormatInt(item.ProjectId, 10)
393 394
 				cms.Descr = item.ProjectName
394 395
 
395 396
 				tm := time.Unix(item.Ctime, 0)
@@ -464,7 +465,7 @@ func GetDataInsertDB(org_id int64) {
464 465
 					cms.Diagnosis = name
465 466
 					cms.Stype = ""
466 467
 					cms.Samstate = ""
467
-					cms.Desccode = strconv.FormatInt(item.ID, 10)
468
+					cms.Desccode = strconv.FormatInt(item.ItemId, 10)
468 469
 					cms.Descr = item.ProjectName
469 470
 
470 471
 					//data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
@@ -510,7 +511,7 @@ func GetDataInsertDB(org_id int64) {
510 511
 					cms.Diagnosis = name
511 512
 					cms.Stype = ""
512 513
 					cms.Samstate = ""
513
-					cms.Desccode = strconv.FormatInt(item.ID, 10)
514
+					cms.Desccode = strconv.FormatInt(item.ProjectId, 10)
514 515
 					cms.Descr = item.ProjectName
515 516
 					tm := time.Unix(item.Ctime, 0)
516 517
 					cms.Sampletime = tm
@@ -1018,3 +1019,8 @@ func GetHisLabelPrintInfoById(id string) (info HisLabelPrintInfo, err error) {
1018 1019
 	err = readDb.Model(&HisLabelPrintInfo{}).Where("id = ?", id).First(&info).Error
1019 1020
 	return
1020 1021
 }
1022
+
1023
+func GetPatientsInfoByIDCardNo(id_card_no string, org_id int64) (info models.Patients, err error) {
1024
+	err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, org_id).First(&info).Error
1025
+	return
1026
+}

+ 20 - 0
service/db.go Voir le fichier

@@ -38,6 +38,7 @@ var backupDb *gorm.DB
38 38
 var err error
39 39
 
40 40
 var blDb *gorm.DB
41
+var shDb *gorm.DB
41 42
 
42 43
 func ConnectDB() {
43 44
 
@@ -107,6 +108,12 @@ func ConnectDB() {
107 108
 	// fmt.Println(blPass)
108 109
 	// fmt.Println(blName)
109 110
 
111
+	shHost := beego.AppConfig.String("shmysqlhost")
112
+	shPort := beego.AppConfig.String("shmysqlport")
113
+	shUser := beego.AppConfig.String("shmysqluser")
114
+	shPass := beego.AppConfig.String("shmysqlpass")
115
+	shName := beego.AppConfig.String("shmysqlname")
116
+
110 117
 	rdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUser, readPass, readHost, readPort, readName)
111 118
 	wdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUser, writePass, writeHost, writePort, writeName)
112 119
 	tempwdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", tempwriteUser, tempwritePass, tempwriteHost, tempwritePort, tempwriteName)
@@ -120,6 +127,8 @@ func ConnectDB() {
120 127
 
121 128
 	// bldsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", blUser, blPass, blHost, blPort, blName)
122 129
 
130
+	shdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", shUser, shPass, shHost, shPort, shName)
131
+
123 132
 	// bdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", backupUser, backupPass, backupHost, backupPort, backupName)
124 133
 
125 134
 	readDb, err = gorm.Open("mysql", rdsn)
@@ -207,6 +216,17 @@ func ConnectDB() {
207 216
 	// blDb.DB().SetMaxOpenConns(100)
208 217
 	// blDb.LogMode(true)
209 218
 
219
+	shDb, err = gorm.Open("mysql", shdsn)
220
+	if err != nil {
221
+		fmt.Println("12344")
222
+		fmt.Println(bldsn)
223
+
224
+		fmt.Println(err)
225
+	}
226
+	shDb.DB().SetMaxIdleConns(10)
227
+	shDb.DB().SetMaxOpenConns(100)
228
+	shDb.LogMode(true)
229
+
210 230
 }
211 231
 
212 232
 //func DisconnectDB() {

+ 1 - 1
service/ms_db.go Voir le fichier

@@ -35,7 +35,7 @@ var (
35 35
 	dbname   = beego.AppConfig.DefaultString(dbName+"::dbname", "hyDB")
36 36
 )
37 37
 
38
-func ConnectMSDB() {
38
+func ConnectSHMSDB() {
39 39
 	connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s",
40 40
 		host, user, password, port, dbname)
41 41
 	fmt.Println(connectionString)

+ 52 - 0
service/ms_two_db.go Voir le fichier

@@ -0,0 +1,52 @@
1
+// Pipe - A small and beautiful blogging platform written in golang.
2
+// Copyright (C) 2017-2018, b3log.org
3
+//
4
+// This program is free software: you can redistribute it and/or modify
5
+// it under the terms of the GNU General Public License as published by
6
+// the Free Software Foundation, either version 3 of the License, or
7
+// (at your option) any later version.
8
+//
9
+// This program is distributed in the hope that it will be useful,
10
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
+// GNU General Public License for more details.
13
+//
14
+// You should have received a copy of the GNU General Public License
15
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
+
17
+package service
18
+
19
+import (
20
+	"fmt"
21
+	"github.com/astaxie/beego"
22
+	"github.com/jinzhu/gorm"
23
+	_ "github.com/jinzhu/gorm/dialects/mssql" // mssql
24
+	_ "github.com/jinzhu/gorm/dialects/mysql" // mysql
25
+)
26
+
27
+var dataBase2 *gorm.DB
28
+
29
+var (
30
+	dbName2   = "local"
31
+	user2     = beego.AppConfig.DefaultString(dbName2+"::user", "KingMed")
32
+	password2 = beego.AppConfig.DefaultString(dbName2+"::password", "KingMed")
33
+	host2     = beego.AppConfig.DefaultString(dbName2+"::host", "192.168.10.80")
34
+	port2     = beego.AppConfig.DefaultInt(dbName2+"::port", 1633)
35
+	dbname2   = beego.AppConfig.DefaultString(dbName2+"::dbname", "KMDB")
36
+)
37
+
38
+func ConnectMSDB2() {
39
+	connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s",
40
+		host2, user2, password2, port2, dbname2)
41
+	fmt.Println(connectionString)
42
+	db, err := gorm.Open("mssql", connectionString)
43
+	if err != nil {
44
+		fmt.Println("failed to connect database")
45
+		fmt.Println(err)
46
+
47
+	}
48
+	db.LogMode(true)
49
+	db.CommonDB()
50
+	dataBase = db
51
+
52
+}

+ 363 - 0
service/sh_service.go Voir le fichier

@@ -0,0 +1,363 @@
1
+package service
2
+
3
+import (
4
+	"fmt"
5
+	"regexp"
6
+	"unicode"
7
+)
8
+
9
+type KMResult struct {
10
+	FRequestCode           string `gorm:"column:F_RequestCode" json:"F_RequestCode" form:"F_RequestCode"`
11
+	FHospSampleID          string `gorm:"column:F_HospSampleID" json:"F_HospSampleID" form:"F_HospSampleID"`
12
+	FHospSampleNumber      string `gorm:"column:F_HospSampleNumber" json:"F_HospSampleNumber" form:"F_HospSampleNumber"`
13
+	FInputDate             string `gorm:"column:F_InputDate" json:"F_InputDate" form:"F_InputDate"`
14
+	FSamplingDate          string `gorm:"column:F_SamplingDate" json:"F_SamplingDate" form:"F_SamplingDate"`
15
+	FName                  string `gorm:"column:F_Name" json:"F_Name" form:"F_Name"`
16
+	FSex                   string `gorm:"column:F_Sex" json:"F_Sex" form:"F_Sex"`
17
+	FAge                   string `gorm:"column:F_Age" json:"F_Age" form:"F_Age"`
18
+	FAgeUnit               string `gorm:"column:F_AgeUnit" json:"F_AgeUnit" form:"F_AgeUnit"`
19
+	FPatientNumber         string `gorm:"column:F_PatientNumber" json:"F_PatientNumber" form:"F_PatientNumber"`
20
+	FItemType              string `gorm:"column:F_ItemType" json:"F_ItemType" form:"F_ItemType"`
21
+	FCompoundItem          string `gorm:"column:F_CompoundItem" json:"F_CompoundItem" form:"F_CompoundItem"`
22
+	FCompoundItemName      string `gorm:"column:F_CompoundItemName" json:"F_CompoundItemName" form:"F_CompoundItemName"`
23
+	FNaturalItem           string `gorm:"column:F_NaturalItem" json:"F_NaturalItem" form:"F_NaturalItem"`
24
+	FNaturalItemName       string `gorm:"column:F_NaturalItemName" json:"F_NaturalItemName" form:"F_NaturalItemName"`
25
+	FSingleItem            string `gorm:"column:F_SingleItem" json:"F_SingleItem" form:"F_SingleItem"`
26
+	FSingleItemName        string `gorm:"column:F_SingleItemName" json:"F_SingleItemName" form:"F_SingleItemName"`
27
+	FHospNaturalItem       string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem" form:"F_HospNaturalItem"`
28
+	FHospNaturalItemName   string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName" form:"F_HospNaturalItemName"`
29
+	FHospItem              string `gorm:"column:F_HospItem" json:"F_HospItem" form:"F_HospItem"`
30
+	FHospItemName          string `gorm:"column:F_HospItemName" json:"F_HospItemName" form:"F_HospItemName"`
31
+	FTestNO                string `gorm:"column:F_TestNO" json:"F_TestNO" form:"F_TestNO"`
32
+	FResult                string `gorm:"column:F_Result" json:"F_Result" form:"F_Result"`
33
+	FUnit                  string `gorm:"column:F_Unit" json:"F_Unit" form:"F_Unit"`
34
+	FHint                  string `gorm:"column:F_Hint" json:"F_Hint" form:"F_Hint"`
35
+	FSuggestion            string `gorm:"column:F_Suggestion" json:"F_Suggestion" form:"F_Suggestion"`
36
+	FReference             string `gorm:"column:F_Reference" json:"F_Reference" form:"F_Reference"`
37
+	FReference2            string `gorm:"column:F_Reference2" json:"F_Reference2" form:"F_Reference2"`
38
+	FDepartmentName        string `gorm:"column:F_DepartmentName" json:"F_DepartmentName" form:"F_DepartmentName"`
39
+	FRecorderName          string `gorm:"column: F_RecorderName" json:"F_RecorderName" form:"F_RecorderName"`
40
+	FRecordTime            string `gorm:"column:F_RecordTime" json:"F_RecordTime" form:"F_RecordTime"`
41
+	FCheckerName           string `gorm:"column:F_CheckerName" json:"F_CheckerName" form:"F_CheckerName"`
42
+	FCheckTime             string `gorm:"column:F_CheckTime" json:"F_CheckTime" form:"F_CheckTime"`
43
+	FAuthorizeName         string `gorm:"column:F_AuthorizeName" json:"F_AuthorizeName" form:"F_AuthorizeName"`
44
+	FAuthorizeTime         string `gorm:"column:F_AuthorizeTime" json:"F_AuthorizeTime" form:"F_AuthorizeTime"`
45
+	FSubResults            string `gorm:"column:F_SubResults" json:"F_SubResults" form:"F_SubResults"`
46
+	FPathologyGrossingDesc string `gorm:"column:F_PathologyGrossingDesc" json:"F_PathologyGrossingDesc" form:"F_PathologyGrossingDesc"`
47
+	FReportBarCode         string `gorm:"column:F_ReportBarCode" json:"F_ReportBarCode" form:"F_ReportBarCode"`
48
+	FReceiveTime           string `gorm:"column:F_ReceiveTime" json:"F_ReceiveTime" form:"F_ReceiveTime"`
49
+	FStatus                string `gorm:"column:F_Status" json:"F_Status" form:"F_Status"`
50
+	FRemark                string `gorm:"column:F_Remark" json:"F_Remark" form:"F_Remark"`
51
+	FTestMethodName        string `gorm:"column:F_TestMethodName" json:"F_TestMethodName" form:"F_TestMethodName"`
52
+	FMachineName           string `gorm:"column:F_MachineName" json:"F_MachineName" form:"F_MachineName"`
53
+	FItemDesc              string `gorm:"column:F_ItemDesc" json:"F_ItemDesc" form:"F_ItemDesc"`
54
+	FIsDelayed             string `gorm:"column:F_IsDelayed" json:"F_IsDelayed" form:"F_IsDelayed"`
55
+	FDelayeddesc           string `gorm:"column:F_Delayeddesc" json:"F_Delayeddesc" form:"F_Delayeddesc"`
56
+	FIsReimbu              string `gorm:"column:F_IsReimbu" json:"F_IsReimbu" form:"F_IsReimbu"`
57
+	FReimbuDesc            string `gorm:"column:F_ReimbuDesc" json:"F_ReimbuDesc" form:"F_ReimbuDesc"`
58
+	FDetailItemID          string `gorm:"column:F_DetailItemID" json:"F_DetailItemID" form:"F_DetailItemID"`
59
+	FIDCardNo              string `gorm:"column:F_IDCardNo" json:"F_IDCardNo" form:"F_IDCardNo"`
60
+}
61
+
62
+func (KMResult) TableName() string {
63
+	return "v_km_lis_result"
64
+}
65
+
66
+//获取lis返回检验检查结果数据
67
+func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
68
+	record, _ := GetLastSyncResultRecord(org_id)
69
+	fmt.Println(record)
70
+	//if record.ID == 0 {
71
+	//	list, err := GetSHResultRecord()
72
+	//	if err == nil {
73
+	//		fmt.Println(list)
74
+	//
75
+	//		//插入到系统检验检查数据
76
+	//		for _, item := range list {
77
+	//			project_id := int64(0)
78
+	//			if len(item.FIDCardNo) > 0 {
79
+	//				project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
80
+	//			} else {
81
+	//				continue
82
+	//			}
83
+	//			printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
84
+	//
85
+	//			if printInfo.ID == 0 {
86
+	//				fmt.Println(item)
87
+	//				fmt.Println(printInfo)
88
+	//				fmt.Println("暂无该患者")
89
+	//				continue
90
+	//			}
91
+	//
92
+	//			item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
93
+	//
94
+	//			tx := writeMiddleDb.Begin()
95
+	//			var inspection models.MiddleInspection
96
+	//			var inspection_reference models.MiddleInspectionReference
97
+	//
98
+	//			recordDateStr := ""
99
+	//			//inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
100
+	//
101
+	//			recordDateStr = item.FRecordTime
102
+	//			date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
103
+	//			record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
104
+	//			var total int
105
+	//			var RangeOptions string
106
+	//			var RangeMin string
107
+	//			var RangeMax string
108
+	//			// 判断检查类型
109
+	//			var ItemType int
110
+	//			if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
111
+	//				ItemType = 2
112
+	//			} else {
113
+	//				if strings.Contains(item.FReference, "-") {
114
+	//					ItemType = 1
115
+	//				} else {
116
+	//					ItemType = 2
117
+	//				}
118
+	//			}
119
+	//
120
+	//			if ItemType == 1 {
121
+	//				Range := strings.Split(item.FReference, "-")
122
+	//				RangeMin = Range[0]
123
+	//				RangeMax = Range[1]
124
+	//			} else {
125
+	//				RangeOptions = item.FReference
126
+	//			}
127
+	//
128
+	//			err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
129
+	//			if inspection_reference.ID > 0 {
130
+	//				ItemType = inspection_reference.RangeType
131
+	//			}
132
+	//			if total <= 0 {
133
+	//				inspection_reference.OrgId = org_id
134
+	//				inspection_reference.ProjectName = item.FCompoundItemName
135
+	//				inspection_reference.Project = item.FCompoundItemName
136
+	//				inspection_reference.ProjectId = project_id
137
+	//				inspection_reference.ItemName = item.FSingleItemName
138
+	//				inspection_reference.ItemNameAddition = ""
139
+	//				inspection_reference.ItemId = item_id
140
+	//				inspection_reference.RangeType = ItemType
141
+	//				inspection_reference.RangeMin = RangeMin
142
+	//				inspection_reference.RangeMax = RangeMax
143
+	//				inspection_reference.RangeOptions = RangeOptions
144
+	//				inspection_reference.Unit = item.FUnit
145
+	//				inspection_reference.Status = 1
146
+	//				inspection_reference.CreatedTime = time.Now().Unix()
147
+	//				inspection_reference.UpdatedTime = time.Now().Unix()
148
+	//				inspection_reference.InspectDate = item.FCheckTime
149
+	//				inspection_reference.UTime = item.FCheckTime
150
+	//				err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
151
+	//				if err != nil {
152
+	//					tx.Rollback()
153
+	//				}
154
+	//			}
155
+	//
156
+	//			var itotal int
157
+	//			err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, record_date.Unix(), printInfo.ID).Find(&inspection).Count(&itotal).Error
158
+	//			if itotal <= 0 {
159
+	//				inspection.PatientId = printInfo.ID
160
+	//				inspection.OrgId = org_id
161
+	//				inspection.ProjectId = project_id
162
+	//				inspection.ItemName = inspection_reference.ItemName
163
+	//				inspection.ProjectName = inspection_reference.ProjectName
164
+	//				inspection.InspectType = ItemType
165
+	//				inspection.ItemId = item_id
166
+	//				inspection.InspectValue = item.FResult
167
+	//				inspection.InspectDate = item.FCheckTime
168
+	//				inspection.RecordDate = record_date.Unix()
169
+	//				inspection.Status = 1
170
+	//				inspection.CreatedTime = time.Now().Unix()
171
+	//				inspection.UpdatedTime = time.Now().Unix()
172
+	//				inspection.UTime = item.FCheckTime
173
+	//				inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
174
+	//				err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
175
+	//				if err != nil {
176
+	//					tx.Rollback()
177
+	//				}
178
+	//			}
179
+	//
180
+	//			tx.Commit()
181
+	//
182
+	//		}
183
+	//		//插入一条查询检验检查结果记录状态数据
184
+	//		var info LisSyncResultStatusInfo
185
+	//		info.Ctime = time.Now().Unix()
186
+	//		info.Status = 1
187
+	//		info.Mtime = time.Now().Unix()
188
+	//		info.OrgId = org_id
189
+	//		info.IsResult = 1
190
+	//		info.LastId = int64(len(list))
191
+	//		info.ResultDate = time.Now().Unix()
192
+	//		writeMiddleDb.Save(&info)
193
+	//	}
194
+	//
195
+	//} else
196
+	//{
197
+	//	if record.LastId != 0 {
198
+	//		list, err := GetResultRecordByID(record.LastId)
199
+	//		fmt.Println(list)
200
+	//		//插入中间库中
201
+	//		//插入一条插入中间库记录数据
202
+	//		if err == nil {
203
+	//
204
+	//			//插入到系统检验检查数据
205
+	//			for _, item := range list {
206
+	//				project_id := int64(0)
207
+	//				if len(item.Barcode) > 0 {
208
+	//					project_id, _ = GetBljhProjectID(org_id, item.Groupname)
209
+	//				} else {
210
+	//					continue
211
+	//				}
212
+	//				printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
213
+	//				item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
214
+	//
215
+	//				tx := writeMiddleDb.Begin()
216
+	//				var inspection models.MiddleInspection
217
+	//				var inspection_reference models.MiddleInspectionReference
218
+	//
219
+	//				recordDateStr := ""
220
+	//				inspect_date := item.Repdate.Format("2006-01-02 15:04")
221
+	//				if item.Repdate.Unix() == 0 {
222
+	//					recordDateStr = time.Now().Format("2006-01-02 15:04")
223
+	//				} else {
224
+	//
225
+	//					recordDateStr = inspect_date
226
+	//				}
227
+	//
228
+	//				date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
229
+	//				record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
230
+	//				var total int
231
+	//				var RangeOptions string
232
+	//				var RangeMin string
233
+	//				var RangeMax string
234
+	//				// 判断检查类型
235
+	//				var ItemType int
236
+	//				if strings.Contains(item.Refrange, "-") {
237
+	//					ItemType = 1
238
+	//
239
+	//				} else {
240
+	//					ItemType = 2
241
+	//
242
+	//				}
243
+	//
244
+	//				if ItemType == 1 {
245
+	//					Range := strings.Split(item.Refrange, "-")
246
+	//					RangeMin = Range[0]
247
+	//					RangeMax = Range[1]
248
+	//				} else {
249
+	//					RangeOptions = item.Refrange
250
+	//				}
251
+	//
252
+	//				err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
253
+	//				if inspection_reference.ID > 0 {
254
+	//					ItemType = inspection_reference.RangeType
255
+	//				}
256
+	//				if total <= 0 {
257
+	//					inspection_reference.OrgId = org_id
258
+	//					inspection_reference.ProjectName = item.Groupname
259
+	//					inspection_reference.Project = item.Groupname
260
+	//					inspection_reference.ProjectId = project_id
261
+	//					inspection_reference.ItemName = item.Itemname
262
+	//					inspection_reference.ItemNameAddition = item.Barcode
263
+	//					inspection_reference.ItemId = item_id
264
+	//					inspection_reference.RangeType = ItemType
265
+	//					inspection_reference.RangeMin = RangeMin
266
+	//					inspection_reference.RangeMax = RangeMax
267
+	//					inspection_reference.RangeOptions = RangeOptions
268
+	//					inspection_reference.Unit = item.Unit
269
+	//					inspection_reference.Status = 1
270
+	//					inspection_reference.CreatedTime = time.Now().Unix()
271
+	//					inspection_reference.UpdatedTime = time.Now().Unix()
272
+	//					inspection_reference.InspectDate = inspect_date
273
+	//					inspection_reference.UTime = inspect_date
274
+	//					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
275
+	//					if err != nil {
276
+	//						tx.Rollback()
277
+	//					}
278
+	//				}
279
+	//
280
+	//				var itotal int
281
+	//				err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, record_date.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
282
+	//				if itotal <= 0 {
283
+	//					inspection.PatientId = printInfo.PatientId
284
+	//					inspection.OrgId = org_id
285
+	//					inspection.ProjectId = project_id
286
+	//					inspection.ItemName = inspection_reference.ItemName
287
+	//					inspection.ProjectName = inspection_reference.ProjectName
288
+	//					inspection.InspectType = ItemType
289
+	//					inspection.ItemId = item_id
290
+	//					inspection.InspectValue = item.Result
291
+	//					inspection.InspectDate = inspect_date
292
+	//					inspection.RecordDate = record_date.Unix()
293
+	//					inspection.Status = 1
294
+	//					inspection.CreatedTime = time.Now().Unix()
295
+	//					inspection.UpdatedTime = time.Now().Unix()
296
+	//					inspection.UTime = inspect_date
297
+	//					inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
298
+	//					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
299
+	//					if err != nil {
300
+	//						tx.Rollback()
301
+	//					}
302
+	//				}
303
+	//
304
+	//				tx.Commit()
305
+	//
306
+	//			}
307
+	//			//插入一条查询检验检查结果记录状态数据
308
+	//			var info LisSyncResultStatusInfo
309
+	//			info.Ctime = time.Now().Unix()
310
+	//			info.Status = 1
311
+	//			info.Mtime = time.Now().Unix()
312
+	//			info.OrgId = org_id
313
+	//			info.IsResult = 1
314
+	//			code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
315
+	//			info.LastId = code
316
+	//			info.ResultDate = time.Now().Unix()
317
+	//			writeMiddleDb.Save(&info)
318
+	//
319
+	//		}
320
+	//
321
+	//	}
322
+	//
323
+	//}
324
+	//
325
+	//// 第一步:跟进org_id 去中间库查出需要同步的数据
326
+	//inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
327
+	//inspections, _ := GetSyncInspectionByOrgId(org_id)
328
+	//
329
+	//// 第二步:将数据同步到业务库
330
+	//if len(inspection_references) > 0 {
331
+	//	for _, inspection_reference := range inspection_references {
332
+	//		SyncInspectionReference(&inspection_reference)
333
+	//	}
334
+	//}
335
+	//
336
+	//if len(inspections) > 0 {
337
+	//	for _, inspection := range inspections {
338
+	//		SyncInspection(&inspection)
339
+	//	}
340
+	//}
341
+	return
342
+
343
+}
344
+
345
+func GetSHResultRecord() (record []*KMResult, err error) {
346
+	err = dataBase.Model(&KMResult{}).Order("barcode asc").Find(&record).Error
347
+	return
348
+}
349
+
350
+//判断是否包含中文
351
+func IsChineseChar(str string) bool {
352
+	for _, r := range str {
353
+		if unicode.Is(unicode.Scripts["Han"], r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) {
354
+			return true
355
+		}
356
+	}
357
+	return false
358
+}
359
+
360
+func GetResultRecordByTime(id int64) (record []*KMResult, err error) {
361
+	err = readDb.Model(&KMResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
362
+	return
363
+}

+ 33 - 0
service/ystx_service.go Voir le fichier

@@ -1400,3 +1400,36 @@ func GetBlItemID(org_id int64, project_name string, item_name string, project_id
1400 1400
 		}
1401 1401
 	}
1402 1402
 }
1403
+
1404
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
1405
+func GetShjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
1406
+	var inspection_reference models.MiddleInspectionReference
1407
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
1408
+	if inspection_reference.ID > 0 {
1409
+		return inspection_reference.ProjectId, err
1410
+	} else {
1411
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
1412
+		if inspection_reference.ProjectId > 0 {
1413
+			return inspection_reference.ProjectId + 1, err
1414
+		} else {
1415
+			return 5210215, err
1416
+		}
1417
+	}
1418
+}
1419
+
1420
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1421
+func GetShItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1422
+	var inspection_reference models.MiddleInspectionReference
1423
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
1424
+	if inspection_reference.ID > 0 {
1425
+		return inspection_reference.ItemId, err
1426
+	} else {
1427
+		err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
1428
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
1429
+		if inspection_reference.ItemId > 0 {
1430
+			return inspection_reference.ItemId + 1, err
1431
+		} else {
1432
+			return project_id*10 + 1, err
1433
+		}
1434
+	}
1435
+}