陈少旭 1 gadu atpakaļ
vecāks
revīzija
244ce2f95c

+ 1 - 1
controllers/lis.go Parādīt failu

@@ -39,7 +39,7 @@ func (c *LisController) SyncTest() {
39 39
 	// 获取备份库里所有的医嘱信息
40 40
 	// service.EmrBloodDiaylOrder()
41 41
 	// service.EmrBloodDiaylDetail()
42
-	service.SyncScpaLis()
42
+	//service.SyncScpaLis()
43 43
 	c.ServeSuccessJSON(map[string]interface{}{
44 44
 		"resultList": "12345",
45 45
 	})

+ 4 - 1
main.go Parādīt failu

@@ -15,11 +15,14 @@ func init() {
15 15
 }
16 16
 
17 17
 func main() {
18
-	service.BeginAutoSyncLis()
18
+	//service.BeginAutoSyncLis()
19 19
 	//service.GetDataInsertDB(10138)
20 20
 	//service.GetResultDataInsertDB(10138)
21 21
 	// service.GetSHResultDataInsertDB(10215)
22 22
 	// service.Synctfyz()
23 23
 	// service.GetSHResultDataInsertDB(10215)
24
+
25
+	service.SyncSYData2(10191)
26
+	//service.UploadSYData(10191)
24 27
 	beego.Run()
25 28
 }

+ 1 - 0
models/exists_report.go Parādīt failu

@@ -0,0 +1 @@
1
+package models

+ 77 - 0
models/jy_apply.go Parādīt failu

@@ -0,0 +1,77 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type JYApplyEnvelope struct {
6
+	XMLName xml.Name    `xml:"soap:Envelope"`
7
+	Soap    string      `xml:"xmlns:soap,attr"`
8
+	Xsi     string      `xml:"xmlns:xsi,attr"`
9
+	Xsd     string      `xml:"xmlns:xsd,attr"`
10
+	Body    JYApplyBody `xml:"soap:Body"`
11
+}
12
+
13
+type JYApplyBody struct {
14
+	XMLName         xml.Name        `xml:"soap:Body"`
15
+	InspectApplyReq InspectApplyReq `xml:"InspectApplyByInstituteItemCode"`
16
+}
17
+
18
+type InspectApplyReq struct {
19
+	XMLName         xml.Name `xml:"http://tempuri.org/ InspectApplyByInstituteItemCode"`
20
+	ApiKey          string   `xml:"apiKey"`
21
+	Apply           JYApply  `xml:"apply"`
22
+	ApplyDetailList struct {
23
+		CustomerApplyDetail []CustomerApplyDetail `xml:"CustomerApplyDetail"`
24
+	} `xml:"applyDetailList"`
25
+	//ApplyDetailList []JYApplyDetail    `xml:"applyDetailList>JYApplyDetail"`
26
+	ApplyAdditional *JYApplyAdditional `xml:"applyAdditional,omitempty"`
27
+}
28
+
29
+type EnvelopeFour struct {
30
+	XMLName xml.Name         `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
31
+	Body    EnvelopeBodyFour `xml:"Body"`
32
+}
33
+
34
+type EnvelopeBodyFour struct {
35
+	InspectApplyByInstituteItemCodeResponse InspectApplyByInstituteItemCodeResponse `xml:"InspectApplyByInstituteItemCodeResponse"`
36
+}
37
+
38
+type InspectApplyByInstituteItemCodeResponse struct {
39
+	XMLName      xml.Name `xml:"http://tempuri.org/ InspectApplyByInstituteItemCodeResponse"`
40
+	InspectApply string   `xml:"InspectApplyByInstituteItemCodeResult"`
41
+}
42
+
43
+type InspectApplyData struct {
44
+	Res           int           `json:"Res"`
45
+	Error         string        `json:"Error"`
46
+	JYApplyResult JYApplyResult `json:"Data"`
47
+}
48
+
49
+type JYApply struct {
50
+	XMLName      xml.Name `xml:"apply"`
51
+	PatientName  string   `xml:"PatientName"`
52
+	Sex          string   `xml:"Sex"`
53
+	Age          string   `xml:"Age"`
54
+	AgeUnit      string   `xml:"AgeUnit"`
55
+	RegisterCode string   `xml:"RegisterCode"`
56
+	Diagnosis    string   `xml:"Diagnosis"`
57
+	Ward         string   `xml:"Ward"`
58
+	BedCode      string   `xml:"BedCode"`
59
+	SendDoctor   string   `xml:"SendDoctor"`
60
+	PatientType  int      `xml:"PatientType"`
61
+	PatientPhone string   `xml:"PatientPhone"`
62
+}
63
+
64
+type CustomerApplyDetail struct {
65
+	RowIndex               int64  `xml:"RowIndex"`
66
+	CustomerChargeItemCode string `xml:"CustomerChargeItemCode"`
67
+	TakeSampleTime         string `xml:"TakeSampleTime"`
68
+	Barcode                string `xml:"Barcode"`
69
+	CustomerBarcode        string `xml:"CustomerBarcode"`
70
+	Comment                string `xml:"Comment"`
71
+}
72
+type JYApplyResult struct {
73
+	ApplyCode   string  `xml:"ApplyCode"`
74
+	TotalAmount float64 `xml:"TotalAmount"`
75
+}
76
+type JYApplyAdditional struct {
77
+}

+ 44 - 14
models/lis_model.go Parādīt failu

@@ -140,6 +140,8 @@ type Patients struct {
140 140
 	ContactName     string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
141 141
 	Gender          int64  `gorm:"column:gender" json:"gender" form:"gender"`
142 142
 	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"`
143 145
 }
144 146
 
145 147
 func (Patients) TableName() string {
@@ -207,20 +209,22 @@ func (TBLISItem) TableName() string {
207 209
 }
208 210
 
209 211
 type Inspection struct {
210
-	ID           int64  `gorm:"column:id" json:"id" form:"id"`
211
-	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
212
-	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
213
-	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
214
-	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
215
-	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
216
-	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
217
-	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
218
-	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
219
-	InspectTips  string `gorm:"column:inspect_tips" json:"inspect_tips" form:"inspect_tips"`
220
-	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
221
-	Status       int64  `gorm:"column:status" json:"status" form:"status"`
222
-	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
223
-	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
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"`
224 228
 }
225 229
 
226 230
 func (Inspection) TableName() string {
@@ -331,6 +335,9 @@ type MiddleInspectionReference struct {
331 335
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
332 336
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
333 337
 	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"`
334 341
 }
335 342
 
336 343
 func (MiddleInspectionReference) TableName() string {
@@ -447,3 +454,26 @@ type VMItemProjectList struct {
447 454
 func (VMItemProjectList) TableName() string {
448 455
 	return "xt_his_project_list"
449 456
 }
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
+}

+ 70 - 0
models/report_list.go Parādīt failu

@@ -0,0 +1,70 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type ReportListEnvelope struct {
6
+	XMLName xml.Name       `xml:"soap:Envelope"`
7
+	Soap    string         `xml:"xmlns:soap,attr"`
8
+	Xsi     string         `xml:"xmlns:xsi,attr"`
9
+	Xsd     string         `xml:"xmlns:xsd,attr"`
10
+	Body    ReportListBody `xml:"soap:Body"`
11
+}
12
+
13
+type ReportListBody struct {
14
+	XMLName      xml.Name     `xml:"soap:Body"`
15
+	GetReportReq GetReportReq `xml:"GetAllSampleList"`
16
+}
17
+
18
+type GetReportReq struct {
19
+	XMLName       xml.Name `xml:"http://tempuri.org/ GetAllSampleList"`
20
+	Key           string   `xml:"key"`
21
+	BeginDateTime string   `xml:"BeginDateTime"`
22
+	EndDateTime   string   `xml:"EndDateTime"`
23
+	DateType      int      `xml:"DateType"`
24
+	PrintState    int      `xml:"PrintState"`
25
+}
26
+
27
+type EnvelopeTwo struct {
28
+	XMLName xml.Name     `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
29
+	Body    EnvelopeBody `xml:"Body"`
30
+}
31
+
32
+type EnvelopeBody struct {
33
+	GetAllSampleListResponse GetAllSampleListResponse `xml:"GetAllSampleListResponse"`
34
+}
35
+
36
+type GetAllSampleListResponse struct {
37
+	XMLName                xml.Name `xml:"http://tempuri.org/ GetAllSampleListResponse"`
38
+	GetAllSampleListResult string   `xml:"GetAllSampleListResult"`
39
+}
40
+
41
+type ReportData struct {
42
+	Res                    int                      `json:"Res"`
43
+	Error                  string                   `json:"Error"`
44
+	GPReportListResultData []GPReportListResultData `json:"Data"`
45
+}
46
+
47
+type GPReportListResultData struct {
48
+	RecordID           string `json:"RecordID"`
49
+	PatientName        string `json:"PatientName"`
50
+	Sex                string `json:"Sex"`
51
+	Age                int    `json:"Age"`
52
+	AgeUnit            string `json:"AgeUnit"`
53
+	OfficeName         string `json:"OfficeName"`
54
+	BedCode            string `json:"BedCode"`
55
+	Barcode            string `json:"Barcode"`
56
+	CustomerBarcode    string `json:"CustomerBarcode"`
57
+	SampleCode         string `json:"SampleCode"`
58
+	SampleCategory     string `json:"SampleCategory"`
59
+	SampleDescription  string `json:"SampleDescription"`
60
+	Diagnostics        string `json:"Diagnostics"`
61
+	TakeSampleDateTime string `json:"TakeSampleDateTime"`
62
+	ReceiveDateTime    string `json:"ReceiveDateTime"`
63
+	AuditDateTime      string `json:"AuditDateTime"`
64
+	InspectDate        string `json:"InspectDate"`
65
+	SendDoctor         string `json:"SendDoctor"`
66
+	InspectDoctorName  string `json:"InspectDoctorName"`
67
+	AuditorName        string `json:"AuditorName"`
68
+	Instrument         string `json:"Instrument"`
69
+	Comment            string `json:"Comment"`
70
+}

+ 55 - 0
models/report_result.go Parādīt failu

@@ -0,0 +1,55 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type ReportResultEnvelope struct {
6
+	XMLName xml.Name         `xml:"soap:Envelope"`
7
+	Soap    string           `xml:"xmlns:soap,attr"`
8
+	Xsi     string           `xml:"xmlns:xsi,attr"`
9
+	Xsd     string           `xml:"xmlns:xsd,attr"`
10
+	Body    ReportResultBody `xml:"soap:Body"`
11
+}
12
+
13
+type ReportResultBody struct {
14
+	XMLName            xml.Name           `xml:"soap:Body"`
15
+	GetReportResultReq GetReportResultReq `xml:"GetJSONReportItemListByCustomerBarocde"`
16
+}
17
+
18
+type GetReportResultReq struct {
19
+	XMLName         xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByCustomerBarocde"`
20
+	Key             string   `xml:"key"`
21
+	CustomerBarCode string   `xml:"CustomerBarCode"`
22
+}
23
+
24
+type EnvelopeThree struct {
25
+	XMLName xml.Name          `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
26
+	Body    EnvelopeBodyThree `xml:"Body"`
27
+}
28
+
29
+type EnvelopeBodyThree struct {
30
+	GetJSONReportItemListByCustomerBarocdeResponse GetJSONReportItemListByCustomerBarocdeResponse `xml:"GetJSONReportItemListByCustomerBarocdeResponse"`
31
+}
32
+
33
+type GetJSONReportItemListByCustomerBarocdeResponse struct {
34
+	XMLName                                      xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByCustomerBarocdeResponse"`
35
+	GetJSONReportItemListByCustomerBarocdeResult string   `xml:"GetJSONReportItemListByCustomerBarocdeResult"`
36
+}
37
+
38
+type ReportResultData struct {
39
+	Res           int             `json:"Res"`
40
+	Error         string          `json:"Error"`
41
+	InspectResult []InspectResult `json:"Data"`
42
+}
43
+
44
+type InspectResult struct {
45
+	ChargeItemName string `json:"ChargeItemName"`
46
+	InspectionName string `json:"InspectionName"`
47
+	InspectionCode string `json:"InspectionCode"`
48
+	Result         string `json:"Result"`
49
+	Reference      string `json:"Reference"`
50
+	Barcode        string `json:"Barcode"`
51
+	Unit           string `json:"Unit"`
52
+	Flag           string `json:"Flag"`
53
+	intFlag        int    `json:"intFlag"`
54
+	ListResult     GPReportListResultData
55
+}

+ 55 - 0
models/report_result_two.go Parādīt failu

@@ -0,0 +1,55 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type GPReportResultEnvelope struct {
6
+	XMLName xml.Name           `xml:"soap:Envelope"`
7
+	Soap    string             `xml:"xmlns:soap,attr"`
8
+	Xsi     string             `xml:"xmlns:xsi,attr"`
9
+	Xsd     string             `xml:"xmlns:xsd,attr"`
10
+	Body    GPReportResultBody `xml:"soap:Body"`
11
+}
12
+
13
+type GPReportResultBody struct {
14
+	XMLName            xml.Name             `xml:"soap:Body"`
15
+	GetReportResultReq GetGPReportResultReq `xml:"GetJSONReportItemListByGPBarocde"`
16
+}
17
+
18
+type GetGPReportResultReq struct {
19
+	XMLName   xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByGPBarocde"`
20
+	Key       string   `xml:"key"`
21
+	GPBarCode string   `xml:"GPBarCode"`
22
+}
23
+
24
+type EnvelopeFive struct {
25
+	XMLName xml.Name         `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
26
+	Body    EnvelopeBodyFive `xml:"Body"`
27
+}
28
+
29
+type EnvelopeBodyFive struct {
30
+	GetJSONReportItemListByGPBarocdeResponse GetJSONReportItemListByGPBarocdeResponse `xml:"GetJSONReportItemListByGPBarocdeResponse"`
31
+}
32
+
33
+type GetJSONReportItemListByGPBarocdeResponse struct {
34
+	XMLName                                xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByGPBarocdeResponse"`
35
+	GetJSONReportItemListByGPBarocdeResult string   `xml:"GetJSONReportItemListByGPBarocdeResult"`
36
+}
37
+
38
+type ReportResultDataFive struct {
39
+	Res           int                 `json:"Res"`
40
+	Error         string              `json:"Error"`
41
+	InspectResult []InspectResultFive `json:"Data"`
42
+}
43
+
44
+type InspectResultFive struct {
45
+	ChargeItemName string `json:"ChargeItemName"`
46
+	InspectionName string `json:"InspectionName"`
47
+	InspectionCode string `json:"InspectionCode"`
48
+	Result         string `json:"Result"`
49
+	Reference      string `json:"Reference"`
50
+	Barcode        string `json:"Barcode"`
51
+	Unit           string `json:"Unit"`
52
+	Flag           string `json:"Flag"`
53
+	IntFlag        int    `json:"intFlag"`
54
+	ListResult     GPReportListResultData
55
+}

+ 1 - 1
routers/router.go Parādīt failu

@@ -28,6 +28,6 @@ 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")
31
+	//beego.Router("/api/test", &controllers.LisController{}, "get:SyncScpaLis")
32 32
 
33 33
 }

+ 219 - 83
service/bl_service.go Parādīt failu

@@ -146,23 +146,25 @@ func (CmLisitems) TableName() string {
146 146
 }
147 147
 
148 148
 type HisLabelPrintInfo struct {
149
-	ID                     int64                  `gorm:"column:id" json:"id" form:"id"`
150
-	PatientId              int64                  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
151
-	Number                 string                 `gorm:"column:number" json:"number" form:"number"`
152
-	Ctime                  int64                  `gorm:"column:ctime" json:"ctime" form:"ctime"`
153
-	Mtime                  int64                  `gorm:"column:mtime" json:"mtime" form:"mtime"`
154
-	DoctorId               int64                  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
155
-	Status                 int64                  `gorm:"column:status" json:"status" form:"status"`
156
-	ProjectName            string                 `gorm:"column:project_name" json:"project_name" form:"project_name"`
157
-	ProjectId              int64                  `gorm:"column:project_id" json:"project_id" form:"project_id"`
158
-	IsPrint                int64                  `gorm:"column:is_print" json:"is_print" form:"is_print"`
159
-	RecordDate             int64                  `gorm:"column:record_date" json:"record_date" form:"record_date"`
160
-	ItemId                 int64                  `gorm:"column:item_id" json:"item_id" form:"item_id"`
161
-	PProjectId             int64                  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
162
-	UserOrgId              int64                  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
163
-	DoctorName             string                 `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
164
-	PatientName            string                 `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
165
-	FeedetlSn              string                 `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
149
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
150
+	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
151
+	Number      string `gorm:"column:number" json:"number" form:"number"`
152
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
153
+	Mtime       int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
154
+	DoctorId    int64  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
155
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
156
+	ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
157
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
158
+	IsPrint     int64  `gorm:"column:is_print" json:"is_print" form:"is_print"`
159
+	RecordDate  int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
160
+	ItemId      int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
161
+	PProjectId  int64  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
162
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
163
+	DoctorName  string `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
164
+	PatientName string `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
165
+	FeedetlSn   string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
166
+	Phone       string `gorm:"column:phone" json:"phone" form:"phone"`
167
+
166 168
 	PrescriptionId         int64                  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
167 169
 	HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
168 170
 	Patient                models.Patients        `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
@@ -216,14 +218,15 @@ func (CmResult) TableName() string {
216 218
 }
217 219
 
218 220
 type LisSyncResultStatusInfo struct {
219
-	ID         int64 `gorm:"column:id" json:"id" form:"id"`
220
-	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
221
-	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
222
-	Status     int64 `gorm:"column:status" json:"status" form:"status"`
223
-	LastId     int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
224
-	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
225
-	IsResult   int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
226
-	ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
221
+	ID            int64  `gorm:"column:id" json:"id" form:"id"`
222
+	Ctime         int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
223
+	Mtime         int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
224
+	Status        int64  `gorm:"column:status" json:"status" form:"status"`
225
+	LastId        int64  `gorm:"column:last_id" json:"last_id" form:"last_id"`
226
+	OrgId         int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
227
+	IsResult      int64  `gorm:"column:is_result" json:"is_result" form:"is_result"`
228
+	ResultDate    int64  `gorm:"column:result_date" json:"result_date" form:"result_date"`
229
+	GpSyncEndDate string `gorm:"column:gp_sync_end_date" json:"gp_sync_end_date" form:"gp_sync_end_date"`
227 230
 }
228 231
 
229 232
 func (LisSyncResultStatusInfo) TableName() string {
@@ -293,7 +296,7 @@ func GetLisResultDataByRecord(org_id int64) (list []*CmResult, err error) {
293 296
 	return
294 297
 }
295 298
 
296
-//插入中间件逻辑
299
+// 插入中间件逻辑
297 300
 func GetDataInsertDB(org_id int64) {
298 301
 	record, _ := GetLastSyncRecord(org_id)
299 302
 	if record.ID == 0 {
@@ -540,7 +543,7 @@ func GetDataInsertDB(org_id int64) {
540 543
 	}
541 544
 }
542 545
 
543
-//获取lis返回检验检查结果数据
546
+// 获取lis返回检验检查结果数据
544 547
 func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
545 548
 	record, _ := GetLastSyncResultRecord(org_id)
546 549
 	if record.ID == 0 {
@@ -551,8 +554,9 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
551 554
 			//插入到系统检验检查数据
552 555
 			for _, item := range list {
553 556
 				project_id := int64(0)
557
+				xt_project_id := int64(0)
554 558
 				if len(item.Barcode) > 0 {
555
-					project_id, _ = GetBljhProjectID(org_id, item.Groupname)
559
+					project_id, xt_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
556 560
 				} else {
557 561
 					continue
558 562
 				}
@@ -565,7 +569,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
565 569
 					continue
566 570
 				}
567 571
 
568
-				item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
572
+				item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
569 573
 
570 574
 				tx := writeMiddleDb.Begin()
571 575
 				var inspection models.MiddleInspection
@@ -590,7 +594,6 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
590 594
 				var ItemType int
591 595
 				if strings.Contains(item.Refrange, "-") {
592 596
 					ItemType = 1
593
-
594 597
 				} else {
595 598
 					ItemType = 2
596 599
 
@@ -604,60 +607,123 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
604 607
 					RangeOptions = item.Refrange
605 608
 				}
606 609
 
607
-				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
608
-				if inspection_reference.ID > 0 {
609
-					ItemType = inspection_reference.RangeType
610
-				}
611
-				if total <= 0 {
612
-					inspection_reference.OrgId = org_id
613
-					inspection_reference.ProjectName = item.Groupname
614
-					inspection_reference.Project = item.Groupname
615
-					inspection_reference.ProjectId = project_id
616
-					inspection_reference.ItemName = item.Itemname
617
-					inspection_reference.ItemNameAddition = item.Barcode
618
-					inspection_reference.ItemId = item_id
619
-					inspection_reference.RangeType = ItemType
620
-					inspection_reference.RangeMin = RangeMin
621
-					inspection_reference.RangeMax = RangeMax
622
-					inspection_reference.RangeOptions = RangeOptions
623
-					inspection_reference.Unit = item.Unit
624
-					inspection_reference.Status = 1
625
-					inspection_reference.CreatedTime = time.Now().Unix()
626
-					inspection_reference.UpdatedTime = time.Now().Unix()
627
-					inspection_reference.InspectDate = inspect_date
628
-					inspection_reference.UTime = inspect_date
629
-					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
630
-					if err != nil {
631
-						tx.Rollback()
610
+				if xt_project_id > 0 && sys_item_id > 0 {
611
+					err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and status = 1", org_id, xt_project_id, sys_item_id).Find(&inspection_reference).Count(&total).Error
612
+					if inspection_reference.ID > 0 {
613
+						ItemType = inspection_reference.RangeType
614
+					}
615
+					if total <= 0 {
616
+						inspection_reference.OrgId = org_id
617
+						inspection_reference.ProjectName = item.Groupname
618
+						inspection_reference.Project = item.Groupname
619
+						inspection_reference.ProjectId = project_id
620
+						inspection_reference.ItemName = item.Itemname
621
+						inspection_reference.ItemNameAddition = item.Barcode
622
+						inspection_reference.ItemId = item_id
623
+						inspection_reference.RangeType = ItemType
624
+						inspection_reference.RangeMin = RangeMin
625
+						inspection_reference.RangeMax = RangeMax
626
+						inspection_reference.RangeOptions = RangeOptions
627
+						inspection_reference.Unit = item.Unit
628
+						inspection_reference.Status = 1
629
+						inspection_reference.CreatedTime = time.Now().Unix()
630
+						inspection_reference.UpdatedTime = time.Now().Unix()
631
+						inspection_reference.InspectDate = inspect_date
632
+						inspection_reference.UTime = inspect_date
633
+						err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
634
+						if err != nil {
635
+							tx.Rollback()
636
+						}
632 637
 					}
633
-				}
634 638
 
635
-				var itotal int
636
-				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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
637
-				if itotal <= 0 {
638
-					//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
639
-					//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
640
-					inspection.PatientId = printInfo.PatientId
641
-					inspection.OrgId = org_id
642
-					inspection.ProjectId = project_id
643
-					inspection.ItemName = inspection_reference.ItemName
644
-					inspection.ProjectName = inspection_reference.ProjectName
645
-					inspection.InspectType = ItemType
646
-					inspection.ItemId = item_id
647
-					inspection.InspectValue = item.Result
648
-					inspection.InspectDate = inspect_date
649
-					inspection.RecordDate = record_date.Unix()
650
-					inspection.Status = 1
651
-					inspection.CreatedTime = time.Now().Unix()
652
-					inspection.UpdatedTime = time.Now().Unix()
653
-					inspection.UTime = inspect_date
654
-					inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
655
-					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
656
-					if err != nil {
657
-						tx.Rollback()
639
+				} else {
640
+					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
641
+					if inspection_reference.ID > 0 {
642
+						ItemType = inspection_reference.RangeType
658 643
 					}
644
+					if total <= 0 {
645
+						inspection_reference.OrgId = org_id
646
+						inspection_reference.ProjectName = item.Groupname
647
+						inspection_reference.Project = item.Groupname
648
+						inspection_reference.ProjectId = project_id
649
+						inspection_reference.ItemName = item.Itemname
650
+						inspection_reference.ItemNameAddition = item.Barcode
651
+						inspection_reference.ItemId = item_id
652
+						inspection_reference.RangeType = ItemType
653
+						inspection_reference.RangeMin = RangeMin
654
+						inspection_reference.RangeMax = RangeMax
655
+						inspection_reference.RangeOptions = RangeOptions
656
+						inspection_reference.Unit = item.Unit
657
+						inspection_reference.Status = 1
658
+						inspection_reference.CreatedTime = time.Now().Unix()
659
+						inspection_reference.UpdatedTime = time.Now().Unix()
660
+						inspection_reference.InspectDate = inspect_date
661
+						inspection_reference.UTime = inspect_date
662
+						err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
663
+						if err != nil {
664
+							tx.Rollback()
665
+						}
666
+					}
667
+
659 668
 				}
660 669
 
670
+				if xt_project_id > 0 && sys_item_id > 0 {
671
+					var itotal int
672
+					err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, xt_project_id, sys_item_id, record_date.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
673
+					if itotal <= 0 {
674
+						//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
675
+						//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
676
+						inspection.PatientId = printInfo.PatientId
677
+						inspection.OrgId = org_id
678
+						inspection.ProjectId = project_id
679
+						inspection.ItemName = inspection_reference.ItemName
680
+						inspection.ProjectName = inspection_reference.ProjectName
681
+						inspection.InspectType = ItemType
682
+						inspection.ItemId = item_id
683
+
684
+						inspection.InspectValue = item.Result
685
+						inspection.InspectDate = inspect_date
686
+						inspection.RecordDate = record_date.Unix()
687
+						inspection.Status = 1
688
+						inspection.CreatedTime = time.Now().Unix()
689
+						inspection.UpdatedTime = time.Now().Unix()
690
+						inspection.UTime = inspect_date
691
+						inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
692
+						err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
693
+						if err != nil {
694
+							tx.Rollback()
695
+						}
696
+					}
697
+
698
+				} else {
699
+					var itotal int
700
+					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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
701
+					if itotal <= 0 {
702
+						//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
703
+						//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
704
+						inspection.PatientId = printInfo.PatientId
705
+						inspection.OrgId = org_id
706
+						inspection.ProjectId = project_id
707
+						inspection.ItemName = inspection_reference.ItemName
708
+						inspection.ProjectName = inspection_reference.ProjectName
709
+						inspection.InspectType = ItemType
710
+						inspection.ItemId = item_id
711
+
712
+						inspection.InspectValue = item.Result
713
+						inspection.InspectDate = inspect_date
714
+						inspection.RecordDate = record_date.Unix()
715
+						inspection.Status = 1
716
+						inspection.CreatedTime = time.Now().Unix()
717
+						inspection.UpdatedTime = time.Now().Unix()
718
+						inspection.UTime = inspect_date
719
+						inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
720
+						err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
721
+						if err != nil {
722
+							tx.Rollback()
723
+						}
724
+					}
725
+
726
+				}
661 727
 				tx.Commit()
662 728
 
663 729
 			}
@@ -686,13 +752,15 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
686 752
 				//插入到系统检验检查数据
687 753
 				for _, item := range list {
688 754
 					project_id := int64(0)
755
+					sys_project_id := int64(0)
756
+
689 757
 					if len(item.Barcode) > 0 {
690
-						project_id, _ = GetBljhProjectID(org_id, item.Groupname)
758
+						project_id, sys_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
691 759
 					} else {
692 760
 						continue
693 761
 					}
694 762
 					printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
695
-					item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
763
+					item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
696 764
 
697 765
 					tx := writeMiddleDb.Begin()
698 766
 					var inspection models.MiddleInspection
@@ -731,7 +799,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
731 799
 						RangeOptions = item.Refrange
732 800
 					}
733 801
 
734
-					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
802
+					err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
735 803
 					if inspection_reference.ID > 0 {
736 804
 						ItemType = inspection_reference.RangeType
737 805
 					}
@@ -783,6 +851,64 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
783 851
 						}
784 852
 					}
785 853
 
854
+					if sys_project_id > 0 && sys_item_id > 0 {
855
+						var itotal int
856
+						err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, sys_item_id, record_date.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
857
+						if itotal <= 0 {
858
+							//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
859
+							//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
860
+							inspection.PatientId = printInfo.PatientId
861
+							inspection.OrgId = org_id
862
+							inspection.ProjectId = project_id
863
+							inspection.ItemName = inspection_reference.ItemName
864
+							inspection.ProjectName = inspection_reference.ProjectName
865
+							inspection.InspectType = ItemType
866
+							inspection.ItemId = item_id
867
+
868
+							inspection.InspectValue = item.Result
869
+							inspection.InspectDate = inspect_date
870
+							inspection.RecordDate = record_date.Unix()
871
+							inspection.Status = 1
872
+							inspection.CreatedTime = time.Now().Unix()
873
+							inspection.UpdatedTime = time.Now().Unix()
874
+							inspection.UTime = inspect_date
875
+							inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
876
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
877
+							if err != nil {
878
+								tx.Rollback()
879
+							}
880
+						}
881
+
882
+					} else {
883
+						var itotal int
884
+						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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
885
+						if itotal <= 0 {
886
+							//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
887
+							//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
888
+							inspection.PatientId = printInfo.PatientId
889
+							inspection.OrgId = org_id
890
+							inspection.ProjectId = project_id
891
+							inspection.ItemName = inspection_reference.ItemName
892
+							inspection.ProjectName = inspection_reference.ProjectName
893
+							inspection.InspectType = ItemType
894
+							inspection.ItemId = item_id
895
+
896
+							inspection.InspectValue = item.Result
897
+							inspection.InspectDate = inspect_date
898
+							inspection.RecordDate = record_date.Unix()
899
+							inspection.Status = 1
900
+							inspection.CreatedTime = time.Now().Unix()
901
+							inspection.UpdatedTime = time.Now().Unix()
902
+							inspection.UTime = inspect_date
903
+							inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
904
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
905
+							if err != nil {
906
+								tx.Rollback()
907
+							}
908
+						}
909
+
910
+					}
911
+
786 912
 					tx.Commit()
787 913
 
788 914
 				}
@@ -811,7 +937,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
811 937
 	// 第二步:将数据同步到业务库
812 938
 	if len(inspection_references) > 0 {
813 939
 		for _, inspection_reference := range inspection_references {
814
-			SyncInspectionReference(&inspection_reference)
940
+			SyncInspectionReferenceTwo(&inspection_reference)
815 941
 		}
816 942
 	}
817 943
 
@@ -1024,3 +1150,13 @@ func GetPatientsInfoByIDCardNo(id_card_no string, org_id int64) (info models.Pat
1024 1150
 	err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, org_id).First(&info).Error
1025 1151
 	return
1026 1152
 }
1153
+
1154
+func GetAllLisDataFor10191(org_id int64) (list []models.HisLabelPrintStatusInfo, err error) {
1155
+	err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1  and apply_code = ''", org_id).Find(&list).Error
1156
+	return
1157
+}
1158
+
1159
+func GetAllLisDataFor10191LastId(org_id int64, last_id int64) (list []*models.HisLabelPrintStatusInfo, err error) {
1160
+	err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1 and is_print = 1 and id > ?", org_id, last_id).Find(&list).Error
1161
+	return
1162
+}

+ 40 - 41
service/cron.go Parādīt failu

@@ -6,7 +6,6 @@ import (
6 6
 	"encoding/json"
7 7
 	_ "fmt"
8 8
 	_ "github.com/jinzhu/gorm"
9
-	"github.com/robfig/cron"
10 9
 	_ "strings"
11 10
 	"time"
12 11
 )
@@ -18,40 +17,40 @@ func init() {
18 17
 
19 18
 }
20 19
 
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
-		SyncScpaLis()
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
-}
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
+//}
55 54
 
56 55
 func AutoSyncLis() {
57 56
 	utils.TraceLog("检验检查任务开始执行")
@@ -127,7 +126,7 @@ func AutoSyncLis() {
127 126
 				}
128 127
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
129 128
 				continue
130
-			} 
129
+			}
131 130
 
132 131
 			// 第四部:将同步过来的数据插入到中间库对应的表
133 132
 			syncSuccessNum := 0
@@ -194,11 +193,11 @@ func SyncToBase() {
194 193
 	utils.SuccessLog("检验检查同步任务完成")
195 194
 }
196 195
 
197
-// func SyncSZblLis() {
198
-// 	utils.TraceLog("检验检查同步任务开始执行")
199
-// 	org_id := int64(10138)
200
-// 	GetDataInsertDB(org_id)
201
-// }
196
+func SyncSZblLis() {
197
+	utils.TraceLog("检验检查同步任务开始执行")
198
+	org_id := int64(10138)
199
+	GetDataInsertDB(org_id)
200
+}
202 201
 
203 202
 // func SyncSZblLisResult() {
204 203
 // 	utils.TraceLog("获取检验检查结果任务开始执行")

+ 89 - 49
service/lis_service.go Parādīt failu

@@ -3,28 +3,28 @@ package service
3 3
 import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6
-	_"strconv"
6
+	_ "IC/utils"
7
+	_ "fmt"
8
+	_ "github.com/jinzhu/gorm"
9
+	_ "strconv"
7 10
 	"strings"
8 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 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,7 +64,46 @@ 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
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 107
 	if total <= 0 {
69 108
 		inspection_reference.OrgId = data.OrgId
70 109
 		inspection_reference.ProjectName = data.ProjectName
@@ -104,7 +143,7 @@ func SyncInspection(data *models.MiddleInspection) error {
104 143
 	tx := writeDb.Begin()
105 144
 	var inspection models.Inspection
106 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.InspectDate).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.InspectDate).Find(&inspection).Count(&total).Error
108 147
 	if total <= 0 {
109 148
 		inspection.OrgId = data.OrgId
110 149
 		inspection.PatientId = data.PatientId
@@ -119,7 +158,9 @@ func SyncInspection(data *models.MiddleInspection) error {
119 158
 		inspection.InspectDate = data.RecordDate
120 159
 		inspection.Status = 1
121 160
 		inspection.CreatedTime = time.Now().Unix()
122
-		inspection.UpdatedTime = time.Now().Unix()
161
+		//inspection.ReferenceProjectId = data.
162
+		//inspection.UpdatedTime = time.Now().Unix()
163
+		//inspection.ReferenceItemId = data.
123 164
 
124 165
 		err := tx.Model(&models.Inspection{}).Create(&inspection).Error
125 166
 		if err != nil {
@@ -139,13 +180,13 @@ func SyncInspection(data *models.MiddleInspection) error {
139 180
 }
140 181
 
141 182
 // 跟进org_id获取未同步的检验检查选项信息
142
-func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference,err error) {
183
+func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference, err error) {
143 184
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&InspectionReferences).Error
144 185
 	return
145 186
 }
146 187
 
147 188
 // 跟进org_id获取未同步的检验检查信息
148
-func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection,err error) {
189
+func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection, err error) {
149 190
 	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&Inspection).Error
150 191
 	return
151 192
 }
@@ -169,48 +210,48 @@ func CreateReportHandle(report *models.MiddleReportHandle) error {
169 210
 }
170 211
 
171 212
 // 根据机构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
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
174 215
 	return
175 216
 }
176 217
 
177 218
 // 根据机构ID修改检验检查操作表里的数据
178
-func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle)  error{
219
+func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle) error {
179 220
 	err := writeMiddleDb.Model(&models.MiddleReportHandle{}).Updates(&report_handle).Error
180 221
 	return err
181 222
 }
