csx 2 anni fa
parent
commit
8c6c582295
10 ha cambiato i file con 542 aggiunte e 12 eliminazioni
  1. 11 3
      conf/app.conf
  2. 8 0
      controllers/lis.go
  3. 5 3
      main.go
  4. 38 0
      models/lis_model.go
  5. 11 5
      service/bl_service.go
  6. 20 0
      service/db.go
  7. 1 1
      service/ms_db.go
  8. 52 0
      service/ms_two_db.go
  9. 363 0
      service/sh_service.go
  10. 33 0
      service/ystx_service.go

+ 11 - 3
conf/app.conf Vedi File

@@ -30,11 +30,19 @@ httpdomain = https://api.xt.kuyicloud.com
30 30
 sso_domain = https://sso.kuyicloud.com
31 31
 front_end_domain = "https://xt.kuyicloud.com/#"
32 32
 
33
-blmysqlhost = 192.168.10.10
33
+blmysqlhost = 192.168.2.100
34 34
 blmysqlport = 3306
35 35
 blmysqluser = root
36
-blmysqlpass = 12345678
37
-blmysqlname = kuyicloud
36
+blmysqlpass = KingMed
37
+blmysqlname = KingMed
38
+
39
+
40
+
41
+shmysqlhost = 192.168.10.10
42
+shmysqlport = 3306
43
+shmysqluser = root
44
+shmysqlpass = 12345678
45
+shmysqlname = kuyicloud
38 46
 
39 47
 
40 48
 readmysqlhost = shengws1.mysql.rds.aliyuncs.com

+ 8 - 0
controllers/lis.go Vedi File

@@ -410,3 +410,11 @@ func (c *LisController) SyncBlResultLis() {
410 410
 		"resultList": "同步成功",
411 411
 	})
412 412
 }
413
+
414
+//肇庆三鹤
415
+func (c *LisController) SyncZQSHResultLis() {
416
+	service.GetResultDataInsertDB(10215)
417
+	c.ServeSuccessJSON(map[string]interface{}{
418
+		"resultList": "同步成功",
419
+	})
420
+}

+ 5 - 3
main.go Vedi File

