|
@@ -0,0 +1,773 @@
|
|
1
|
+package service
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "IC/models"
|
|
5
|
+ _ "IC/models"
|
|
6
|
+ "IC/utils"
|
|
7
|
+ "bytes"
|
|
8
|
+ "encoding/json"
|
|
9
|
+ _ "encoding/json"
|
|
10
|
+ _ "encoding/xml"
|
|
11
|
+ "fmt"
|
|
12
|
+ _ "github.com/jinzhu/gorm"
|
|
13
|
+ "io/ioutil"
|
|
14
|
+ "net/http"
|
|
15
|
+ "strconv"
|
|
16
|
+ "strings"
|
|
17
|
+ "time"
|
|
18
|
+)
|
|
19
|
+
|
|
20
|
+func GetbjncProjectID(org_id int64, project_name string) (project_id int64, err error) {
|
|
21
|
+ var inspection_reference models.MiddleInspectionReference
|
|
22
|
+ err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ?", org_id, project_name).First(&inspection_reference).Error
|
|
23
|
+ if inspection_reference.ID > 0 {
|
|
24
|
+ return inspection_reference.ProjectId, err
|
|
25
|
+ } else {
|
|
26
|
+ err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? ", org_id, project_name).First(&inspection_reference).Error
|
|
27
|
+ if inspection_reference.ID > 0 {
|
|
28
|
+ return inspection_reference.ProjectId, err
|
|
29
|
+ } else {
|
|
30
|
+ err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
|
|
31
|
+ if inspection_reference.ProjectId > 0 {
|
|
32
|
+ return inspection_reference.ProjectId + 1, err
|
|
33
|
+ } else {
|
|
34
|
+ return 1060601, err
|
|
35
|
+ }
|
|
36
|
+ }
|
|
37
|
+ }
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
|
|
41
|
+func GetbjncItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
|
|
42
|
+ var inspection_reference models.MiddleInspectionReference
|
|
43
|
+ err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
|
|
44
|
+ if inspection_reference.ID > 0 {
|
|
45
|
+ return inspection_reference.ItemId, err
|
|
46
|
+ } else {
|
|
47
|
+ 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
|
|
48
|
+ if inspection_reference.ItemId > 0 {
|
|
49
|
+ return inspection_reference.ItemId + 1, err
|
|
50
|
+ } else {
|
|
51
|
+ return project_id*100 + 1, err
|
|
52
|
+ }
|
|
53
|
+ }
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+// 北京南诚中西医结合医院Lis同步
|
|
57
|
+func SyncBjncLis() (err error) {
|
|
58
|
+ org_id := int64(10606)
|
|
59
|
+
|
|
60
|
+ // 第一步:获取上一次同步的时间点
|
|
61
|
+ syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
|
|
62
|
+ var sync_time int64
|
|
63
|
+ if syncLastInfo.ID > 0 {
|
|
64
|
+ sync_time = syncLastInfo.SyncTime - 60*60*6
|
|
65
|
+ } else {
|
|
66
|
+ sync_time = 1714492800
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ loc, _ := time.LoadLocation("Local") //重要:获取时区
|
|
70
|
+ sync_time_temp := time.Unix(sync_time, 0)
|
|
71
|
+ startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
|
|
72
|
+ end_time := time.Now().Unix()
|
|
73
|
+ end_time_temp := time.Unix(end_time, 0)
|
|
74
|
+ endTimeStr := end_time_temp.Format("2006-01-02 15:04:05")
|
|
75
|
+ // 第二步:获取所有患者的病历号
|
|
76
|
+
|
|
77
|
+ patientList, _ := GetPatientGzjhByOrgId(org_id)
|
|
78
|
+ if len(patientList) > 0 {
|
|
79
|
+ for _, patient := range patientList {
|
|
80
|
+ if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
|
|
81
|
+ //patient_id := patient.ID
|
|
82
|
+ utils.InfoLog("startTimeStr:%v", startTimeStr)
|
|
83
|
+ // utils.InfoLog("VipStr:%v", VipStr)
|
|
84
|
+ // 跟进身份证获取patientID
|
|
85
|
+ patientList, _ := BjncGetPatientInfo(patient.IdCardNo, endTimeStr)
|
|
86
|
+
|
|
87
|
+ var bjncPatient BjncPatientInfo
|
|
88
|
+ if err := json.Unmarshal([]byte(patientList), &bjncPatient); err != nil {
|
|
89
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ utils.InfoLog("patientId:%v", bjncPatient.Result[0].Patientid)
|
|
93
|
+
|
|
94
|
+ reportList, _ := BjncGetLisReport(bjncPatient.Result[0].Patientid, startTimeStr, endTimeStr)
|
|
95
|
+ var lisReport BjncLisReport
|
|
96
|
+ if err := json.Unmarshal([]byte(reportList), &lisReport); err != nil {
|
|
97
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
98
|
+ }
|
|
99
|
+ utils.InfoLog("reportList:%v", lisReport)
|
|
100
|
+
|
|
101
|
+ if len(lisReport.Result) > 0 {
|
|
102
|
+ for _, linfo := range lisReport.Result {
|
|
103
|
+ infoReprot, _ := BjncGetReportInfo(linfo.Reportno, startTimeStr, endTimeStr)
|
|
104
|
+ var reportInfo ReportDetail
|
|
105
|
+ if err := json.Unmarshal([]byte(infoReprot), &reportInfo); err != nil {
|
|
106
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ for _, ivalue := range reportInfo.Result {
|
|
110
|
+ theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", ivalue.Testtime, loc) //使用模板在对应时区转化为time.time类型
|
|
111
|
+ start_temp_Time := theTime.Format("2006-01-02 15:04")
|
|
112
|
+ SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
|
|
113
|
+ start_time := SxTime.Unix()
|
|
114
|
+
|
|
115
|
+ project_id, _ := GetbjncProjectID(org_id, ivalue.Combinationname)
|
|
116
|
+ item_id, _ := GetbjncItemID(org_id, ivalue.Combinationname, ivalue.Itemname, project_id)
|
|
117
|
+ tx := writeMiddleDb.Begin()
|
|
118
|
+ var inspection models.MiddleInspection
|
|
119
|
+ var inspection_reference models.MiddleInspectionReference
|
|
120
|
+
|
|
121
|
+ var total int
|
|
122
|
+ var RangeOptions string
|
|
123
|
+ var RangeMin string
|
|
124
|
+ var RangeMax string
|
|
125
|
+ var ItemType int
|
|
126
|
+ Range := strings.Split(ivalue.Referscope, "-")
|
|
127
|
+ if len(Range) > 1 {
|
|
128
|
+ RangeMin = Range[0]
|
|
129
|
+ RangeMax = Range[1]
|
|
130
|
+ ItemType = 1
|
|
131
|
+ } else {
|
|
132
|
+ ItemType = 2
|
|
133
|
+ RangeOptions = ivalue.Referscope
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ 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
|
|
137
|
+ if total <= 0 {
|
|
138
|
+ inspection_reference.OrgId = org_id
|
|
139
|
+ inspection_reference.ProjectName = ivalue.Combinationname
|
|
140
|
+ inspection_reference.Project = ivalue.Combinationname
|
|
141
|
+ inspection_reference.ProjectId = project_id
|
|
142
|
+ inspection_reference.ItemName = ivalue.Itemname
|
|
143
|
+ // inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
|
|
144
|
+ inspection_reference.ItemId = item_id
|
|
145
|
+ inspection_reference.RangeType = ItemType
|
|
146
|
+ inspection_reference.RangeMin = RangeMin
|
|
147
|
+ inspection_reference.RangeMax = RangeMax
|
|
148
|
+ // inspection_reference.RangeValue = RangeValue
|
|
149
|
+ inspection_reference.RangeOptions = RangeOptions
|
|
150
|
+ inspection_reference.Unit = ivalue.Unit
|
|
151
|
+ inspection_reference.Status = 1
|
|
152
|
+ inspection_reference.CreatedTime = time.Now().Unix()
|
|
153
|
+ inspection_reference.UpdatedTime = time.Now().Unix()
|
|
154
|
+ inspection_reference.InspectDate = ivalue.Testtime
|
|
155
|
+ inspection_reference.UTime = ivalue.Testtime
|
|
156
|
+ err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
|
|
157
|
+ if err != nil {
|
|
158
|
+ tx.Rollback()
|
|
159
|
+ }
|
|
160
|
+ }
|
|
161
|
+ var itotal int
|
|
162
|
+ 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, start_time, patient.ID).Find(&inspection).Count(&itotal).Error
|
|
163
|
+ if itotal <= 0 {
|
|
164
|
+ // inspection.InspectValue = strings.Replace(LisInfo.Testresult, ">", ">", -1)
|
|
165
|
+ // inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "<", "<", -1)
|
|
166
|
+ inspection.PatientId = patient.ID
|
|
167
|
+ inspection.OrgId = org_id
|
|
168
|
+ inspection.ProjectId = project_id
|
|
169
|
+ inspection.ItemName = inspection_reference.ItemName
|
|
170
|
+ inspection.ProjectName = inspection_reference.ProjectName
|
|
171
|
+ inspection.InspectType = ItemType
|
|
172
|
+ inspection.ItemId = item_id
|
|
173
|
+ inspection.InspectValue = ivalue.Itemreportresult
|
|
174
|
+ inspection.InspectDate = start_temp_Time
|
|
175
|
+ inspection.RecordDate = start_time
|
|
176
|
+ // inspection.InspectTips = report.Resultstate
|
|
177
|
+ inspection.Status = 1
|
|
178
|
+ inspection.CreatedTime = time.Now().Unix()
|
|
179
|
+ inspection.UpdatedTime = time.Now().Unix()
|
|
180
|
+ // inspection.UTime = record_date.Format(timeLayout)
|
|
181
|
+ // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
|
|
182
|
+ err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
|
|
183
|
+ if err != nil {
|
|
184
|
+ tx.Rollback()
|
|
185
|
+ }
|
|
186
|
+ }
|
|
187
|
+ tx.Commit()
|
|
188
|
+ }
|
|
189
|
+ }
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ } else {
|
|
193
|
+ continue
|
|
194
|
+ }
|
|
195
|
+ }
|
|
196
|
+ }
|
|
197
|
+ var syncInfo models.MiddleSyncInfo
|
|
198
|
+ syncInfo.OrgId = org_id
|
|
199
|
+ syncInfo.SyncTime = time.Now().Unix()
|
|
200
|
+ syncInfo.SyncResultType = 1
|
|
201
|
+ syncInfo.SyncRsultRemark = "同步成功"
|
|
202
|
+ syncInfo.SyncTotalNum = 0
|
|
203
|
+ syncInfo.SyncSuccessNum = 0
|
|
204
|
+ syncInfo.SyncInfo = ""
|
|
205
|
+ syncInfo.CreateTime = time.Now().Unix()
|
|
206
|
+ syncInfo.UpdateTime = time.Now().Unix()
|
|
207
|
+
|
|
208
|
+ cwderr := CreateSyncInfo(&syncInfo)
|
|
209
|
+ if cwderr != nil {
|
|
210
|
+ utils.ErrorLog("创建同步信息失败:%v", cwderr)
|
|
211
|
+ return
|
|
212
|
+ }
|
|
213
|
+ SyncToFjtftx()
|
|
214
|
+ return
|
|
215
|
+}
|
|
216
|
+
|
|
217
|
+type BjncPatientInfo struct {
|
|
218
|
+ Msg string `json:"msg"`
|
|
219
|
+ Code string `json:"code"`
|
|
220
|
+ Result []struct {
|
|
221
|
+ Patientid int64 `json:"patientId"`
|
|
222
|
+ Visitid int64 `json:"visitId"`
|
|
223
|
+ Outpatientno string `json:"outPatientNo"`
|
|
224
|
+ Patientname string `json:"patientName"`
|
|
225
|
+ Idcardno string `json:"idCardNo"`
|
|
226
|
+ } `json:"result"`
|
|
227
|
+}
|
|
228
|
+
|
|
229
|
+func BjncGetPatientInfo(id_card_no string, endTime string) (string, string) {
|
|
230
|
+ // 1.生成签名sign
|
|
231
|
+ var sync_time int64
|
|
232
|
+ sync_time = 1690819200 // 2023-08-01 00:00:00
|
|
233
|
+ sync_time_temp := time.Unix(sync_time, 0)
|
|
234
|
+ startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
|
|
235
|
+ signData := make(map[string]interface{})
|
|
236
|
+ //signData["dateType"] = "07"
|
|
237
|
+ signData["startTime"] = startTimeStr
|
|
238
|
+ signData["idCardNo"] = id_card_no
|
|
239
|
+ signData["endTime"] = endTime
|
|
240
|
+ bytesData, _ := json.Marshal(signData)
|
|
241
|
+ inputLog := string(bytesData)
|
|
242
|
+ signStr := "body=" + inputLog + "&operUserCode=100&serv=getRegisterInfo&key=A3195B3D179B01F66C86703E0890A95F"
|
|
243
|
+ signTemp := utils.String2md5(signStr)
|
|
244
|
+ sign := strings.ToUpper(signTemp)
|
|
245
|
+
|
|
246
|
+ // 2.请求参数
|
|
247
|
+ inputData := make(map[string]interface{})
|
|
248
|
+ inputData["body"] = signData
|
|
249
|
+ inputData["serv"] = "getRegisterInfo"
|
|
250
|
+ inputData["operUserCode"] = "100"
|
|
251
|
+ inputData["sign"] = sign
|
|
252
|
+
|
|
253
|
+ postData, err := json.Marshal(inputData)
|
|
254
|
+ postStr := string(postData)
|
|
255
|
+ utils.InfoLog("1111111111:%v", postStr)
|
|
256
|
+ if err != nil {
|
|
257
|
+ fmt.Println(err.Error())
|
|
258
|
+ return err.Error(), ""
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ reader := bytes.NewReader(postData)
|
|
262
|
+ url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
|
|
263
|
+
|
|
264
|
+ request, err := http.NewRequest("POST", url, reader)
|
|
265
|
+ if err != nil {
|
|
266
|
+ fmt.Println(err.Error())
|
|
267
|
+ return err.Error(), ""
|
|
268
|
+ }
|
|
269
|
+
|
|
270
|
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
271
|
+ request.Header.Set("code", "XTXT")
|
|
272
|
+
|
|
273
|
+ client := http.Client{}
|
|
274
|
+ resp, err := client.Do(request)
|
|
275
|
+ if err != nil {
|
|
276
|
+ fmt.Println(err.Error())
|
|
277
|
+ return err.Error(), ""
|
|
278
|
+ }
|
|
279
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
280
|
+ if err != nil {
|
|
281
|
+ fmt.Println(err.Error())
|
|
282
|
+ return err.Error(), ""
|
|
283
|
+ }
|
|
284
|
+ str := string(respBytes)
|
|
285
|
+ utils.InfoLog("22222222:%v", str)
|
|
286
|
+ return str, inputLog
|
|
287
|
+}
|
|
288
|
+
|
|
289
|
+type BjncLisReport struct {
|
|
290
|
+ Code string `json:"code"`
|
|
291
|
+ Msg string `json:"msg"`
|
|
292
|
+ Result []struct {
|
|
293
|
+ Patientid string `json:"patientId"`
|
|
294
|
+ Patientname string `json:"patientName"`
|
|
295
|
+ Reportno int64 `json:"reportNo"`
|
|
296
|
+ Visitid string `json:"visitId"`
|
|
297
|
+ Applydeptname string `json:"applyDeptName"`
|
|
298
|
+ Reportname string `json:"reportName"`
|
|
299
|
+ } `json:"result"`
|
|
300
|
+}
|
|
301
|
+
|
|
302
|
+func BjncGetLisReport(id_card_no int64, startTime string, endTime string) (string, string) {
|
|
303
|
+ // 1.生成签名sign
|
|
304
|
+ signData := make(map[string]interface{})
|
|
305
|
+ signData["patientId"] = strconv.FormatInt(id_card_no, 10)
|
|
306
|
+ signData["dateType"] = "16"
|
|
307
|
+ signData["startTime"] = startTime
|
|
308
|
+ signData["endTime"] = endTime
|
|
309
|
+ bytesData, _ := json.Marshal(signData)
|
|
310
|
+ inputLog := string(bytesData)
|
|
311
|
+ signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReport&key=A3195B3D179B01F66C86703E0890A95F"
|
|
312
|
+ signTemp := utils.String2md5(signStr)
|
|
313
|
+ sign := strings.ToUpper(signTemp)
|
|
314
|
+
|
|
315
|
+ // 2.请求参数
|
|
316
|
+ inputData := make(map[string]interface{})
|
|
317
|
+ inputData["body"] = signData
|
|
318
|
+ inputData["serv"] = "getLisReport"
|
|
319
|
+ inputData["operUserCode"] = "100"
|
|
320
|
+ inputData["sign"] = sign
|
|
321
|
+
|
|
322
|
+ postData, err := json.Marshal(inputData)
|
|
323
|
+ postStr := string(postData)
|
|
324
|
+ utils.InfoLog("1111111111:%v", postStr)
|
|
325
|
+ if err != nil {
|
|
326
|
+ fmt.Println(err.Error())
|
|
327
|
+ return err.Error(), ""
|
|
328
|
+ }
|
|
329
|
+
|
|
330
|
+ reader := bytes.NewReader(postData)
|
|
331
|
+ url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
|
|
332
|
+
|
|
333
|
+ request, err := http.NewRequest("POST", url, reader)
|
|
334
|
+ if err != nil {
|
|
335
|
+ fmt.Println(err.Error())
|
|
336
|
+ return err.Error(), ""
|
|
337
|
+ }
|
|
338
|
+
|
|
339
|
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
340
|
+ request.Header.Set("code", "XTXT")
|
|
341
|
+
|
|
342
|
+ client := http.Client{}
|
|
343
|
+ resp, err := client.Do(request)
|
|
344
|
+ if err != nil {
|
|
345
|
+ fmt.Println(err.Error())
|
|
346
|
+ return err.Error(), ""
|
|
347
|
+ }
|
|
348
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
349
|
+ if err != nil {
|
|
350
|
+ fmt.Println(err.Error())
|
|
351
|
+ return err.Error(), ""
|
|
352
|
+ }
|
|
353
|
+ str := string(respBytes)
|
|
354
|
+ utils.InfoLog("22222222:%v", str)
|
|
355
|
+ return str, inputLog
|
|
356
|
+}
|
|
357
|
+
|
|
358
|
+type ReportDetail struct {
|
|
359
|
+ Msg string `json:"msg"`
|
|
360
|
+ Code string `json:"code"`
|
|
361
|
+ Result []struct {
|
|
362
|
+ Detailid string `json:"detailId"`
|
|
363
|
+ Reportno string `json:"reportNo"`
|
|
364
|
+ Testtime string `json:"testTime"`
|
|
365
|
+ Combinationcode string `json:"combinationCode"`
|
|
366
|
+ Combinationname string `json:"combinationName"`
|
|
367
|
+ Itemcode string `json:"itemCode"`
|
|
368
|
+ Itemname string `json:"itemName"`
|
|
369
|
+ Abbreviation string `json:"abbreviation"`
|
|
370
|
+ Itemreportresult string `json:"itemReportResult"`
|
|
371
|
+ Unit string `json:"unit"`
|
|
372
|
+ Resultpoint string `json:"resultPoint"`
|
|
373
|
+ Rownr string `json:"rownr"`
|
|
374
|
+ Referlow string `json:"referLow"`
|
|
375
|
+ Referhigh string `json:"referHigh"`
|
|
376
|
+ Referscope string `json:"referScope"`
|
|
377
|
+ Low string `json:"low"`
|
|
378
|
+ High string `json:"high"`
|
|
379
|
+ } `json:"result"`
|
|
380
|
+}
|
|
381
|
+
|
|
382
|
+func BjncGetReportInfo(report_no int64, startTime string, endTime string) (string, string) {
|
|
383
|
+ // 1.生成签名sign
|
|
384
|
+ signData := make(map[string]interface{})
|
|
385
|
+ signData["reportNo"] = strconv.FormatInt(report_no, 10)
|
|
386
|
+ signData["dateType"] = "16"
|
|
387
|
+ signData["startTime"] = startTime
|
|
388
|
+ signData["endTime"] = endTime
|
|
389
|
+ bytesData, _ := json.Marshal(signData)
|
|
390
|
+ inputLog := string(bytesData)
|
|
391
|
+ signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReportDetail&key=A3195B3D179B01F66C86703E0890A95F"
|
|
392
|
+ signTemp := utils.String2md5(signStr)
|
|
393
|
+ sign := strings.ToUpper(signTemp)
|
|
394
|
+
|
|
395
|
+ // 2.请求参数
|
|
396
|
+ inputData := make(map[string]interface{})
|
|
397
|
+ inputData["body"] = signData
|
|
398
|
+ inputData["serv"] = "getLisReportDetail"
|
|
399
|
+ inputData["operUserCode"] = "100"
|
|
400
|
+ inputData["sign"] = sign
|
|
401
|
+
|
|
402
|
+ postData, err := json.Marshal(inputData)
|
|
403
|
+ postStr := string(postData)
|
|
404
|
+ utils.InfoLog("1111111111:%v", postStr)
|
|
405
|
+ if err != nil {
|
|
406
|
+ fmt.Println(err.Error())
|
|
407
|
+ return err.Error(), ""
|
|
408
|
+ }
|
|
409
|
+
|
|
410
|
+ reader := bytes.NewReader(postData)
|
|
411
|
+ url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
|
|
412
|
+
|
|
413
|
+ request, err := http.NewRequest("POST", url, reader)
|
|
414
|
+ if err != nil {
|
|
415
|
+ fmt.Println(err.Error())
|
|
416
|
+ return err.Error(), ""
|
|
417
|
+ }
|
|
418
|
+
|
|
419
|
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
420
|
+ request.Header.Set("code", "XTXT")
|
|
421
|
+
|
|
422
|
+ client := http.Client{}
|
|
423
|
+ resp, err := client.Do(request)
|
|
424
|
+ if err != nil {
|
|
425
|
+ fmt.Println(err.Error())
|
|
426
|
+ return err.Error(), ""
|
|
427
|
+ }
|
|
428
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
429
|
+ if err != nil {
|
|
430
|
+ fmt.Println(err.Error())
|
|
431
|
+ return err.Error(), ""
|
|
432
|
+ }
|
|
433
|
+ str := string(respBytes)
|
|
434
|
+ utils.InfoLog("22222222:%v", str)
|
|
435
|
+ return str, inputLog
|
|
436
|
+}
|
|
437
|
+
|
|
438
|
+func SyncBjncHis() (err error) {
|
|
439
|
+ org_id := int64(10606)
|
|
440
|
+ redisClient := RedisClient()
|
|
441
|
+ defer redisClient.Close()
|
|
442
|
+
|
|
443
|
+ // 第一步:获取上一次同步的时间点
|
|
444
|
+ sync_time_tt, _ := redisClient.Get("bjncyyyy_sync_time").Result()
|
|
445
|
+
|
|
446
|
+ sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
|
|
447
|
+
|
|
448
|
+ if sync_time == 0 {
|
|
449
|
+ sync_time = time.Now().Unix() - 60*60*10
|
|
450
|
+ //sync_time = 1719763200
|
|
451
|
+ }
|
|
452
|
+
|
|
453
|
+ loc, _ := time.LoadLocation("Local") //重要:获取时区
|
|
454
|
+ sync_time_temp := time.Unix(sync_time, 0)
|
|
455
|
+ startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
|
|
456
|
+ end_time := time.Now().Unix()
|
|
457
|
+ end_time_temp := time.Unix(end_time, 0)
|
|
458
|
+ endTimeStr := end_time_temp.Format("2006-01-02 15:04:05")
|
|
459
|
+
|
|
460
|
+ new_sync_time := time.Now().Unix() - 60*60
|
|
461
|
+ redisClient.Set("bjncyyyy_sync_time", new_sync_time, time.Minute*60*24)
|
|
462
|
+ // 第二步:获取所有患者的病历号
|
|
463
|
+
|
|
464
|
+ patientList, _ := GetPatientGzjhByOrgId(org_id)
|
|
465
|
+ if len(patientList) > 0 {
|
|
466
|
+ for _, patient := range patientList {
|
|
467
|
+ if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
|
|
468
|
+ //patient_id := patient.ID
|
|
469
|
+ utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
|
|
470
|
+ // utils.InfoLog("VipStr:%v", VipStr)
|
|
471
|
+
|
|
472
|
+ result, _ := BjncGetHis(patient.IdCardNo, startTimeStr, endTimeStr)
|
|
473
|
+ var bjncHis BjncHis
|
|
474
|
+ if err := json.Unmarshal([]byte(result), &bjncHis); err != nil {
|
|
475
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
476
|
+ }
|
|
477
|
+ fmt.Println(bjncHis)
|
|
478
|
+ for _, cinfo := range bjncHis.Result {
|
|
479
|
+ fmt.Println(cinfo.Patientid)
|
|
480
|
+ // 查询该患者当天是否有排班信息
|
|
481
|
+
|
|
482
|
+ STime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
|
|
483
|
+ formattedTime := STime.Format("2006-01-02")
|
|
484
|
+ StTime, _ := time.ParseInLocation("2006-01-02", formattedTime, loc)
|
|
485
|
+ schedulesTime := StTime.Unix()
|
|
486
|
+
|
|
487
|
+ theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
|
|
488
|
+ start_temp_Time := theTime.Format("2006-01-02 15:04")
|
|
489
|
+ SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
|
|
490
|
+ start_time := SxTime.Unix()
|
|
491
|
+ utils.InfoLog("start_time:%v", start_time)
|
|
492
|
+
|
|
493
|
+ schedulesInfo, _ := GetSchedulesByPatientID(org_id, schedulesTime, patient.ID)
|
|
494
|
+ if schedulesInfo.ID > 0 {
|
|
495
|
+ start_time = theTime.Unix()
|
|
496
|
+ } else {
|
|
497
|
+ continue
|
|
498
|
+ }
|
|
499
|
+
|
|
500
|
+ // 根据同步来的 advice_id 来查询库里是否已经存在
|
|
501
|
+ advice_info, _ := GetAdviceBySyncAdviceIdForScyyyy(org_id, cinfo.Medicaladviceid, schedulesTime, patient.ID)
|
|
502
|
+ utils.InfoLog("Orderstatuscode:%v", cinfo.Orderstatuscode)
|
|
503
|
+ utils.InfoLog("AdviceName:%v", cinfo.Diagproname)
|
|
504
|
+ if advice_info.ID > 0 {
|
|
505
|
+ if cinfo.Orderstatuscode == 4 || cinfo.Orderstatuscode == 5 {
|
|
506
|
+ advice_info.Status = 0
|
|
507
|
+ SaveDoctorAdviceHandle(&advice_info)
|
|
508
|
+ } else {
|
|
509
|
+ continue
|
|
510
|
+ }
|
|
511
|
+ } else {
|
|
512
|
+ if cinfo.Orderstatuscode == 1 || cinfo.Orderstatuscode == 8 {
|
|
513
|
+ // 根据姓名获取医生ID
|
|
514
|
+ var doctor_id int64
|
|
515
|
+ temp_doctor_id, _ := redisClient.Get("bjncyyyy_doctor_id_" + cinfo.Orderdoctorcode).Result()
|
|
516
|
+ if len(temp_doctor_id) == 0 {
|
|
517
|
+ doctor, _ := GetAdminUserId(org_id, cinfo.Orderdoctorname)
|
|
518
|
+ doctor_id = doctor.AdminUserId
|
|
519
|
+ if doctor_id > 0 {
|
|
520
|
+ redisClient.Set("bjncyyyy_doctor_id_"+cinfo.Orderdoctorcode, doctor_id, time.Minute*60*2)
|
|
521
|
+ } else {
|
|
522
|
+ continue
|
|
523
|
+ }
|
|
524
|
+ } else {
|
|
525
|
+ doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
|
|
526
|
+ }
|
|
527
|
+ //
|
|
528
|
+ // // 根据排班班次,固定医嘱时间
|
|
529
|
+
|
|
530
|
+ advice := models.XtDoctorAdvice{
|
|
531
|
+ UserOrgId: org_id,
|
|
532
|
+ PatientId: patient.ID,
|
|
533
|
+ AdviceType: 2,
|
|
534
|
+ AdviceDate: schedulesTime,
|
|
535
|
+ StartTime: start_time,
|
|
536
|
+ AdviceName: cinfo.Diagproname,
|
|
537
|
+ RecordDate: schedulesTime,
|
|
538
|
+ SingleDose: cinfo.Dosequantity,
|
|
539
|
+ SingleDoseUnit: cinfo.Dosequantityunit,
|
|
540
|
+ PrescribingNumber: cinfo.Amount,
|
|
541
|
+ PrescribingNumberUnit: cinfo.Unit,
|
|
542
|
+ DeliveryWay: cinfo.Routename,
|
|
543
|
+ ExecutionFrequency: cinfo.Executefrequencyname,
|
|
544
|
+ AdviceDoctor: doctor_id,
|
|
545
|
+ CreatedTime: time.Now().Unix(),
|
|
546
|
+ UpdatedTime: time.Now().Unix(),
|
|
547
|
+ SyncAdviceId: cinfo.Medicaladviceid,
|
|
548
|
+ ExecutionState: 2,
|
|
549
|
+ Status: 1,
|
|
550
|
+ IsSync: 1,
|
|
551
|
+ }
|
|
552
|
+ utils.InfoLog("advice:%v", advice)
|
|
553
|
+
|
|
554
|
+ if len(cinfo.Diagproname) > 0 {
|
|
555
|
+ handleerr := CreateDoctorAdviceHandle(&advice)
|
|
556
|
+ if handleerr != nil {
|
|
557
|
+ utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
|
|
558
|
+ continue
|
|
559
|
+ }
|
|
560
|
+ } else {
|
|
561
|
+ continue
|
|
562
|
+ }
|
|
563
|
+ } else {
|
|
564
|
+ continue
|
|
565
|
+ }
|
|
566
|
+ }
|
|
567
|
+ }
|
|
568
|
+ }
|
|
569
|
+ }
|
|
570
|
+ }
|
|
571
|
+
|
|
572
|
+ //var syncInfo models.MiddleSyncInfo
|
|
573
|
+ //syncInfo.OrgId = org_id
|
|
574
|
+ //syncInfo.SyncTime = time.Now().Unix()
|
|
575
|
+ //syncInfo.SyncResultType = 1
|
|
576
|
+ //syncInfo.SyncRsultRemark = "同步成功"
|
|
577
|
+ //syncInfo.SyncTotalNum = 0
|
|
578
|
+ //syncInfo.SyncSuccessNum = 0
|
|
579
|
+ //syncInfo.SyncInfo = ""
|
|
580
|
+ //syncInfo.CreateTime = time.Now().Unix()
|
|
581
|
+ //syncInfo.UpdateTime = time.Now().Unix()
|
|
582
|
+ //
|
|
583
|
+ //cwderr := CreateSyncInfo(&syncInfo)
|
|
584
|
+ //if cwderr != nil {
|
|
585
|
+ // utils.ErrorLog("创建同步信息失败:%v", cwderr)
|
|
586
|
+ // return
|
|
587
|
+ //}
|
|
588
|
+ //SyncToFjtftx()
|
|
589
|
+ return
|
|
590
|
+}
|
|
591
|
+
|
|
592
|
+type BjncHis struct {
|
|
593
|
+ Msg string `json:"msg"`
|
|
594
|
+ Code string `json:"code"`
|
|
595
|
+ Result []struct {
|
|
596
|
+ Patientid string `json:"patientId"`
|
|
597
|
+ Visitid string `json:"visitId"`
|
|
598
|
+ Outpatientno string `json:"outPatientNo"`
|
|
599
|
+ Patientname string `json:"patientName"`
|
|
600
|
+ Idcardno string `json:"idCardNo"`
|
|
601
|
+ Orderstatuscode int64 `json:"orderStatusCode"`
|
|
602
|
+ Ordercreatetime string `json:"orderCreateTime"`
|
|
603
|
+ Orderdoctorcode string `json:"orderDoctorCode"`
|
|
604
|
+ Orderdoctorname string `json:"orderDoctorName"`
|
|
605
|
+ Medicaladviceid int64 `json:"medicalAdviceId"`
|
|
606
|
+ Medicalordername string `json:"medicalOrderName"`
|
|
607
|
+ Itemname string `json:"itemName"`
|
|
608
|
+ Itemeffectivetimelow string `json:"itemEffectiveTimeLow"`
|
|
609
|
+ Executefrequencyname string `json:"executeFrequencyName"`
|
|
610
|
+ Routename string `json:"routeName"`
|
|
611
|
+ Dosequantity float64 `json:"doseQuantity"`
|
|
612
|
+ Dosequantityunit string `json:"doseQuantityUnit"`
|
|
613
|
+ Totaldosequantity float64 `json:"totalDoseQuantity"`
|
|
614
|
+ Totaldosequantityunit string `json:"totalDoseQuantityUnit"`
|
|
615
|
+ Diagproname string `json:"diagProName"`
|
|
616
|
+ Amount float64 `json:"amount"`
|
|
617
|
+ Unit string `json:"unit"`
|
|
618
|
+ } `json:"result"`
|
|
619
|
+}
|
|
620
|
+
|
|
621
|
+func BjncGetHis(id_card_no string, startTime string, endTime string) (string, string) {
|
|
622
|
+ // 1.生成签名sign
|
|
623
|
+ signData := make(map[string]interface{})
|
|
624
|
+ signData["dateType"] = "07"
|
|
625
|
+ signData["medicalOrderType"] = "1,2,3,A,B,D,E,L,N,O"
|
|
626
|
+ signData["idCardNo"] = id_card_no
|
|
627
|
+ signData["startTime"] = startTime
|
|
628
|
+ signData["endTime"] = endTime
|
|
629
|
+ bytesData, _ := json.Marshal(signData)
|
|
630
|
+ inputLog := string(bytesData)
|
|
631
|
+ signStr := "body=" + inputLog + "&operUserCode=100&serv=getMedicalAdvice&key=A3195B3D179B01F66C86703E0890A95F"
|
|
632
|
+ signTemp := utils.String2md5(signStr)
|
|
633
|
+ sign := strings.ToUpper(signTemp)
|
|
634
|
+
|
|
635
|
+ // 2.请求参数
|
|
636
|
+ inputData := make(map[string]interface{})
|
|
637
|
+ inputData["body"] = signData
|
|
638
|
+ inputData["serv"] = "getMedicalAdvice"
|
|
639
|
+ inputData["operUserCode"] = "100"
|
|
640
|
+ inputData["sign"] = sign
|
|
641
|
+
|
|
642
|
+ postData, err := json.Marshal(inputData)
|
|
643
|
+ postStr := string(postData)
|
|
644
|
+ utils.InfoLog("1111111111:%v", postStr)
|
|
645
|
+ if err != nil {
|
|
646
|
+ fmt.Println(err.Error())
|
|
647
|
+ return err.Error(), ""
|
|
648
|
+ }
|
|
649
|
+
|
|
650
|
+ reader := bytes.NewReader(postData)
|
|
651
|
+ url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
|
|
652
|
+
|
|
653
|
+ request, err := http.NewRequest("POST", url, reader)
|
|
654
|
+ if err != nil {
|
|
655
|
+ fmt.Println(err.Error())
|
|
656
|
+ return err.Error(), ""
|
|
657
|
+ }
|
|
658
|
+
|
|
659
|
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
660
|
+ request.Header.Set("code", "XTXT")
|
|
661
|
+
|
|
662
|
+ client := http.Client{}
|
|
663
|
+ resp, err := client.Do(request)
|
|
664
|
+ if err != nil {
|
|
665
|
+ fmt.Println(err.Error())
|
|
666
|
+ return err.Error(), ""
|
|
667
|
+ }
|
|
668
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
669
|
+ if err != nil {
|
|
670
|
+ fmt.Println(err.Error())
|
|
671
|
+ return err.Error(), ""
|
|
672
|
+ }
|
|
673
|
+ str := string(respBytes)
|
|
674
|
+ utils.InfoLog("22222222:%v", str)
|
|
675
|
+ return str, inputLog
|
|
676
|
+}
|
|
677
|
+
|
|
678
|
+//
|
|
679
|
+//func FjtjGetLac(lab01 int64) (string, string) {
|
|
680
|
+// inputData := make(map[string]interface{})
|
|
681
|
+//
|
|
682
|
+// inputData["lab01"] = lab01
|
|
683
|
+//
|
|
684
|
+// var inputLog string
|
|
685
|
+// bytesData, err := json.Marshal(inputData)
|
|
686
|
+// inputLog = string(bytesData)
|
|
687
|
+// fmt.Println(string(bytesData))
|
|
688
|
+// if err != nil {
|
|
689
|
+// fmt.Println(err.Error())
|
|
690
|
+// return err.Error(), ""
|
|
691
|
+// }
|
|
692
|
+// reader := bytes.NewReader(bytesData)
|
|
693
|
+// url := "http://hip.zptfyy.com/esb/listener/getLac1"
|
|
694
|
+//
|
|
695
|
+// request, err := http.NewRequest("POST", url, reader)
|
|
696
|
+// if err != nil {
|
|
697
|
+// fmt.Println(err.Error())
|
|
698
|
+// return err.Error(), ""
|
|
699
|
+// }
|
|
700
|
+//
|
|
701
|
+// request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
702
|
+// request.Header.Set("code", "xt")
|
|
703
|
+//
|
|
704
|
+// client := http.Client{}
|
|
705
|
+// resp, err := client.Do(request)
|
|
706
|
+// if err != nil {
|
|
707
|
+// fmt.Println(err.Error())
|
|
708
|
+// return err.Error(), ""
|
|
709
|
+// }
|
|
710
|
+// respBytes, err := ioutil.ReadAll(resp.Body)
|
|
711
|
+// if err != nil {
|
|
712
|
+// fmt.Println(err.Error())
|
|
713
|
+// return err.Error(), ""
|
|
714
|
+// }
|
|
715
|
+// str := string(respBytes)
|
|
716
|
+// return str, inputLog
|
|
717
|
+//}
|
|
718
|
+//
|
|
719
|
+//// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
|
|
720
|
+//func GetfjtfProjectID(org_id int64, project_name string) (project_id int64, err error) {
|
|
721
|
+// var inspection_reference models.MiddleInspectionReference
|
|
722
|
+// err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
|
|
723
|
+// if inspection_reference.ID > 0 {
|
|
724
|
+// return inspection_reference.ProjectId, err
|
|
725
|
+// } else {
|
|
726
|
+// err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
|
|
727
|
+// if inspection_reference.ProjectId > 0 {
|
|
728
|
+// return inspection_reference.ProjectId + 1, err
|
|
729
|
+// } else {
|
|
730
|
+// return 330001, err
|
|
731
|
+// }
|
|
732
|
+// }
|
|
733
|
+//}
|
|
734
|
+//
|
|
735
|
+//// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
|
|
736
|
+//func GetFjtfItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
|
|
737
|
+// var inspection_reference models.MiddleInspectionReference
|
|
738
|
+// 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
|
|
739
|
+// if inspection_reference.ID > 0 {
|
|
740
|
+// return inspection_reference.ItemId, err
|
|
741
|
+// } else {
|
|
742
|
+// 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
|
|
743
|
+// utils.InfoLog("inspection_reference: %v", inspection_reference)
|
|
744
|
+// if inspection_reference.ItemId > 0 {
|
|
745
|
+// return inspection_reference.ItemId + 1, err
|
|
746
|
+// } else {
|
|
747
|
+// return project_id*100 + 1, err
|
|
748
|
+// }
|
|
749
|
+// }
|
|
750
|
+//}
|
|
751
|
+//
|
|
752
|
+//func SyncToFjtftx() {
|
|
753
|
+// utils.TraceLog("检验检查同步任务开始执行")
|
|
754
|
+// org_id := int64(10330)
|
|
755
|
+//
|
|
756
|
+// // 第一步:跟进org_id 去中间库查出需要同步的数据
|
|
757
|
+// inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
|
|
758
|
+// inspections, _ := GetSyncInspectionByOrgId(org_id)
|
|
759
|
+//
|
|
760
|
+// // 第二步:将数据同步到业务库
|
|
761
|
+// if len(inspection_references) > 0 {
|
|
762
|
+// for _, inspection_reference := range inspection_references {
|
|
763
|
+// SyncInspectionReference(&inspection_reference)
|
|
764
|
+// }
|
|
765
|
+// }
|
|
766
|
+//
|
|
767
|
+// if len(inspections) > 0 {
|
|
768
|
+// for _, inspection := range inspections {
|
|
769
|
+// SyncInspection(&inspection)
|
|
770
|
+// }
|
|
771
|
+// }
|
|
772
|
+// utils.SuccessLog("检验检查同步任务完成")
|
|
773
|
+//}
|