2 コミット 244ce2f95c ... 637cd84f34

作者 SHA1 メッセージ 日付
  张保健 637cd84f34 1 5 ヶ月 前
  张保健 a4d3a56686 1 5 ヶ月 前
共有13 個のファイルを変更した1703 個の追加1453 個の削除を含む
  1. 127 44
      models/lis_model.go
  2. 4 2
      routers/router.go
  3. 85 40
      service/cron.go
  4. 524 0
      service/gzjhtxzx_service.go
  5. 49 89
      service/lis_service.go
  6. 174 168
      service/pajm_service.go
  7. 345 0
      service/sccdkfyy_service.go
  8. 225 1075
      service/sy_service.go
  9. 3 10
      service/wfnfm_service.go
  10. 2 25
      service/ystx_service.go
  11. 37 0
      tf日志/tf_20220808_log.txt
  12. 43 0
      tf日志/tf_20220809_log.txt
  13. 85 0
      tf日志/tf_20220810_log.txt

+ 127 - 44
models/lis_model.go ファイルの表示

@@ -79,6 +79,117 @@ func (DataUploadConfig) TableName() string {
79 79
 	return "data_upload_config"
80 80
 }
81 81
 
82
+type VYunjingPatientLabItems struct {
83
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
84
+	Zyid			string  `gorm:"column:ZYID" json:"ZYID"`
85
+	Mzid     		string  `gorm:"column:MZID" json:"MZID"`
86
+	PatientId       string  `gorm:"column:PATIENT_ID" json:"PATIENT_ID"`
87
+	Sfzh 			string 	`gorm:"column:SFZH" json:"SFZH"`
88
+	PatientName     string 	`gorm:"column:PATIENT_NAME" json:"PATIENT_NAME"`
89
+	TestOrderNo		string 	`gorm:"column:TEST_ORDER_NO" json:"TEST_ORDER_NO"`
90
+	ItemType		string  `gorm:"column:ITEM_TYPE" json:"ITEM_TYPE"`
91
+	ItemTypeName    string  `gorm:"column:ITEM_TYPE_NAME" json:"ITEM_TYPE_NAME"`
92
+	ItemCode     	string  `gorm:"column:ITEM_CODE" json:"ITEM_CODE"`
93
+	ItemName    	string  `gorm:"column:ITEM_NAME" json:"ITEM_NAME"`
94
+	SubmitAt    	string  `gorm:"column:SUBMIT_AT" json:"SUBMIT_AT"`
95
+	CreateAt    	string  `gorm:"column:CREATE_AT" json:"CREATE_AT"`
96
+	DeptName    	string  `gorm:"column:DEPT_NAME" json:"DEPT_NAME"`
97
+}
98
+
99
+func (VYunjingPatientLabItems) TableName() string {
100
+	return "v_yunjing_patient_lab_items"
101
+}
102
+
103
+type VYunjingPatientLabAnti struct {
104
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
105
+	Zyid			string  `gorm:"column:ZYID" json:"ZYID"`
106
+	Mzid     		string  `gorm:"column:MZID" json:"MZID"`
107
+	PatientId       string  `gorm:"column:PATIENT_ID" json:"PATIENT_ID"`
108
+	Sfzh 			string 	`gorm:"column:SFZH" json:"SFZH"`
109
+	PatientName     string 	`gorm:"column:PATIENT_NAME" json:"PATIENT_NAME"`
110
+	TestOrderNo		string 	`gorm:"column:TEST_ORDER_NO" json:"TEST_ORDER_NO"`
111
+	ResultDate		string 	`gorm:"column:RESULT_DATE" json:"RESULT_DATE"`
112
+	TestResult		string 	`gorm:"column:TEST_RESULT" json:"TEST_RESULT"`
113
+	Unit			string 	`gorm:"column:UNIT" json:"UNIT"`
114
+	ReferRange		string 	`gorm:"column:REFER_RANGE" json:"REFER_RANGE"`
115
+	AntiCode		string 	`gorm:"column:ANTI_CODE" json:"ANTI_CODE"`
116
+	AntiName		string 	`gorm:"column:ANTI_NAME" json:"ANTI_NAME"`
117
+	CreateAt    	string  `gorm:"column:CREATE_AT" json:"CREATE_AT"`
118
+
119
+}
120
+
121
+func (VYunjingPatientLabAnti) TableName() string {
122
+	return "v_yunjing_patient_lab_anti"
123
+}
124
+
125
+type PlugPlugcase struct {
126
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
127
+	Oldserialno		string  `gorm:"column:oldSerialNo" json:"oldSerialNo"`
128
+	Serialno     	string  `gorm:"column:serialNo" json:"serialNo"`
129
+	Name         	string  `gorm:"column:name" json:"name"`
130
+	Gender 			string 	`gorm:"column:gender" json:"gender"`
131
+	Age          	int64 	`gorm:"column:age" json:"age"`
132
+	RegistrantmanId	int64 	`gorm:"column:registrantMan_id" json:"registrantMan_id"`
133
+	Mainindex		string  `gorm:"column:mainIndex" json:"mainIndex"`
134
+	Orddoctor     	string  `gorm:"column:ordDoctor" json:"ordDoctor"`
135
+	Ordloc     		string  `gorm:"column:ordLoc" json:"ordLoc"`
136
+	Birthday    	string  `gorm:"column:birthDay" json:"birthDay"`
137
+}
138
+
139
+func (PlugPlugcase) TableName() string {
140
+	return "plug_plugcase"
141
+}
142
+
143
+type PlugPlugcheckitem struct {
144
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
145
+	Serialno		string  `gorm:"column:serialNo" json:"serialNo"`
146
+	Itemcode     	string  `gorm:"column:itemCode" json:"itemCode"`
147
+	State         	int64  	`gorm:"column:state" json:"state"`
148
+	Itemplug 		string 	`gorm:"column:itemPlug" json:"itemPlug"`
149
+	Checkitemid		string 	`gorm:"column:checkItemId" json:"checkItemId"`
150
+	Oldserialno		string 	`gorm:"column:oldSerialNo" json:"oldSerialNo"`
151
+	Applytime		string 	`gorm:"column:applyTime" json:"applyTime"`
152
+	Specimenname	string  `gorm:"column:specimenName" json:"specimenName"`
153
+	Checkitemname 	string  `gorm:"column:checkItemName" json:"checkItemName"`
154
+	Liscollectuser	string  `gorm:"column:LisCollectUser" json:"LisCollectUser"`
155
+	Liscollecttime	string  `gorm:"column:LisCollectTime" json:"LisCollectTime"`
156
+	Lissignuser    	string  `gorm:"column:LisSignUser" json:"LisSignUser"`
157
+	Lissigntime    	string  `gorm:"column:LissignTime" json:"LissignTime"`
158
+	Lisacceptuser   string  `gorm:"column:LisAcceptUser" json:"LisAcceptUser"`
159
+	Lisaccepttime   string  `gorm:"column:LisAcceptTime" json:"LisAcceptTime"`
160
+	Lisregisteruser	string  `gorm:"column:LisRegisterUser" json:"LisRegisterUser"`
161
+	Lisregistertime	string  `gorm:"column:LisRegisterTime" json:"LisRegisterTime"`
162
+	Lischeckuser    string  `gorm:"column:LisCheckUser" json:"LisCheckUser"`
163
+	Lischecktime    string  `gorm:"column:LisCheckTime" json:"LisCheckTime"`
164
+	Lisrefuseuser   string  `gorm:"column:LisRefuseUser" json:"LisRefuseUser"`
165
+	Lisrefusetime   string  `gorm:"column:LisRefuseTime" json:"LisRefuseTime"`
166
+	Lisstatus    	string  `gorm:"column:LisStatus" json:"LisStatus"`
167
+	Refusereason    string  `gorm:"column:RefuseReason" json:"RefuseReason"`
168
+}
169
+
170
+func (PlugPlugcheckitem) TableName() string {
171
+	return "plug_plugcheckitem"
172
+}
173
+
174
+type PlugPlugresult struct {
175
+	Id             		int64  	`gorm:"column:ID" json:"ID"`
176
+	Serialno			string  `gorm:"column:serialNo" json:"serialNo"`
177
+	Testitemname		string  `gorm:"column:testItemName" json:"testItemName"`
178
+	Itemcode			string  `gorm:"column:itemcode" json:"itemcode"`
179
+	Paritemno			string  `gorm:"column:parItemNo" json:"parItemNo"`
180
+	Reportvalueall		string  `gorm:"column:reportValueAll" json:"reportValueAll"`
181
+	Testitemdatetime	string  `gorm:"column:testItemDateTime" json:"testItemDateTime"`
182
+	Unit				string  `gorm:"column:unit" json:"unit"`
183
+	Refrange			string  `gorm:"column:refrange" json:"refrange"`
184
+	Resultstatus		string  `gorm:"column:resultStatus" json:"resultStatus"`
185
+	Itemorder			int64  	`gorm:"column:itemOrder" json:"itemOrder"`
186
+	Checker				string  `gorm:"column:checker" json:"checker"`
187
+}
188
+
189
+func (PlugPlugresult) TableName() string {
190
+	return "plug_plugresult"
191
+}
192
+
82 193
 type Schedules struct {
83 194
 	ID           int64 `gorm:"column:id" json:"id" form:"id"`
84 195
 	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -129,6 +240,7 @@ func (MiddlePatients) TableName() string {
129 240
 	return "xt_middle_patients"
130 241
 }
131 242
 
243
+
132 244
 type Patients struct {
133 245
 	ID              int64  `gorm:"column:id" json:"id" form:"id"`
134 246
 	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -140,8 +252,6 @@ type Patients struct {
140 252
 	ContactName     string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
141 253
 	Gender          int64  `gorm:"column:gender" json:"gender" form:"gender"`
142 254
 	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
143
-	Phone           string `gorm:"column:phone" json:"phone" form:"phone"`
144
-	Age             int64  `gorm:"column:age" json:"age"`
145 255
 }
146 256
 
147 257
 func (Patients) TableName() string {
@@ -209,22 +319,20 @@ func (TBLISItem) TableName() string {
209 319
 }
210 320
 
211 321
 type Inspection struct {
212
-	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
213
-	PatientId          int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
214
-	OrgId              int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
215
-	ProjectId          int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
216
-	ItemId             int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
217
-	ItemName           string `gorm:"column:item_name" json:"item_name" form:"item_name"`
218
-	ProjectName        string `gorm:"column:project_name" json:"project_name" form:"project_name"`
219
-	InspectType        int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
220
-	InspectValue       string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
221
-	InspectTips        string `gorm:"column:inspect_tips" json:"inspect_tips" form:"inspect_tips"`
222
-	InspectDate        int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
223
-	Status             int64  `gorm:"column:status" json:"status" form:"status"`
224
-	CreatedTime        int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
225
-	UpdatedTime        int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
226
-	ReferenceItemId    int64  `gorm:"column:reference_item_id" json:"reference_item_id" form:"reference_item_id"`
227
-	ReferenceProjectId int64  `gorm:"column:reference_project_id" json:"reference_project_id" form:"reference_project_id"`
322
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
323
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
324
+	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
325
+	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
326
+	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
327
+	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
328
+	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
329
+	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
330
+	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
331
+	InspectTips  string `gorm:"column:inspect_tips" json:"inspect_tips" form:"inspect_tips"`
332
+	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
333
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
334
+	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
335
+	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
228 336
 }
229 337
 
230 338
 func (Inspection) TableName() string {
@@ -335,9 +443,7 @@ type MiddleInspectionReference struct {
335 443
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
336 444
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
337 445
 	SyncId           int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
338
-
339
-	XtProjectId int64 `gorm:"column:xt_project_id" json:"xt_project_id" form:"xt_project_id"`
340
-	XtItemId    int64 `gorm:"column:xt_item_id" json:"xt_item_id" form:"xt_item_id"`
446
+	ItemCode         string  `gorm:"column:item_code" json:"item_code" form:"item_code"`
341 447
 }
342 448
 
343 449
 func (MiddleInspectionReference) TableName() string {
@@ -454,26 +560,3 @@ type VMItemProjectList struct {
454 560
 func (VMItemProjectList) TableName() string {
455 561
 	return "xt_his_project_list"
456 562
 }
457
-
458
-type HisLabelPrintStatusInfo struct {
459
-	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
460
-	PatientId          int64    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
461
-	Ctime              int64    `gorm:"column:ctime" json:"ctime" form:"ctime"`
462
-	Mtime              int64    `gorm:"column:mtime" json:"mtime" form:"mtime"`
463
-	Status             int64    `gorm:"column:status" json:"status" form:"status"`
464
-	IsCombinationPrint int64    `gorm:"column:is_combination_print" json:"is_combination_print" form:"is_combination_print"`
465
-	RecordDate         string   `gorm:"column:record_date" json:"record_date" form:"record_date"`
466
-	ItemIds            string   `gorm:"column:item_ids" json:"item_ids" form:"item_ids"`
467
-	UserOrgId          int64    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
468
-	ProjectIds         string   `gorm:"column:project_ids" json:"project_ids" form:"project_ids"`
469
-	DoctorId           int64    `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
470
-	Ids                string   `gorm:"column:ids" json:"ids" form:"ids"`
471
-	IsTeam             int64    `gorm:"column:is_team" json:"is_team" form:"is_team"`
472
-	IsPrint            int64    `gorm:"column:is_print" json:"is_print" form:"is_print"`
473
-	Patient            Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
474
-	ApplyCode          string   `gorm:"column:apply_code" json:"apply_code" form:"apply_code"`
475
-}
476
-
477
-func (HisLabelPrintStatusInfo) TableName() string {
478
-	return "his_label_print_status_info"
479
-}

+ 4 - 2
routers/router.go ファイルの表示

@@ -28,6 +28,8 @@ func init() {
28 28
 
29 29
 	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
30 30
 	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
31
-	//beego.Router("/api/test", &controllers.LisController{}, "get:SyncScpaLis")
32
-
31
+	beego.Router("/api/test", &controllers.LisController{}, "get:SyncTest")
32
+	beego.Router("/api/lis/gzjhxytx", &controllers.LisController{}, "get:SyncGzjhxytx")
33
+	beego.Router("/api/lis/scdckfyy", &controllers.LisController{}, "get:SyncSccdkfyyLis")
34
+	beego.Router("/api/lis/pajm", &controllers.LisController{}, "get:SyncPajmLis")
33 35
 }

+ 85 - 40
service/cron.go ファイルの表示

@@ -6,6 +6,7 @@ import (
6 6
 	"encoding/json"
7 7
 	_ "fmt"
8 8
 	_ "github.com/jinzhu/gorm"
9
+	"github.com/robfig/cron"
9 10
 	_ "strings"
10 11
 	"time"
11 12
 )
@@ -17,40 +18,84 @@ func init() {
17 18
 
18 19
 }
19 20
 
20
-//// 返回一个支持至 秒 级别的 cron
21
-//func newWithSeconds() *cron.Cron {
22
-//	secondParser := cron.NewParser(cron.Second | cron.Minute |
23
-//		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
24
-//	return cron.New(cron.WithParser(secondParser), cron.WithChain())
25
-//}
26
-//
27
-//func BeginAutoSyncLis() {
28
-//	utils.InfoLog("开启自动检验检查同步定时任务")
29
-//	createLisSyncCronJob := newWithSeconds()
30
-//
31
-//	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
32
-//	// createLisSyncCronJob.AddFunc(specgzjh, func() {
33
-//	// 	// SyncGzjhyz()
34
-//	// 	Synctfyz()
35
-//	// })
36
-//
37
-//	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
38
-//	createLisSyncCronJob.AddFunc(specys, func() {
39
-//		SyncScpaLis()
40
-//	})
41
-//
42
-//	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
43
-//	createLisSyncCronJob.AddFunc(specys1, func() {
44
-//		// SyncCsnyLis()
45
-//	})
46
-//
47
-//	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
48
-//	createLisSyncCronJob.AddFunc(spec, func() {
49
-//		// SyncHbdyLis()
50
-//	})
51
-//
52
-//	createLisSyncCronJob.Start()
53
-//}
21
+// 返回一个支持至 秒 级别的 cron
22
+func newWithSeconds() *cron.Cron {
23
+	secondParser := cron.NewParser(cron.Second | cron.Minute |
24
+		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
25
+	return cron.New(cron.WithParser(secondParser), cron.WithChain())
26
+}
27
+
28
+// func BeginAutoSyncLis() {
29
+// 	utils.InfoLog("开启自动检验检查同步定时任务")
30
+// 	createLisSyncCronJob := newWithSeconds()
31
+
32
+// 	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
33
+// 	// createLisSyncCronJob.AddFunc(specgzjh, func() {
34
+// 	// 	// SyncGzjhyz()
35
+// 	// 	Synctfyz()
36
+// 	// })
37
+
38
+// 	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
39
+// 	createLisSyncCronJob.AddFunc(specys, func() {
40
+// 		// SyncStsyLis()
41
+// 	})
42
+
43
+// 	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
44
+// 	createLisSyncCronJob.AddFunc(specys1, func() {
45
+// 		// SyncCsnyLis()
46
+// 	})
47
+
48
+// 	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
49
+// 	createLisSyncCronJob.AddFunc(spec, func() {
50
+// 		// SyncHbdyLis()
51
+// 	})
52
+
53
+// 	createLisSyncCronJob.Start()
54
+// }
55
+
56
+func BeginAutoSyncLis() {
57
+	utils.InfoLog("开启自动检验检查同步定时任务")
58
+	createLisSyncCronJob := newWithSeconds()
59
+
60
+	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
61
+	// createLisSyncCronJob.AddFunc(specgzjh, func() {
62
+	// 	// SyncGzjhyz()
63
+	// 	Synctfyz()
64
+	// })
65
+
66
+	// specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
67
+	// createLisSyncCronJob.AddFunc(specys, func() {
68
+	// 	SyncTscyLis()
69
+	// })
70
+
71
+	// specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
72
+	// createLisSyncCronJob.AddFunc(specys1, func() {
73
+	// 	SyncCsnyLis()
74
+	// })
75
+
76
+	// spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
77
+	// createLisSyncCronJob.AddFunc(spec, func() {
78
+	// 	SyncHbdyLis()
79
+	// })
80
+	
81
+	// spec2 := "0 50 2 * * ?" // 每天凌晨2点同步 龙岗二院
82
+	// createLisSyncCronJob.AddFunc(spec2, func() {
83
+	// 	SyncLisLgty()
84
+	// })
85
+
86
+	// spec3 := "0 50 3 * * ?" // 每天凌晨2点同步 广州暨华血液透析中心
87
+	// createLisSyncCronJob.AddFunc(spec3, func() {
88
+	// 	SyncLisGzjhtx()
89
+	// })
90
+
91
+	specgzjh := "0 0 */2 * * ?" // 每2个小时同步 汕头三优血液透析中心LIS
92
+	createLisSyncCronJob.AddFunc(specgzjh, func() {
93
+		SyncScpaLis()
94
+	})
95
+
96
+	createLisSyncCronJob.Start()
97
+}
98
+
54 99
 
55 100
 func AutoSyncLis() {
56 101
 	utils.TraceLog("检验检查任务开始执行")
@@ -126,7 +171,7 @@ func AutoSyncLis() {
126 171
 				}
127 172
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
128 173
 				continue
129
-			}
174
+			} 
130 175
 
131 176
 			// 第四部:将同步过来的数据插入到中间库对应的表
132 177
 			syncSuccessNum := 0
@@ -193,11 +238,11 @@ func SyncToBase() {
193 238
 	utils.SuccessLog("检验检查同步任务完成")
194 239
 }
195 240
 
196
-func SyncSZblLis() {
197
-	utils.TraceLog("检验检查同步任务开始执行")
198
-	org_id := int64(10138)
199
-	GetDataInsertDB(org_id)
200
-}
241
+// func SyncSZblLis() {
242
+// 	utils.TraceLog("检验检查同步任务开始执行")
243
+// 	org_id := int64(10138)
244
+// 	GetDataInsertDB(org_id)
245
+// }
201 246
 
202 247
 // func SyncSZblLisResult() {
203 248
 // 	utils.TraceLog("获取检验检查结果任务开始执行")

+ 524 - 0
service/gzjhtxzx_service.go ファイルの表示

@@ -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, "&lt;", "<", -1)
143
+	xmlString = strings.Replace(xmlString, "&gt;", ">", -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, "&gt;", ">", -1)
439
+		report.Result = strings.Replace(report.Result, "&lt;", "<", -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
+}

+ 49 - 89
service/lis_service.go ファイルの表示

@@ -3,28 +3,28 @@ package service
3 3
 import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6
-	_ "IC/utils"
7
-	_ "fmt"
8
-	_ "github.com/jinzhu/gorm"
9
-	_ "strconv"
6
+	_"strconv"
10 7
 	"strings"
11 8
 	"time"
9
+	_"IC/utils"
10
+	_"fmt"
11
+	_"github.com/jinzhu/gorm"
12 12
 )
13 13
 
14 14
 // 获取备份库所有的医嘱信息
15
-func GetAllAdvice() (Advice []models.DoctorAdvice, err error) {
15
+func GetAllAdvice() (Advice []models.DoctorAdvice,err error) {
16 16
 	err = backupDb.Model(&models.DoctorAdvice{}).Offset(100000).Limit(10000).Find(&Advice).Error
17 17
 	return
18 18
 }
19 19
 
20 20
 // 获取备份库所有的医嘱信息
21
-func GetScheduless(id int64) (schedule models.Schedules, err error) {
22
-	err = tempwriteDb.Model(&models.Schedules{}).Where("id = ?", id).First(&schedule).Error
21
+func GetScheduless(id int64) (schedule models.Schedules,err error) {
22
+	err = tempwriteDb.Model(&models.Schedules{}).Where("id = ?",id).First(&schedule).Error
23 23
 	return
24 24
 }
25 25
 
26
-func UpdateSchedule(id int64, status int64) error {
27
-	err := writeDb.Model(&models.Schedules{}).Where("id = ? ", id).Updates(map[string]interface{}{"status": status}).Error
26
+func UpdateSchedule(id int64,status int64) error{
27
+	err := writeDb.Model(&models.Schedules{}).Where("id = ? ", id).Updates(map[string]interface{}{"status":status}).Error
28 28
 	return err
29 29
 }
30 30
 
@@ -34,23 +34,23 @@ func SyncAdvice(Advice *models.DoctorAdvice) error {
34 34
 	return err
35 35
 }
36 36
 
37
-// 查找有字段的机构
38
-func GetfiledConfigOrg() (FiledConfig []models.FiledConfig, err error) {
37
+// 查找有字段的机构 
38
+func GetfiledConfigOrg() (FiledConfig []models.FiledConfig,err error) {
39 39
 	db := readDb.Begin()
40 40
 	err = db.Table("xt_filed_config").Group("org_id").Select("org_id,module,filed_name").Where("org_id > 0").Scan(&FiledConfig).Error
41 41
 	return
42 42
 }
43 43
 
44
-// 查询系统字段
45
-func GetfiledConfigSys() (FiledConfig []models.FiledConfig, err error) {
44
+// 查询系统字段 
45
+func GetfiledConfigSys() (FiledConfig []models.FiledConfig,err error) {
46 46
 	err = readDb.Model(&models.FiledConfig{}).Where("org_id = 0").Find(&FiledConfig).Error
47
-	return
47
+	return 
48 48
 }
49 49
 
50 50
 // 跟进查询条件查询结果
51
-func GetfiledConfigByOrgId(org_id int64, module int64, filed_name string) (FiledConfig models.FiledConfig, err error) {
52
-	err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? and module = ? and filed_name = ?", org_id, module, filed_name).First(&FiledConfig).Error
53
-	return
51
+func GetfiledConfigByOrgId(org_id int64,module int64,filed_name string)(FiledConfig models.FiledConfig,err error) {
52
+	err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? and module = ? and filed_name = ?",org_id,module,filed_name).First(&FiledConfig).Error
53
+	return 
54 54
 }
55 55
 
56 56
 // 创建一条字段数据详情
@@ -64,46 +64,7 @@ func SyncInspectionReference(data *models.MiddleInspectionReference) error {
64 64
 	tx := writeDb.Begin()
65 65
 	var inspection_reference models.InspectionReference
66 66
 	var total int
67
-	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.ProjectId, data.ItemId).Find(&inspection_reference).Count(&total).Error
68
-	if total <= 0 {
69
-		inspection_reference.OrgId = data.OrgId
70
-		inspection_reference.ProjectName = data.ProjectName
71
-		inspection_reference.Project = data.ProjectName
72
-		inspection_reference.ProjectId = data.ProjectId
73
-		inspection_reference.ItemName = data.ItemName
74
-		inspection_reference.ItemId = data.ItemId
75
-		inspection_reference.RangeType = data.RangeType
76
-		inspection_reference.RangeMin = data.RangeMin
77
-		inspection_reference.RangeMax = data.RangeMax
78
-		inspection_reference.RangeValue = data.RangeValue
79
-		inspection_reference.RangeOptions = data.RangeOptions
80
-		inspection_reference.Unit = data.Unit
81
-		inspection_reference.Status = 1
82
-		inspection_reference.CreatedTime = time.Now().Unix()
83
-		inspection_reference.UpdatedTime = time.Now().Unix()
84
-
85
-		err := tx.Model(&models.InspectionReference{}).Create(&inspection_reference).Error
86
-		if err != nil {
87
-			tx.Rollback()
88
-		}
89
-
90
-		data.IsSync = 1
91
-		data.SyncId = inspection_reference.ID
92
-		data.UpdatedTime = time.Now().Unix()
93
-		ierr := writeMiddleDb.Save(&data).Error
94
-		if ierr != nil {
95
-			tx.Rollback()
96
-		}
97
-	}
98
-	tx.Commit()
99
-	return err
100
-}
101
-
102
-func SyncInspectionReferenceTwo(data *models.MiddleInspectionReference) error {
103
-	tx := writeDb.Begin()
104
-	var inspection_reference models.InspectionReference
105
-	var total int
106
-	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.XtProjectId, data.XtItemId).Find(&inspection_reference).Count(&total).Error
67
+	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.ProjectId,data.ItemId).Find(&inspection_reference).Count(&total).Error
107 68
 	if total <= 0 {
108 69
 		inspection_reference.OrgId = data.OrgId
109 70
 		inspection_reference.ProjectName = data.ProjectName
@@ -143,7 +104,7 @@ func SyncInspection(data *models.MiddleInspection) error {
143 104
 	tx := writeDb.Begin()
144 105
 	var inspection models.Inspection
145 106
 	var total int
146
-	err := readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=?  and status = 1", data.OrgId, data.ProjectId, data.ItemId, data.PatientId, data.InspectDate).Find(&inspection).Count(&total).Error
107
+	err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=?  and status = 1", data.OrgId, data.ProjectId,data.ItemId,data.PatientId,data.RecordDate).Find(&inspection).Count(&total).Error
147 108
 	if total <= 0 {
148 109
 		inspection.OrgId = data.OrgId
149 110
 		inspection.PatientId = data.PatientId
@@ -158,9 +119,7 @@ func SyncInspection(data *models.MiddleInspection) error {
158 119
 		inspection.InspectDate = data.RecordDate
159 120
 		inspection.Status = 1
160 121
 		inspection.CreatedTime = time.Now().Unix()
161
-		//inspection.ReferenceProjectId = data.
162
-		//inspection.UpdatedTime = time.Now().Unix()
163
-		//inspection.ReferenceItemId = data.
122
+		inspection.UpdatedTime = time.Now().Unix()
164 123
 
165 124
 		err := tx.Model(&models.Inspection{}).Create(&inspection).Error
166 125
 		if err != nil {
@@ -180,13 +139,13 @@ func SyncInspection(data *models.MiddleInspection) error {
180 139
 }
181 140
 
182 141
 // 跟进org_id获取未同步的检验检查选项信息
183
-func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference, err error) {
142
+func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference,err error) {
184 143
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&InspectionReferences).Error
185 144
 	return
186 145
 }
187 146
 
188 147
 // 跟进org_id获取未同步的检验检查信息
189
-func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection, err error) {
148
+func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection,err error) {
190 149
 	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&Inspection).Error
191 150
 	return
192 151
 }
@@ -210,48 +169,48 @@ func CreateReportHandle(report *models.MiddleReportHandle) error {
210 169
 }
211 170
 
212 171
 // 根据机构ID获取该机构检验检查操作表里状态为0的数据
213
-func GetReportHandleListyOrgID(org_id int64) (report_handle_list []models.MiddleReportHandle, err error) {
214
-	err = readMiddleDb.Model(&models.MiddleReportHandle{}).Where("org_id = ?  and  handle_type = 0 ", org_id).Find(&report_handle_list).Error
172
+func GetReportHandleListyOrgID(org_id int64) (report_handle_list []models.MiddleReportHandle ,err error){
173
+	err = readMiddleDb.Model(&models.MiddleReportHandle{}).Where("org_id = ?  and  handle_type = 0 ",  org_id).Find(&report_handle_list).Error
215 174
 	return
216 175
 }
217 176
 
218 177
 // 根据机构ID修改检验检查操作表里的数据
219
-func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle) error {
178
+func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle)  error{
220 179
 	err := writeMiddleDb.Model(&models.MiddleReportHandle{}).Updates(&report_handle).Error
221 180
 	return err
222 181
 }
223 182
 
224 183
 // 跟进机构ID获取该机构所有病人的his_user_id
225
-func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients, err error) {
184
+func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients ,err error) {
226 185
 	err = readMiddleDb.Model(&models.MiddlePatients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patients).Error
227 186
 	return
228 187
 }
229 188
 
230 189
 // 根据机构ID获取该机构上次同步信息
231
-func GetSyncTimeByOrgID(org_id int64, his_user_id string) (sync_info models.MiddleSyncInfo, err error) {
232
-	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Last(&sync_info).Error
190
+func GetSyncTimeByOrgID(org_id int64,his_user_id string) (sync_info models.MiddleSyncInfo ,err error){
191
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ?  and  his_user_id =? ",  org_id,his_user_id).Last(&sync_info).Error
233 192
 	return
234 193
 }
235 194
 
236 195
 // 根据机构ID获取该机构上次同步信息
237
-func GetSyncTimeByOrgIDForYs(org_id int64) (sync_info models.MiddleSyncInfo, err error) {
238
-	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ? ", org_id).Last(&sync_info).Error
196
+func GetSyncTimeByOrgIDForYs(org_id int64) (sync_info models.MiddleSyncInfo ,err error){
197
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ? ",  org_id).Last(&sync_info).Error
239 198
 	return
240 199
 }
241 200
 
242 201
 // 根据机构ID和His_useer_id获取该患者最后一条同步检查数据
243
-func GetInspectionLastInfoByOrgID(org_id int64, his_user_id string) (inspectionLastInfo models.MiddleInspection, err error) {
244
-	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Order("created_time desc").First(&inspectionLastInfo).Error
202
+func GetInspectionLastInfoByOrgID(org_id int64,his_user_id string) (inspectionLastInfo models.MiddleInspection ,err error){
203
+	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ?  and  his_user_id =? ",  org_id,his_user_id).Order("created_time desc").First(&inspectionLastInfo).Error
245 204
 	return
246 205
 }
247 206
 
248 207
 // 从机构将数据同步到中间库
249
-func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
208
+func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleInspectionReference,*models.MiddleInspection,error) {
250 209
 	tx := writeMiddleDb.Begin()
251 210
 	var inspection models.MiddleInspection
252 211
 	var inspection_reference models.MiddleInspectionReference
253 212
 	recordDateStr := data.UTime
254
-	if len(data.UTime) == 0 {
213
+	if len(data.UTime) == 0 { 
255 214
 		recordDateStr = time.Now().Format("2006-01-02 15:04")
256 215
 	}
257 216
 	record_date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
@@ -264,17 +223,17 @@ func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.Middl
264 223
 	} else {
265 224
 		data.ItemType = 1
266 225
 		if len(data.RangeMax) > 0 {
267
-			Range := strings.Split(data.RangeMax, "-")
226
+			Range := strings.Split(data.RangeMax,"-")
268 227
 			if len(Range) > 1 {
269 228
 				data.RangeMin = Range[0]
270
-				data.RangeMax = Range[1]
229
+				data.RangeMax = Range[1] 
271 230
 			} else {
272 231
 				data.RangeMin = Range[0]
273 232
 			}
274 233
 		}
275 234
 	}
276 235
 
277
-	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, data.ProjectId, data.ItemId).Find(&inspection_reference).Count(&total).Error
236
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, data.ProjectId,data.ItemId).Find(&inspection_reference).Count(&total).Error
278 237
 	if total <= 0 && len(data.ProjectName) > 0 {
279 238
 		inspection_reference.OrgId = org_id
280 239
 		inspection_reference.ProjectName = data.ProjectName
@@ -299,7 +258,7 @@ func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.Middl
299 258
 		}
300 259
 	}
301 260
 
302
-	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, data.ProjectId, data.ItemId, record_date.Unix(), patient_id).Find(&inspection).Count(&itotal).Error
261
+	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, data.ProjectId,data.ItemId,record_date.Unix(),patient_id).Find(&inspection).Count(&itotal).Error
303 262
 	if itotal <= 0 {
304 263
 		inspection.PatientId = patient_id
305 264
 		inspection.OrgId = org_id
@@ -327,21 +286,22 @@ func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.Middl
327 286
 	}
328 287
 
329 288
 	tx.Commit()
330
-	return &inspection_reference, &inspection, err
289
+	return &inspection_reference,&inspection,err
331 290
 }
332 291
 
333
-// GetPatientList 返回患者的列表
334
-func GetList(his_user_id []interface{}, syncTimes string) (lis []*models.TBLISItem, err error) {
335
-	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id in (?)  ", syncTimes, his_user_id).Find(&lis).Error
292
+//GetPatientList 返回患者的列表
293
+func GetList(his_user_id []interface{},syncTimes string) (lis []*models.TBLISItem,  err error) {
294
+	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id in (?)  ",syncTimes,his_user_id).Find(&lis).Error
336 295
 	return
337 296
 }
338 297
 
339
-// GetPatientList 返回患者的列表
340
-func GetListByHisUserID(his_user_id string, syncTimes string, selectType int64) (lis []*models.TBLISItem, err error) {
298
+//GetPatientList 返回患者的列表
299
+func GetListByHisUserID(his_user_id string,syncTimes string,selectType int64) (lis []*models.TBLISItem,err error) {
341 300
 	if selectType == 1 {
342
-		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND patient_name = ?  ", syncTimes, his_user_id).Find(&lis).Error
343
-	} else {
344
-		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id = ? ", syncTimes, his_user_id).Find(&lis).Error
345
-	}
301
+	 	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND patient_name = ?  ",syncTimes,his_user_id).Find(&lis).Error
302
+	 } else {
303
+		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id = ? ",syncTimes,his_user_id).Find(&lis).Error
304
+	 }
346 305
 	return
347 306
 }
307
+

+ 174 - 168
service/pajm_service.go ファイルの表示

@@ -1,13 +1,15 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	//"Data_Upload_Api/models/sz"
5
-	//"Data_Upload_Api/service"
6 4
 	"IC/models"
7 5
 	"IC/utils"
8 6
 	_ "encoding/json"
9 7
 	_ "encoding/xml"
8
+	"github.com/jinzhu/gorm"
10 9
 	_ "github.com/jinzhu/gorm"
10
+	"strconv"
11
+	"strings"
12
+	"time"
11 13
 )
12 14
 
13 15
 type scpalis struct {
@@ -25,7 +27,7 @@ type scpalis struct {
25 27
 	RangeValue   string `gorm:"column:range_value" json:"range_value"`
26 28
 	RangeOptions string `gorm:"column:range_options" json:"range_options"`
27 29
 	Unit         string `gorm:"column:unit" json:"unit"`
28
-	State        int64  `gorm:"column:state" json:"state"`
30
+	State        string  `gorm:"column:state" json:"state"`
29 31
 	CTime        int64  `gorm:"column:c_time" json:"c_time"`
30 32
 	UTime        int64  `gorm:"column:u_time" json:"u_time"`
31 33
 }
@@ -34,11 +36,10 @@ func (scpalis) TableName() string {
34 36
 	return "检验检查信息"
35 37
 }
36 38
 
37
-//
38
-//func GetScpaLis(rdb *gorm.DB, synctime int64, hisuserid string) (record []*scpalis, err error) {
39
-//	err = rdb.Model(&scpalis{}).Where("inspect_date >= ? and his_user_id = ?", synctime, hisuserid).Find(&record).Error
40
-//	return
41
-//}
39
+func GetScpaLis(rdb *gorm.DB, synctime int64, hisuserid string) (record []*scpalis, err error) {
40
+	err = rdb.Model(&scpalis{}).Where("inspect_date >= ? and his_user_id = ?", synctime, hisuserid).Find(&record).Error
41
+	return
42
+}
42 43
 
43 44
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
44 45
 func GetScpaProjectID(org_id int64, project_name string) (project_id int64, err error) {
@@ -73,167 +74,172 @@ func GetScpaItemID(org_id int64, project_name string, item_name string, project_
73 74
 	}
74 75
 }
75 76
 
77
+func GetPatientPajmByOrgId(org_id int64) (patientList []*models.Patients, err error) {
78
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
79
+	return
80
+}
81
+
76 82
 // 四川蓬安济民透析中心Lis同步
77
-//func SyncScpaLis() (err error) {
78
-//	org_id := int64(9829)
79
-//
80
-//	org := &sz.DataUploadConfig{
81
-//		OrgId:  org_id,
82
-//		DbHost: "192.168.0.254",
83
-//		DbPort: "1433",
84
-//		DbPass: "999999",
85
-//		DbUser: "sa",
86
-//		DbName: "nfjiminhis",
87
-//	}
88
-//
89
-//	orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
90
-//	if err != nil {
91
-//		utils.ErrorLog("创建数据库连接失败:%v", err)
92
-//		return
93
-//	}
94
-//
95
-//	// var sync_time int64
96
-//	// sync_time = 1627747200
97
-//
98
-//	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
99
-//	// utils.InfoLog("IdCardNo:%v",scpaLis)
100
-//
101
-//	// 第一步:获取上一次同步的时间点
102
-//	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
103
-//	var sync_time int64
104
-//	if syncLastInfo.ID > 0 {
105
-//		sync_time = syncLastInfo.SyncTime
106
-//	} else {
107
-//		sync_time = 1627747200
108
-//	}
109
-//	// 第二步:获取所有患者的病历号
110
-//
111
-//	patientList, _ := GetPatientGzjhByOrgId(org_id)
112
-//	if len(patientList) > 0 {
113
-//		for _, patient := range patientList {
114
-//			if len(patient.IdCardNo) > 0 {
115
-//				// 上次同步时间转换为接口需要的格式
116
-//				patient_id := patient.ID
117
-//				utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
118
-//				scpaLis, _ := GetScpaLis(orgDb, sync_time, patient.IdCardNo)
119
-//				if len(scpaLis) > 0 {
120
-//					for _, info := range scpaLis {
121
-//						utils.InfoLog("Result:%v", info)
122
-//						// 根据project_id和item_id 判断该项是否存在
123
-//						project_id := int64(0)
124
-//						if info.ProjectId > 0 {
125
-//							project_id, _ = GetScpaProjectID(org_id, info.ProjectName)
126
-//						} else {
127
-//							continue
128
-//						}
129
-//						item_id, _ := GetScpaItemID(org_id, info.ProjectName, info.ItemName, project_id)
130
-//						tx := writeMiddleDb.Begin()
131
-//						var inspection models.MiddleInspection
132
-//						var inspection_reference models.MiddleInspectionReference
133
-//						record_date := info.InspectDate
134
-//						if info.InspectDate == 0 {
135
-//							record_date = time.Now().Unix()
136
-//						}
137
-//						inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
138
-//						var total int
139
-//						var RangeOptions string
140
-//						var RangeMin string
141
-//						var RangeMax string
142
-//
143
-//						// // 判断检查类型
144
-//						ItemType := info.ItemType
145
-//						RangeMin = info.RangeMin
146
-//						RangeMax = info.RangeMax
147
-//						RangeOptions = info.RangeValue
148
-//						// Range := strings.Split(info.RangeValue, "-")
149
-//						// if len(Range) > 1 {
150
-//						// 	RangeMin = Range[0]
151
-//						// 	RangeMax = Range[1]
152
-//						// 	ItemType = 1
153
-//						// } else {
154
-//						// 	ItemType = 2
155
-//						// 	RangeOptions = info.RangeOptions
156
-//						// }
157
-//
158
-//						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
159
-//						if total <= 0 {
160
-//							inspection_reference.OrgId = org_id
161
-//							inspection_reference.ProjectName = info.ProjectName
162
-//							inspection_reference.Project = info.ProjectName
163
-//							inspection_reference.ProjectId = project_id
164
-//							inspection_reference.ItemName = info.ItemName
165
-//							inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
166
-//							inspection_reference.ItemId = item_id
167
-//							inspection_reference.RangeType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
168
-//							inspection_reference.RangeMin = RangeMin
169
-//							inspection_reference.RangeMax = RangeMax
170
-//							// inspection_reference.RangeValue = RangeValue
171
-//							inspection_reference.RangeOptions = RangeOptions
172
-//							inspection_reference.Unit = info.Unit
173
-//							inspection_reference.Status = 1
174
-//							inspection_reference.CreatedTime = time.Now().Unix()
175
-//							inspection_reference.UpdatedTime = time.Now().Unix()
176
-//							inspection_reference.InspectDate = inspect_date
177
-//							inspection_reference.UTime = inspect_date
178
-//							err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
179
-//							if err != nil {
180
-//								tx.Rollback()
181
-//							}
182
-//						}
183
-//
184
-//						var itotal int
185
-//						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
186
-//						if itotal <= 0 {
187
-//							info.ItemValue = strings.Replace(info.ItemValue, "&gt;", ">", -1)
188
-//							info.ItemValue = strings.Replace(info.ItemValue, "&lt;", "<", -1)
189
-//							inspection.PatientId = patient_id
190
-//							inspection.OrgId = org_id
191
-//							inspection.ProjectId = project_id
192
-//							inspection.ItemName = inspection_reference.ItemName
193
-//							inspection.ProjectName = inspection_reference.ProjectName
194
-//							inspection.InspectType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
195
-//							inspection.ItemId = item_id
196
-//							inspection.InspectValue = info.ItemValue
197
-//							inspection.InspectDate = inspect_date
198
-//							inspection.RecordDate = record_date
199
-//							// inspection.InspectTips = report.Resultstate
200
-//							inspection.Status = 1
201
-//							inspection.CreatedTime = time.Now().Unix()
202
-//							inspection.UpdatedTime = time.Now().Unix()
203
-//							inspection.UTime = inspect_date
204
-//							inspection.HisUserId = strconv.FormatInt(patient_id, 10)
205
-//							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
206
-//							if err != nil {
207
-//								tx.Rollback()
208
-//							}
209
-//						}
210
-//						tx.Commit()
211
-//					}
212
-//				}
213
-//			} else {
214
-//				continue
215
-//			}
216
-//		}
217
-//	}
218
-//	var syncInfo models.MiddleSyncInfo
219
-//	syncInfo.OrgId = org_id
220
-//	syncInfo.SyncTime = time.Now().Unix()
221
-//	syncInfo.SyncResultType = 1
222
-//	syncInfo.SyncRsultRemark = "同步成功"
223
-//	syncInfo.SyncTotalNum = 0
224
-//	syncInfo.SyncSuccessNum = 0
225
-//	syncInfo.SyncInfo = ""
226
-//	syncInfo.CreateTime = time.Now().Unix()
227
-//	syncInfo.UpdateTime = time.Now().Unix()
228
-//
229
-//	cwderr := CreateSyncInfo(&syncInfo)
230
-//	if cwderr != nil {
231
-//		utils.ErrorLog("创建同步信息失败:%v", cwderr)
232
-//		return
233
-//	}
234
-//	SyncToScpatx()
235
-//	return
236
-//}
83
+func SyncScpaLis() (err error) {
84
+	org_id := int64(9829)
85
+
86
+	org := &models.DataUploadConfig{
87
+		OrgId:  org_id,
88
+		DbHost: "192.168.0.254",
89
+		DbPort: "1433",
90
+		DbPass: "999999",
91
+		DbUser: "sa",
92
+		DbName: "nfjiminhis",
93
+	}
94
+
95
+	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
96
+	if err != nil {
97
+		utils.ErrorLog("创建数据库连接失败:%v", err)
98
+		return
99
+	}
100
+
101
+	// var sync_time int64
102
+	// sync_time = 1627747200
103
+
104
+	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
105
+	// utils.InfoLog("IdCardNo:%v",scpaLis)
106
+
107
+	// 第一步:获取上一次同步的时间点
108
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
109
+	var sync_time int64
110
+	if syncLastInfo.ID > 0 {
111
+		sync_time = syncLastInfo.SyncTime
112
+	} else {
113
+		sync_time = 1627747200
114
+	}
115
+	// 第二步:获取所有患者的病历号
116
+
117
+	patientList, _ := GetPatientPajmByOrgId(org_id)
118
+	if len(patientList) > 0 {
119
+		for _, patient := range patientList {
120
+			if len(patient.IdCardNo) > 0 {
121
+				// 上次同步时间转换为接口需要的格式
122
+				patient_id := patient.ID
123
+				utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
124
+				scpaLis, _ := GetScpaLis(orgDb, sync_time, patient.IdCardNo)
125
+				if len(scpaLis) > 0 {
126
+					for _, info := range scpaLis {
127
+						utils.InfoLog("Result:%v", info)
128
+						// 根据project_id和item_id 判断该项是否存在
129
+						project_id := int64(0)
130
+						if info.ProjectId > 0 {
131
+							project_id, _ = GetScpaProjectID(org_id, info.ProjectName)
132
+						} else {
133
+							continue
134
+						}
135
+						item_id, _ := GetScpaItemID(org_id, info.ProjectName, info.ItemName, project_id)
136
+						tx := writeMiddleDb.Begin()
137
+						var inspection models.MiddleInspection
138
+						var inspection_reference models.MiddleInspectionReference
139
+						record_date := info.InspectDate
140
+						if info.InspectDate == 0 {
141
+							record_date = time.Now().Unix()
142
+						}
143
+						inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
144
+						var total int
145
+						var RangeOptions string
146
+						var RangeMin string
147
+						var RangeMax string
148
+
149
+						// // 判断检查类型
150
+						ItemType := info.ItemType
151
+						RangeMin = info.RangeMin
152
+						RangeMax = info.RangeMax
153
+						RangeOptions = info.RangeValue
154
+						// Range := strings.Split(info.RangeValue, "-")
155
+						// if len(Range) > 1 {
156
+						// 	RangeMin = Range[0]
157
+						// 	RangeMax = Range[1]
158
+						// 	ItemType = 1
159
+						// } else {
160
+						// 	ItemType = 2
161
+						// 	RangeOptions = info.RangeOptions
162
+						// }
163
+
164
+						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
165
+						if total <= 0 {
166
+							inspection_reference.OrgId = org_id
167
+							inspection_reference.ProjectName = info.ProjectName
168
+							inspection_reference.Project = info.ProjectName
169
+							inspection_reference.ProjectId = project_id
170
+							inspection_reference.ItemName = info.ItemName
171
+							inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
172
+							inspection_reference.ItemId = item_id
173
+							inspection_reference.RangeType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
174
+							inspection_reference.RangeMin = RangeMin
175
+							inspection_reference.RangeMax = RangeMax
176
+							// inspection_reference.RangeValue = RangeValue
177
+							inspection_reference.RangeOptions = RangeOptions
178
+							inspection_reference.Unit = info.Unit
179
+							inspection_reference.Status = 1
180
+							inspection_reference.CreatedTime = time.Now().Unix()
181
+							inspection_reference.UpdatedTime = time.Now().Unix()
182
+							inspection_reference.InspectDate = inspect_date
183
+							inspection_reference.UTime = inspect_date
184
+							err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
185
+							if err != nil {
186
+								tx.Rollback()
187
+							}
188
+						}
189
+
190
+						var itotal int
191
+						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
192
+						if itotal <= 0 {
193
+							info.ItemValue = strings.Replace(info.ItemValue, "&gt;", ">", -1)
194
+							info.ItemValue = strings.Replace(info.ItemValue, "&lt;", "<", -1)
195
+							inspection.PatientId = patient_id
196
+							inspection.OrgId = org_id
197
+							inspection.ProjectId = project_id
198
+							inspection.ItemName = inspection_reference.ItemName
199
+							inspection.ProjectName = inspection_reference.ProjectName
200
+							inspection.InspectType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
201
+							inspection.ItemId = item_id
202
+							inspection.InspectValue = info.ItemValue
203
+							inspection.InspectDate = inspect_date
204
+							inspection.RecordDate = record_date
205
+							// inspection.InspectTips = report.Resultstate
206
+							inspection.Status = 1
207
+							inspection.CreatedTime = time.Now().Unix()
208
+							inspection.UpdatedTime = time.Now().Unix()
209
+							inspection.UTime = inspect_date
210
+							inspection.HisUserId = strconv.FormatInt(patient_id, 10)
211
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
212
+							if err != nil {
213
+								tx.Rollback()
214
+							}
215
+						}
216
+						tx.Commit()
217
+					}
218
+				}
219
+			} else {
220
+				continue
221
+			}
222
+		}
223
+	}
224
+	var syncInfo models.MiddleSyncInfo
225
+	syncInfo.OrgId = org_id
226
+	syncInfo.SyncTime = time.Now().Unix()
227
+	syncInfo.SyncResultType = 1
228
+	syncInfo.SyncRsultRemark = "同步成功"
229
+	syncInfo.SyncTotalNum = 0
230
+	syncInfo.SyncSuccessNum = 0
231
+	syncInfo.SyncInfo = ""
232
+	syncInfo.CreateTime = time.Now().Unix()
233
+	syncInfo.UpdateTime = time.Now().Unix()
234
+
235
+	cwderr := CreateSyncInfo(&syncInfo)
236
+	if cwderr != nil {
237
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
238
+		return
239
+	}
240
+	SyncToScpatx()
241
+	return
242
+}
237 243
 
238 244
 func SyncToScpatx() {
239 245
 	utils.TraceLog("检验检查同步任务开始执行")

+ 345 - 0
service/sccdkfyy_service.go ファイルの表示

@@ -0,0 +1,345 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"IC/utils"
6
+	"github.com/jinzhu/gorm"
7
+	"strconv"
8
+	"strings"
9
+	"time"
10
+)
11
+
12
+// 四川城东康复医院Lis同步
13
+func SyncSccdkfyyLis() (err error) {
14
+	org_id := int64(10551)
15
+
16
+	org := &models.DataUploadConfig{
17
+		OrgId:  org_id,
18
+		DbHost: "192.168.1.5",
19
+		DbPort: "1433",
20
+		DbPass: "XTXT_User",
21
+		DbUser: "XTXT_User",
22
+		DbName: "ndlmis15",
23
+	}
24
+
25
+	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
26
+	if err != nil {
27
+		utils.ErrorLog("创建数据库连接失败:%v", err)
28
+		return
29
+	}
30
+
31
+	// var sync_time int64
32
+	// sync_time = 1627747200
33
+
34
+	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
35
+	// utils.InfoLog("IdCardNo:%v",scpaLis)
36
+
37
+	// 第一步:获取上一次同步的plug_plugcase的ID
38
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
39
+	var sync_time int64
40
+	if syncLastInfo.ID > 0 {
41
+		sync_time = syncLastInfo.SyncTime
42
+	} else {
43
+		sync_time = 0
44
+	}
45
+
46
+	sync_time_temp := time.Unix(sync_time, 0)
47
+	syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
48
+
49
+
50
+	// 第二步:获取时间内所有检验结果
51
+	sccdLis, _ := GetScdckfyyLis(orgDb, syncTimeStr)
52
+
53
+	if len(sccdLis) > 0 {
54
+		for _, item := range sccdLis {
55
+			printInfo, _ := GetPatientsInfoBySfzh(item.Sfzh, 10551)
56
+			if printInfo.ID == 0 {
57
+				continue
58
+			}
59
+			// result 里查询
60
+			antiRresult,_ := GetScCdkfyyAnti(orgDb,item.TestOrderNo)
61
+			if len(antiRresult) > 0  {
62
+				for _,anti := range antiRresult {
63
+					LgthScdckfyySync(anti,item, org_id, printInfo.ID)
64
+				}
65
+			}
66
+		}
67
+	}
68
+
69
+	// 第二步:获取所有患者的病历号
70
+
71
+	// patientList, _ := GetPatientGzjhByOrgId(org_id)
72
+	// if len(patientList) > 0 {
73
+	// 	for _, patient := range patientList {
74
+	// 		if len(patient.IdCardNo) > 0 {
75
+	// 			patient_id := patient.ID
76
+	// 			utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
77
+	// 			scdcCaseList, _ := GetScCdkfyyCase(orgDb, sync_time,lastId, patient.IdCardNo)
78
+	// 			// 如果存在纪录,再在plug_plugCheckitem里根据信息查询检验信息
79
+	// 			if len(scdcCaseList) > 0 {
80
+	// 				for _, info := range scdcCaseList {
81
+	// 					utils.InfoLog("Result:%v", info)
82
+	// 					scdcItemList,_ := GetScCdkfyyCheckItem(orgDb,info.Serialno)
83
+	// 					//根据item里的数据,查询检验结果
84
+	// 					if len(scdcItemList) > 0 {
85
+	// 						for _,item := range scdcItemList {
86
+	// 							resultList,_ := GetScCdkfyyResult(orgDb,item.Serialno,item.Itemcode)
87
+	// 							if len(resultList) > 0 {
88
+	// 								for _ ,resultinfo := range resultList{
89
+	// 									LgthScdckfyySync(resultinfo,item, org_id, patient_id)
90
+	// 								}
91
+	// 							}
92
+	// 						}
93
+	// 					}
94
+	// 				}
95
+	// 			}
96
+	// 		}
97
+	// 	}
98
+	// }
99
+	var syncInfo models.MiddleSyncInfo
100
+	syncInfo.OrgId = org_id
101
+	syncInfo.SyncTime = time.Now().Unix()
102
+	syncInfo.SyncResultType = 1
103
+	syncInfo.SyncRsultRemark = "同步成功"
104
+	syncInfo.SyncTotalNum = 0
105
+	syncInfo.SyncSuccessNum = 0
106
+	syncInfo.SyncInfo = ""
107
+	syncInfo.CreateTime = time.Now().Unix()
108
+	syncInfo.UpdateTime = time.Now().Unix()
109
+
110
+	cwderr := CreateSyncInfo(&syncInfo)
111
+	if cwderr != nil {
112
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
113
+		return
114
+	}
115
+	SyncToSccdkfyy()
116
+	return
117
+}
118
+
119
+func SyncToSccdkfyy() {
120
+	utils.TraceLog("检验检查同步任务开始执行")
121
+	org_id := int64(10551)
122
+
123
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
124
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
125
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
126
+
127
+	// 第二步:将数据同步到业务库
128
+	if len(inspection_references) > 0 {
129
+		for _, inspection_reference := range inspection_references {
130
+			SyncInspectionReference(&inspection_reference)
131
+		}
132
+	}
133
+
134
+	if len(inspections) > 0 {
135
+		for _, inspection := range inspections {
136
+			SyncInspection(&inspection)
137
+		}
138
+	}
139
+	utils.SuccessLog("检验检查同步任务完成")
140
+}
141
+
142
+func GetScCdkfyyAnti(rdb *gorm.DB, test_order_no string) (record []*models.VYunjingPatientLabAnti, err error) {
143
+	err = rdb.Model(&models.VYunjingPatientLabAnti{}).Where("TEST_ORDER_NO = ?", test_order_no).Find(&record).Error
144
+	return
145
+}
146
+
147
+func GetPatientsInfoBySfzh(sfzh string, org_id int64) (info models.Patients, err error) {
148
+	err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", sfzh, org_id).First(&info).Error
149
+	return
150
+}
151
+
152
+func GetScdckfyyLis(rdb *gorm.DB, synctime string) (record []*models.VYunjingPatientLabItems, err error) {
153
+	err = rdb.Model(&models.VYunjingPatientLabItems{}).Where("CREATE_AT >= ? ", synctime).Find(&record).Error
154
+	return
155
+}
156
+
157
+
158
+func SyncToScdckfyytx() {
159
+	utils.TraceLog("检验检查同步任务开始执行")
160
+	org_id := int64(10551)
161
+
162
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
163
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
164
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
165
+
166
+	// 第二步:将数据同步到业务库
167
+	if len(inspection_references) > 0 {
168
+		for _, inspection_reference := range inspection_references {
169
+			SyncInspectionReference(&inspection_reference)
170
+		}
171
+	}
172
+
173
+	if len(inspections) > 0 {
174
+		for _, inspection := range inspections {
175
+			SyncInspection(&inspection)
176
+		}
177
+	}
178
+	utils.SuccessLog("检验检查同步任务完成")
179
+}
180
+
181
+
182
+// 从机构将数据同步到中间库
183
+func LgthScdckfyySync(result *models.VYunjingPatientLabAnti, checkItem *models.VYunjingPatientLabItems, org_id int64, patient_id int64) (*models.MiddleInspectionReference, error) {
184
+	tx := writeMiddleDb.Begin()
185
+	var inspection models.MiddleInspection
186
+	var inspection_reference models.MiddleInspectionReference
187
+
188
+	timstr := strings.Split(checkItem.CreateAt, "T")
189
+	timstem := strings.Split(timstr[1], "Z")
190
+	recordDateStr := timstr[0] + " " + timstem[0]
191
+	utils.InfoLog("recordDateStr: %v", recordDateStr)
192
+
193
+	if len(recordDateStr) == 0 {
194
+		recordDateStr = time.Now().Format("2006-01-02 15:04")
195
+	}
196
+
197
+	
198
+
199
+	record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
200
+	utils.InfoLog("record_date_str: %v", record_date_str)
201
+	record_date := record_date_str.Unix()
202
+	utils.InfoLog("record_date: %v", record_date)
203
+	inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
204
+	utils.InfoLog("inspect_date: %v", inspect_date)
205
+
206
+	var total int
207
+	var RangeOptions string
208
+	var RangeMin string
209
+	var RangeMax string
210
+
211
+	// // 判断检查类型
212
+	ItemType := 1
213
+	Range := strings.Split(result.ReferRange, "-")
214
+	if len(Range) > 1 {
215
+		RangeMin = Range[0]
216
+		RangeMax = Range[1]
217
+		ItemType = 1
218
+	} else {
219
+		ItemType = 2
220
+		RangeOptions = result.ReferRange
221
+	}
222
+
223
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_name = ? and item_name = ? and status = 1", org_id,checkItem.ItemTypeName,result.AntiName).Find(&inspection_reference).Count(&total).Error
224
+	if inspection_reference.ID > 0 {
225
+		ItemType = inspection_reference.RangeType
226
+	}
227
+	if total <= 0 {
228
+		//  如果配置表里没有相关配置,则创建project_id,item_id和相关配置信息
229
+		project_id, _ := GetSccdkfyyProjectID(org_id,checkItem.ItemTypeName)
230
+		item_id,_ := GetSccdkfyyItemID(org_id, checkItem.ItemTypeName, result.AntiName, project_id)
231
+
232
+		inspection_reference.OrgId = org_id
233
+		inspection_reference.ProjectName = checkItem.ItemTypeName
234
+		inspection_reference.Project = checkItem.ItemType
235
+		inspection_reference.ProjectId = project_id
236
+		inspection_reference.ItemName = result.AntiName
237
+		inspection_reference.ItemNameAddition = result.AntiName
238
+		inspection_reference.ItemId = item_id
239
+		inspection_reference.ItemCode = result.AntiName
240
+		inspection_reference.RangeType = ItemType
241
+		inspection_reference.RangeMin = RangeMin
242
+		inspection_reference.RangeMax = RangeMax
243
+		// inspection_reference.RangeValue = RangeValue
244
+		inspection_reference.RangeOptions = RangeOptions
245
+		inspection_reference.Unit = result.Unit
246
+		inspection_reference.Status = 1
247
+		inspection_reference.CreatedTime = time.Now().Unix()
248
+		inspection_reference.UpdatedTime = time.Now().Unix()
249
+		inspection_reference.InspectDate = inspect_date
250
+		inspection_reference.UTime = inspect_date
251
+		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
252
+		if err != nil {
253
+			tx.Rollback()
254
+		}
255
+	}
256
+
257
+	var itotal int
258
+	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, inspection_reference.ProjectId, inspection_reference.ItemId, record_date, patient_id).Find(&inspection).Count(&itotal).Error
259
+	if itotal <= 0 {
260
+		result.TestResult = strings.Replace(result.TestResult, "&gt;", ">", -1)
261
+		result.TestResult = strings.Replace(result.TestResult, "&lt;", "<", -1)
262
+		inspection.PatientId = patient_id
263
+		inspection.OrgId = org_id
264
+		inspection.ProjectId = inspection_reference.ProjectId
265
+		inspection.ItemName = inspection_reference.ItemName
266
+		inspection.ProjectName = inspection_reference.ProjectName
267
+		inspection.InspectType = ItemType
268
+		inspection.ItemId = inspection_reference.ItemId
269
+		inspection.InspectValue = result.TestResult
270
+		inspection.InspectDate = inspect_date
271
+		inspection.RecordDate = record_date
272
+		inspection.InspectTips = result.AntiCode
273
+		inspection.Status = 1
274
+		inspection.CreatedTime = time.Now().Unix()
275
+		inspection.UpdatedTime = time.Now().Unix()
276
+		inspection.UTime = inspect_date
277
+		inspection.HisUserId = strconv.FormatInt(patient_id, 10)
278
+		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
279
+		if err != nil {
280
+			tx.Rollback()
281
+		}
282
+	}
283
+	tx.Commit()
284
+	return nil, err
285
+}
286
+
287
+func GetProjectInfoSccdkfyy(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
288
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
289
+	return
290
+}
291
+
292
+
293
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
294
+func GetSccdkfyyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
295
+	var inspection_reference models.MiddleInspectionReference
296
+	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
297
+	if inspection_reference.ID > 0 {
298
+		return inspection_reference.ItemId, err
299
+	} else {
300
+		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
301
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
302
+		if inspection_reference.ItemId > 0 {
303
+			return inspection_reference.ItemId + 1, err
304
+		} else {
305
+			return project_id*100 + 1, err
306
+		}
307
+	}
308
+}
309
+
310
+
311
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
312
+func GetSccdkfyyProjectID(org_id int64, project_name string) (project_id int64, err error) {
313
+	var inspection_reference models.MiddleInspectionReference
314
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
315
+	if inspection_reference.ID > 0 {
316
+		return inspection_reference.ProjectId, err
317
+	} else {
318
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
319
+		if inspection_reference.ProjectId > 0 {
320
+			return inspection_reference.ProjectId + 1, err
321
+		} else {
322
+			return 1055101, err
323
+		}
324
+	}
325
+}
326
+
327
+func GetScCdkfyyResult(rdb *gorm.DB, serialNo string,parItemNo string) (record []*models.PlugPlugresult, err error) {
328
+	err = rdb.Model(&models.PlugPlugresult{}).Where("serialNo = ? and parItemNo = ?", serialNo,parItemNo).Find(&record).Error
329
+	return
330
+}
331
+
332
+func GetScCdkfyyCheckItem(rdb *gorm.DB, serialNo string) (record []*models.PlugPlugcheckitem, err error) {
333
+	err = rdb.Model(&models.PlugPlugcheckitem{}).Where("serialNo = ? ", serialNo).Find(&record).Error
334
+	return
335
+}
336
+
337
+func GetScCdkfyyCase(rdb *gorm.DB, startId int64,endId int64, hisuserid string) (record []*models.PlugPlugcase, err error) {
338
+	err = rdb.Model(&models.PlugPlugcase{}).Where("ID >= ? and ID <= ? and mainIndex = ?", startId,endId, hisuserid).Find(&record).Error
339
+	return
340
+}
341
+
342
+func GetScCdkfyyCaseMaxID(rdb *gorm.DB) (record models.PlugPlugcase, err error) {
343
+	err = rdb.Model(&models.PlugPlugcase{}).Select("TOP 1 *").Order("ID desc").Find(&record).Error
344
+	return
345
+}

File diff suppressed because it is too large
+ 225 - 1075
service/sy_service.go


+ 3 - 10
service/wfnfm_service.go ファイルの表示

@@ -75,13 +75,6 @@ func FindDoctorAdviceOrderById(orgID int64,patientId int64, recordDate int64) (p
75 75
 	return
76 76
 }
77 77
 
78
-type DataUploadConfig struct {
79
-	DbHost         string `gorm:"column:db_host" json:"db_host"`
80
-	DbPort         string `gorm:"column:db_port" json:"db_port"`
81
-	DbUser         string `gorm:"column:db_user" json:"db_user"`
82
-	DbPass         string `gorm:"column:db_pass" json:"db_pass"`
83
-	DbName         string `gorm:"column:db_name" json:"db_name"`
84
-}
85 78
 
86 79
 func BatchCreateRecord(ps *models.EmrBloodDialyRecord, rdb *gorm.DB) (err error) {
87 80
 	err = rdb.Create(&ps).Error
@@ -100,7 +93,7 @@ func BatchCreateOrder(ps *models.EmrBloodDialyOrder, rdb *gorm.DB) (err error) {
100 93
 
101 94
 // 潍坊内分泌医院 同步健康数据上报
102 95
 func  EmrBloodDiaylOrder() {
103
-	org := &DataUploadConfig{
96
+	org := &models.DataUploadConfig{
104 97
 		DbHost:         "127.0.0.1",
105 98
 		DbPort:         "1433",
106 99
 		DbPass:         "Aa123456",
@@ -205,7 +198,7 @@ func  EmrBloodDiaylOrder() {
205 198
 
206 199
 // 潍坊内分泌医院 同步健康数据上报
207 200
 func  EmrBloodDiaylDetail() {
208
-	org := &DataUploadConfig{
201
+	org := &models.DataUploadConfig{
209 202
 		DbHost:         "localhost",
210 203
 		DbPort:         "1433",
211 204
 		DbPass:         "Aa123456",
@@ -303,7 +296,7 @@ func  EmrBloodDiaylDetail() {
303 296
 
304 297
 // 潍坊内分泌医院 同步健康数据上报
305 298
 func  EmrBloodDiaylRecord() {
306
-	org := &DataUploadConfig{
299
+	org := &models.DataUploadConfig{
307 300
 		DbHost:         "localhost",
308 301
 		DbPort:         "1433",
309 302
 		DbPass:         "Aa123456",

+ 2 - 25
service/ystx_service.go ファイルの表示

@@ -200,7 +200,7 @@ func SyncLisYstx() (err error) {
200 200
 	// 第一步:获取艾迪康下发的Key
201 201
 	org_id := int64(9919)
202 202
 	login := "R26028"
203
-	password := "abc123"
203
+	password := "Abc123456@"
204 204
 	key := GetAdKey(login, password)
205 205
 	// 第二步:获取上一次同步的时间点
206 206
 	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
@@ -368,7 +368,7 @@ func YsReportInfoHandle(CheckInfo adkCheck, org_id int64, patientId int64) {
368 368
 		}
369 369
 	}
370 370
 
371
-	SyncToYstx()
371
+	SyncToGzczjhtx()
372 372
 }
373 373
 
374 374
 type adkResult struct {
@@ -502,29 +502,6 @@ func LgthYsSync(report adkResult, project_id int64, item_id int64, org_id int64,
502 502
 	return nil, err
503 503
 }
504 504
 
505
-func SyncToYstx() {
506
-	utils.TraceLog("检验检查同步任务开始执行")
507
-	org_id := int64(9919)
508
-
509
-	// 第一步:跟进org_id 去中间库查出需要同步的数据
510
-	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
511
-	inspections, _ := GetSyncInspectionByOrgId(org_id)
512
-
513
-	// 第二步:将数据同步到业务库
514
-	if len(inspection_references) > 0 {
515
-		for _, inspection_reference := range inspection_references {
516
-			SyncInspectionReference(&inspection_reference)
517
-		}
518
-	}
519
-
520
-	if len(inspections) > 0 {
521
-		for _, inspection := range inspections {
522
-			SyncInspection(&inspection)
523
-		}
524
-	}
525
-	utils.SuccessLog("检验检查同步任务完成")
526
-}
527
-
528 505
 // 根据姓名获取patient_id
529 506
 func GetPatientGzjhList(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
530 507
 	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

+ 37 - 0
tf日志/tf_20220808_log.txt ファイルの表示

@@ -0,0 +1,37 @@
1
+记录日志
2
+
3
+
4
+2022-08-08 09:50:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-08 09:49:00","病人来源":"1","身份证号":""}
6
+2022-08-08 09:50:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-08 09:51:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-08 09:50:00","病人来源":"1","身份证号":""}
12
+2022-08-08 09:51:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-08 09:52:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-08 09:51:00","病人来源":"1","身份证号":""}
18
+2022-08-08 09:52:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-08 09:53:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-08 09:52:00","病人来源":"1","身份证号":""}
24
+2022-08-08 09:53:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-08 09:54:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-08 09:53:00","病人来源":"1","身份证号":""}
30
+2022-08-08 09:54:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-08 09:55:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-08 09:54:00","病人来源":"1","身份证号":""}
36
+2022-08-08 09:55:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}

+ 43 - 0
tf日志/tf_20220809_log.txt ファイルの表示

@@ -0,0 +1,43 @@
1
+记录日志
2
+
3
+
4
+2022-08-09 15:09:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"999999190001018888"}
6
+2022-08-09 15:09:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-09 15:09:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"430581200205182779"}
12
+2022-08-09 15:09:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-09 15:09:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"350425200411242430"}
18
+2022-08-09 15:09:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-09 15:10:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"999999190001019999"}
24
+2022-08-09 15:10:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-09 15:10:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"999999190001018888"}
30
+2022-08-09 15:10:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-09 15:10:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"430581200205182779"}
36
+2022-08-09 15:10:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}
38
+
39
+
40
+2022-08-09 15:10:00 【 tftf入参 】:
41
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"350425200411242430"}
42
+2022-08-09 15:10:00 【 tftf出参 】:
43
+{"msg":"成功","result":[],"code":"10000"}

+ 85 - 0
tf日志/tf_20220810_log.txt ファイルの表示

@@ -0,0 +1,85 @@
1
+记录日志
2
+
3
+
4
+2022-08-10 20:31:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-10 20:31:00","病人来源":"1","身份证号":"350425200411242430"}
6
+2022-08-10 20:31:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-10 20:31:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-10 20:31:00","病人来源":"1","身份证号":"35062319500804667X"}
12
+2022-08-10 20:31:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-10 20:32:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"350623198802116616"}
18
+2022-08-10 20:32:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-10 20:32:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"350425200411242430"}
24
+2022-08-10 20:32:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-10 20:32:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"35062319500804667X"}
30
+2022-08-10 20:32:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-10 20:33:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"350623198802116616"}
36
+2022-08-10 20:33:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}
38
+
39
+
40
+2022-08-10 20:33:00 【 tftf入参 】:
41
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"350425200411242430"}
42
+2022-08-10 20:33:00 【 tftf出参 】:
43
+{"msg":"成功","result":[],"code":"10000"}
44
+
45
+
46
+2022-08-10 20:33:01 【 tftf入参 】:
47
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"35062319500804667X"}
48
+2022-08-10 20:33:01 【 tftf出参 】:
49
+{"msg":"成功","result":[],"code":"10000"}
50
+
51
+
52
+2022-08-10 20:37:00 【 tftf入参 】:
53
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"350623198802116616"}
54
+2022-08-10 20:37:00 【 tftf出参 】:
55
+{"msg":"成功","result":[],"code":"10000"}
56
+
57
+
58
+2022-08-10 20:37:00 【 tftf入参 】:
59
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"350425200411242430"}
60
+2022-08-10 20:37:00 【 tftf出参 】:
61
+{"msg":"成功","result":[],"code":"10000"}
62
+
63
+
64
+2022-08-10 20:37:00 【 tftf入参 】:
65
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"35062319500804667X"}
66
+2022-08-10 20:37:00 【 tftf出参 】:
67
+{"msg":"成功","result":[],"code":"10000"}
68
+
69
+
70
+2022-08-10 20:39:00 【 tftf入参 】:
71
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"350623198802116616"}
72
+2022-08-10 20:39:00 【 tftf出参 】:
73
+{"msg":"成功","result":[],"code":"10000"}
74
+
75
+
76
+2022-08-10 20:39:00 【 tftf入参 】:
77
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"350425200411242430"}
78
+2022-08-10 20:39:00 【 tftf出参 】:
79
+{"msg":"成功","result":[],"code":"10000"}
80
+
81
+
82
+2022-08-10 20:39:00 【 tftf入参 】:
83
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"35062319500804667X"}
84
+2022-08-10 20:39:00 【 tftf出参 】:
85
+{"msg":"成功","result":[],"code":"10000"}