182 223
 
183 224
 // 跟进机构ID获取该机构所有病人的his_user_id
184
-func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients ,err error) {
225
+func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients, err error) {
185 226
 	err = readMiddleDb.Model(&models.MiddlePatients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patients).Error
186 227
 	return
187 228
 }
188 229
 
189 230
 // 根据机构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
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
192 233
 	return
193 234
 }
194 235
 
195 236
 // 根据机构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
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
198 239
 	return
199 240
 }
200 241
 
201 242
 // 根据机构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
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
204 245
 	return
205 246
 }
206 247
 
207 248
 // 从机构将数据同步到中间库
208
-func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleInspectionReference,*models.MiddleInspection,error) {
249
+func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
209 250
 	tx := writeMiddleDb.Begin()
210 251
 	var inspection models.MiddleInspection
211 252
 	var inspection_reference models.MiddleInspectionReference
212 253
 	recordDateStr := data.UTime
213
-	if len(data.UTime) == 0 { 
254
+	if len(data.UTime) == 0 {
214 255
 		recordDateStr = time.Now().Format("2006-01-02 15:04")
215 256
 	}
216 257
 	record_date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
@@ -223,17 +264,17 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
223 264
 	} else {
224 265
 		data.ItemType = 1
225 266
 		if len(data.RangeMax) > 0 {
226
-			Range := strings.Split(data.RangeMax,"-")
267
+			Range := strings.Split(data.RangeMax, "-")
227 268
 			if len(Range) > 1 {
228 269
 				data.RangeMin = Range[0]
229
-				data.RangeMax = Range[1] 
270
+				data.RangeMax = Range[1]
230 271
 			} else {
231 272
 				data.RangeMin = Range[0]
232 273
 			}
233 274
 		}
234 275
 	}
235 276
 
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
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
237 278
 	if total <= 0 && len(data.ProjectName) > 0 {
238 279
 		inspection_reference.OrgId = org_id
239 280
 		inspection_reference.ProjectName = data.ProjectName
@@ -258,7 +299,7 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
258 299
 		}
259 300
 	}
