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