张保健 1 year ago
parent
commit
9be80b40f4
9 changed files with 1486 additions and 261 deletions
  1. 18 0
      controllers/lis.go
  2. 107 80
      models/lis_model.go
  3. 5 3
      routers/router.go
  4. 34 64
      service/cron.go
  5. 86 48
      service/lis_service.go
  6. 2 7
      service/pajm_service.go
  7. 1008 0
      service/sssy_service.go
  8. 33 34
      service/sy_service.go
  9. 193 25
      service/tscyyy_service.go

+ 18 - 0
controllers/lis.go View File

35
 
35
 
36
 }
36
 }
37
 
37
 
38
+// 石狮盛誉LIS同步
39
+func (c *LisController) SyncSssy() {
40
+	service.SyncToSssytx()
41
+	c.ServeSuccessJSON(map[string]interface{}{
42
+		"resultList": "12345",
43
+	})
44
+	return
45
+}
46
+
38
 func (c *LisController) SyncTest() {
47
 func (c *LisController) SyncTest() {
39
 	// 获取备份库里所有的医嘱信息
48
 	// 获取备份库里所有的医嘱信息
40
 	// service.EmrBloodDiaylOrder()
49
 	// service.EmrBloodDiaylOrder()
64
 	return
73
 	return
65
 }
74
 }
66
 
75
 
76
+// 唐山朝阳医院LIS
77
+func (c *LisController) SyncTscyVipLis() {
78
+	service.SyncTscyVipLis()
79
+	c.ServeSuccessJSON(map[string]interface{}{
80
+		"resultList": "12345",
81
+	})
82
+	return
83
+}
84
+
67
 func (c *LisController) SyncShLis() {
85
 func (c *LisController) SyncShLis() {
68
 	// 获取备份库里所有的医嘱信息
86
 	// 获取备份库里所有的医嘱信息
69
 
87
 

+ 107 - 80
models/lis_model.go View File

80
 }
80
 }
81
 
81
 
82
 type VYunjingPatientLabItems struct {
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"`
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
 }
97
 }
98
 
98
 
99
 func (VYunjingPatientLabItems) TableName() string {
99
 func (VYunjingPatientLabItems) TableName() string {
101
 }
101
 }
102
 
102
 
103
 type VYunjingPatientLabAnti struct {
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
-
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"`
119
 }
118
 }
120
 
119
 
121
 func (VYunjingPatientLabAnti) TableName() string {
120
 func (VYunjingPatientLabAnti) TableName() string {
123
 }
122
 }
124
 
123
 
125
 type PlugPlugcase struct {
124
 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"`
125
+	Id              int64  `gorm:"column:ID" json:"ID"`
126
+	Oldserialno     string `gorm:"column:oldSerialNo" json:"oldSerialNo"`
127
+	Serialno        string `gorm:"column:serialNo" json:"serialNo"`
128
+	Name            string `gorm:"column:name" json:"name"`
129
+	Gender          string `gorm:"column:gender" json:"gender"`
130
+	Age             int64  `gorm:"column:age" json:"age"`
131
+	RegistrantmanId int64  `gorm:"column:registrantMan_id" json:"registrantMan_id"`
132
+	Mainindex       string `gorm:"column:mainIndex" json:"mainIndex"`
133
+	Orddoctor       string `gorm:"column:ordDoctor" json:"ordDoctor"`
134
+	Ordloc          string `gorm:"column:ordLoc" json:"ordLoc"`
135
+	Birthday        string `gorm:"column:birthDay" json:"birthDay"`
137
 }
136
 }
138
 
137
 
139
 func (PlugPlugcase) TableName() string {
138
 func (PlugPlugcase) TableName() string {
141
 }
140
 }
142
 
141
 
143
 type PlugPlugcheckitem struct {
142
 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"`
143
+	Id              int64  `gorm:"column:ID" json:"ID"`
144
+	Serialno        string `gorm:"column:serialNo" json:"serialNo"`
145
+	Itemcode        string `gorm:"column:itemCode" json:"itemCode"`
146
+	State           int64  `gorm:"column:state" json:"state"`
147
+	Itemplug        string `gorm:"column:itemPlug" json:"itemPlug"`
148
+	Checkitemid     string `gorm:"column:checkItemId" json:"checkItemId"`
149
+	Oldserialno     string `gorm:"column:oldSerialNo" json:"oldSerialNo"`
150
+	Applytime       string `gorm:"column:applyTime" json:"applyTime"`
151
+	Specimenname    string `gorm:"column:specimenName" json:"specimenName"`
152
+	Checkitemname   string `gorm:"column:checkItemName" json:"checkItemName"`
153
+	Liscollectuser  string `gorm:"column:LisCollectUser" json:"LisCollectUser"`
154
+	Liscollecttime  string `gorm:"column:LisCollectTime" json:"LisCollectTime"`
155
+	Lissignuser     string `gorm:"column:LisSignUser" json:"LisSignUser"`
156
+	Lissigntime     string `gorm:"column:LissignTime" json:"LissignTime"`
157
+	Lisacceptuser   string `gorm:"column:LisAcceptUser" json:"LisAcceptUser"`
158
+	Lisaccepttime   string `gorm:"column:LisAcceptTime" json:"LisAcceptTime"`
159
+	Lisregisteruser string `gorm:"column:LisRegisterUser" json:"LisRegisterUser"`
160
+	Lisregistertime string `gorm:"column:LisRegisterTime" json:"LisRegisterTime"`
161
+	Lischeckuser    string `gorm:"column:LisCheckUser" json:"LisCheckUser"`
162
+	Lischecktime    string `gorm:"column:LisCheckTime" json:"LisCheckTime"`
163
+	Lisrefuseuser   string `gorm:"column:LisRefuseUser" json:"LisRefuseUser"`
164
+	Lisrefusetime   string `gorm:"column:LisRefuseTime" json:"LisRefuseTime"`
165
+	Lisstatus       string `gorm:"column:LisStatus" json:"LisStatus"`
166
+	Refusereason    string `gorm:"column:RefuseReason" json:"RefuseReason"`
168
 }
167
 }
169
 
168
 
170
 func (PlugPlugcheckitem) TableName() string {
169
 func (PlugPlugcheckitem) TableName() string {
172
 }
171
 }