260 301
 
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
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
262 303
 	if itotal <= 0 {
263 304
 		inspection.PatientId = patient_id
264 305
 		inspection.OrgId = org_id
@@ -286,22 +327,21 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
286 327
 	}
287 328
 
288 329
 	tx.Commit()
289
-	return &inspection_reference,&inspection,err
330
+	return &inspection_reference, &inspection, err
290 331
 }
291 332
 
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
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
295 336
 	return
296 337
 }
297 338
 
298
-//GetPatientList 返回患者的列表
299
-func GetListByHisUserID(his_user_id string,syncTimes string,selectType int64) (lis []*models.TBLISItem,err error) {
339
+// GetPatientList 返回患者的列表
340
+func GetListByHisUserID(his_user_id string, syncTimes string, selectType int64) (lis []*models.TBLISItem, err error) {
300 341
 	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
-	 }
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
+	}
305 346
 	return
306 347
 }
307
-

+ 167 - 170
service/pajm_service.go Parādīt failu

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

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1127 - 0
service/sy_service.go


+ 412 - 0
service/xml_service.go Parādīt failu

@@ -0,0 +1,412 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"bytes"
6
+	"encoding/json"
7
+	"encoding/xml"
8
+	"fmt"
9
+	"io/ioutil"
10
+	"net/http"
11
+)
12
+
13
+// 获取可下载标本列表
14
+func GetGPReportListData(start_date string, end_date string, key string) (result []models.GPReportListResultData) {
15
+	// 构建SOAP请求数据
16
+	requestData := &models.ReportListEnvelope{
17
+		Soap: "http://schemas.xmlsoap.org/soap/envelope/",
18
+		Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
19
+		Xsd:  "http://www.w3.org/2001/XMLSchema",
20
+		Body: models.ReportListBody{
21
+			GetReportReq: models.GetReportReq{
22
+				XMLName:       xml.Name{Local: "GetAllSampleList", Space: "http://tempuri.org/"},
23
+				Key:           key,
24
+				BeginDateTime: start_date,
25
+				EndDateTime:   end_date,
26
+				DateType:      1,
27
+				PrintState:    0,
28
+			},
29
+		},
30
+	}
31
+
32
+	// 将SOAP请求数据转换为XML格式
33
+	requestBody, err := xml.Marshal(requestData)
34
+	if err != nil {
35
+		fmt.Println("XML Marshal error:", err)
36
+		return result
37
+	}
38
+
39
+	// 创建POST请求
40
+	url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
41
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
42
+	if err != nil {
43
+		fmt.Println("Request creation error:", err)
44
+		return result
45
+	}
46
+
47
+	// 设置请求头
48
+	req.Header.Set("Content-Type", "text/xml; charset=utf-8")
49
+	req.Header.Set("Content-Length", "length")
50
+	req.Header.Set("SOAPAction", "http://tempuri.org/GetAllSampleList")
51
+
52
+	// 发送请求
53
+	client := &http.Client{}
54
+	resp, err := client.Do(req)
55
+	if err != nil {
56
+		fmt.Println("Request error:", err)
57
+		return result
58
+	}
59
+	defer resp.Body.Close()
60
+
61
+	// 读取响应数据
62
+	responseBody, err := ioutil.ReadAll(resp.Body)
63
+	//fmt.Println(string(responseBody))
64
+	if err != nil {
65
+		fmt.Println("Response read error:", err)
66
+		return result
67
+	}
68
+
69
+	// 解析XML数据
70
+	var envelope_two models.EnvelopeTwo
71
+	err2 := xml.Unmarshal(responseBody, &envelope_two)
72
+	if err2 != nil {
73
+		fmt.Println("XML Unmarshal error:", err2)
74
+		return result
75
+	}
76
+
77
+	// 获取GetReportListResult的JSON字符串
78
+	jsonStr := envelope_two.Body.GetAllSampleListResponse.GetAllSampleListResult
79
+	//fmt.Println(jsonStr)
80
+	// 解析JSON字符串到结构体
81
+	var reportData models.ReportData
82
+	err = json.Unmarshal([]byte(jsonStr), &reportData)
83
+	if err != nil {
84
+		fmt.Println("JSON Unmarshal error:", err)
85
+		return result
86
+	}
87
+	if reportData.Res == 0 {
88
+		//fmt.Println( . ."Data:", reportData.GPReportListResultData)
89
+		return reportData.GPReportListResultData
90
+	}
91
+	return result
92
+}
93
+
94
+// 根据院所自身条码获取标本检测结果或诊断结果,遍历结果
95
+//func GetGPResultData(result []models.GPReportListResultData, key string) (results []models.InspectResult) {
96
+//	for _, item := range result {
97
+//
98
+//		// 构建SOAP请求数据
99
+//		requestData := &models.ReportResultEnvelope{
100
+//			Soap: "http://schemas.xmlsoap.org/soap/envelope/",
101
+//			Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
102
+//			Xsd:  "http://www.w3.org/2001/XMLSchema",
103
+//			Body: models.ReportResultBody{
104
+//				GetReportResultReq: models.GetReportResultReq{
105
+//					XMLName:         xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
106
+//					Key:             key,
107
+//					CustomerBarCode: item.CustomerBarcode,
108
+//				},
109
+//			},
110
+//		}
111
+//
112
+//		// 将SOAP请求数据转换为XML格式
113
+//		requestBody, err := xml.Marshal(requestData)
114
+//		if err != nil {
115
+//			fmt.Println("XML Marshal error:", err)
116
+//
117
+//		}
118
+//
119
+//		// 创建POST请求
120
+//		url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
121
+//		req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
122
+//		if err != nil {
123
+//			fmt.Println("Request creation error:", err)
124
+//		}
125
+//		// 设置请求头
126
+//		req.Header.Set("Content-Type", "text/xml; charset=utf-8")
127
+//		req.Header.Set("Content-Length", "length")
128
+//		req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
129
+//		// 发送请求
130
+//		client := &http.Client{}
131
+//		resp, err := client.Do(req)
132
+//		if err != nil {
133
+//			fmt.Println("Request error:", err)
134
+//
135
+//		}
136
+//		defer resp.Body.Close()
137
+//		// 读取响应数据
138
+//		responseBody, err := ioutil.ReadAll(resp.Body)
139
+//		if err != nil {
140
+//			fmt.Println("Response read error:", err)
141
+//		}
142
+//
143
+//		// 解析XML数据
144
+//		var envelope_three models.EnvelopeThree
145
+//		err2 := xml.Unmarshal(responseBody, &envelope_three)
146
+//		if err2 != nil {
147
+//			fmt.Println("XML Unmarshal error:", err2)
148
+//		}
149
+//		// 获取GetReportListResult的JSON字符串
150
+//		jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
151
+//		// 解析JSON字符串到结构体
152
+//		fmt.Println(jsonStr)
153
+//		var reportData models.ReportResultData
154
+//		err = json.Unmarshal([]byte(jsonStr), &reportData)
155
+//		if err != nil {
156
+//			fmt.Println("JSON Unmarshal error:", err)
157
+//		}
158
+//		if reportData.Res == 0 {
159
+//			fmt.Println("Data:", reportData.InspectResult)
160
+//			reportData.InspectResult.ListResult = item
161
+//			results = append(results, reportData.InspectResult)
162
+//		}
163
+//	}
164
+//	return results
165
+//}
166
+
167
+// 根据高品条码获取标本检测结果或诊断结果,遍历结果
168
+func GetGPResultDataTwo(result []models.GPReportListResultData, key string) (results []models.InspectResultFive) {
169
+	for _, item := range result {
170
+		if len(item.CustomerBarcode) > 0 {
171
+			fmt.Println("~~~~~~-------")
172
+			// 构建SOAP请求数据
173
+			requestData := &models.ReportResultEnvelope{
174
+				Soap: "http://schemas.xmlsoap.org/soap/envelope/",
175
+				Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
176
+				Xsd:  "http://www.w3.org/2001/XMLSchema",
177
+				Body: models.ReportResultBody{
178
+					GetReportResultReq: models.GetReportResultReq{
179
+						XMLName:         xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
180
+						Key:             key,
181
+						CustomerBarCode: item.CustomerBarcode,
182
+					},
183
+				},
184
+			}
185
+
186
+			// 将SOAP请求数据转换为XML格式
187
+			requestBody, err := xml.Marshal(requestData)
188
+			if err != nil {
189
+				fmt.Println("XML Marshal error:", err)
190
+
191
+			}
192
+
193
+			// 创建POST请求
194
+			url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
195
+			req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
196
+			if err != nil {
197
+				fmt.Println("Request creation error:", err)
198
+			}
199
+			// 设置请求头
200
+			req.Header.Set("Content-Type", "text/xml; charset=utf-8")
201
+			req.Header.Set("Content-Length", "length")
202
+			req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
203
+			// 发送请求
204
+			client := &http.Client{}
205
+			resp, err := client.Do(req)
206
+			if err != nil {
207
+				fmt.Println("Request error:", err)
208
+
209
+			}
210
+			defer resp.Body.Close()
211
+			// 读取响应数据
212
+			responseBody, err := ioutil.ReadAll(resp.Body)
213
+			if err != nil {
214
+				fmt.Println("Response read error:", err)
215
+			}
216
+
217
+			// 解析XML数据
218
+			var envelope_three models.EnvelopeThree
219
+			err2 := xml.Unmarshal(responseBody, &envelope_three)
220
+			if err2 != nil {
221
+				fmt.Println("XML Unmarshal error:", err2)
222
+			}
223
+			// 获取GetReportListResult的JSON字符串
224
+			jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
225
+			// 解析JSON字符串到结构体
226
+			//fmt.Println(jsonStr)
227
+			var reportData models.ReportResultData
228
+			err = json.Unmarshal([]byte(jsonStr), &reportData)
229
+			if err != nil {
230
+				fmt.Println("JSON Unmarshal error:", err)
231
+			}
232
+			if reportData.Res == 0 {
233
+				//reportData.ListResult = item
234
+				for _, subItem := range reportData.InspectResult {
235
+					subItem.ListResult = item
236
+					var resultTwo models.InspectResultFive
237
+					resultTwo.ListResult = subItem.ListResult
238
+					resultTwo.Result = subItem.Result
239
+					resultTwo.Barcode = subItem.Barcode
240
+					resultTwo.Flag = subItem.Flag
241
+					resultTwo.Unit = subItem.Unit
242
+					resultTwo.ChargeItemName = subItem.ChargeItemName
243
+					resultTwo.InspectionName = subItem.InspectionName
244
+					resultTwo.InspectionCode = subItem.InspectionCode
245
+					resultTwo.Reference = subItem.Reference
246
+					results = append(results, resultTwo)
247
+				}
248
+			}
249
+		} else {
250
+
251
+			if len(item.Barcode) > 0 {
252
+				//fmt.Println("11122222")
253
+				// 构建SOAP请求数据
254
+				requestData := &models.GPReportResultEnvelope{
255
+					Soap: "http://schemas.xmlsoap.org/soap/envelope/",
256
+					Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
257
+					Xsd:  "http://www.w3.org/2001/XMLSchema",
258
+					Body: models.GPReportResultBody{
259
+						GetReportResultReq: models.GetGPReportResultReq{
260
+							XMLName:   xml.Name{Local: "GetJSONReportItemListByGPBarocde", Space: "http://tempuri.org/"},
261
+							Key:       key,
262
+							GPBarCode: item.Barcode,
263
+						},
264
+					},
265
+				}
266
+
267
+				// 将SOAP请求数据转换为XML格式
268
+				requestBody, err := xml.Marshal(requestData)
269
+				if err != nil {
270
+					fmt.Println("XML Marshal error:", err)
271
+
272
+				}
273
+
274
+				// 创建POST请求
275
+				url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
276
+				req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
277
+				if err != nil {
278
+					fmt.Println("Request creation error:", err)
279
+				}
280
+				// 设置请求头
281
+				req.Header.Set("Content-Type", "text/xml; charset=utf-8")
282
+				req.Header.Set("Content-Length", "length")
283
+				req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByGPBarocde")
284
+				// 发送请求
285
+				client := &http.Client{}
286
+				resp, err := client.Do(req)
287
+				if err != nil {
288
+					fmt.Println("Request error:", err)
289
+
290
+				}
291
+				defer resp.Body.Close()
292
+				// 读取响应数据
293
+				responseBody, err := ioutil.ReadAll(resp.Body)
294
+				if err != nil {
295
+					fmt.Println("Response read error:", err)
296
+				}
297
+
298
+				// 解析XML数据
299
+				var envelope_five models.EnvelopeFive
300
+				err2 := xml.Unmarshal(responseBody, &envelope_five)
301
+				if err2 != nil {
302
+					fmt.Println("XML Unmarshal error:", err2)
303
+				}
304
+
305
+				// 获取GetReportListResult的JSON字符串
306
+				jsonStr := envelope_five.Body.GetJSONReportItemListByGPBarocdeResponse.GetJSONReportItemListByGPBarocdeResult
307
+				// 解析JSON字符串到结构体
308
+				var reportData models.ReportResultDataFive
309
+				err = json.Unmarshal([]byte(jsonStr), &reportData)
310
+				if err != nil {
311
+					fmt.Println("JSON Unmarshal error:", err)
312
+				}
313
+				//fmt.Println(reportData)
314
+
315
+				if reportData.Res == 0 {
316
+					//reportData.ListResult = item
317
+					for _, subItem := range reportData.InspectResult {
318
+						subItem.ListResult = item
319
+						results = append(results, subItem)
320
+
321
+					}
322
+				}
323
+
324
+			}
325
+		}
326
+
327
+	}
328
+	return results
329
+
330
+}
331
+
332
+// 送检单
333
+func PostInspectApply(key string, apply models.JYApply, list []models.CustomerApplyDetail) models.InspectApplyData {
334
+	// 构建SOAP请求数据
335
+	requestData := &models.JYApplyEnvelope{
336
+		Soap: "http://schemas.xmlsoap.org/soap/envelope/",
337
+		Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
338
+		Xsd:  "http://www.w3.org/2001/XMLSchema",
339
+		Body: models.JYApplyBody{
340
+			InspectApplyReq: models.InspectApplyReq{
341
+				XMLName: xml.Name{Local: "InspectApplyByInstituteItemCode", Space: "http://tempuri.org/"},
342
+				ApiKey:  key,
343
+				Apply:   apply,
344
+				ApplyDetailList: struct {
345
+					CustomerApplyDetail []models.CustomerApplyDetail `xml:"CustomerApplyDetail"`
346
+				}{
347
+					CustomerApplyDetail: list,
348
+				},
349
+				ApplyAdditional: nil,
350
+			},
351
+		},
352
+	}
353
+
354
+	// 将SOAP请求数据转换为XML格式
355
+	requestBody, err := xml.Marshal(requestData)
356
+	if err != nil {
357
+		fmt.Println("XML Marshal error:", err)
358
+	}
359
+	fmt.Println(string(requestBody))
360
+
361
+	// 创建POST请求
362
+	url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
363
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
364
+	if err != nil {
365
+		fmt.Println("Request creation error:", err)
366
+	}
367
+
368
+	// 设置请求头
369
+	req.Header.Set("Content-Type", "text/xml; charset=utf-8")
370
+	req.Header.Set("Content-Length", "length")
371
+	req.Header.Set("SOAPAction", "http://tempuri.org/InspectApplyByInstituteItemCode")
372
+
373
+	// 发送请求
374
+	client := &http.Client{}
375
+	resp, err := client.Do(req)
376
+	if err != nil {
377
+		fmt.Println("Request error:", err)
378
+	}
379
+	defer resp.Body.Close()
380
+
381
+	// 读取响应数据
382
+	responseBody, err := ioutil.ReadAll(resp.Body)
383
+	if err != nil {
384
+		fmt.Println("Response read error:", err)
385
+
386
+	}
387
+	fmt.Println(string(responseBody))
388
+
389
+	// 解析XML数据
390
+	var envelope_four models.EnvelopeFour
391
+	err2 := xml.Unmarshal(responseBody, &envelope_four)
392
+	if err2 != nil {
393
+		fmt.Println("XML Unmarshal error:", err2)
394
+
395
+	}
396
+
397
+	// 获取GetReportListResult的JSON字符串
398
+	jsonStr := envelope_four.Body.InspectApplyByInstituteItemCodeResponse.InspectApply
399
+
400
+	// 解析JSON字符串到结构体
401
+	var reportData models.InspectApplyData
402
+	err = json.Unmarshal([]byte(jsonStr), &reportData)
403
+
404
+	if err != nil {
405
+		fmt.Println("JSON Unmarshal error:", err)
406
+	}
407
+	if reportData.Res != 0 {
408
+		fmt.Println("Data:", reportData)
409
+		//return reportData.JYApplyResult
410
+	}
411
+	return reportData
412
+}

