|
@@ -0,0 +1,524 @@
|
|
1
|
+package service
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "IC/models"
|
|
5
|
+ "IC/utils"
|
|
6
|
+ "encoding/json"
|
|
7
|
+ "encoding/xml"
|
|
8
|
+ "github.com/astaxie/beego/httplib"
|
|
9
|
+ "net/url"
|
|
10
|
+ "strconv"
|
|
11
|
+ "strings"
|
|
12
|
+ "time"
|
|
13
|
+)
|
|
14
|
+
|
|
15
|
+type RequestResultGzjh struct {
|
|
16
|
+ Msg string `json:"msg"`
|
|
17
|
+ ResultGzjh []struct {
|
|
18
|
+ AdviceId int64 `json:"医嘱ID"`
|
|
19
|
+ OtherId int64 `json:"相关ID"`
|
|
20
|
+ Source int `json:"病人来源"`
|
|
21
|
+ PatientId int64 `json:"病人ID"`
|
|
22
|
+ JzId int64 `json:"就诊ID"`
|
|
23
|
+ BabyId int `json:"婴儿ID"`
|
|
24
|
+ PatientDepartmentId int `json:"病人科室ID"`
|
|
25
|
+ OrderId int `json:"次序"`
|
|
26
|
+ AdviceStatus int `json:"医嘱状态"`
|
|
27
|
+ AdviceType int `json:"医嘱类型"`
|
|
28
|
+ DiagnosisType string `json:"诊疗类型"`
|
|
29
|
+ DiagnosisItemId int `json:"诊疗项目ID"`
|
|
30
|
+ CheckMethd string `json:"检查方法"`
|
|
31
|
+ ChargeItemId int `json:"收费项目ID"`
|
|
32
|
+ Day int `json:"天数"`
|
|
33
|
+ JiLiang float64 `json:"剂量"`
|
|
34
|
+ YongLiang string `json:"用量"`
|
|
35
|
+ DanLiang float64 `json:"单量"`
|
|
36
|
+ Shuliang float64 `json:"数量"`
|
|
37
|
+ Advice string `json:"医嘱"`
|
|
38
|
+ GeiYaoTuJing string `json:"给药途径"`
|
|
39
|
+ ShuoMing string `json:"说明"`
|
|
40
|
+ ZhiXingKeShiId int `json:"执行科室ID"`
|
|
41
|
+ ZhiXingKeShi string `json:"执行科室"`
|
|
42
|
+ PN string `json:"P(+)或N(-)表示阳性或阴性"`
|
|
43
|
+ ZhiXingPinCi string `json:"执行频次"`
|
|
44
|
+ PinLvCiShu int `json:"频率次数"`
|
|
45
|
+ PinLvJianGe int `json:"频率间隔"`
|
|
46
|
+ JianGeDanWei string `json:"间隔单位"`
|
|
47
|
+ ZhiXingShiJianFangAn string `json:"执行时间方案"`
|
|
48
|
+ JiJiaTeXing int `json:"计价特性"`
|
|
49
|
+ ZhiXingXingZhi int `json:"执行性质"`
|
|
50
|
+ ZhiXingBiaoZhi int `json:"执行标记"`
|
|
51
|
+ KeFouFenLing int `json:"可否分零"`
|
|
52
|
+ JinJiBiaoZhi int `json:"紧急标志"`
|
|
53
|
+ KaiShiZhiXingShiJian int64 `json:"开始执行时间"`
|
|
54
|
+ ZhiXingZhongZhiShiJian int64 `json:"执行终止时间"`
|
|
55
|
+ ShangCiZhiXingShiJian int64 `json:"上次执行时间"`
|
|
56
|
+ KaiZhuKeShiId int `json:"开嘱科室ID"`
|
|
57
|
+ DoctorCode string `json:"医师编码"`
|
|
58
|
+ Doctor string `json:"开嘱医师"`
|
|
59
|
+ AdviceTime int64 `json:"开嘱时间"`
|
|
60
|
+ StopTime int64 `json:"停嘱时间"`
|
|
61
|
+ ApplyId int `json:"申请ID"`
|
|
62
|
+ UploadLable int `json:"上传标志"`
|
|
63
|
+ CheckResult int `json:"审查结果"`
|
|
64
|
+ NoPrint int `json:"忽略打印"`
|
|
65
|
+ Summary string `json:"摘要"`
|
|
66
|
+ AdviceOrderId int64 `json:"医嘱单id"`
|
|
67
|
+ GeiYaoKeShi int `json:"给药科室"`
|
|
68
|
+ GeiYaoXingZhi int `json:"给药性质"`
|
|
69
|
+ GroupNo int `json:"组号"`
|
|
70
|
+ Speed string `json:"滴速"`
|
|
71
|
+ ShouRiCiShu float64 `json:"首日次数"`
|
|
72
|
+ MoRiCiShu float64 `json:"末日次数"`
|
|
73
|
+ AdviceDoctorId int `json:"开嘱医师ID"`
|
|
74
|
+ AdviceNurseId int `json:"开嘱护士ID"`
|
|
75
|
+ OperaId int `json:"操作员ID"`
|
|
76
|
+ Opera string `json:"操作员"`
|
|
77
|
+ CheckTime int64 `json:"审核时间"`
|
|
78
|
+ ReplyAdviceTime int64 `json:"重整医嘱时间"`
|
|
79
|
+ } `json:"result"`
|
|
80
|
+ Code string `json:"code"`
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+type XmlKeyGzjh struct {
|
|
84
|
+ XMLName xml.Name `xml:"string"`
|
|
85
|
+ StringName string `xml:"name,attr"`
|
|
86
|
+ InnerText string `xml:",innerxml"`
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+// 获取艾迪康的key
|
|
90
|
+func GetGzjhAdKey(logid string, password string) (key string) {
|
|
91
|
+ Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/Login?"
|
|
92
|
+ apiurl := "logid=" + logid + "&password=" + password
|
|
93
|
+ apiurl = url.PathEscape(apiurl)
|
|
94
|
+ utils.InfoLog("apiUrl: %v", apiurl)
|
|
95
|
+ apiurl = Domain + apiurl
|
|
96
|
+ xmlKey := XmlKeyGzjh{}
|
|
97
|
+ httplib.Get(apiurl).ToXML(&xmlKey)
|
|
98
|
+ utils.InfoLog("xmlKey: %v", xmlKey)
|
|
99
|
+ return xmlKey.InnerText
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+type ADStringGzjh struct {
|
|
103
|
+ XMLName xml.Name `xml:"string" json:"string"`
|
|
104
|
+ NewDataSet rpnewDataSetGzjh `xml:"NewDataSet" json:"NewDataSetGzjh"`
|
|
105
|
+}
|
|
106
|
+
|
|
107
|
+type rpnewDataSetGzjh struct {
|
|
108
|
+ ListTable []rplisttableGzjh `xml:"listtable" json:"listtableGzjh"`
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+type rplisttableGzjh struct {
|
|
112
|
+ Id string `xml:"Id" json:"Id"`
|
|
113
|
+ PatientName string `xml:"PatientName" json:"PatientName"`
|
|
114
|
+ Bgrq string `xml:"Bgrq" json:"Bgrq"`
|
|
115
|
+ Instrument string `xml:"Instrument" json:"Instrument"`
|
|
116
|
+ LisDate string `xml:"LisDate" json:"LisDate"`
|
|
117
|
+ Sampleid string `xml:"Sampleid" json:"Sampleid"`
|
|
118
|
+}
|
|
119
|
+
|
|
120
|
+type ReportListXml struct {
|
|
121
|
+ XMLName xml.Name `xml:"GetReportList"`
|
|
122
|
+ Key string `xml:"Key"`
|
|
123
|
+ BeginDateTime string `xml:"BeginDateTime"`
|
|
124
|
+ EndDateTime string `xml:"EndDateTime"`
|
|
125
|
+ TypeDateTime string `xml:"TypeDateTime"`
|
|
126
|
+ AgainFlag string `xml:"AgainFlag"`
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+// 获取机构一段时间内检验检查列表
|
|
130
|
+func GetAdGetReportListGzjh(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADStringGzjh) {
|
|
131
|
+ Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetReportList"
|
|
132
|
+ var xmlKey ADStringGzjh
|
|
133
|
+ reportPost := httplib.Post(Domain)
|
|
134
|
+ reportPost.Param("Key",Key)
|
|
135
|
+ reportPost.Param("BeginDateTime",BeginDateTime)
|
|
136
|
+ reportPost.Param("EndDateTime",EndDateTime)
|
|
137
|
+ reportPost.Param("TypeDateTime",TypeDateTime)
|
|
138
|
+ reportPost.Param("AgainFlag",AgainFlag)
|
|
139
|
+ reportPost.Header("Content-Type", "application/xml")
|
|
140
|
+
|
|
141
|
+ xmlString,_ := reportPost.String()
|
|
142
|
+ xmlString = strings.Replace(xmlString, "<", "<", -1)
|
|
143
|
+ xmlString = strings.Replace(xmlString, ">", ">", -1)
|
|
144
|
+ xml.Unmarshal([]byte(xmlString), &xmlKey)
|
|
145
|
+ return xmlKey
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+type adkCheckGzjh struct {
|
|
149
|
+ ApplyId string `json:"applyid"`
|
|
150
|
+ ReportNo string `json:"reportno"`
|
|
151
|
+ PatName string `json:"patname"`
|
|
152
|
+ Sex string `json:"sex"`
|
|
153
|
+ Age string `json:"age"`
|
|
154
|
+ DptName string `json:"dptname"`
|
|
155
|
+ Testtype string `json:"testtype"`
|
|
156
|
+ Testcode string `json:"testcode"`
|
|
157
|
+ ExecuteTime string `json:"receivetime"`
|
|
158
|
+ Checktime string `json:"checktime"`
|
|
159
|
+ Checkcode string `json:"checkcode"`
|
|
160
|
+ Result []adkResultGzjh `json:"result"`
|
|
161
|
+}
|
|
162
|
+
|
|
163
|
+func GetAdkInfoGzjh(key string, id string) (str []adkCheckGzjh, checkStr string) {
|
|
164
|
+ Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListById"
|
|
165
|
+
|
|
166
|
+ reportPost := httplib.Post(Domain)
|
|
167
|
+ reportPost.Param("Key",key)
|
|
168
|
+ reportPost.Param("id",id)
|
|
169
|
+ reportPost.Header("Content-Type", "application/xml")
|
|
170
|
+ xmlKey := XmlKey{}
|
|
171
|
+ reportPost.ToXML(&xmlKey)
|
|
172
|
+ var checkJSON []adkCheckGzjh
|
|
173
|
+ json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
|
|
174
|
+ return checkJSON, xmlKey.InnerText
|
|
175
|
+}
|
|
176
|
+
|
|
177
|
+// 广州暨华血液透析中心Lis同步
|
|
178
|
+func SyncLisGzjhtx() (err error) {
|
|
179
|
+ // 第一步:获取艾迪康下发的Key
|
|
180
|
+ org_id := int64(10015)
|
|
181
|
+ login := "RH0046"
|
|
182
|
+ password := "Abc123123"
|
|
183
|
+ key := GetGzjhAdKey(login, password)
|
|
184
|
+ utils.InfoLog("key: %v", key)
|
|
185
|
+ // 第二步:获e取上一次同步的时间点
|
|
186
|
+ syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
|
|
187
|
+ var sync_time int64
|
|
188
|
+ if syncLastInfo.ID > 0 {
|
|
189
|
+ sync_time = syncLastInfo.SyncTime + 86400
|
|
190
|
+ } else {
|
|
191
|
+ sync_time = 1672502400
|
|
192
|
+ }
|
|
193
|
+ nowTimes := time.Now().Unix()
|
|
194
|
+ // syncTimes := time.Unix(sync_time,0).Format("2006-01-02")
|
|
195
|
+ if sync_time < nowTimes {
|
|
196
|
+ for i := sync_time; i < nowTimes; i = i + 86400 {
|
|
197
|
+ tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
|
|
198
|
+ utils.InfoLog("tempsyncTimes:%v", tempsyncTimes)
|
|
199
|
+ adString := GetAdGetReportListGzjh(key, tempsyncTimes, tempsyncTimes, "2", "2")
|
|
200
|
+ listtable := adString.NewDataSet.ListTable
|
|
201
|
+ utils.InfoLog("listtable: %v", listtable)
|
|
202
|
+ if len(listtable) > 3 {
|
|
203
|
+ // 第三步:根据检查列表获取的ID来获取检验检查详情
|
|
204
|
+ for _, list := range listtable {
|
|
205
|
+ listId := list.Id
|
|
206
|
+ utils.InfoLog("listId: %v", listId)
|
|
207
|
+ checkInfo, checkStr := GetAdkInfoGzjh(key, listId)
|
|
208
|
+ utils.InfoLog("checkInfo: %v", checkInfo)
|
|
209
|
+ for _, info := range checkInfo {
|
|
210
|
+ // 根据姓名 去查询对应的patient_id
|
|
211
|
+ patient, _ := GetPatientIDGzjh(org_id, info.PatName)
|
|
212
|
+ utils.InfoLog("patient: %v", patient)
|
|
213
|
+ if patient.ID > 0 {
|
|
214
|
+ middleReportHandle := models.MiddleReportHandle{
|
|
215
|
+ OrgId: org_id,
|
|
216
|
+ HisUserId: strconv.FormatInt(patient.ID, 10),
|
|
217
|
+ ApplyNo: info.ApplyId,
|
|
218
|
+ ReportId: info.ReportNo,
|
|
219
|
+ Name: info.PatName,
|
|
220
|
+ Sex: info.Sex,
|
|
221
|
+ Age: info.Age,
|
|
222
|
+ Dept: info.DptName,
|
|
223
|
+ PatientId: strconv.FormatInt(patient.ID, 10),
|
|
224
|
+ RequestTime: info.ExecuteTime,
|
|
225
|
+ ExecuteTime: info.ExecuteTime,
|
|
226
|
+ ReceiveTime: info.ExecuteTime,
|
|
227
|
+ CheckTime: info.ExecuteTime,
|
|
228
|
+ ReportInfo: checkStr,
|
|
229
|
+ CreatedTime: time.Now().Unix(),
|
|
230
|
+ UpdatedTime: time.Now().Unix(),
|
|
231
|
+ }
|
|
232
|
+ handleerr := CreateReportHandle(&middleReportHandle)
|
|
233
|
+ if handleerr != nil {
|
|
234
|
+ utils.ErrorLog("创建检验检查操作数据失败:%v", handleerr)
|
|
235
|
+ return
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+ GzjhReportInfoHandle(info, org_id, patient.ID)
|
|
239
|
+ }
|
|
240
|
+ }
|
|
241
|
+ }
|
|
242
|
+ var syncInfo models.MiddleSyncInfo
|
|
243
|
+ syncInfo.OrgId = org_id
|
|
244
|
+
|
|
245
|
+ syncInfo.SyncTime = i
|
|
246
|
+ syncInfo.SyncResultType = 1
|
|
247
|
+ syncInfo.SyncRsultRemark = "同步成功"
|
|
248
|
+ syncInfo.SyncTotalNum = 0
|
|
249
|
+ syncInfo.SyncSuccessNum = 0
|
|
250
|
+ syncInfo.SyncInfo = ""
|
|
251
|
+ syncInfo.CreateTime = time.Now().Unix()
|
|
252
|
+ syncInfo.UpdateTime = time.Now().Unix()
|
|
253
|
+
|
|
254
|
+ cwderr := CreateSyncInfo(&syncInfo)
|
|
255
|
+ if cwderr != nil {
|
|
256
|
+ utils.ErrorLog("创建同步信息失败:%v", cwderr)
|
|
257
|
+ return
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+
|
|
262
|
+ }
|
|
263
|
+ SyncToGzczjhtx()
|
|
264
|
+
|
|
265
|
+ return
|
|
266
|
+}
|
|
267
|
+
|
|
268
|
+// 根据姓名获取patient_id
|
|
269
|
+func GetPatientIDGzjh(org_id int64, patient_name string) (patient models.Patients, err error) {
|
|
270
|
+ err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ? ", org_id, patient_name).First(&patient).Error
|
|
271
|
+ return
|
|
272
|
+}
|
|
273
|
+
|
|
274
|
+func GetProjectInfoGzjh(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
|
|
275
|
+ err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
|
|
276
|
+ return
|
|
277
|
+}
|
|
278
|
+
|
|
279
|
+// 修改配置信息
|
|
280
|
+// func UpdateInspectionReference(InspectionReference *models.MiddleInspectionReference) error {
|
|
281
|
+// err := readMiddleDb.Model(&models.MiddleInspectionReference{}).Updates(&InspectionReference).Error
|
|
282
|
+// return err
|
|
283
|
+// }
|
|
284
|
+
|
|
285
|
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
|
|
286
|
+func GetGzzcjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
|
|
287
|
+ var inspection_reference models.MiddleInspectionReference
|
|
288
|
+ err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
|
|
289
|
+ if inspection_reference.ID > 0 {
|
|
290
|
+ return inspection_reference.ProjectId, err
|
|
291
|
+ } else {
|
|
292
|
+ err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
|
|
293
|
+ utils.InfoLog("inspection_reference: %v", inspection_reference)
|
|
294
|
+ if inspection_reference.ProjectId > 0 {
|
|
295
|
+ return inspection_reference.ProjectId + 1, err
|
|
296
|
+ } else {
|
|
297
|
+ return 1001501, err
|
|
298
|
+ }
|
|
299
|
+ }
|
|
300
|
+}
|
|
301
|
+
|
|
302
|
+// // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
|
|
303
|
+// func GetGzjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
|
|
304
|
+// var inspection_reference models.MiddleInspectionReference
|
|
305
|
+// err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
|
|
306
|
+// if inspection_reference.ID > 0 {
|
|
307
|
+// return inspection_reference.ProjectId, err
|
|
308
|
+// } else {
|
|
309
|
+// err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
|
|
310
|
+// if inspection_reference.ProjectId > 0 {
|
|
311
|
+// return inspection_reference.ProjectId + 1, err
|
|
312
|
+// } else {
|
|
313
|
+// return 116001, err
|
|
314
|
+// }
|
|
315
|
+// }
|
|
316
|
+// }
|
|
317
|
+
|
|
318
|
+func GzjhReportInfoHandle(CheckInfo adkCheckGzjh, org_id int64, patientId int64) {
|
|
319
|
+ // 1.先把所有的检查项弄出来
|
|
320
|
+ for _, info := range CheckInfo.Result {
|
|
321
|
+ // 根据project_id和item_id 判断该项是否存在
|
|
322
|
+ curitemcode, _ := strconv.ParseInt(info.Itemcode, 10, 64)
|
|
323
|
+ reference, _ := GetProjectInfoGzjh(curitemcode, org_id)
|
|
324
|
+ utils.InfoLog("info: %v", info)
|
|
325
|
+ utils.InfoLog("reference: %v", info)
|
|
326
|
+ if reference.ID > 0 {
|
|
327
|
+ if reference.ProjectId > 0 {
|
|
328
|
+ LgthYsSyncGzjh(info, reference.ProjectId, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
|
|
329
|
+ } else {
|
|
330
|
+ project_id := int64(0)
|
|
331
|
+ if len(info.Groupitemcode) > 0 {
|
|
332
|
+ // 对没有project信息的项目进行修改
|
|
333
|
+ project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
|
|
334
|
+ reference.ProjectId = project_id
|
|
335
|
+ reference.ProjectName = info.Groupitemcode
|
|
336
|
+ reference.Project = info.Groupitemcode
|
|
337
|
+ // 修改配置信息
|
|
338
|
+ UpdateInspectionReference(&reference)
|
|
339
|
+ }
|
|
340
|
+ LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
|
|
341
|
+ }
|
|
342
|
+ } else {
|
|
343
|
+ project_id := int64(0)
|
|
344
|
+ if len(info.Groupitemcode) > 0 {
|
|
345
|
+ project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
|
|
346
|
+ }
|
|
347
|
+ LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
|
|
348
|
+ }
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+ // SyncLisGzjhtx()
|
|
352
|
+}
|
|
353
|
+
|
|
354
|
+type adkResultGzjh struct {
|
|
355
|
+ Testno string `json:"testno"`
|
|
356
|
+ Reportno string `json:"reportno"`
|
|
357
|
+ Itemord string `json:"itemord"`
|
|
358
|
+ Itemcode string `json:"itemcode"`
|
|
359
|
+ Itemname string `json:"itemname"`
|
|
360
|
+ ItemEname string `json:"itemename"`
|
|
361
|
+ Result string `json:"result"`
|
|
362
|
+ Units string `json:"units"`
|
|
363
|
+ Testdate string `json:"testdate"`
|
|
364
|
+ Eqpname string `json:"eqpname"`
|
|
365
|
+ Groupitemcode string `json:"groupitemcode"`
|
|
366
|
+ Groupitemname string `json:"groupitemname"`
|
|
367
|
+ Limit string `json:"limit"`
|
|
368
|
+ Resultstate string `json:"resultstate"`
|
|
369
|
+ Criticalflag string `json:"criticalflag"`
|
|
370
|
+ Itemename string `json:"itemename"`
|
|
371
|
+}
|
|
372
|
+
|
|
373
|
+// 从机构将数据同步到中间库
|
|
374
|
+func LgthYsSyncGzjh(report adkResultGzjh, project_id int64, item_id int64, org_id int64, patient_id int64, receivetime string) (*models.MiddleInspectionReference, error) {
|
|
375
|
+ tx := writeMiddleDb.Begin()
|
|
376
|
+ var inspection models.MiddleInspection
|
|
377
|
+ var inspection_reference models.MiddleInspectionReference
|
|
378
|
+ recordDateStr := receivetime
|
|
379
|
+
|
|
380
|
+ if len(receivetime) == 0 {
|
|
381
|
+ recordDateStr = time.Now().Format("2006-01-02 15:04")
|
|
382
|
+ }
|
|
383
|
+
|
|
384
|
+ record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
|
|
385
|
+ record_date := record_date_str.Unix()
|
|
386
|
+ inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
|
|
387
|
+ // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
|
|
388
|
+ // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
|
|
389
|
+ var total int
|
|
390
|
+ var RangeOptions string
|
|
391
|
+ var RangeMin string
|
|
392
|
+ var RangeMax string
|
|
393
|
+
|
|
394
|
+ // // 判断检查类型
|
|
395
|
+ ItemType := 1
|
|
396
|
+ Range := strings.Split(report.Limit, "-")
|
|
397
|
+ if len(Range) > 1 {
|
|
398
|
+ RangeMin = Range[0]
|
|
399
|
+ RangeMax = Range[1]
|
|
400
|
+ ItemType = 1
|
|
401
|
+ } else {
|
|
402
|
+ ItemType = 2
|
|
403
|
+ RangeOptions = report.Limit
|
|
404
|
+ }
|
|
405
|
+
|
|
406
|
+ 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
|
|
407
|
+ if inspection_reference.ID > 0 {
|
|
408
|
+ ItemType = inspection_reference.RangeType
|
|
409
|
+ }
|
|
410
|
+ if total <= 0 {
|
|
411
|
+ inspection_reference.OrgId = org_id
|
|
412
|
+ inspection_reference.ProjectName = report.Groupitemname
|
|
413
|
+ inspection_reference.Project = report.Groupitemcode
|
|
414
|
+ inspection_reference.ProjectId = project_id
|
|
415
|
+ inspection_reference.ItemName = report.Itemname
|
|
416
|
+ inspection_reference.ItemNameAddition = report.ItemEname
|
|
417
|
+ inspection_reference.ItemId = item_id
|
|
418
|
+ inspection_reference.RangeType = ItemType
|
|
419
|
+ inspection_reference.RangeMin = RangeMin
|
|
420
|
+ inspection_reference.RangeMax = RangeMax
|
|
421
|
+ // inspection_reference.RangeValue = RangeValue
|
|
422
|
+ inspection_reference.RangeOptions = RangeOptions
|
|
423
|
+ inspection_reference.Unit = report.Units
|
|
424
|
+ inspection_reference.Status = 1
|
|
425
|
+ inspection_reference.CreatedTime = time.Now().Unix()
|
|
426
|
+ inspection_reference.UpdatedTime = time.Now().Unix()
|
|
427
|
+ inspection_reference.InspectDate = inspect_date
|
|
428
|
+ inspection_reference.UTime = inspect_date
|
|
429
|
+ err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
|
|
430
|
+ if err != nil {
|
|
431
|
+ tx.Rollback()
|
|
432
|
+ }
|
|
433
|
+ }
|
|
434
|
+
|
|
435
|
+ var itotal int
|
|
436
|
+ 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
|
|
437
|
+ if itotal <= 0 {
|
|
438
|
+ report.Result = strings.Replace(report.Result, ">", ">", -1)
|
|
439
|
+ report.Result = strings.Replace(report.Result, "<", "<", -1)
|
|
440
|
+ inspection.PatientId = patient_id
|
|
441
|
+ inspection.OrgId = org_id
|
|
442
|
+ inspection.ProjectId = project_id
|
|
443
|
+ inspection.ItemName = inspection_reference.ItemName
|
|
444
|
+ inspection.ProjectName = inspection_reference.ProjectName
|
|
445
|
+ inspection.InspectType = ItemType
|
|
446
|
+ inspection.ItemId = item_id
|
|
447
|
+ inspection.InspectValue = report.Result
|
|
448
|
+ inspection.InspectDate = inspect_date
|
|
449
|
+ inspection.RecordDate = record_date
|
|
450
|
+ inspection.InspectTips = report.Resultstate
|
|
451
|
+ inspection.Status = 1
|
|
452
|
+ inspection.CreatedTime = time.Now().Unix()
|
|
453
|
+ inspection.UpdatedTime = time.Now().Unix()
|
|
454
|
+ inspection.UTime = inspect_date
|
|
455
|
+ inspection.HisUserId = strconv.FormatInt(patient_id, 10)
|
|
456
|
+ err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
|
|
457
|
+ if err != nil {
|
|
458
|
+ tx.Rollback()
|
|
459
|
+ }
|
|
460
|
+ }
|
|
461
|
+
|
|
462
|
+ // //处理检验检查操作表里同步条数和状态
|
|
463
|
+ // cur_num := Head.ReportInfoItemHandleNum + 1
|
|
464
|
+ // Head.ReportInfoItemHandleNum = cur_num
|
|
465
|
+ // handleType := 2
|
|
466
|
+ // if cur_num == Head.ReportInfoItemNum {
|
|
467
|
+ // handleType = 1
|
|
468
|
+ // }
|
|
469
|
+ // middleReportHandle := models.MiddleReportHandle{
|
|
470
|
+ // ID: Head.ID,
|
|
471
|
+ // ReportInfoItemHandleNum: cur_num,
|
|
472
|
+ // HandleType: int64(handleType),
|
|
473
|
+ // UpdatedTime: time.Now().Unix(),
|
|
474
|
+ // }
|
|
475
|
+ // err = UpdateReportHandleListyOrgID(&middleReportHandle)
|
|
476
|
+ // if err != nil {
|
|
477
|
+ // tx.Rollback()
|
|
478
|
+ // }
|
|
479
|
+ // }
|
|
480
|
+
|
|
481
|
+ tx.Commit()
|
|
482
|
+ return nil, err
|
|
483
|
+}
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+// 根据姓名获取patient_id
|
|
487
|
+func GetPatientGzjhListGzjh(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
|
|
488
|
+ err = readDb.Model(&models.DialysisSchedule{}).Where("user_org_id = ? and status = 1 and schedule_date = ?", org_id, schedulesTime).Preload("Patients", "status = 1").Find(&schedules).Error
|
|
489
|
+ return
|
|
490
|
+}
|
|
491
|
+
|
|
492
|
+// 根据姓名获取admin_user_id
|
|
493
|
+func GetAdminUserIdGzjh(org_id int64, doctor_name string) (doctor models.UserAdminRole, err error) {
|
|
494
|
+ err = writeUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? and status = 1 and user_name = ?", org_id, doctor_name).First(&doctor).Error
|
|
495
|
+ return
|
|
496
|
+}
|
|
497
|
+
|
|
498
|
+func GetPatientGzjhByOrgIdGzjh(org_id int64) (patientList []*models.Patients, err error) {
|
|
499
|
+ err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
|
|
500
|
+ return
|
|
501
|
+}
|
|
502
|
+
|
|
503
|
+func SyncToGzczjhtx() {
|
|
504
|
+ utils.TraceLog("检验检查同步任务开始执行")
|
|
505
|
+ org_id := int64(10015)
|
|
506
|
+
|
|
507
|
+ // 第一步:跟进org_id 去中间库查出需要同步的数据
|
|
508
|
+ inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
|
|
509
|
+ inspections, _ := GetSyncInspectionByOrgId(org_id)
|
|
510
|
+
|
|
511
|
+ // 第二步:将数据同步到业务库
|
|
512
|
+ if len(inspection_references) > 0 {
|
|
513
|
+ for _, inspection_reference := range inspection_references {
|
|
514
|
+ SyncInspectionReference(&inspection_reference)
|
|
515
|
+ }
|
|
516
|
+ }
|
|
517
|
+
|
|
518
|
+ if len(inspections) > 0 {
|
|
519
|
+ for _, inspection := range inspections {
|
|
520
|
+ SyncInspection(&inspection)
|
|
521
|
+ }
|
|
522
|
+ }
|
|
523
|
+ utils.SuccessLog("检验检查同步任务完成")
|
|
524
|
+}
|