173
 
172
 
174
 type PlugPlugresult struct {
173
 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"`
174
+	Id               int64  `gorm:"column:ID" json:"ID"`
175
+	Serialno         string `gorm:"column:serialNo" json:"serialNo"`
176
+	Testitemname     string `gorm:"column:testItemName" json:"testItemName"`
177
+	Itemcode         string `gorm:"column:itemcode" json:"itemcode"`
178
+	Paritemno        string `gorm:"column:parItemNo" json:"parItemNo"`
179
+	Reportvalueall   string `gorm:"column:reportValueAll" json:"reportValueAll"`
180
+	Testitemdatetime string `gorm:"column:testItemDateTime" json:"testItemDateTime"`
181
+	Unit             string `gorm:"column:unit" json:"unit"`
182
+	Refrange         string `gorm:"column:refrange" json:"refrange"`
183
+	Resultstatus     string `gorm:"column:resultStatus" json:"resultStatus"`
184
+	Itemorder        int64  `gorm:"column:itemOrder" json:"itemOrder"`
185
+	Checker          string `gorm:"column:checker" json:"checker"`
187
 }
186
 }
188
 
187
 
189
 func (PlugPlugresult) TableName() string {
188
 func (PlugPlugresult) TableName() string {
240
 	return "xt_middle_patients"
239
 	return "xt_middle_patients"
241
 }
240
 }
242
 
241
 
243
-
244
 type Patients struct {
242
 type Patients struct {
245
 	ID              int64  `gorm:"column:id" json:"id" form:"id"`
243
 	ID              int64  `gorm:"column:id" json:"id" form:"id"`
246
 	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
244
 	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
252
 	ContactName     string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
250
 	ContactName     string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
253
 	Gender          int64  `gorm:"column:gender" json:"gender" form:"gender"`
251
 	Gender          int64  `gorm:"column:gender" json:"gender" form:"gender"`
254
 	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
252
 	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
253
+	Phone           string `gorm:"column:phone" json:"phone" form:"phone"`
254
+	Age             int64  `gorm:"column:age" json:"age"`
255
 }
255
 }
256
 
256
 
257
 func (Patients) TableName() string {
257
 func (Patients) TableName() string {
412
 	UTime        string `gorm:"column:u_time" json:"u_time" form:"u_time"`
412
 	UTime        string `gorm:"column:u_time" json:"u_time" form:"u_time"`
413
 	IsSync       int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
413
 	IsSync       int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
414
 	// SyncItemId int64 `gorm:"column:sync_item_id" json:"sync_item_id" form:"sync_item_id"`
414
 	// SyncItemId int64 `gorm:"column:sync_item_id" json:"sync_item_id" form:"sync_item_id"`
415
-	HisUserId string `gorm:"column:his_user_id" json:"his_user_id" form:"his_user_id"`
416
-	SyncId    int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
415
+	HisUserId    string `gorm:"column:his_user_id" json:"his_user_id" form:"his_user_id"`
416
+	SyncId       int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
417
+	SysProjectId int64  `gorm:"column:sys_project_id" json:"sys_project_id" form:"sys_project_id"`
418
+	SysItemId    int64  `gorm:"column:sys_item_id" json:"sys_item_id" form:"sys_item_id"`
417
 }
419
 }
418
 
420
 
419
 func (MiddleInspection) TableName() string {
421
 func (MiddleInspection) TableName() string {
443
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
445
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
444
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
446
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
445
 	SyncId           int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
447
 	SyncId           int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
446
-	ItemCode         string  `gorm:"column:item_code" json:"item_code" form:"item_code"`
448
+	ItemCode         string `gorm:"column:item_code" json:"item_code" form:"item_code"`
449
+	XtProjectId      int64  `gorm:"column:xt_project_id" json:"xt_project_id" form:"xt_project_id"`
450
+	XtItemId         int64  `gorm:"column:xt_item_id" json:"xt_item_id" form:"xt_item_id"`
447
 }
451
 }
448
 
452
 