+ 27 - 10
service/ystx_service.go Parādīt failu

@@ -1520,34 +1520,51 @@ func SyncToHbdytx() {
1520 1520
 }
1521 1521
 
1522 1522
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
1523
-func GetBljhProjectID(org_id int64, project_name string) (project_id int64, err error) {
1523
+func GetBljhProjectID(org_id int64, project_name string) (project_id int64, sys_project_id int64, err error) {
1524 1524
 	var inspection_reference models.MiddleInspectionReference
1525 1525
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
1526 1526
 	if inspection_reference.ID > 0 {
1527
-		return inspection_reference.ProjectId, err
1527
+		return inspection_reference.ProjectId, inspection_reference.XtProjectId, err
1528 1528
 	} else {
1529 1529
 		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
1530 1530
 		if inspection_reference.ProjectId > 0 {
1531
-			return inspection_reference.ProjectId + 1, err
1531
+			return inspection_reference.ProjectId + 1, 0, err
1532 1532
 		} else {
1533
-			return 5210138, err
1533
+			return 5210138, 0, err
1534 1534
 		}
1535 1535
 	}
1536 1536
 }
1537 1537
 
1538
+//// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1539
+//func GetBlItemIDTwo(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, sys_project_id int64, err error) {
1540
+//	var inspection_reference models.MiddleInspectionReference
1541
+//	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
1542
+//	if inspection_reference.ID > 0 {
1543
+//		return inspection_reference.ItemId, err
1544
+//	} else {
1545
+//		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
1546
+//		utils.InfoLog("inspection_reference: %v", inspection_reference)
1547
+//		if inspection_reference.ItemId > 0 {
1548
+//			return inspection_reference.ItemId + 1, err
1549
+//		} else {
1550
+//			return project_id*10 + 1, err
1551
+//		}
1552
+//	}
1553
+//}
1554
+
1538 1555
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1539
-func GetBlItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1556
+func GetBlItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, sys_item_id int64, err error) {
1540 1557
 	var inspection_reference models.MiddleInspectionReference
1541 1558
 	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
1542 1559
 	if inspection_reference.ID > 0 {
1543
-		return inspection_reference.ItemId, err
1560
+		return inspection_reference.ItemId, inspection_reference.XtItemId, err
1544 1561
 	} else {
1545
-		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
1562
+		err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and xt_project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
1546 1563
 		utils.InfoLog("inspection_reference: %v", inspection_reference)
1547 1564
 		if inspection_reference.ItemId > 0 {
1548
-			return inspection_reference.ItemId + 1, err
1565
+			return inspection_reference.ItemId + 1, 0, err
1549 1566
 		} else {
1550
-			return project_id*10 + 1, err
1567
+			return project_id*10 + 1, 0, err
1551 1568
 		}
1552 1569
 	}
1553 1570
 }
@@ -1719,7 +1736,7 @@ func Synctfyz() (err error) {
1719 1736
 				}
1720 1737
 				utils.InfoLog("advice:%v", advice)
1721 1738
 				// 根据同步来的 advice_id 来查询库里是否已经存在
1722
-				advice_info, _ := GetAdviceBySyncAdviceIdTwo(org_id, strconv.FormatInt(yz.AdviceId,10))
1739
+				advice_info, _ := GetAdviceBySyncAdviceIdTwo(org_id, strconv.FormatInt(yz.AdviceId, 10))
1723 1740
 				utils.InfoLog("advice_info:%v", advice_info)
1724 1741
 				if advice_info.ID > 0 {
1725 1742
 					key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"