@@ -8,13 +8,15 @@ import (
8 8
 
9 9
 func init() {
10 10
 	service.ConnectDB()
11
-	service.ConnectMSDB()
11
+	//service.ConnectMSDB()
12
+	service.ConnectSHMSDB()
13
+
12 14
 }
13 15
 
14 16
 func main() {
15
-	service.BeginAutoSyncLis()
17
+	//service.BeginAutoSyncLis()
16 18
 	//service.GetDataInsertDB(10138)
17 19
 	//service.GetResultDataInsertDB(10138)
18
-
20
+	service.GetSHResultDataInsertDB(10215)
19 21
 	beego.Run()
20 22
 }

+ 38 - 0
models/lis_model.go Vedi File

@@ -361,3 +361,41 @@ type UserAdminRole struct {
361 361
 func (UserAdminRole) TableName() string {
362 362
 	return "sgj_user_admin_role"
363 363
 }
364
+
365
+type VMHisProjectTeam struct {
366
+	ID                int64                `gorm:"column:id" json:"id" form:"id"`
367
+	ProjectTeam       string               `gorm:"column:project_team" json:"project_team" form:"project_team"`
368
+	Price             float64              `gorm:"column:price" json:"price" form:"price"`
369
+	Pinyin            string               `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
370
+	Wubi              string               `gorm:"column:wubi" json:"wubi" form:"wubi"`
371
+	TubeColor         int64                `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
372
+	TeamType          int64                `gorm:"column:team_type" json:"team_type" form:"team_type"`
373
+	Remark            string               `gorm:"column:remark" json:"remark" form:"remark"`
374
+	UserOrgId         int64                `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
375
+	Status            int64                `gorm:"column:status" json:"status" form:"status"`
376
+	CreatedTime       int64                `gorm:"column:created_time" json:"created_time" form:"created_time"`
377
+	UpdatedTime       int64                `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
378
+	ProjectId         string               `gorm:"column:project_id" json:"project_id" form:"project_id"`
379
+	VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
380
+	ItemId            string               `gorm:"column:item_id" json:"item_id" form:"item_id"`
381
+}
382
+
383
+func (VMHisProjectTeam) TableName() string {
384
+	return "xt_his_project_team"
385
+}
386
+
387
+type VMItemProjectList struct {
388
+	ID          int64 `gorm:"column:id" json:"id" form:"id"`
389
+	Number      int64 `gorm:"column:number" json:"number" form:"number"`
390
+	UserOrgId   int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
391
+	ProjectId   int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
392
+	Status      int64 `gorm:"column:status" json:"status" form:"status"`
393
+	CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
394
+	UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
395
+	TeamId      int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
396
+	Type        int64 `gorm:"column:type" json:"type" form:"type"`
397
+}
398
+
399
+func (VMItemProjectList) TableName() string {
400
+	return "xt_his_project_list"
401
+}

+ 11 - 5
service/bl_service.go Vedi File

@@ -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 Vedi File

@@ -37,6 +37,7 @@ var backupDb *gorm.DB
37 37
 var err error
38 38
 
39 39
 var blDb *gorm.DB
40
+var shDb *gorm.DB
40 41
 
41 42
 func ConnectDB() {
42 43
 
@@ -100,6 +101,12 @@ func ConnectDB() {
100 101
 	fmt.Println(blPass)
101 102
 	fmt.Println(blName)
102 103
 
104
+	shHost := beego.AppConfig.String("shmysqlhost")
105
+	shPort := beego.AppConfig.String("shmysqlport")
106
+	shUser := beego.AppConfig.String("shmysqluser")
107
+	shPass := beego.AppConfig.String("shmysqlpass")
108
+	shName := beego.AppConfig.String("shmysqlname")
109
+
103 110
 	rdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUser, readPass, readHost, readPort, readName)
104 111
 	wdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUser, writePass, writeHost, writePort, writeName)
105 112
 
@@ -112,6 +119,8 @@ func ConnectDB() {
112 119
 
113 120
 	bldsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", blUser, blPass, blHost, blPort, blName)
114 121
 
122
+	shdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", shUser, shPass, shHost, shPort, shName)
123
+
115 124
 	// bdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", backupUser, backupPass, backupHost, backupPort, backupName)
116 125
 
117 126
 	readDb, err = gorm.Open("mysql", rdsn)
@@ -191,6 +200,17 @@ func ConnectDB() {
191 200
 	blDb.DB().SetMaxOpenConns(100)
192 201
 	blDb.LogMode(true)
193 202
 
203
+	shDb, err = gorm.Open("mysql", shdsn)
204
+	if err != nil {
205
+		fmt.Println("12344")
206
+		fmt.Println(bldsn)
207
+
208
+		fmt.Println(err)
209
+	}
210
+	shDb.DB().SetMaxIdleConns(10)
211
+	shDb.DB().SetMaxOpenConns(100)
212
+	shDb.LogMode(true)
213
+
194 214
 }
195 215
 
196 216
 //func DisconnectDB() {

+ 1 - 1
service/ms_db.go Vedi File

@@ -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 Vedi File

@@ -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 Vedi File

@@ -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 Vedi File

@@ -1385,3 +1385,36 @@ func GetBlItemID(org_id int64, project_name string, item_name string, project_id
1385 1385
 		}
1386 1386
 	}
1387 1387
 }
1388
+
1389
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
1390
+func GetShjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
1391
+	var inspection_reference models.MiddleInspectionReference
1392
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
1393
+	if inspection_reference.ID > 0 {
1394
+		return inspection_reference.ProjectId, err
1395
+	} else {
1396
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
1397
+		if inspection_reference.ProjectId > 0 {
1398
+			return inspection_reference.ProjectId + 1, err
1399
+		} else {
1400
+			return 5210215, err
1401
+		}
1402
+	}
1403
+}
1404
+
1405
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1406
+func GetShItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1407
+	var inspection_reference models.MiddleInspectionReference
1408
+	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
1409
+	if inspection_reference.ID > 0 {
1410
+		return inspection_reference.ItemId, err
1411
+	} else {
1412
+		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
1413
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
1414
+		if inspection_reference.ItemId > 0 {
1415
+			return inspection_reference.ItemId + 1, err
1416
+		} else {
1417
+			return project_id*10 + 1, err
1418
+		}
1419
+	}
1420
+}