449
 func (MiddleInspectionReference) TableName() string {
453
 func (MiddleInspectionReference) TableName() string {
560
 func (VMItemProjectList) TableName() string {
564
 func (VMItemProjectList) TableName() string {
561
 	return "xt_his_project_list"
565
 	return "xt_his_project_list"
562
 }
566
 }
567
+
568
+type HisLabelPrintStatusInfo struct {
569
+	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
570
+	PatientId          int64    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
571
+	Ctime              int64    `gorm:"column:ctime" json:"ctime" form:"ctime"`
572
+	Mtime              int64    `gorm:"column:mtime" json:"mtime" form:"mtime"`
573
+	Status             int64    `gorm:"column:status" json:"status" form:"status"`
574
+	IsCombinationPrint int64    `gorm:"column:is_combination_print" json:"is_combination_print" form:"is_combination_print"`
575
+	RecordDate         string   `gorm:"column:record_date" json:"record_date" form:"record_date"`
576
+	ItemIds            string   `gorm:"column:item_ids" json:"item_ids" form:"item_ids"`
577
+	UserOrgId          int64    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
578
+	ProjectIds         string   `gorm:"column:project_ids" json:"project_ids" form:"project_ids"`
579
+	DoctorId           int64    `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
580
+	Ids                string   `gorm:"column:ids" json:"ids" form:"ids"`
581
+	IsTeam             int64    `gorm:"column:is_team" json:"is_team" form:"is_team"`
582
+	IsPrint            int64    `gorm:"column:is_print" json:"is_print" form:"is_print"`
583
+	Patient            Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
584
+	ApplyCode          string   `gorm:"column:apply_code" json:"apply_code" form:"apply_code"`
585
+}
586
+
587
+func (HisLabelPrintStatusInfo) TableName() string {
588
+	return "his_label_print_status_info"
589
+}

+ 5 - 3
routers/router.go View File

29
 	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
29
 	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
30
 	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
30
 	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
31
 	beego.Router("/api/test", &controllers.LisController{}, "get:SyncTest")
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")
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")
35
+	beego.Router("/api/lis/sssy", &controllers.LisController{}, "get:SyncSssy")
36
+	beego.Router("/api/lis/tscyvip", &controllers.LisController{}, "get:SyncTscyVipLis")
35
 }
37
 }

+ 34 - 64
service/cron.go View File

25
 	return cron.New(cron.WithParser(secondParser), cron.WithChain())
25
 	return cron.New(cron.WithParser(secondParser), cron.WithChain())
26
 }
26
 }
27
 
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() {
28
 func BeginAutoSyncLis() {
57
 	utils.InfoLog("开启自动检验检查同步定时任务")
29
 	utils.InfoLog("开启自动检验检查同步定时任务")
58
 	createLisSyncCronJob := newWithSeconds()
30
 	createLisSyncCronJob := newWithSeconds()
59
 
31
 
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()
32
+	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
33
+	createLisSyncCronJob.AddFunc(specys, func() {
34
+		SyncTscyLis()
35
+	})
36
+
37
+	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
38
+	createLisSyncCronJob.AddFunc(specys1, func() {
39
+		SyncCsnyLis()
40
+	})
41
+
42
+	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
43
+	createLisSyncCronJob.AddFunc(spec, func() {
44
+		SyncHbdyLis()
45
+	})
46
+
47
+	spec2 := "0 50 2 * * ?" // 每天凌晨2点同步 龙岗二院
48
+	createLisSyncCronJob.AddFunc(spec2, func() {
49
+		SyncLisLgty()
50
+	})
51
+
52
+	spec3 := "0 50 3 * * ?" // 每天凌晨2点同步 广州暨华血液透析中心
53
+	createLisSyncCronJob.AddFunc(spec3, func() {
54
+		SyncLisGzjhtx()
55
+	})
56
+
57
+	spec4 := "0 20 3 * * ?" // 每天凌晨同步 石狮盛誉血液透析中心
58
+	createLisSyncCronJob.AddFunc(spec4, func() {
59
+		SyncSYData2()
60
+	})
61
+
62
+	spec5 := "0 20 4 * * ?" // 每天凌晨同步 石狮盛誉血液透析中心
63
+	createLisSyncCronJob.AddFunc(spec5, func() {
64
+		SyncTscyVipLis()
94
 	})
65
 	})
95
 
66
 
96
 	createLisSyncCronJob.Start()
67
 	createLisSyncCronJob.Start()
97
 }
68
 }
98
 
69
 
99
-
100
 func AutoSyncLis() {
70
 func AutoSyncLis() {
101
 	utils.TraceLog("检验检查任务开始执行")
71
 	utils.TraceLog("检验检查任务开始执行")
102
 	org_id := int64(9538)
72
 	org_id := int64(9538)
171
 				}
141
 				}
172
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
142
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
173
 				continue
143
 				continue
174
-			} 
144
+			}
175
 
145
 
176
 			// 第四部:将同步过来的数据插入到中间库对应的表
146
 			// 第四部:将同步过来的数据插入到中间库对应的表
177
 			syncSuccessNum := 0
147
 			syncSuccessNum := 0

+ 86 - 48
service/lis_service.go View File

3
 import (
3
 import (
4
 	"IC/models"
4
 	"IC/models"
5
 	"IC/utils"
5
 	"IC/utils"
6
-	_"strconv"
6
+	_ "IC/utils"
7
+	_ "fmt"
8
+	_ "github.com/jinzhu/gorm"
9
+	_ "strconv"
7
 	"strings"
10
 	"strings"
8
 	"time"
11
 	"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
 	err = backupDb.Model(&models.DoctorAdvice{}).Offset(100000).Limit(10000).Find(&Advice).Error
16
 	err = backupDb.Model(&models.DoctorAdvice{}).Offset(100000).Limit(10000).Find(&Advice).Error
17
 	return
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
 	return
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
 	return err
28
 	return err
29
 }
29
 }
30
 
30
 
34
 	return err
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
 	db := readDb.Begin()
39
 	db := readDb.Begin()
40
 	err = db.Table("xt_filed_config").Group("org_id").Select("org_id,module,filed_name").Where("org_id > 0").Scan(&FiledConfig).Error
40
 	err = db.Table("xt_filed_config").Group("org_id").Select("org_id,module,filed_name").Where("org_id > 0").Scan(&FiledConfig).Error
41
 	return
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
 	err = readDb.Model(&models.FiledConfig{}).Where("org_id = 0").Find(&FiledConfig).Error
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
 	tx := writeDb.Begin()
64
 	tx := writeDb.Begin()
65
 	var inspection_reference models.InspectionReference
65
 	var inspection_reference models.InspectionReference
66
 	var total int
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
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
68
 	if total <= 0 {
107
 	if total <= 0 {
69
 		inspection_reference.OrgId = data.OrgId
108
 		inspection_reference.OrgId = data.OrgId
70
 		inspection_reference.ProjectName = data.ProjectName
109
 		inspection_reference.ProjectName = data.ProjectName
104
 	tx := writeDb.Begin()
143
 	tx := writeDb.Begin()
105
 	var inspection models.Inspection
144
 	var inspection models.Inspection
106
 	var total int
145
 	var total int
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
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.RecordDate).Find(&inspection).Count(&total).Error
108
 	if total <= 0 {
147
 	if total <= 0 {
109
 		inspection.OrgId = data.OrgId
148
 		inspection.OrgId = data.OrgId
110
 		inspection.PatientId = data.PatientId
149
 		inspection.PatientId = data.PatientId
139
 }
178
 }
140
 
179
 
141
 // 跟进org_id获取未同步的检验检查选项信息
180
 // 跟进org_id获取未同步的检验检查选项信息
142
-func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference,err error) {
181
+func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference, err error) {
143
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&InspectionReferences).Error
182
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&InspectionReferences).Error
144
 	return
183
 	return
145
 }
184
 }
146
 
185
 
147
 // 跟进org_id获取未同步的检验检查信息
186
 // 跟进org_id获取未同步的检验检查信息
148
-func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection,err error) {
187
+func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection, err error) {
149
 	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&Inspection).Error
188
 	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&Inspection).Error
150
 	return
189
 	return
151
 }
190
 }
169
 }
208
 }
170
 
209
 
171
 // 根据机构ID获取该机构检验检查操作表里状态为0的数据
210
 // 根据机构ID获取该机构检验检查操作表里状态为0的数据
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
211
+func GetReportHandleListyOrgID(org_id int64) (report_handle_list []models.MiddleReportHandle, err error) {
212
+	err = readMiddleDb.Model(&models.MiddleReportHandle{}).Where("org_id = ?  and  handle_type = 0 ", org_id).Find(&report_handle_list).Error
174
 	return
213
 	return
175
 }
214
 }
176
 
215
 
177
 // 根据机构ID修改检验检查操作表里的数据
216
 // 根据机构ID修改检验检查操作表里的数据
178
-func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle)  error{
217
+func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle) error {
179
 	err := writeMiddleDb.Model(&models.MiddleReportHandle{}).Updates(&report_handle).Error
218
 	err := writeMiddleDb.Model(&models.MiddleReportHandle{}).Updates(&report_handle).Error
180
 	return err
219
 	return err
181
 }
220
 }
182
 
221
 
183
 // 跟进机构ID获取该机构所有病人的his_user_id
222
 // 跟进机构ID获取该机构所有病人的his_user_id
184
-func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients ,err error) {
223
+func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients, err error) {
185
 	err = readMiddleDb.Model(&models.MiddlePatients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patients).Error
224
 	err = readMiddleDb.Model(&models.MiddlePatients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patients).Error
186
 	return
225
 	return
187
 }
226
 }
188
 
227
 
189
 // 根据机构ID获取该机构上次同步信息
228
 // 根据机构ID获取该机构上次同步信息
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
229
+func GetSyncTimeByOrgID(org_id int64, his_user_id string) (sync_info models.MiddleSyncInfo, err error) {
230
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Last(&sync_info).Error
192
 	return
231
 	return
193
 }
232
 }
194
 
233
 
195
 // 根据机构ID获取该机构上次同步信息
234
 // 根据机构ID获取该机构上次同步信息
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
235
+func GetSyncTimeByOrgIDForYs(org_id int64) (sync_info models.MiddleSyncInfo, err error) {
236
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ? ", org_id).Last(&sync_info).Error
198
 	return
237
 	return
199
 }
238
 }
200
 
239
 
201
 // 根据机构ID和His_useer_id获取该患者最后一条同步检查数据
240
 // 根据机构ID和His_useer_id获取该患者最后一条同步检查数据
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
241
+func GetInspectionLastInfoByOrgID(org_id int64, his_user_id string) (inspectionLastInfo models.MiddleInspection, err error) {
242
+	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Order("created_time desc").First(&inspectionLastInfo).Error
204
 	return
243
 	return
205
 }
244
 }
206
 
245
 
207
 // 从机构将数据同步到中间库
246
 // 从机构将数据同步到中间库
208
-func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleInspectionReference,*models.MiddleInspection,error) {
247
+func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
209
 	tx := writeMiddleDb.Begin()
248
 	tx := writeMiddleDb.Begin()
210
 	var inspection models.MiddleInspection
249
 	var inspection models.MiddleInspection
211
 	var inspection_reference models.MiddleInspectionReference
250
 	var inspection_reference models.MiddleInspectionReference
212
 	recordDateStr := data.UTime
251
 	recordDateStr := data.UTime
213
-	if len(data.UTime) == 0 { 
252
+	if len(data.UTime) == 0 {
214
 		recordDateStr = time.Now().Format("2006-01-02 15:04")
253
 		recordDateStr = time.Now().Format("2006-01-02 15:04")
215
 	}
254
 	}
216
 	record_date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
255
 	record_date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
223
 	} else {
262
 	} else {
224
 		data.ItemType = 1
263
 		data.ItemType = 1
225
 		if len(data.RangeMax) > 0 {
264
 		if len(data.RangeMax) > 0 {
226
-			Range := strings.Split(data.RangeMax,"-")
265
+			Range := strings.Split(data.RangeMax, "-")
227
 			if len(Range) > 1 {
266
 			if len(Range) > 1 {
228
 				data.RangeMin = Range[0]
267
 				data.RangeMin = Range[0]
229
-				data.RangeMax = Range[1] 
268
+				data.RangeMax = Range[1]
230
 			} else {
269
 			} else {
231
 				data.RangeMin = Range[0]
270
 				data.RangeMin = Range[0]
232
 			}
271
 			}
233
 		}
272
 		}
234
 	}
273
 	}
235
 
274
 
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
275
+	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
237
 	if total <= 0 && len(data.ProjectName) > 0 {
276
 	if total <= 0 && len(data.ProjectName) > 0 {
238
 		inspection_reference.OrgId = org_id
277
 		inspection_reference.OrgId = org_id
239
 		inspection_reference.ProjectName = data.ProjectName
278
 		inspection_reference.ProjectName = data.ProjectName
258
 		}
297
 		}
259
 	}
298
 	}
260
 
299
 
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
300
+	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
262
 	if itotal <= 0 {
301
 	if itotal <= 0 {
263
 		inspection.PatientId = patient_id
302
 		inspection.PatientId = patient_id
264
 		inspection.OrgId = org_id
303
 		inspection.OrgId = org_id
286
 	}
325
 	}
287
 
326
 
288
 	tx.Commit()
327
 	tx.Commit()
289
-	return &inspection_reference,&inspection,err
328
+	return &inspection_reference, &inspection, err
290
 }
329
 }
291
 
330
 
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
331
+// GetPatientList 返回患者的列表
332
+func GetList(his_user_id []interface{}, syncTimes string) (lis []*models.TBLISItem, err error) {
333
+	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id in (?)  ", syncTimes, his_user_id).Find(&lis).Error
295
 	return
334
 	return
296
 }
335
 }
297
 
336
 
298
-//GetPatientList 返回患者的列表
299
-func GetListByHisUserID(his_user_id string,syncTimes string,selectType int64) (lis []*models.TBLISItem,err error) {
337
+// GetPatientList 返回患者的列表
338
+func GetListByHisUserID(his_user_id string, syncTimes string, selectType int64) (lis []*models.TBLISItem, err error) {
300
 	if selectType == 1 {
339
 	if selectType == 1 {
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
-	 }
340
+		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND patient_name = ?  ", syncTimes, his_user_id).Find(&lis).Error
341
+	} else {
342
+		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id = ? ", syncTimes, his_user_id).Find(&lis).Error
343
+	}
305
 	return
344
 	return
306
 }
345
 }
307
-

+ 2 - 7
service/pajm_service.go View File

27
 	RangeValue   string `gorm:"column:range_value" json:"range_value"`
27
 	RangeValue   string `gorm:"column:range_value" json:"range_value"`
28
 	RangeOptions string `gorm:"column:range_options" json:"range_options"`
28
 	RangeOptions string `gorm:"column:range_options" json:"range_options"`
29
 	Unit         string `gorm:"column:unit" json:"unit"`
29
 	Unit         string `gorm:"column:unit" json:"unit"`
30
-	State        string  `gorm:"column:state" json:"state"`
30
+	State        int64  `gorm:"column:state" json:"state"`
31
 	CTime        int64  `gorm:"column:c_time" json:"c_time"`
31
 	CTime        int64  `gorm:"column:c_time" json:"c_time"`
32
 	UTime        int64  `gorm:"column:u_time" json:"u_time"`
32
 	UTime        int64  `gorm:"column:u_time" json:"u_time"`
33
 }
33
 }
74
 	}
74
 	}
75
 }
75
 }
76
 
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
-
82
 // 四川蓬安济民透析中心Lis同步
77
 // 四川蓬安济民透析中心Lis同步
83
 func SyncScpaLis() (err error) {
78
 func SyncScpaLis() (err error) {
84
 	org_id := int64(9829)
79
 	org_id := int64(9829)
114
 	}
109
 	}
115
 	// 第二步:获取所有患者的病历号
110
 	// 第二步:获取所有患者的病历号
116
 
111
 
117
-	patientList, _ := GetPatientPajmByOrgId(org_id)
112
+	patientList, _ := GetPatientGzjhByOrgId(org_id)
118
 	if len(patientList) > 0 {
113
 	if len(patientList) > 0 {
119
 		for _, patient := range patientList {
114
 		for _, patient := range patientList {
120
 			if len(patient.IdCardNo) > 0 {
115
 			if len(patient.IdCardNo) > 0 {

File diff suppressed because it is too large
+ 1008 - 0
service/sssy_service.go


+ 33 - 34
service/sy_service.go View File

6
 	"IC/utils"
6
 	"IC/utils"
7
 	_ "encoding/json"
7
 	_ "encoding/json"
8
 	_ "encoding/xml"
8
 	_ "encoding/xml"
9
+	"fmt"
9
 	"github.com/jinzhu/gorm"
10
 	"github.com/jinzhu/gorm"
10
 	_ "github.com/jinzhu/gorm"
11
 	_ "github.com/jinzhu/gorm"
11
-	_"strconv"
12
+	_ "strconv"
12
 	"strings"
13
 	"strings"
13
 	"time"
14
 	"time"
14
-	"fmt"
15
 )
15
 )
16
 
16
 
17
 type stsylis struct {
17
 type stsylis struct {
18
-	Testno    	string  `gorm:"column:testno " json:"testno "`
19
-	Seqno    	string  `gorm:"column:seqno  " json:"seqno  "`
20
-	Itemno     	string  `gorm:"column:itemno " json:"itemno "`
21
-	Itemname  	string  `gorm:"column:itemname" json:"itemname"`
22
-	Testresult  string  `gorm:"column:testresult" json:"testresult"`
23
-	Result1  	string  `gorm:"column:result1" json:"result1"`
24
-	Result2     string  `gorm:"column:result2" json:"result2"`
25
-	Resultflag	string  `gorm:"column:resultflag" json:"resultflag"`
26
-	Units    	string  `gorm:"column:units" json:"units"`
27
-	Ranges     	string  `gorm:"column:ranges" json:"ranges"`
28
-	Resulttime	string  `gorm:"column:resulttime" json:"resulttime"`
29
-	Checkman   	string  `gorm:"column:checkman" json:"checkman"`
30
-	Testman 	string  `gorm:"column:testman" json:"testman"`
31
-	Lastmodify	string  `gorm:"column:lastmodify" json:"lastmodify"`
32
-	Instrument	string  `gorm:"column:instrument" json:"instrument"`
33
-	Sampleno	string  `gorm:"column:sampleno" json:"sampleno"`
34
-	Brdh        string  `gorm:"column:brdh" json:"brdh"`
35
-	Brxm        string  `gorm:"column:brxm" json:"brxm"`
36
-	Sfxmdh      string  `gorm:"column:sfxmdh" json:"sfxmdh"`
37
-	Sendflag    string  `gorm:"column:sendflag" json:"sendflag"`
38
-	Myid        string  `gorm:"column:myid" json:"myid"`
39
-	Uploadflag  string  `gorm:"column:uploadflag" json:"uploadflag"`
18
+	Testno     string `gorm:"column:testno " json:"testno "`
19
+	Seqno      string `gorm:"column:seqno  " json:"seqno  "`
20
+	Itemno     string `gorm:"column:itemno " json:"itemno "`
21
+	Itemname   string `gorm:"column:itemname" json:"itemname"`
22
+	Testresult string `gorm:"column:testresult" json:"testresult"`
23
+	Result1    string `gorm:"column:result1" json:"result1"`
24
+	Result2    string `gorm:"column:result2" json:"result2"`
25
+	Resultflag string `gorm:"column:resultflag" json:"resultflag"`
26
+	Units      string `gorm:"column:units" json:"units"`
27
+	Ranges     string `gorm:"column:ranges" json:"ranges"`
28
+	Resulttime string `gorm:"column:resulttime" json:"resulttime"`
29
+	Checkman   string `gorm:"column:checkman" json:"checkman"`
30
+	Testman    string `gorm:"column:testman" json:"testman"`
31
+	Lastmodify string `gorm:"column:lastmodify" json:"lastmodify"`
32
+	Instrument string `gorm:"column:instrument" json:"instrument"`
33
+	Sampleno   string `gorm:"column:sampleno" json:"sampleno"`
34
+	Brdh       string `gorm:"column:brdh" json:"brdh"`
35
+	Brxm       string `gorm:"column:brxm" json:"brxm"`
36
+	Sfxmdh     string `gorm:"column:sfxmdh" json:"sfxmdh"`
37
+	Sendflag   string `gorm:"column:sendflag" json:"sendflag"`
38
+	Myid       string `gorm:"column:myid" json:"myid"`
39
+	Uploadflag string `gorm:"column:uploadflag" json:"uploadflag"`
40
 }
40
 }
41
 
41
 
42
 func (stsylis) TableName() string {
42
 func (stsylis) TableName() string {
49
 }
49
 }
50
 
50
 
51
 // 根据机构ID和患者姓名获取患者信息
51
 // 根据机构ID和患者姓名获取患者信息
52
-func GetUserInfoByName(org_id int64,name string) (patients models.Patients, err error) {
53
-	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ?", org_id,name).First(&patients).Error
52
+func GetUserInfoByName(org_id int64, name string) (patients models.Patients, err error) {
53
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ?", org_id, name).First(&patients).Error
54
 	return
54
 	return
55
 }
55
 }
56
 
56
 
57
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
57
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
58
-func GetStsyProjectID(org_id int64, project_name string,item_name string) (project_id int64, err error) {
58
+func GetStsyProjectID(org_id int64, project_name string, item_name string) (project_id int64, err error) {
59
 	var inspection_reference models.MiddleInspectionReference
59
 	var inspection_reference models.MiddleInspectionReference
60
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ?  and item_name = ? ", org_id, project_name, item_name).First(&inspection_reference).Error
60
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ?  and item_name = ? ", org_id, project_name, item_name).First(&inspection_reference).Error
61
 	if inspection_reference.ID > 0 {
61
 	if inspection_reference.ID > 0 {
120
 		sync_time = 1685548800
120
 		sync_time = 1685548800
121
 	}
121
 	}
122
 
122
 
123
-	SyncTime := time.Unix(sync_time,0)
123
+	SyncTime := time.Unix(sync_time, 0)
124
 
124
 
125
 	fmt.Println(SyncTime)
125
 	fmt.Println(SyncTime)
126
 	// 第二步:获取时间内所有检验结果
126
 	// 第二步:获取时间内所有检验结果
127
 	stsyLis, _ := GetStsyLis(orgDb, SyncTime)
127
 	stsyLis, _ := GetStsyLis(orgDb, SyncTime)
128
 
128
 
129
 	if len(stsyLis) > 0 {
129
 	if len(stsyLis) > 0 {
130
-		for _,LisInfo := range stsyLis{
130
+		for _, LisInfo := range stsyLis {
131
 			brxm := LisInfo.Brxm
131
 			brxm := LisInfo.Brxm
132
 			// 根据姓名获取患者ID
132
 			// 根据姓名获取患者ID
133
-			patient,_ := GetUserInfoByName(org_id,brxm)
133
+			patient, _ := GetUserInfoByName(org_id, brxm)
134
 			if patient.ID > 0 {
134
 			if patient.ID > 0 {
135
 				project_id, _ := GetStsyProjectID(org_id, LisInfo.Instrument, LisInfo.Itemname)
135
 				project_id, _ := GetStsyProjectID(org_id, LisInfo.Instrument, LisInfo.Itemname)
136
 				item_id, _ := GetStsyItemID(org_id, LisInfo.Instrument, LisInfo.Itemname, project_id)
136
 				item_id, _ := GetStsyItemID(org_id, LisInfo.Instrument, LisInfo.Itemname, project_id)
147
 
147
 
148
 				recordTime, _ := time.ParseInLocation("2006-01-02 15:04:05", tempRecord, loc)
148
 				recordTime, _ := time.ParseInLocation("2006-01-02 15:04:05", tempRecord, loc)
149
 				recordTimeInt := recordTime.Unix()
149
 				recordTimeInt := recordTime.Unix()
150
-				recordTimeStr := time.Unix(recordTimeInt,0).Format(timeLayout)
150
+				recordTimeStr := time.Unix(recordTimeInt, 0).Format(timeLayout)
151
 
151
 
152
 				var total int
152
 				var total int
153
 				var RangeOptions string
153
 				var RangeOptions string
190
 					}
190
 					}
191
 				}
191
 				}
192
 				var itotal int
192
 				var itotal int
193
-				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, recordTimeInt, patient.ID).Find(&inspection).Count(&itotal).Error
193
+				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, recordTimeStr, patient.ID).Find(&inspection).Count(&itotal).Error
194
 				if itotal <= 0 {
194
 				if itotal <= 0 {
195
 					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
195
 					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
196
 					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
196
 					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
219
 			} else {
219
 			} else {
220
 				continue
220
 				continue
221
 			}
221
 			}
222
-		}				
222
+		}
223
 	}
223
 	}
224
 	var syncInfo models.MiddleSyncInfo
224
 	var syncInfo models.MiddleSyncInfo
225
 	syncInfo.OrgId = org_id
225
 	syncInfo.OrgId = org_id
251
 // 	return
251
 // 	return
252
 // }
252
 // }
253
 
253
 
254
-
255
 func SyncToStsytx() {
254
 func SyncToStsytx() {
256
 
255
 
257
 	utils.TraceLog("检验检查同步任务开始执行")
256
 	utils.TraceLog("检验检查同步任务开始执行")

+ 193 - 25
service/tscyyy_service.go View File

4
 	"IC/models"
4
 	"IC/models"
5
 	"IC/utils"
5
 	"IC/utils"
6
 	_ "IC/utils"
6
 	_ "IC/utils"
7
-	_"bytes"
7
+	_ "bytes"
8
 	"encoding/json"
8
 	"encoding/json"
9
 	_ "encoding/json"
9
 	_ "encoding/json"
10
-	_"encoding/xml"
11
-	_"fmt"
10
+	_ "encoding/xml"
12
 	_ "fmt"
11
 	_ "fmt"
13
 	"github.com/astaxie/beego/httplib"
12
 	"github.com/astaxie/beego/httplib"
14
 	_ "github.com/jinzhu/gorm"
13
 	_ "github.com/jinzhu/gorm"
18
 	"time"
17
 	"time"
19
 )
18
 )
20
 
19
 
21
-
22
 type tscylis struct {
20
 type tscylis struct {
23
 	HisUserId    string `json:"his_user_id"`
21
 	HisUserId    string `json:"his_user_id"`
24
 	PatientName  string `json:"patient_name"`
22
 	PatientName  string `json:"patient_name"`
25
-	ProjectId    string  `json:"project_id"`
23
+	ProjectId    string `json:"project_id"`
26
 	ProjectName  string `json:"project_name"`
24
 	ProjectName  string `json:"project_name"`
27
-	InspectDate  string  `json:"inspect_date"`
28
-	ItemId       string  `json:"item_id"`
25
+	InspectDate  string `json:"inspect_date"`
26
+	ItemId       string `json:"item_id"`
29
 	ItemName     string `json:"item_name"`
27
 	ItemName     string `json:"item_name"`
30
-	ItemType     string  `json:"item_type"`
28
+	ItemType     string `json:"item_type"`
31
 	ItemValue    string `json:"item_value"`
29
 	ItemValue    string `json:"item_value"`
32
 	RangeMin     string `json:"range_min"`
30
 	RangeMin     string `json:"range_min"`
33
 	RangeMax     string `json:"range_max"`
31
 	RangeMax     string `json:"range_max"`
34
 	RangeValue   string `json:"range_value"`
32
 	RangeValue   string `json:"range_value"`
35
 	RangeOptions string `json:"range_options"`
33
 	RangeOptions string `json:"range_options"`
36
 	Unit         string `json:"unit"`
34
 	Unit         string `json:"unit"`
37
-	State        string  `json:"state"`
38
-	CTime        string  `json:"c_time"`
39
-	UTime        string  `json:"u_time"`
35
+	State        string `json:"state"`
36
+	CTime        string `json:"c_time"`
37
+	UTime        string `json:"u_time"`
40
 }
38
 }
41
 
39
 
42
 type tscyLisResult struct {
40
 type tscyLisResult struct {
53
 	if err != nil {
51
 	if err != nil {
54
 		utils.InfoLog("err:%v", err)
52
 		utils.InfoLog("err:%v", err)
55
 	}
53
 	}
56
-	utils.InfoLog("str:%v", strs)
57
-
58
 	var checkJSON tscyLisResult
54
 	var checkJSON tscyLisResult
59
 	json.Unmarshal([]byte(strs), &checkJSON)
55
 	json.Unmarshal([]byte(strs), &checkJSON)
60
 	// utils.InfoLog("checkJSON:%v", checkJSON)
56
 	// utils.InfoLog("checkJSON:%v", checkJSON)
77
 	}
73
 	}
78
 }
74
 }
79
 
75
 
76
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
77
+func GetTscyVipProjectID(org_id int64, project_name string) (project_id int64, err error) {
78
+	var inspection_reference models.MiddleInspectionReference
79
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
80
+	if inspection_reference.ID > 0 {
81
+		return inspection_reference.ProjectId, err
82
+	} else {
83
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
84
+		if inspection_reference.ProjectId > 0 {
85
+			return inspection_reference.ProjectId + 1, err
86
+		} else {
87
+			return 1056201, err
88
+		}
89
+	}
90
+}
91
+
80
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
92
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
81
-func GetTscyItemID(org_id int64,project_name string,item_name string,project_id int64) (item_id int64 ,err error) {
93
+func GetTscyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
82
 	var inspection_reference models.MiddleInspectionReference
94
 	var inspection_reference models.MiddleInspectionReference
83
-	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
95
+	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
84
 	if inspection_reference.ID > 0 {
96
 	if inspection_reference.ID > 0 {
85
-		return inspection_reference.ItemId,err
97
+		return inspection_reference.ItemId, err
86
 	} else {
98
 	} else {
87
-		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
88
-		utils.InfoLog("inspection_reference: %v",inspection_reference)
99
+		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
100
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
89
 		if inspection_reference.ItemId > 0 {
101
 		if inspection_reference.ItemId > 0 {
90
-			return inspection_reference.ItemId + 1,err
102
+			return inspection_reference.ItemId + 1, err
91
 		} else {
103
 		} else {
92
-			return project_id * 100 + 1 ,err
104
+			return project_id*100 + 1, err
93
 		}
105
 		}
94
 	}
106
 	}
95
 }
107
 }
135
 						// 根据project_id和item_id 判断该项是否存在
147
 						// 根据project_id和item_id 判断该项是否存在
136
 						project_id := int64(0)
148
 						project_id := int64(0)
137
 						// if info.ProjectId > 0 {
149
 						// if info.ProjectId > 0 {
138
-							project_id, _ = GetTscyProjectID(org_id, info.ProjectName)
150
+						project_id, _ = GetTscyProjectID(org_id, info.ProjectName)
139
 						// } else {
151
 						// } else {
140
 						// 	continue
152
 						// 	continue
141
 						// }
153
 						// }
146
 						var inspection models.MiddleInspection
158
 						var inspection models.MiddleInspection
147
 						var inspection_reference models.MiddleInspectionReference
159
 						var inspection_reference models.MiddleInspectionReference
148
 
160
 
149
-						record_date,_ := strconv.ParseInt(info.InspectDate, 10, 64)
161
+						record_date, _ := strconv.ParseInt(info.InspectDate, 10, 64)
150
 
162
 
151
 						if record_date == 0 {
163
 						if record_date == 0 {
152
 							record_date = time.Now().Unix()
164
 							record_date = time.Now().Unix()
166
 						ItemType := info.ItemType
178
 						ItemType := info.ItemType
167
 						// Range := strings.Split(info.RangeValue, "-")
179
 						// Range := strings.Split(info.RangeValue, "-")
168
 						// if len(Range) > 1 {
180
 						// if len(Range) > 1 {
169
-							RangeMin = info.RangeMin
170
-							RangeMax = info.RangeMax
181
+						RangeMin = info.RangeMin
182
+						RangeMax = info.RangeMax
171
 						// 	ItemType = 1
183
 						// 	ItemType = 1
172
 						// } else {
184
 						// } else {
173
 						// 	ItemType = 2
185
 						// 	ItemType = 2
174
-							RangeOptions = info.RangeOptions
186
+						RangeOptions = info.RangeOptions
175
 						// }
187
 						// }
176
 
188
 
177
 						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
189
 						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
280
 	}
292
 	}
281
 	utils.SuccessLog("检验检查同步任务完成")
293
 	utils.SuccessLog("检验检查同步任务完成")
282
 }
294
 }
295
+
296
+// 唐山朝阳医院Vip区透析中心Lis同步
297
+func SyncTscyVipLis() (err error) {
298
+	org_id := int64(10562)
299
+	// 第一步:获取上一次同步的时间点
300
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
301
+	var sync_time int64
302
+	if syncLastInfo.ID > 0 {
303
+		sync_time = syncLastInfo.SyncTime
304
+	} else {
305
+		sync_time = 1651334400
306
+	}
307
+	// 第二步:获取所有患者的病历号
308
+
309
+	patientList, _ := GetPatientGzjhByOrgId(org_id)
310
+	if len(patientList) > 0 {
311
+		for _, patient := range patientList {
312
+			if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
313
+				// 上次同步时间转换为接口需要的格式
314
+				patient_id := patient.ID
315
+				utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
316
+				gzjhLis, _ := GetTscyLis(strconv.FormatInt(sync_time, 10), patient.IdCardNo)
317
+
318
+				if len(gzjhLis.Result) > 0 {
319
+					for _, info := range gzjhLis.Result {
320
+						// 根据project_id和item_id 判断该项是否存在
321
+						project_id := int64(0)
322
+						project_id, _ = GetTscyVipProjectID(org_id, info.ProjectName)
323
+
324
+						item_id, _ := GetTscyItemID(org_id, info.ProjectName, info.ItemName, project_id)
325
+
326
+						tx := writeMiddleDb.Begin()
327
+						var inspection models.MiddleInspection
328
+						var inspection_reference models.MiddleInspectionReference
329
+
330
+						record_date, _ := strconv.ParseInt(info.InspectDate, 10, 64)
331
+
332
+						if record_date == 0 {
333
+							record_date = time.Now().Unix()
334
+						}
335
+						inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
336
+						var total int
337
+						var RangeOptions string
338
+						var RangeMin string
339
+						var RangeMax string
340
+
341
+						// // 判断检查类型
342
+						ItemType := info.ItemType
343
+						RangeMin = info.RangeMin
344
+						RangeMax = info.RangeMax
345
+
346
+						RangeOptions = info.RangeOptions
347
+						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
348
+
349
+						if total <= 0 {
350
+							inspection_reference.OrgId = org_id
351
+							inspection_reference.ProjectName = info.ProjectName
352
+							inspection_reference.Project = info.ProjectName
353
+							inspection_reference.ProjectId = project_id
354
+							inspection_reference.ItemName = info.ItemName
355
+							inspection_reference.ItemNameAddition = info.ItemId
356
+							inspection_reference.ItemId = item_id
357
+							inspection_reference.RangeType, _ = strconv.Atoi(ItemType)
358
+							inspection_reference.RangeMin = RangeMin
359
+							inspection_reference.RangeMax = RangeMax
360
+							// inspection_reference.RangeValue = RangeValue
361
+							inspection_reference.RangeOptions = RangeOptions
362
+							inspection_reference.Unit = info.Unit
363
+							inspection_reference.Status = 1
364
+							inspection_reference.CreatedTime = time.Now().Unix()
365
+							inspection_reference.UpdatedTime = time.Now().Unix()
366
+							inspection_reference.InspectDate = inspect_date
367
+							inspection_reference.UTime = inspect_date
368
+							err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
369
+							if err != nil {
370
+								tx.Rollback()
371
+							}
372
+						}
373
+
374
+						var itotal int
375
+						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
376
+						if itotal <= 0 {
377
+							info.ItemValue = strings.Replace(info.ItemValue, "&gt;", ">", -1)
378
+							info.ItemValue = strings.Replace(info.ItemValue, "&lt;", "<", -1)
379
+							inspection.PatientId = patient_id
380
+							inspection.OrgId = org_id
381
+							inspection.ProjectId = project_id
382
+							inspection.ItemName = inspection_reference.ItemName
383
+							inspection.ProjectName = inspection_reference.ProjectName
384
+							inspection.InspectType, _ = strconv.Atoi(ItemType)
385
+							inspection.ItemId = item_id
386
+							inspection.InspectValue = info.ItemValue
387
+							inspection.InspectDate = inspect_date
388
+							inspection.RecordDate = record_date
389
+							// inspection.InspectTips = report.Resultstate
390
+							inspection.Status = 1
391
+							inspection.CreatedTime = time.Now().Unix()
392
+							inspection.UpdatedTime = time.Now().Unix()
393
+							inspection.UTime = inspect_date
394
+							inspection.HisUserId = strconv.FormatInt(patient_id, 10)
395
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
396
+							if err != nil {
397
+								tx.Rollback()
398
+							}
399
+						}
400
+
401
+						tx.Commit()
402
+					}
403
+				}
404
+			} else {
405
+				continue
406
+			}
407
+		}
408
+	}
409
+	var syncInfo models.MiddleSyncInfo
410
+	syncInfo.OrgId = org_id
411
+	syncInfo.SyncTime = time.Now().Unix()
412
+	syncInfo.SyncResultType = 1
413
+	syncInfo.SyncRsultRemark = "同步成功"
414
+	syncInfo.SyncTotalNum = 0
415
+	syncInfo.SyncSuccessNum = 0
416
+	syncInfo.SyncInfo = ""
417
+	syncInfo.CreateTime = time.Now().Unix()
418
+	syncInfo.UpdateTime = time.Now().Unix()
419
+
420
+	cwderr := CreateSyncInfo(&syncInfo)
421
+	if cwderr != nil {
422
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
423
+		return
424
+	}
425
+	SyncToTscyVip()
426
+	return
427
+}
428
+
429
+func SyncToTscyVip() {
430
+	utils.TraceLog("检验检查同步任务开始执行")
431
+	org_id := int64(10562)
432
+
433
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
434
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
435
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
436
+
437
+	// 第二步:将数据同步到业务库
438
+	if len(inspection_references) > 0 {
439
+		for _, inspection_reference := range inspection_references {
440
+			SyncInspectionReference(&inspection_reference)
441
+		}
442
+	}
443
+
444
+	if len(inspections) > 0 {
445
+		for _, inspection := range inspections {
446
+			SyncInspection(&inspection)
447
+		}
448
+	}
449
+	utils.SuccessLog("检验检查同步任务完成")
450
+}