Ver código fonte

医保对接

csx 3 anos atrás
pai
commit
39364c589c

+ 126 - 2
controllers/his_api_controller.go Ver arquivo

@@ -349,6 +349,24 @@ func (c *HisApiController) GetHisPatientList() {
349 349
 	})
350 350
 }
351 351
 
352
+type CustomTemplate struct {
353
+	ID                             int64                                   `gorm:"column:id" json:"id" form:"id"`
354
+	UserOrgId                      int64                                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
355
+	RecordDate                     int64                                   `gorm:"column:record_date" json:"record_date" form:"record_date"`
356
+	PatientId                      int64                                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
357
+	Status                         int64                                   `gorm:"column:status" json:"status" form:"status"`
358
+	Ctime                          int64                                   `gorm:"column:ctime" json:"ctime" form:"ctime"`
359
+	Mtime                          int64                                   `gorm:"column:mtime" json:"mtime" form:"mtime"`
360
+	Type                           int64                                   `gorm:"column:type" json:"type" form:"type"`
361
+	Creator                        int64                                   `gorm:"column:creator" json:"creator" form:"creator"`
362
+	Modifier                       int64                                   `gorm:"column:modifier" json:"modifier" form:"modifier"`
363
+	PType                          int64                                   `gorm:"column:p_type" json:"p_type" form:"p_type"`
364
+	PTemplateId                    int64                                   `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
365
+	HisPrescriptionAdviceTemplate  []models.HisPrescriptionAdviceTemplate  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
366
+	HisPrescriptionProjectTemplate []models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
367
+	MedType                        string                                  `gorm:"column:med_type" json:"med_type" form:"med_type"`
368
+}
369
+
352 370
 func (c *HisApiController) GetHisPatientInfo() {
353 371
 	patient_id, _ := c.GetInt64("patient_id")
354 372
 	his_patient_id, _ := c.GetInt64("his_patient_id")
@@ -384,7 +402,7 @@ func (c *HisApiController) GetHisPatientInfo() {
384 402
 
385 403
 	var prescriptions []*models.HisPrescription
386 404
 	var last_prescriptions []*models.HisPrescription
387
-	var sch_prescriptions []*models.HisPrescriptionInfoTemplate
405
+	var sch_prescriptions []CustomTemplate
388 406
 	last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
389 407
 	if p_type == 1 { //住院
390 408
 		prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
@@ -396,10 +414,116 @@ func (c *HisApiController) GetHisPatientInfo() {
396 414
 
397 415
 	sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
398 416
 	if sch.ID > 0 {
417
+		var week string
418
+		t := time.Now()
419
+		switch t.Weekday().String() {
420
+		case "Monday":
421
+			week = "周一"
422
+			break
423
+		case "Tuesday":
424
+			week = "周二"
425
+
426
+			break
427
+		case "Wednesday":
428
+			week = "周三"
429
+
430
+			break
431
+		case "Thursday":
432
+			week = "周四"
433
+
434
+			break
435
+		case "Friday":
436
+			week = "周五"
437
+
438
+			break
439
+		case "Saturday":
440
+			week = "周六"
441
+
442
+			break
443
+		case "Sunday":
444
+			week = "周日"
445
+
446
+			break
447
+
448
+		}
449
+
399 450
 		mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
400
-		sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
451
+		temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
452
+
453
+		//根据推送频率组装新的数组
454
+		for _, item := range temp_sch_prescriptions {
455
+			var cus CustomTemplate
456
+			cus.ID = item.ID
457
+			cus.UserOrgId = item.UserOrgId
458
+			cus.PatientId = item.PatientId
459
+			cus.MedType = item.MedType
460
+			cus.RecordDate = item.RecordDate
461
+			cus.Type = item.Type
462
+			cus.PType = item.PType
463
+			for _, subItem := range item.HisPrescriptionAdviceTemplate {
464
+				if subItem.FrequencyType == 1 { //每次必推
465
+					cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
466
+				}
467
+
468
+				if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
469
+					cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
470
+				}
471
+
472
+				if subItem.FrequencyType == 2 { //按照天数频率
473
+					p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
474
+					now := p.Unix()
475
+					dayStr := strconv.FormatInt(subItem.DayCount, 10)
476
+					dayStr2 := "-" + dayStr
477
+					count, _ := strconv.ParseInt(dayStr2, 10, 64)
478
+					oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
479
+					advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
480
+					if len(advices) == 0 {
481
+						cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
482
+					}
483
+				}
484
+
485
+			}
401 486
 
487
+			for _, subItem := range item.HisPrescriptionProjectTemplate {
488
+
489
+				if subItem.FrequencyType == 1 {
490
+					cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
491
+				}
492
+
493
+				if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
494
+					cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
495
+				}
496
+
497
+				if subItem.FrequencyType == 2 {
498
+					p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
499
+					now := p.Unix()
500
+					dayStr := strconv.FormatInt(subItem.DayCount, 10)
501
+					dayStr2 := "-" + dayStr
502
+					count, _ := strconv.ParseInt(dayStr2, 10, 64)
503
+					oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
504
+					projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
505
+					if len(projects) == 0 {
506
+						cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
507
+					}
508
+				}
509
+
510
+			}
511
+
512
+			sch_prescriptions = append(sch_prescriptions, cus)
513
+
514
+		}
515
+
516
+		for _, item := range sch_prescriptions {
517
+			if len(item.HisPrescriptionProjectTemplate) == 0 {
518
+				item.HisPrescriptionProjectTemplate = make([]models.HisPrescriptionProjectTemplate, 0)
519
+			}
520
+			if len(item.HisPrescriptionAdviceTemplate) == 0 {
521
+				item.HisPrescriptionAdviceTemplate = make([]models.HisPrescriptionAdviceTemplate, 0)
522
+			}
523
+
524
+		}
402 525
 	}
526
+
403 527
 	//prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
404 528
 	//monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
405 529
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)

+ 128 - 2
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Ver arquivo

@@ -10,6 +10,7 @@ import (
10 10
 	"math/rand"
11 11
 	"reflect"
12 12
 	"strconv"
13
+	"strings"
13 14
 	"time"
14 15
 )
15 16
 
@@ -44,6 +45,25 @@ func (c *MobileHisApiController) GetHisPrescriptionConfig() {
44 45
 		"good_info":        good_info,
45 46
 	})
46 47
 }
48
+
49
+type CustomTemplate struct {
50
+	ID                             int64                                   `gorm:"column:id" json:"id" form:"id"`
51
+	UserOrgId                      int64                                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
52
+	RecordDate                     int64                                   `gorm:"column:record_date" json:"record_date" form:"record_date"`
53
+	PatientId                      int64                                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
54
+	Status                         int64                                   `gorm:"column:status" json:"status" form:"status"`
55
+	Ctime                          int64                                   `gorm:"column:ctime" json:"ctime" form:"ctime"`
56
+	Mtime                          int64                                   `gorm:"column:mtime" json:"mtime" form:"mtime"`
57
+	Type                           int64                                   `gorm:"column:type" json:"type" form:"type"`
58
+	Creator                        int64                                   `gorm:"column:creator" json:"creator" form:"creator"`
59
+	Modifier                       int64                                   `gorm:"column:modifier" json:"modifier" form:"modifier"`
60
+	PType                          int64                                   `gorm:"column:p_type" json:"p_type" form:"p_type"`
61
+	PTemplateId                    int64                                   `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
62
+	HisPrescriptionAdviceTemplate  []models.HisPrescriptionAdviceTemplate  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
63
+	HisPrescriptionProjectTemplate []models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
64
+	MedType                        string                                  `gorm:"column:med_type" json:"med_type" form:"med_type"`
65
+}
66
+
47 67
 func (c *MobileHisApiController) GetHisPatientInfo() {
48 68
 	patient_id, _ := c.GetInt64("patient_id")
49 69
 	record_date := c.GetString("record_date")
@@ -72,7 +92,7 @@ func (c *MobileHisApiController) GetHisPatientInfo() {
72 92
 	endRecordDateTime := endTime.Unix()
73 93
 
74 94
 	var last_prescriptions []*models.HisPrescription
75
-	var sch_prescriptions []*models.HisPrescriptionInfoTemplate
95
+	var sch_prescriptions []CustomTemplate
76 96
 
77 97
 	admin := c.GetMobileAdminUserInfo()
78 98
 	his_patient_info, _ := service.GetHisPatientInfo(admin.Org.Id, patient_id, recordDateTime)
@@ -91,8 +111,114 @@ func (c *MobileHisApiController) GetHisPatientInfo() {
91 111
 	last_prescriptions, _ = service.GetHisPrescription(admin.Org.Id, patient_id, last_p_info.RecordDate, 2)
92 112
 	sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.Org.Id)
93 113
 	if sch.ID > 0 {
114
+		var week string
115
+		t := time.Now()
116
+		switch t.Weekday().String() {
117
+		case "Monday":
118
+			week = "周一"
119
+			break
120
+		case "Tuesday":
121
+			week = "周二"
122
+
123
+			break
124
+		case "Wednesday":
125
+			week = "周三"
126
+
127
+			break
128
+		case "Thursday":
129
+			week = "周四"
130
+
131
+			break
132
+		case "Friday":
133
+			week = "周五"
134
+
135
+			break
136
+		case "Saturday":
137
+			week = "周六"
138
+
139
+			break
140
+		case "Sunday":
141
+			week = "周日"
142
+
143
+			break
144
+
145
+		}
146
+
94 147
 		mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.Org.Id)
95
-		sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.Org.Id)
148
+		temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.Org.Id)
149
+
150
+		//根据推送频率组装新的数组
151
+		for _, item := range temp_sch_prescriptions {
152
+			var cus CustomTemplate
153
+			cus.ID = item.ID
154
+			cus.UserOrgId = item.UserOrgId
155
+			cus.PatientId = item.PatientId
156
+			cus.MedType = item.MedType
157
+			cus.RecordDate = item.RecordDate
158
+			cus.Type = item.Type
159
+			cus.PType = item.PType
160
+			for _, subItem := range item.HisPrescriptionAdviceTemplate {
161
+				if subItem.FrequencyType == 1 { //每次必推
162
+					cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
163
+				}
164
+
165
+				if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
166
+					cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
167
+				}
168
+
169
+				if subItem.FrequencyType == 2 { //按照天数频率
170
+					p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
171
+					now := p.Unix()
172
+					dayStr := strconv.FormatInt(subItem.DayCount, 10)
173
+					dayStr2 := "-" + dayStr
174
+					count, _ := strconv.ParseInt(dayStr2, 10, 64)
175
+					oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
176
+					advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
177
+					if len(advices) == 0 {
178
+						cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
179
+					}
180
+				}
181
+
182
+			}
183
+
184
+			for _, subItem := range item.HisPrescriptionProjectTemplate {
185
+
186
+				if subItem.FrequencyType == 1 {
187
+					cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
188
+				}
189
+
190
+				if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
191
+					cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
192
+				}
193
+
194
+				if subItem.FrequencyType == 2 {
195
+					p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
196
+					now := p.Unix()
197
+					dayStr := strconv.FormatInt(subItem.DayCount, 10)
198
+					dayStr2 := "-" + dayStr
199
+					count, _ := strconv.ParseInt(dayStr2, 10, 64)
200
+					oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
201
+					projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
202
+					if len(projects) == 0 {
203
+						cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
204
+					}
205
+				}
206
+
207
+			}
208
+
209
+			sch_prescriptions = append(sch_prescriptions, cus)
210
+
211
+		}
212
+
213
+		for _, item := range sch_prescriptions {
214
+			if len(item.HisPrescriptionProjectTemplate) == 0 {
215
+				item.HisPrescriptionProjectTemplate = make([]models.HisPrescriptionProjectTemplate, 0)
216
+			}
217
+			if len(item.HisPrescriptionAdviceTemplate) == 0 {
218
+				item.HisPrescriptionAdviceTemplate = make([]models.HisPrescriptionAdviceTemplate, 0)
219
+			}
220
+
221
+		}
96 222
 	}
