张保健 2 yıl önce
ebeveyn
işleme
a691869ce7

+ 22 - 0
controllers/lis.go Dosyayı Görüntüle

@@ -35,6 +35,28 @@ func (c *LisController) Schedule() {
35 35
 
36 36
 }
37 37
 
38
+func (c *LisController) SyncSzblLis() {
39
+	// 获取备份库里所有的医嘱信息
40
+	
41
+	service.GetSZBLResultDataInsertDB(10138)
42
+	c.ServeSuccessJSON(map[string]interface{}{
43
+		"resultList": "12345",
44
+	})
45
+	return
46
+
47
+}
48
+
49
+func (c *LisController) SyncShLis() {
50
+	// 获取备份库里所有的医嘱信息
51
+	
52
+	service.GetSHResultDataInsertDB(10215)
53
+	c.ServeSuccessJSON(map[string]interface{}{
54
+		"resultList": "12345",
55
+	})
56
+	return
57
+
58
+}
59
+
38 60
 func (c *LisController) SyncAdvice() {
39 61
 	// 获取备份库里所有的医嘱信息
40 62
 	advices, _ := service.GetAllAdvice()

+ 4 - 4
main.go Dosyayı Görüntüle

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

+ 26 - 0
models/lis_model.go Dosyayı Görüntüle

@@ -53,6 +53,32 @@ func (DoctorAdvice) TableName() string {
53 53
 	return "xt_doctor_advice"
54 54
 }
55 55
 
56
+type DataUploadConfig struct {
57
+	ID             int64  `gorm:"column:id" json:"id"`
58
+	OrgId          int64  `gorm:"column:org_id" json:"org_id"`
59
+	ProvinceId     int64  `gorm:"column:province_id" json:"province_id"`
60
+	CityId         int64  `gorm:"column:city_id" json:"city_id"`
61
+	GatewayAddress string `gorm:"column:gateway_address" json:"gateway_address"`
62
+	AppId          string `gorm:"column:app_id" json:"app_id"`
63
+	Key            string `gorm:"column:key" json:"key"`
64
+	Status         int64  `gorm:"column:status" json:"status"`
65
+	CreateTime     int64  `gorm:"column:create_time" json:"create_time"`
66
+	ModifyTime     int64  `gorm:"column:modify_time" json:"modify_time"`
67
+	TimeQuantum    int64  `gorm:"column:time_quantum" json:"time_quantum"`
68
+	DepartmentName string `gorm:"column:department_name" json:"department_name"`
69
+	HospitalId     string `gorm:"column:hospital_id" json:"hospital_id"`
70
+	InstType       int64  `gorm:"column:inst_type" json:"inst_type"`
71
+	DbHost         string `gorm:"column:db_host" json:"db_host"`
72
+	DbPort         string `gorm:"column:db_port" json:"db_port"`
73
+	DbUser         string `gorm:"column:db_user" json:"db_user"`
74
+	DbPass         string `gorm:"column:db_pass" json:"db_pass"`
75
+	DbName         string `gorm:"column:db_name" json:"db_name"`
76
+}
77
+
78
+func (DataUploadConfig) TableName() string {
79
+	return "data_upload_config"
80
+}
81
+
56 82
 type Schedules struct {
57 83
 	ID           int64 `gorm:"column:id" json:"id" form:"id"`
58 84
 	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 3 - 0
routers/router.go Dosyayı Görüntüle

@@ -23,4 +23,7 @@ func init() {
23 23
 	beego.Router("/api/lis/blresulttest", &controllers.LisController{}, "get:SyncBlResultLis")
24 24
 	beego.Router("/api/schedule", &controllers.LisController{}, "get:Schedule")
25 25
 
26
+	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
27
+	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
28
+
26 29
 }

+ 1 - 1
service/bl_service.go Dosyayı Görüntüle

@@ -1021,6 +1021,6 @@ func GetHisLabelPrintInfoById(id string) (info HisLabelPrintInfo, err error) {
1021 1021
 }
1022 1022
 
1023 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
1024
+	err = readDb.Model(&models.Patients{}).Where("Name = ? AND user_org_id = ?", id_card_no, org_id).First(&info).Error
1025 1025
 	return
1026 1026
 }

+ 5 - 5
service/cron.go Dosyayı Görüntüle

@@ -66,14 +66,14 @@ func BeginAutoSyncLis() {
66 66
 	utils.InfoLog("开启自动检验检查同步定时任务")
67 67
 	createLisSyncCronJob := newWithSeconds()
68 68
 
69
-	specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
70
-	createLisSyncCronJob.AddFunc(specgzjh, func() {
71
-		SyncGzjhyz()
72
-	})
69
+	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
70
+	// createLisSyncCronJob.AddFunc(specgzjh, func() {
71
+	// 	SyncGzjhyz()
72
+	// })
73 73
 
74 74
 	specys := "0 0 3 * * ?" // 每天凌晨3点同步 湖北监利
75 75
 	createLisSyncCronJob.AddFunc(specys, func() {
76
-		SyncHbdyLis()
76
+		GetSZBLResultDataInsertDB(10138)
77 77
 	})
78 78
 
79 79
 	// spec := "0 0 1 * * ?" // 每天凌晨1点同步 中能建的

+ 46 - 27
service/db.go Dosyayı Görüntüle

@@ -40,6 +40,25 @@ var err error
40 40
 var blDb *gorm.DB
41 41
 var shDb *gorm.DB
42 42
 
43
+
44
+func CreateSqlServiceDB(Host string, Port string, User string, Pass string, Name string) (mssqlDb *gorm.DB, err error) {
45
+	//rdb := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", User, Pass, Host, Port, Name)
46
+	mssqlstring := fmt.Sprintf("server=%s;port=%s;database=%s;user id=%s;password=%s;encrypt=disable", Host, Port, Name, User, Pass)
47
+	fmt.Println(mssqlstring)
48
+	mssqlDb, err = gorm.Open("mssql", mssqlstring)
49
+	if err != nil {
50
+		panic(err)
51
+	}
52
+	mssqlDb.DB().SetMaxIdleConns(5)
53
+	mssqlDb.DB().SetMaxOpenConns(20)
54
+	mssqlDb.LogMode(true)
55
+	return
56
+}
57
+
58
+func CloseDB(DB *gorm.DB) {
59
+	DB.Close()
60
+}
61
+
43 62
 func ConnectDB() {
44 63
 
45 64
 	readHost := beego.AppConfig.String("readmysqlhost")
@@ -54,11 +73,11 @@ func ConnectDB() {
54 73
 	writePass := beego.AppConfig.String("writemysqlpass")
55 74
 	writeName := beego.AppConfig.String("writemysqlname")
56 75
 
57
-	tempwriteHost := beego.AppConfig.String("tempwritemysqlhost")
58
-	tempwritePort := beego.AppConfig.String("tempwritemysqlport")
59
-	tempwriteUser := beego.AppConfig.String("tempwritemysqluser")
60
-	tempwritePass := beego.AppConfig.String("tempwritemysqlpass")
61
-	tempwriteName := beego.AppConfig.String("tempwritemysqlname")
76
+	// tempwriteHost := beego.AppConfig.String("tempwritemysqlhost")
77
+	// tempwritePort := beego.AppConfig.String("tempwritemysqlport")
78
+	// tempwriteUser := beego.AppConfig.String("tempwritemysqluser")
79
+	// tempwritePass := beego.AppConfig.String("tempwritemysqlpass")
80
+	// tempwriteName := beego.AppConfig.String("tempwritemysqlname")
62 81
 
63 82
 	readUserHost := beego.AppConfig.String("readuserhost")
64 83
 	readUserPort := beego.AppConfig.String("readuserport")
@@ -108,15 +127,15 @@ func ConnectDB() {
108 127
 	// fmt.Println(blPass)
109 128
 	// fmt.Println(blName)
110 129
 
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")
130
+	// shHost := beego.AppConfig.String("shmysqlhost")
131
+	// shPort := beego.AppConfig.String("shmysqlport")
132
+	// shUser := beego.AppConfig.String("shmysqluser")
133
+	// shPass := beego.AppConfig.String("shmysqlpass")
134
+	// shName := beego.AppConfig.String("shmysqlname")
116 135
 
117 136
 	rdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUser, readPass, readHost, readPort, readName)
118 137
 	wdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUser, writePass, writeHost, writePort, writeName)
119
-	tempwdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", tempwriteUser, tempwritePass, tempwriteHost, tempwritePort, tempwriteName)
138
+	// tempwdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", tempwriteUser, tempwritePass, tempwriteHost, tempwritePort, tempwriteName)
120 139
 
121 140
 	// rudsn := fmt.Sprintf("server=%s;port=%s;database=%s;user id=%s;password=%s", readRemoteHost, readRemotePort, readRemoteName, readRemoteUser, readRemotePass)
122 141
 	wudsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUserUser, writeUserPass, writeUserHost, writeUserPort, writeUserName)
@@ -127,7 +146,7 @@ func ConnectDB() {
127 146
 
128 147
 	// bldsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", blUser, blPass, blHost, blPort, blName)
129 148
 
130
-	shdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", shUser, shPass, shHost, shPort, shName)
149
+	// shdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", shUser, shPass, shHost, shPort, shName)
131 150
 
132 151
 	// bdsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", backupUser, backupPass, backupHost, backupPort, backupName)
133 152
 
@@ -155,13 +174,13 @@ func ConnectDB() {
155 174
 	writeDb.DB().SetMaxOpenConns(100)
156 175
 	writeDb.LogMode(true)
157 176
 
158
-	tempwriteDb, err = gorm.Open("mysql", tempwdsn)
159
-	if err != nil {
160
-		//beego.Error(err)
161
-	}
162
-	tempwriteDb.DB().SetMaxIdleConns(10)
163
-	tempwriteDb.DB().SetMaxOpenConns(100)
164
-	tempwriteDb.LogMode(true)
177
+	// tempwriteDb, err = gorm.Open("mysql", tempwdsn)
178
+	// if err != nil {
179
+	// 	//beego.Error(err)
180
+	// }
181
+	// tempwriteDb.DB().SetMaxIdleConns(10)
182
+	// tempwriteDb.DB().SetMaxOpenConns(100)
183
+	// tempwriteDb.LogMode(true)
165 184
 
166 185
 	// fmt.Println(rudsn)
167 186
 
@@ -216,15 +235,15 @@ func ConnectDB() {
216 235
 	// blDb.DB().SetMaxOpenConns(100)
217 236
 	// blDb.LogMode(true)
218 237
 
219
-	shDb, err = gorm.Open("mysql", shdsn)
220
-	if err != nil {
221
-		fmt.Println("12344")
238
+	// shDb, err = gorm.Open("mysql", shdsn)
239
+	// if err != nil {
240
+	// 	fmt.Println("12344")
222 241
 
223
-		fmt.Println(err)
224
-	}
225
-	shDb.DB().SetMaxIdleConns(10)
226
-	shDb.DB().SetMaxOpenConns(100)
227
-	shDb.LogMode(true)
242
+	// 	fmt.Println(err)
243
+	// }
244
+	// shDb.DB().SetMaxIdleConns(10)
245
+	// shDb.DB().SetMaxOpenConns(100)
246
+	// shDb.LogMode(true)
228 247
 
229 248
 }
230 249
 

+ 4 - 5
service/ms_two_db.go Dosyayı Görüntüle

@@ -28,16 +28,15 @@ var dataBase2 *gorm.DB
28 28
 
29 29
 var (
30 30
 	dbName2   = "local"
31
-	user2     = beego.AppConfig.DefaultString(dbName2+"::user", "sa")
31
+	user2     = beego.AppConfig.DefaultString(dbName2+"::user", "KingMed")
32 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)
33
+	host2     = beego.AppConfig.DefaultString(dbName2+"::host", "localhost")
34
+	port2     = beego.AppConfig.DefaultString(dbName2+"::port", "1433")
35 35
 	dbname2   = beego.AppConfig.DefaultString(dbName2+"::dbname", "KMDB")
36 36
 )
37 37
 
38 38
 func ConnectMSDB2() {
39
-	connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s",
40
-		host2, user2, password2, port2, dbname2)
39
+	connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;encrypt=disable", host2, user2, password2, port2, dbname2)
41 40
 	fmt.Println(connectionString)
42 41
 	db, err := gorm.Open("mssql", connectionString)
43 42
 	if err != nil {

+ 75 - 147
service/sh_service.go Dosyayı Görüntüle

@@ -9,6 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"time"
11 11
 	"unicode"
12
+	"github.com/jinzhu/gorm"
12 13
 )
13 14
 
14 15
 type KMResult struct {
@@ -68,24 +69,64 @@ func (KMResult) TableName() string {
68 69
 	return "v_km_lis_result"
69 70
 }
70 71
 
72
+type KMSheet struct {
73
+	FName                  string `gorm:"column:F_Name" json:"F_Name" form:"F_Name"`
74
+	FCompoundItemName      string `gorm:"column:F_CompoundItemName" json:"F_CompoundItemName" form:"F_CompoundItemName"`
75
+	FReference             string `gorm:"column:F_Reference" json:"F_Reference" form:"F_Reference"`
76
+	FSingleItemName        string `gorm:"column:F_SingleItemName" json:"F_SingleItemName" form:"F_SingleItemName"`
77
+	FRecordTime            string `gorm:"column:F_RecordTime" json:"F_RecordTime" form:"F_RecordTime"`
78
+	FCheckTime             string `gorm:"column:F_CheckTime" json:"F_CheckTime" form:"F_CheckTime"`
79
+	FResult                string `gorm:"column:F_Result" json:"F_Result" form:"F_Result"`
80
+	FUnit                  string `gorm:"column:F_Unit" json:"F_Unit" form:"F_Unit"`
81
+}
82
+
83
+func (KMSheet) TableName() string {
84
+	return "Sheet"
85
+}
86
+
71 87
 //获取lis返回检验检查结果数据
72 88
 func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
89
+
90
+	org := &models.DataUploadConfig{
91
+		OrgId:          10138,
92
+		ProvinceId:     19,
93
+		CityId:         291,
94
+		DepartmentName: "深圳市百霖血液透析中心",
95
+		HospitalId:     "MA5DB4KB6",
96
+		InstType:       1,
97
+		DbHost:         "localhost",
98
+		DbPort:         "1433",
99
+		DbPass:         "KingMed",
100
+		DbUser:         "KingMed",
101
+		DbName:         "KMDB",
102
+	}
103
+
104
+	if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
105
+		orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
106
+		if err != nil {
107
+			utils.ErrorLog("创建数据库连接失败:%v", err)
108
+			return
109
+		}
110
+
73 111
 	record, _ := GetLastSyncResultRecord(org_id)
74 112
 	fmt.Println(record)
75
-	if record.ID == 0 {
76
-		list, err := GetSHResultRecord()
113
+	var sync_time int64
114
+	if record.ID > 0 {
115
+		sync_time = record.Ctime
116
+	} else {
117
+		sync_time = 1627747200
118
+	}
119
+
120
+	sync_time_temp := time.Unix(sync_time,0)
121
+	syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
122
+
123
+		list, err := GetSHResultRecord(orgDb,syncTimeStr)
77 124
 		if err == nil {
78
-			fmt.Println(list)
125
+			// fmt.Println(list)
79 126
 
80 127
 			//插入到系统检验检查数据
81 128
 			for _, item := range list {
82
-				project_id := int64(0)
83
-				if len(item.FIDCardNo) > 0 {
84
-					project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
85
-				} else {
86
-					continue
87
-				}
88
-				printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
129
+				printInfo, _ := GetPatientsInfoByIDCardNo(item.FName, 10215)
89 130
 
90 131
 				if printInfo.ID == 0 {
91 132
 					fmt.Println(item)
@@ -94,6 +135,12 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
94 135
 					continue
95 136
 				}
96 137
 
138
+				project_id := int64(0)
139
+				
140
+				project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
141
+				
142
+				
143
+
97 144
 				item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
98 145
 
99 146
 				tx := writeMiddleDb.Begin()
@@ -103,9 +150,20 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
103 150
 				recordDateStr := ""
104 151
 				//inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
105 152
 
153
+				// timstr := strings.Split(item.FRecordTime, "T")
154
+				// timstem := strings.Split(timstr[1], "Z")
155
+
156
+				// recordDateStr = timstr[0] + " " + timstem[0]
106 157
 				recordDateStr = item.FRecordTime
107
-				date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
158
+				date ,_ :=  utils.ParseTimeStringToTime("2006-01-02 15:04:05",recordDateStr)
108 159
 				record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
160
+			
161
+				// ftimstr := strings.Split(item.FCheckTime, "T")
162
+				// ftimstem := strings.Split(timstr[1], "Z")
163
+
164
+				// fdate := ftimstr[0] + " " + ftimstem[0]
165
+				fdate := item.FCheckTime
166
+
109 167
 				var total int
110 168
 				var RangeOptions string
111 169
 				var RangeMin string
@@ -150,8 +208,8 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
150 208
 					inspection_reference.Status = 1
151 209
 					inspection_reference.CreatedTime = time.Now().Unix()
152 210
 					inspection_reference.UpdatedTime = time.Now().Unix()
153
-					inspection_reference.InspectDate = item.FCheckTime
154
-					inspection_reference.UTime = item.FCheckTime
211
+					inspection_reference.InspectDate = fdate
212
+					inspection_reference.UTime = fdate
155 213
 					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
156 214
 					if err != nil {
157 215
 						tx.Rollback()
@@ -197,137 +255,6 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
197 255
 			writeMiddleDb.Save(&info)
198 256
 		}
199 257
 
200
-	}
201
-	//else
202
-	//{
203
-	//	if record.LastId != 0 {
204
-	//		list, err := GetResultRecordByID(record.LastId)
205
-	//		fmt.Println(list)
206
-	//		//插入中间库中
207
-	//		//插入一条插入中间库记录数据
208
-	//		if err == nil {
209
-	//
210
-	//			//插入到系统检验检查数据
211
-	//			for _, item := range list {
212
-	//				project_id := int64(0)
213
-	//				if len(item.Barcode) > 0 {
214
-	//					project_id, _ = GetBljhProjectID(org_id, item.Groupname)
215
-	//				} else {
216
-	//					continue
217
-	//				}
218
-	//				printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
219
-	//				item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
220
-	//
221
-	//				tx := writeMiddleDb.Begin()
222
-	//				var inspection models.MiddleInspection
223
-	//				var inspection_reference models.MiddleInspectionReference
224
-	//
225
-	//				recordDateStr := ""
226
-	//				inspect_date := item.Repdate.Format("2006-01-02 15:04")
227
-	//				if item.Repdate.Unix() == 0 {
228
-	//					recordDateStr = time.Now().Format("2006-01-02 15:04")
229
-	//				} else {
230
-	//
231
-	//					recordDateStr = inspect_date
232
-	//				}
233
-	//
234
-	//				date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
235
-	//				record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
236
-	//				var total int
237
-	//				var RangeOptions string
238
-	//				var RangeMin string
239
-	//				var RangeMax string
240
-	//				// 判断检查类型
241
-	//				var ItemType int
242
-	//				if strings.Contains(item.Refrange, "-") {
243
-	//					ItemType = 1
244
-	//
245
-	//				} else {
246
-	//					ItemType = 2
247
-	//
248
-	//				}
249
-	//
250
-	//				if ItemType == 1 {
251
-	//					Range := strings.Split(item.Refrange, "-")
252
-	//					RangeMin = Range[0]
253
-	//					RangeMax = Range[1]
254
-	//				} else {
255
-	//					RangeOptions = item.Refrange
256
-	//				}
257
-	//
258
-	//				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
259
-	//				if inspection_reference.ID > 0 {
260
-	//					ItemType = inspection_reference.RangeType
261
-	//				}
262
-	//				if total <= 0 {
263
-	//					inspection_reference.OrgId = org_id
264
-	//					inspection_reference.ProjectName = item.Groupname
265
-	//					inspection_reference.Project = item.Groupname
266
-	//					inspection_reference.ProjectId = project_id
267
-	//					inspection_reference.ItemName = item.Itemname
268
-	//					inspection_reference.ItemNameAddition = item.Barcode
269
-	//					inspection_reference.ItemId = item_id
270
-	//					inspection_reference.RangeType = ItemType
271
-	//					inspection_reference.RangeMin = RangeMin
272
-	//					inspection_reference.RangeMax = RangeMax
273
-	//					inspection_reference.RangeOptions = RangeOptions
274
-	//					inspection_reference.Unit = item.Unit
275
-	//					inspection_reference.Status = 1
276
-	//					inspection_reference.CreatedTime = time.Now().Unix()
277
-	//					inspection_reference.UpdatedTime = time.Now().Unix()
278
-	//					inspection_reference.InspectDate = inspect_date
279
-	//					inspection_reference.UTime = inspect_date
280
-	//					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
281
-	//					if err != nil {
282
-	//						tx.Rollback()
283
-	//					}
284
-	//				}
285
-	//
286
-	//				var itotal int
287
-	//				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
288
-	//				if itotal <= 0 {
289
-	//					inspection.PatientId = printInfo.PatientId
290
-	//					inspection.OrgId = org_id
291
-	//					inspection.ProjectId = project_id
292
-	//					inspection.ItemName = inspection_reference.ItemName
293
-	//					inspection.ProjectName = inspection_reference.ProjectName
294
-	//					inspection.InspectType = ItemType
295
-	//					inspection.ItemId = item_id
296
-	//					inspection.InspectValue = item.Result
297
-	//					inspection.InspectDate = inspect_date
298
-	//					inspection.RecordDate = record_date.Unix()
299
-	//					inspection.Status = 1
300
-	//					inspection.CreatedTime = time.Now().Unix()
301
-	//					inspection.UpdatedTime = time.Now().Unix()
302
-	//					inspection.UTime = inspect_date
303
-	//					inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
304
-	//					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
305
-	//					if err != nil {
306
-	//						tx.Rollback()
307
-	//					}
308
-	//				}
309
-	//
310
-	//				tx.Commit()
311
-	//
312
-	//			}
313
-	//			//插入一条查询检验检查结果记录状态数据
314
-	//			var info LisSyncResultStatusInfo
315
-	//			info.Ctime = time.Now().Unix()
316
-	//			info.Status = 1
317
-	//			info.Mtime = time.Now().Unix()
318
-	//			info.OrgId = org_id
319
-	//			info.IsResult = 1
320
-	//			code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
321
-	//			info.LastId = code
322
-	//			info.ResultDate = time.Now().Unix()
323
-	//			writeMiddleDb.Save(&info)
324
-	//
325
-	//		}
326
-	//
327
-	//	}
328
-	//
329
-	//}
330
-	//
331 258
 	// 第一步:跟进org_id 去中间库查出需要同步的数据
332 259
 	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
333 260
 	inspections, _ := GetSyncInspectionByOrgId(org_id)
@@ -344,12 +271,13 @@ func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
344 271
 			SyncInspection(&inspection)
345 272
 		}
346 273
 	}
347
-	return
274
+}
275
+return
348 276
 
349 277
 }
350 278
 
351
-func GetSHResultRecord() (record []*KMResult, err error) {
352
-	err = dataBase.Model(&KMResult{}).Order("barcode asc").Find(&record).Error
279
+func GetSHResultRecord(rdb *gorm.DB,synctime string) (record []*KMSheet, err error) {
280
+	err = rdb.Model(&KMSheet{}).Where("F_CheckTime >= ?",synctime).Find(&record).Error
353 281
 	return
354 282
 }
355 283
 

+ 245 - 0
service/szbl_service.go Dosyayı Görüntüle

@@ -0,0 +1,245 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"IC/utils"
6
+	"fmt"
7
+	_"regexp"
8
+	"strconv"
9
+	"strings"
10
+	"time"
11
+	_"unicode"
12
+	"github.com/jinzhu/gorm"
13
+)
14
+
15
+
16
+
17
+type SZBLJYJC struct {
18
+	FName                  string `gorm:"column:name" json:"name" form:"name"`
19
+	FCompoundItemName      string `gorm:"column:DockingApplyItemName" json:"DockingApplyItemName" form:"DockingApplyItemName"`
20
+	FReference             string `gorm:"column:refrange" json:"refrange" form:"refrange"`
21
+	FSingleItemName        string `gorm:"column:itemname" json:"itemname" form:"itemname"`
22
+	FRecordTime            string `gorm:"column:recordTime" json:"recordTime" form:"recordTime"`
23
+	FCheckTime             string `gorm:"column:repdate" json:"repdate" form:"repdate"`
24
+	FResult                string `gorm:"column:result" json:"result" form:"result"`
25
+	FUnit                  string `gorm:"column:unit" json:"unit" form:"unit"`
26
+}
27
+
28
+func (SZBLJYJC) TableName() string {
29
+	return "v_cm_result"
30
+}
31
+
32
+//获取lis返回检验检查结果数据
33
+func GetSZBLResultDataInsertDB(org_id int64) (result []*SZBLJYJC) {
34
+
35
+	org := &models.DataUploadConfig{
36
+		OrgId:          10138,
37
+		ProvinceId:     19,
38
+		CityId:         291,
39
+		DepartmentName: "深圳市百霖血液透析中心",
40
+		HospitalId:     "MA5DB4KB6",
41
+		InstType:       1,
42
+		DbHost:         "localhost",
43
+		DbPort:         "1433",
44
+		DbPass:         "1Q2W3e4r!@#$",
45
+		DbUser:         "adapter",
46
+		DbName:         "hyDB",
47
+	}
48
+
49
+	if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
50
+		orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
51
+		if err != nil {
52
+			utils.ErrorLog("创建数据库连接失败:%v", err)
53
+			return
54
+		}
55
+
56
+	record, _ := GetLastSyncResultRecord(org_id)
57
+	fmt.Println(record)
58
+	var sync_time int64
59
+	if record.ID > 0 {
60
+		sync_time = record.Ctime
61
+	} else {
62
+		sync_time = 1627747200
63
+	}
64
+
65
+	sync_time_temp := time.Unix(sync_time,0)
66
+	syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
67
+
68
+		list, err := GetSZBLResultRecord(orgDb,syncTimeStr)
69
+		if err == nil {
70
+			// fmt.Println(list)
71
+
72
+			//插入到系统检验检查数据
73
+			for _, item := range list {
74
+				printInfo, _ := GetPatientsInfoByIDCardNo(item.FName, 10138)
75
+
76
+				if printInfo.ID == 0 {
77
+					fmt.Println(item)
78
+					fmt.Println(printInfo)
79
+					fmt.Println("暂无该患者")
80
+					continue
81
+				}
82
+
83
+				project_id := int64(0)
84
+				
85
+				project_id, _ = GetSzbljhProjectID(org_id, item.FCompoundItemName)
86
+				
87
+				
88
+
89
+				item_id, _ := GetSzblItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
90
+
91
+				tx := writeMiddleDb.Begin()
92
+				var inspection models.MiddleInspection
93
+				var inspection_reference models.MiddleInspectionReference
94
+
95
+				recordDateStr := ""
96
+				//inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
97
+
98
+				timstr := strings.Split(item.FCheckTime, "T")
99
+				timstem := strings.Split(timstr[1], "Z")
100
+
101
+				recordDateStr = timstr[0] + " " + timstem[0]
102
+				// recordDateStr = item.FCheckTime
103
+				fmt.Println(recordDateStr)
104
+				date ,_ :=  utils.ParseTimeStringToTime("2006-01-02 15:04:05",recordDateStr)
105
+				fmt.Println(date)
106
+				record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
107
+				fmt.Println(record_date)
108
+			
109
+				// ftimstr := strings.Split(item.FCheckTime, "T")
110
+				// ftimstem := strings.Split(timstr[1], "Z")
111
+
112
+				// fdate := ftimstr[0] + " " + ftimstem[0]
113
+				fdate := recordDateStr
114
+
115
+				var total int
116
+				var RangeOptions string
117
+				var RangeMin string
118
+				var RangeMax string
119
+				// 判断检查类型
120
+				var ItemType int
121
+				if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
122
+					ItemType = 2
123
+				} else {
124
+					if strings.Contains(item.FReference, "-") {
125
+						ItemType = 1
126
+					} else {
127
+						ItemType = 2
128
+					}
129
+				}
130
+
131
+				if ItemType == 1 {
132
+					Range := strings.Split(item.FReference, "-")
133
+					RangeMin = Range[0]
134
+					RangeMax = Range[1]
135
+				} else {
136
+					RangeOptions = item.FReference
137
+				}
138
+
139
+				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
140
+				if inspection_reference.ID > 0 {
141
+					ItemType = inspection_reference.RangeType
142
+				}
143
+				if total <= 0 {
144
+					inspection_reference.OrgId = org_id
145
+					inspection_reference.ProjectName = item.FCompoundItemName
146
+					inspection_reference.Project = item.FCompoundItemName
147
+					inspection_reference.ProjectId = project_id
148
+					inspection_reference.ItemName = item.FSingleItemName
149
+					inspection_reference.ItemNameAddition = ""
150
+					inspection_reference.ItemId = item_id
151
+					inspection_reference.RangeType = ItemType
152
+					inspection_reference.RangeMin = RangeMin
153
+					inspection_reference.RangeMax = RangeMax
154
+					inspection_reference.RangeOptions = RangeOptions
155
+					inspection_reference.Unit = item.FUnit
156
+					inspection_reference.Status = 1
157
+					inspection_reference.CreatedTime = time.Now().Unix()
158
+					inspection_reference.UpdatedTime = time.Now().Unix()
159
+					inspection_reference.InspectDate = fdate
160
+					inspection_reference.UTime = fdate
161
+					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
162
+					if err != nil {
163
+						tx.Rollback()
164
+					}
165
+				}
166
+
167
+				var itotal int
168
+				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
169
+				if itotal <= 0 {
170
+					inspection.PatientId = printInfo.ID
171
+					inspection.OrgId = org_id
172
+					inspection.ProjectId = project_id
173
+					inspection.ItemName = inspection_reference.ItemName
174
+					inspection.ProjectName = inspection_reference.ProjectName
175
+					inspection.InspectType = ItemType
176
+					inspection.ItemId = item_id
177
+					inspection.InspectValue = item.FResult
178
+					inspection.InspectDate = item.FCheckTime
179
+					inspection.RecordDate = record_date.Unix()
180
+					inspection.Status = 1
181
+					inspection.CreatedTime = time.Now().Unix()
182
+					inspection.UpdatedTime = time.Now().Unix()
183
+					inspection.UTime = item.FCheckTime
184
+					inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
185
+					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
186
+					if err != nil {
187
+						tx.Rollback()
188
+					}
189
+				}
190
+
191
+				tx.Commit()
192
+
193
+			}
194
+			//插入一条查询检验检查结果记录状态数据
195
+			var info LisSyncResultStatusInfo
196
+			info.Ctime = time.Now().Unix()
197
+			info.Status = 1
198
+			info.Mtime = time.Now().Unix()
199
+			info.OrgId = org_id
200
+			info.IsResult = 1
201
+			info.LastId = int64(len(list))
202
+			info.ResultDate = time.Now().Unix()
203
+			writeMiddleDb.Save(&info)
204
+		}
205
+
206
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
207
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
208
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
209
+
210
+	// 第二步:将数据同步到业务库
211
+	if len(inspection_references) > 0 {
212
+		for _, inspection_reference := range inspection_references {
213
+			SyncInspectionReference(&inspection_reference)
214
+		}
215
+	}
216
+
217
+	if len(inspections) > 0 {
218
+		for _, inspection := range inspections {
219
+			SyncInspection(&inspection)
220
+		}
221
+	}
222
+}
223
+return
224
+
225
+}
226
+
227
+func GetSZBLResultRecord(rdb *gorm.DB,synctime string) (record []*SZBLJYJC, err error) {
228
+	err = rdb.Model(&SZBLJYJC{}).Where("repdate >= ?",synctime).Find(&record).Error
229
+	return
230
+}
231
+
232
+//判断是否包含中文
233
+// func IsChineseChar(str string) bool {
234
+// 	for _, r := range str {
235
+// 		if unicode.Is(unicode.Scripts["Han"], r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) {
236
+// 			return true
237
+// 		}
238
+// 	}
239
+// 	return false
240
+// }
241
+
242
+// func GetResultRecordByTime(id int64) (record []*KMResult, err error) {
243
+// 	err = readDb.Model(&KMResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
244
+// 	return
245
+// }

