|
@@ -12,15 +12,34 @@ import (
|
12
|
12
|
_ "github.com/jinzhu/gorm"
|
13
|
13
|
"io/ioutil"
|
14
|
14
|
"net/http"
|
|
15
|
+ "unicode/utf8"
|
15
|
16
|
|
16
|
17
|
"strconv"
|
17
|
18
|
"strings"
|
18
|
19
|
"time"
|
19
|
20
|
)
|
20
|
21
|
|
|
22
|
+func lastThreeChars(s string) string {
|
|
23
|
+ runeCount := 0
|
|
24
|
+ for i := len(s); i > 0; {
|
|
25
|
+ _, size := utf8.DecodeLastRuneInString(s[:i])
|
|
26
|
+ i -= size
|
|
27
|
+ runeCount++
|
|
28
|
+ if runeCount == 3 {
|
|
29
|
+ return s[i:]
|
|
30
|
+ }
|
|
31
|
+ }
|
|
32
|
+ // 如果字符串长度少于3个字符,则返回整个字符串或空字符串
|
|
33
|
+ if runeCount == 0 {
|
|
34
|
+ return ""
|
|
35
|
+ }
|
|
36
|
+ return s
|
|
37
|
+}
|
|
38
|
+
|
21
|
39
|
// 福建天福医院透析中心Lis同步
|
22
|
40
|
func SyncCsnyLis() (err error) {
|
23
|
41
|
org_id := int64(10340)
|
|
42
|
+ //org_id_other := int64(103401)
|
24
|
43
|
|
25
|
44
|
// 第一步:获取上一次同步的时间点
|
26
|
45
|
syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
|
|
@@ -31,22 +50,176 @@ func SyncCsnyLis() (err error) {
|
31
|
50
|
sync_time = 1651334400 // 2022-05-01 00:00:00
|
32
|
51
|
}
|
33
|
52
|
|
|
53
|
+ //syncLastInfo1, _ := GetSyncTimeByOrgIDForYs(org_id_other)
|
|
54
|
+ //var sync_time_other int64
|
|
55
|
+ //if syncLastInfo1.ID > 0 {
|
|
56
|
+ // sync_time_other = syncLastInfo1.SyncTime
|
|
57
|
+ //} else {
|
|
58
|
+ // sync_time_other = 1651334400 // 2022-05-01 00:00:00
|
|
59
|
+ //}
|
|
60
|
+
|
34
|
61
|
sync_time_temp := time.Unix(sync_time, 0)
|
35
|
62
|
syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
|
|
63
|
+
|
|
64
|
+ //sync_time_temp_1 := time.Unix(sync_time_other, 0)
|
|
65
|
+ //syncTimeStr_1 := sync_time_temp_1.Format("2006-01-02 15:04:05")
|
36
|
66
|
// 第二步:获取所有患者的病历号
|
37
|
67
|
|
38
|
68
|
patientList, _ := GetPatientGzjhByOrgId(org_id)
|
39
|
69
|
if len(patientList) > 0 {
|
|
70
|
+ // 体检的检验数据
|
|
71
|
+ //for _, patient := range patientList {
|
|
72
|
+ // if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
|
|
73
|
+ // patient_id := patient.ID
|
|
74
|
+ // var patient_name string
|
|
75
|
+ // length := len(patient.Name)
|
|
76
|
+ // if length >= 3 {
|
|
77
|
+ // utils.InfoLog("名字:%v", patient.Name)
|
|
78
|
+ // lastThree := lastThreeChars(patient.Name)
|
|
79
|
+ // utils.InfoLog("截取后的名字:%v", lastThree)
|
|
80
|
+ // re := regexp.MustCompile("[0-9]+")
|
|
81
|
+ // patient_name = re.ReplaceAllString(lastThree, "")
|
|
82
|
+ // } else {
|
|
83
|
+ // patient_name = patient.Name
|
|
84
|
+ // }
|
|
85
|
+ // result, _ := CsnyGetLabTj(patient_name, syncTimeStr_1)
|
|
86
|
+ // utils.InfoLog("result:%v", result)
|
|
87
|
+ // var fjtfLab LabCsnyResult
|
|
88
|
+ // if err := json.Unmarshal([]byte(result), &fjtfLab); err != nil {
|
|
89
|
+ // utils.ErrorLog("解析失败:%v", err)
|
|
90
|
+ // }
|
|
91
|
+ // fmt.Println(fjtfLab)
|
|
92
|
+ //
|
|
93
|
+ // if len(fjtfLab.Result) > 0 {
|
|
94
|
+ // // 根据获取的头部lab01获取检查结果
|
|
95
|
+ //
|
|
96
|
+ // for _, info := range fjtfLab.Result {
|
|
97
|
+ // lacResult, _ := CsnyGetLac(info.Lab01)
|
|
98
|
+ // utils.InfoLog("lacResult:%v", lacResult)
|
|
99
|
+ // var fjtfLac LacCsnyResult
|
|
100
|
+ // if err := json.Unmarshal([]byte(lacResult), &fjtfLac); err != nil {
|
|
101
|
+ // utils.ErrorLog("解析失败:%v", err)
|
|
102
|
+ // }
|
|
103
|
+ // fmt.Println(fjtfLac)
|
|
104
|
+ // for _, cinfo := range fjtfLac.Result {
|
|
105
|
+ // project_id := int64(0)
|
|
106
|
+ // item_id := int64(0)
|
|
107
|
+ // if len(cinfo.Bbx05a) > 0 {
|
|
108
|
+ // project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05a)
|
|
109
|
+ // item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05a, cinfo.Bbx05, project_id)
|
|
110
|
+ // } else {
|
|
111
|
+ // project_id, _ = GetCsnyProjectID(org_id, cinfo.Bbx05)
|
|
112
|
+ // item_id, _ = GetCsnyItemID(org_id, cinfo.Bbx05, cinfo.Bbx05, project_id)
|
|
113
|
+ // }
|
|
114
|
+ //
|
|
115
|
+ // tx := writeMiddleDb.Begin()
|
|
116
|
+ // var inspection models.MiddleInspection
|
|
117
|
+ // var inspection_reference models.MiddleInspectionReference
|
|
118
|
+ //
|
|
119
|
+ // loc, _ := time.LoadLocation("Local")
|
|
120
|
+ // theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Lac25, loc)
|
|
121
|
+ // record_date := theTime.Unix()
|
|
122
|
+ //
|
|
123
|
+ // if record_date == 0 {
|
|
124
|
+ // record_date = time.Now().Unix()
|
|
125
|
+ // }
|
|
126
|
+ //
|
|
127
|
+ // inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
|
|
128
|
+ // var total int
|
|
129
|
+ // var RangeOptions string
|
|
130
|
+ // var RangeMin string
|
|
131
|
+ // var RangeMax string
|
|
132
|
+ //
|
|
133
|
+ // // // 判断检查类型
|
|
134
|
+ // ItemType := 1
|
|
135
|
+ // Range := strings.Split(cinfo.Lac15, "-")
|
|
136
|
+ // if len(Range) > 1 {
|
|
137
|
+ // RangeMin = cinfo.Lac13
|
|
138
|
+ // RangeMax = cinfo.Lac14
|
|
139
|
+ // ItemType = 1
|
|
140
|
+ // } else {
|
|
141
|
+ // ItemType = 2
|
|
142
|
+ // RangeOptions = cinfo.Lac15
|
|
143
|
+ // }
|
|
144
|
+ //
|
|
145
|
+ // 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
|
|
146
|
+ // // if inspection_reference.ID > 0 {
|
|
147
|
+ // // ItemType = int64(inspection_reference.RangeType)
|
|
148
|
+ // // }
|
|
149
|
+ //
|
|
150
|
+ // if total <= 0 {
|
|
151
|
+ // inspection_reference.OrgId = org_id
|
|
152
|
+ // if len(cinfo.Bbx05a) > 0 {
|
|
153
|
+ // inspection_reference.ProjectName = cinfo.Bbx05a
|
|
154
|
+ // inspection_reference.Project = cinfo.Bbx05a
|
|
155
|
+ // } else {
|
|
156
|
+ // inspection_reference.ProjectName = cinfo.Bbx05
|
|
157
|
+ // inspection_reference.Project = cinfo.Bbx05
|
|
158
|
+ // }
|
|
159
|
+ // inspection_reference.ProjectId = project_id
|
|
160
|
+ // inspection_reference.ItemName = cinfo.Bbx05
|
|
161
|
+ // inspection_reference.ItemId = item_id
|
|
162
|
+ // inspection_reference.RangeType = ItemType
|
|
163
|
+ // inspection_reference.RangeMin = RangeMin
|
|
164
|
+ // inspection_reference.RangeMax = RangeMax
|
|
165
|
+ // // inspection_reference.RangeValue = RangeValue
|
|
166
|
+ // inspection_reference.RangeOptions = RangeOptions
|
|
167
|
+ // inspection_reference.Unit = cinfo.Bdg02
|
|
168
|
+ // inspection_reference.Status = 1
|
|
169
|
+ // inspection_reference.CreatedTime = time.Now().Unix()
|
|
170
|
+ // inspection_reference.UpdatedTime = time.Now().Unix()
|
|
171
|
+ // inspection_reference.InspectDate = inspect_date
|
|
172
|
+ // inspection_reference.UTime = inspect_date
|
|
173
|
+ // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
|
|
174
|
+ // if err != nil {
|
|
175
|
+ // tx.Rollback()
|
|
176
|
+ // }
|
|
177
|
+ // }
|
|
178
|
+ //
|
|
179
|
+ // var itotal int
|
|
180
|
+ // 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, patient_id).Find(&inspection).Count(&itotal).Error
|
|
181
|
+ // if itotal <= 0 {
|
|
182
|
+ // inspection.PatientId = patient_id
|
|
183
|
+ // inspection.OrgId = org_id
|
|
184
|
+ // inspection.ProjectId = project_id
|
|
185
|
+ // inspection.ItemName = inspection_reference.ItemName
|
|
186
|
+ // inspection.ProjectName = inspection_reference.ProjectName
|
|
187
|
+ // inspection.InspectType = ItemType
|
|
188
|
+ // inspection.ItemId = item_id
|
|
189
|
+ // inspection.InspectValue = cinfo.Lac10
|
|
190
|
+ // inspection.InspectDate = inspect_date
|
|
191
|
+ // inspection.RecordDate = record_date
|
|
192
|
+ // inspection.InspectTips = cinfo.Lac11
|
|
193
|
+ // inspection.Status = 1
|
|
194
|
+ // inspection.CreatedTime = time.Now().Unix()
|
|
195
|
+ // inspection.UpdatedTime = time.Now().Unix()
|
|
196
|
+ // inspection.UTime = inspect_date
|
|
197
|
+ // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
|
|
198
|
+ // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
|
|
199
|
+ // if err != nil {
|
|
200
|
+ // tx.Rollback()
|
|
201
|
+ // }
|
|
202
|
+ // }
|
|
203
|
+ //
|
|
204
|
+ // tx.Commit()
|
|
205
|
+ //
|
|
206
|
+ // }
|
|
207
|
+ // }
|
|
208
|
+ // }
|
|
209
|
+ // } else {
|
|
210
|
+ // continue
|
|
211
|
+ // }
|
|
212
|
+ //}
|
40
|
213
|
for _, patient := range patientList {
|
41
|
214
|
if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
|
42
|
215
|
patient_id := patient.ID
|
43
|
216
|
utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
|
44
|
217
|
// utils.InfoLog("VipStr:%v", VipStr)
|
45
|
218
|
|
46
|
|
- result, _ := CsnyGetLab(patient.IdCardNo, syncTimeStr)
|
47
|
|
- utils.InfoLog("result:%v", result)
|
|
219
|
+ result1, _ := CsnyGetLab(patient.IdCardNo, syncTimeStr)
|
|
220
|
+ utils.InfoLog("result:%v", result1)
|
48
|
221
|
var fjtfLab LabCsnyResult
|
49
|
|
- if err := json.Unmarshal([]byte(result), &fjtfLab); err != nil {
|
|
222
|
+ if err := json.Unmarshal([]byte(result1), &fjtfLab); err != nil {
|
50
|
223
|
utils.ErrorLog("解析失败:%v", err)
|
51
|
224
|
}
|
52
|
225
|
fmt.Println(fjtfLab)
|
|
@@ -188,6 +361,23 @@ func SyncCsnyLis() (err error) {
|
188
|
361
|
utils.ErrorLog("创建同步信息失败:%v", cwderr)
|
189
|
362
|
return
|
190
|
363
|
}
|
|
364
|
+
|
|
365
|
+ //var syncInfos models.MiddleSyncInfo
|
|
366
|
+ //syncInfos.OrgId = org_id_other
|
|
367
|
+ //syncInfos.SyncTime = time.Now().Unix()
|
|
368
|
+ //syncInfos.SyncResultType = 1
|
|
369
|
+ //syncInfos.SyncRsultRemark = "同步成功"
|
|
370
|
+ //syncInfos.SyncTotalNum = 0
|
|
371
|
+ //syncInfos.SyncSuccessNum = 0
|
|
372
|
+ //syncInfos.SyncInfo = ""
|
|
373
|
+ //syncInfos.CreateTime = time.Now().Unix()
|
|
374
|
+ //syncInfos.UpdateTime = time.Now().Unix()
|
|
375
|
+ //
|
|
376
|
+ //cwderrs := CreateSyncInfo(&syncInfos)
|
|
377
|
+ //if cwderrs != nil {
|
|
378
|
+ // utils.ErrorLog("创建同步信息失败:%v", cwderrs)
|
|
379
|
+ // return
|
|
380
|
+ //}
|
191
|
381
|
SyncToCsnytx()
|
192
|
382
|
return
|
193
|
383
|
}
|
|
@@ -242,6 +432,47 @@ func CsnyGetLab(id_card_no string, synctime string) (string, string) {
|
242
|
432
|
return str, inputLog
|
243
|
433
|
}
|
244
|
434
|
|
|
435
|
+func CsnyGetLabTj(patient_name string, synctime string) (string, string) {
|
|
436
|
+ inputData := make(map[string]interface{})
|
|
437
|
+
|
|
438
|
+ inputData["vaa05"] = patient_name
|
|
439
|
+ inputData["begintime"] = synctime
|
|
440
|
+
|
|
441
|
+ var inputLog string
|
|
442
|
+ bytesData, err := json.Marshal(inputData)
|
|
443
|
+ inputLog = string(bytesData)
|
|
444
|
+ fmt.Println(string(bytesData))
|
|
445
|
+ if err != nil {
|
|
446
|
+ fmt.Println(err.Error())
|
|
447
|
+ return err.Error(), ""
|
|
448
|
+ }
|
|
449
|
+ reader := bytes.NewReader(bytesData)
|
|
450
|
+ url := "http://218.104.146.179:9091/esb/listener/getLab1"
|
|
451
|
+
|
|
452
|
+ request, err := http.NewRequest("POST", url, reader)
|
|
453
|
+ if err != nil {
|
|
454
|
+ fmt.Println(err.Error())
|
|
455
|
+ return err.Error(), ""
|
|
456
|
+ }
|
|
457
|
+
|
|
458
|
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
|
459
|
+ request.Header.Set("code", "Xmrjyy")
|
|
460
|
+
|
|
461
|
+ client := http.Client{}
|
|
462
|
+ resp, err := client.Do(request)
|
|
463
|
+ if err != nil {
|
|
464
|
+ fmt.Println(err.Error())
|
|
465
|
+ return err.Error(), ""
|
|
466
|
+ }
|
|
467
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
468
|
+ if err != nil {
|
|
469
|
+ fmt.Println(err.Error())
|
|
470
|
+ return err.Error(), ""
|
|
471
|
+ }
|
|
472
|
+ str := string(respBytes)
|
|
473
|
+ return str, inputLog
|
|
474
|
+}
|
|
475
|
+
|
245
|
476
|
type LacCsnyResult struct {
|
246
|
477
|
Msg string `json:"msg"`
|
247
|
478
|
Result []struct {
|