97 223
 	count, _ := service.GetHisPatientCount(admin.Org.Id, patient_id, recordDateTime)
98 224
 	c.ServeSuccessJSON(map[string]interface{}{

+ 16 - 16
models/his_models.go Ver arquivo

@@ -1400,7 +1400,7 @@ type HisPrescriptionProjectTemplate struct {
1400 1400
 	GoodInfo           GoodInfo     `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
1401 1401
 	FrequencyType      int64        `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
1402 1402
 	DayCount           int64        `gorm:"column:day_count" json:"day_count" form:"day_count"`
1403
-	WeekDay            int64        `gorm:"column:week_day" json:"week_day" form:"week_day"`
1403
+	WeekDay            string       `gorm:"column:week_day" json:"week_day" form:"week_day"`
1404 1404
 }
1405 1405
 
1406 1406
 func (HisPrescriptionProjectTemplate) TableName() string {
@@ -1408,21 +1408,21 @@ func (HisPrescriptionProjectTemplate) TableName() string {
1408 1408
 }
1409 1409
 
1410 1410
 type HisPrescriptionInfoTemplate struct {
1411
-	ID                             int64                             `gorm:"column:id" json:"id" form:"id"`
1412
-	UserOrgId                      int64                             `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1413
-	RecordDate                     int64                             `gorm:"column:record_date" json:"record_date" form:"record_date"`
1414
-	PatientId                      int64                             `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1415
-	Status                         int64                             `gorm:"column:status" json:"status" form:"status"`
1416
-	Ctime                          int64                             `gorm:"column:ctime" json:"ctime" form:"ctime"`
1417
-	Mtime                          int64                             `gorm:"column:mtime" json:"mtime" form:"mtime"`
1418
-	Type                           int64                             `gorm:"column:type" json:"type" form:"type"`
1419
-	Creator                        int64                             `gorm:"column:creator" json:"creator" form:"creator"`
1420
-	Modifier                       int64                             `gorm:"column:modifier" json:"modifier" form:"modifier"`
1421
-	PType                          int64                             `gorm:"column:p_type" json:"p_type" form:"p_type"`
1422
-	PTemplateId                    int64                             `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
1423
-	HisPrescriptionAdviceTemplate  []*HisPrescriptionAdviceTemplate  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
1424
-	HisPrescriptionProjectTemplate []*HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
1425
-	MedType                        string                            `gorm:"column:med_type" json:"med_type" form:"med_type"`
1411
+	ID                             int64                            `gorm:"column:id" json:"id" form:"id"`
1412
+	UserOrgId                      int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1413
+	RecordDate                     int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
1414
+	PatientId                      int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1415
+	Status                         int64                            `gorm:"column:status" json:"status" form:"status"`
1416
+	Ctime                          int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
1417
+	Mtime                          int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
1418
+	Type                           int64                            `gorm:"column:type" json:"type" form:"type"`
1419
+	Creator                        int64                            `gorm:"column:creator" json:"creator" form:"creator"`
1420
+	Modifier                       int64                            `gorm:"column:modifier" json:"modifier" form:"modifier"`
1421
+	PType                          int64                            `gorm:"column:p_type" json:"p_type" form:"p_type"`
1422
+	PTemplateId                    int64                            `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
1423
+	HisPrescriptionAdviceTemplate  []HisPrescriptionAdviceTemplate  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
1424
+	HisPrescriptionProjectTemplate []HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
1425
+	MedType                        string                           `gorm:"column:med_type" json:"med_type" form:"med_type"`
1426 1426
 }
1427 1427
 
1428 1428
 func (HisPrescriptionInfoTemplate) TableName() string {

+ 10 - 0
service/his_service.go Ver arquivo

@@ -2126,3 +2126,13 @@ func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderI
2126 2126
 	}).Find(&order).Error
2127 2127
 	return
2128 2128
 }
2129
+
2130
+func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
2131
+	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ?  AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
2132
+	return
2133
+}
2134
+
2135
+func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
2136
+	err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ?  AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
2137
+	return
2138
+}