+ 32 - 0
service/ystx_service.go Dosyayı Görüntüle

@@ -1417,6 +1417,22 @@ func GetShjhProjectID(org_id int64, project_name string) (project_id int64, err
1417 1417
 	}
1418 1418
 }
1419 1419
 
1420
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
1421
+func GetSzbljhProjectID(org_id int64, project_name string) (project_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 = ?", org_id, project_name).First(&inspection_reference).Error
1424
+	if inspection_reference.ID > 0 {
1425
+		return inspection_reference.ProjectId, err
1426
+	} else {
1427
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
1428
+		if inspection_reference.ProjectId > 0 {
1429
+			return inspection_reference.ProjectId + 1, err
1430
+		} else {
1431
+			return 1013800, err
1432
+		}
1433
+	}
1434
+}
1435
+
1420 1436
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1421 1437
 func GetShItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1422 1438
 	var inspection_reference models.MiddleInspectionReference
@@ -1433,3 +1449,19 @@ func GetShItemID(org_id int64, project_name string, item_name string, project_id
1433 1449
 		}
1434 1450
 	}
1435 1451
 }
1452
+
1453
+func GetSzblItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1454
+	var inspection_reference models.MiddleInspectionReference
1455
+	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
1456
+	if inspection_reference.ID > 0 {
1457
+		return inspection_reference.ItemId, err
1458
+	} else {
1459
+		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
1460
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
1461
+		if inspection_reference.ItemId > 0 {
1462
+			return inspection_reference.ItemId + 1, err
1463
+		} else {
1464
+			return project_id*100 + 1, err
1465
+		}
1466
+	}
1467
+}