Browse Source

医保对接

csx 4 years ago
parent
commit
33e1ca7e37

+ 5 - 5
controllers/base_api_controller.go View File

@@ -81,7 +81,7 @@ func (this *BaseAuthAPIController) Prepare() {
81 81
 		userAdmin.ModifyTime = 1530786071
82 82
 		var subscibe models.ServeSubscibe
83 83
 		subscibe.ID = 1
84
-		subscibe.OrgId = 4
84
+		subscibe.OrgId = 3877
85 85
 		subscibe.PeriodStart = 1538035409
86 86
 		subscibe.PeriodEnd = 1569571409
87 87
 		subscibe.State = 1
@@ -91,8 +91,8 @@ func (this *BaseAuthAPIController) Prepare() {
91 91
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92 92
 		subscibes[4] = &subscibe
93 93
 		var adminUserInfo service.AdminUserInfo
94
-		adminUserInfo.CurrentOrgId = 4
95
-		adminUserInfo.CurrentAppId = 8642
94
+		adminUserInfo.CurrentOrgId = 3877
95
+		adminUserInfo.CurrentAppId = 3877
96 96
 		adminUserInfo.AdminUser = &userAdmin
97 97
 		adminUserInfo.Subscibes = subscibes
98 98
 		this.SetSession("admin_user_info", &adminUserInfo)
@@ -327,7 +327,7 @@ func (this *BaseServeAPIController) Prepare() {
327 327
 		userAdmin.ModifyTime = 1530786071
328 328
 		var subscibe models.ServeSubscibe
329 329
 		subscibe.ID = 1
330
-		subscibe.OrgId = 4
330
+		subscibe.OrgId = 3877
331 331
 		subscibe.PeriodStart = 1538035409
332 332
 		subscibe.PeriodEnd = 1569571409
333 333
 		subscibe.State = 1
@@ -337,7 +337,7 @@ func (this *BaseServeAPIController) Prepare() {
337 337
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338 338
 		subscibes[4] = &subscibe
339 339
 		var adminUserInfo service.AdminUserInfo
340
-		adminUserInfo.CurrentOrgId = 4
340
+		adminUserInfo.CurrentOrgId = 3877
341 341
 		adminUserInfo.CurrentAppId = 8642
342 342
 		adminUserInfo.AdminUser = &userAdmin
343 343
 		adminUserInfo.Subscibes = subscibes

+ 705 - 126
controllers/his_api_controller.go View File

@@ -40,6 +40,7 @@ func HisManagerApiRegistRouters() {
40 40
 	beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
41 41
 
42 42
 	beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
43
+	beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
43 44
 
44 45
 	beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
45 46
 	beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
@@ -69,6 +70,13 @@ func HisManagerApiRegistRouters() {
69 70
 	beego.Router("/api/hisprescription/get", &DialysisApiController{}, "Get:GetLastOrNextHisPrescription")
70 71
 
71 72
 	beego.Router("/api/callhisprescription/get", &DialysisApiController{}, "Get:GetCallHisPrescription")
73
+
74
+	beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
75
+
76
+	beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
77
+
78
+	beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
79
+
72 80
 }
73 81
 
74 82
 func (c *HisApiController) Sscard() {
@@ -131,7 +139,10 @@ func (c *HisApiController) GetHisPatientList() {
131 139
 	}
132 140
 	recordDateTime := theTime.Unix()
133 141
 	adminInfo := c.GetAdminUserInfo()
134
-	patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
142
+	patients, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
143
+	patients_two, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
144
+	patients = append(patients, patients_two...)
145
+
135 146
 	var total_one int64
136 147
 	var total_two int64
137 148
 
@@ -162,7 +173,7 @@ func (c *HisApiController) GetHisPatientList() {
162 173
 		})
163 174
 
164 175
 	} else if types == 1 { //未就诊
165
-		var patientsOne []*service.Schedule
176
+		var patientsOne []*service.Patients
166 177
 		for _, item := range patients {
167 178
 			if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
168 179
 				patientsOne = append(patientsOne, item)
@@ -178,7 +189,7 @@ func (c *HisApiController) GetHisPatientList() {
178 189
 		})
179 190
 
180 191
 	} else if types == 2 { //已就诊
181
-		var patientsTwo []*service.Schedule
192
+		var patientsTwo []*service.Patients
182 193
 		for _, item := range patients {
183 194
 
184 195
 			if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
@@ -201,6 +212,9 @@ func (c *HisApiController) GetHisPatientInfo() {
201 212
 	record_date := c.GetString("record_date")
202 213
 	number := c.GetString("number")
203 214
 
215
+	start_time := c.GetString("start_time")
216
+	end_time := c.GetString("end_time")
217
+
204 218
 	timeLayout := "2006-01-02"
205 219
 	loc, _ := time.LoadLocation("Local")
206 220
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
@@ -210,25 +224,34 @@ func (c *HisApiController) GetHisPatientInfo() {
210 224
 	}
211 225
 	recordDateTime := theTime.Unix()
212 226
 
227
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
228
+	if err != nil {
229
+
230
+	}
231
+	startRecordDateTime := startTime.Unix()
232
+
233
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
234
+	if err != nil {
235
+
236
+	}
237
+	endRecordDateTime := endTime.Unix()
238
+
213 239
 	admin := c.GetAdminUserInfo()
214 240
 	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
215 241
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
216 242
 	prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
217
-
243
+	monthPrescriptions, _ := service.GetMonthHisPrescription(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
218 244
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
219 245
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
220
-	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
221 246
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
222
-	//addtions, _ := service.GetAllAdditionCharge(admin.CurrentOrgId, patient_id, recordDateTime)
223
-
224 247
 	c.ServeSuccessJSON(map[string]interface{}{
225
-		"his_info":     his_patient_info,
226
-		"xt_info":      xt_patient_info,
227
-		"prescription": prescriptions,
228
-		"case_history": case_history,
229
-		"info":         patientPrescriptionInfo,
230
-		"last_info":    lastPatientPrescriptionInfo,
231
-		"order":        order,
248
+		"his_info":            his_patient_info,
249
+		"xt_info":             xt_patient_info,
250
+		"prescription":        prescriptions,
251
+		"case_history":        case_history,
252
+		"info":                patientPrescriptionInfo,
253
+		"month_prescriptions": monthPrescriptions,
254
+		"order":               order,
232 255
 	})
233 256
 	return
234 257
 
@@ -526,6 +549,236 @@ func (c *HisApiController) CreateHisPrescription() {
526 549
 		return
527 550
 	}
528 551
 }
552
+func (c *HisApiController) EditHisPrescription() {
553
+	record_date := c.GetString("record_date")
554
+	patient_id, _ := c.GetInt64("patient_id")
555
+	reg_type, _ := c.GetInt64("reg_type")
556
+	diagnose, _ := c.GetInt64("diagnose")
557
+	sick_type, _ := c.GetInt64("sick_type")
558
+	sick_history := c.GetString("sick_history")
559
+	doctor_id, _ := c.GetInt64("doctor", 0)
560
+	department, _ := c.GetInt64("department", 0)
561
+	his_patient_id, _ := c.GetInt64("his_patient_id")
562
+	dataBody := make(map[string]interface{}, 0)
563
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
564
+	if err != nil {
565
+		utils.ErrorLog(err.Error())
566
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
567
+		return
568
+	}
569
+
570
+	timeLayout := "2006-01-02"
571
+	loc, _ := time.LoadLocation("Local")
572
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
573
+	if err != nil {
574
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
575
+		return
576
+	}
577
+	adminInfo := c.GetAdminUserInfo()
578
+	recordDateTime := theTime.Unix()
579
+
580
+	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
581
+
582
+	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
583
+	var hpInfo models.HisPrescriptionInfo
584
+	if info.ID == 0 {
585
+		var randNum int
586
+		randNum = rand.Intn(10000) + 1000
587
+		timestamp := time.Now().Unix()
588
+		tempTime := time.Unix(timestamp, 0)
589
+		timeFormat := tempTime.Format("20060102150405")
590
+		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
591
+
592
+		hpInfo = models.HisPrescriptionInfo{
593
+			UserOrgId:          adminInfo.CurrentOrgId,
594
+			RecordDate:         theTime.Unix(),
595
+			PatientId:          patient_id,
596
+			Status:             1,
597
+			Ctime:              time.Now().Unix(),
598
+			Mtime:              time.Now().Unix(),
599
+			Creator:            adminInfo.AdminUser.Id,
600
+			Modifier:           adminInfo.AdminUser.Id,
601
+			Diagnosis:          diagnose,
602
+			SickHistory:        sick_history,
603
+			Departments:        department,
604
+			RegisterType:       reg_type,
605
+			PrescriptionNumber: p_number,
606
+			PrescriptionStatus: 1,
607
+			Doctor:             role.UserName,
608
+			DoctorId:           doctor_id,
609
+			SickType:           sick_type,
610
+		}
611
+		service.SavePatientPrescriptionInfo(hpInfo)
612
+
613
+	} else {
614
+		hpInfo = models.HisPrescriptionInfo{
615
+			ID:                 info.ID,
616
+			UserOrgId:          adminInfo.CurrentOrgId,
617
+			RecordDate:         info.RecordDate,
618
+			PatientId:          info.PatientId,
619
+			Status:             1,
620
+			Ctime:              info.Ctime,
621
+			Mtime:              time.Now().Unix(),
622
+			Creator:            info.Creator,
623
+			Modifier:           adminInfo.AdminUser.Id,
624
+			Diagnosis:          diagnose,
625
+			SickHistory:        sick_history,
626
+			Departments:        department,
627
+			RegisterType:       reg_type,
628
+			PrescriptionNumber: info.PrescriptionNumber,
629
+			Doctor:             role.UserName,
630
+			PrescriptionStatus: info.PrescriptionStatus,
631
+			DoctorId:           doctor_id,
632
+			SickType:           sick_type,
633
+		}
634
+		service.SavePatientPrescriptionInfo(hpInfo)
635
+	}
636
+
637
+	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
638
+		prescriptions, _ := dataBody["prescriptions"].([]interface{})
639
+
640
+		if len(prescriptions) > 0 {
641
+			for _, item := range prescriptions {
642
+				items := item.(map[string]interface{})
643
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
644
+					utils.ErrorLog("id")
645
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
646
+					return
647
+				}
648
+				id := int64(items["id"].(float64))
649
+
650
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
651
+					utils.ErrorLog("type")
652
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
653
+					return
654
+				}
655
+				types := int64(items["type"].(float64))
656
+
657
+				historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
658
+
659
+				ctime := time.Now().Unix()
660
+
661
+				prescription := &models.HisPrescription{
662
+					ID:                 id,
663
+					PatientId:          patient_id,
664
+					UserOrgId:          adminInfo.CurrentOrgId,
665
+					RecordDate:         recordDateTime,
666
+					Ctime:              ctime,
667
+					Mtime:              ctime,
668
+					Type:               types,
669
+					Modifier:           adminInfo.AdminUser.Id,
670
+					Creator:            adminInfo.AdminUser.Id,
671
+					Status:             1,
672
+					Doctor:             role.UserName,
673
+					HisPatientId:       his_patient_id,
674
+					OrderStatus:        1,
675
+					BatchNumber:        "",
676
+					PrescriptionNumber: hpInfo.PrescriptionNumber,
677
+				}
678
+
679
+				if historyPrescription.ID > 0 {
680
+					prescription.PreTime = historyPrescription.PreTime
681
+				}
682
+
683
+				service.SaveHisPrescription(prescription)
684
+
685
+				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
686
+					advices := items["advices"].([]interface{})
687
+					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
688
+					groupNo := int64(0)
689
+					ctime := time.Now().Unix()
690
+					mtime := ctime
691
+					if len(advices) > 0 {
692
+						for _, advice := range advices {
693
+							var s models.HisDoctorAdviceInfo
694
+							s.PrescriptionId = prescription.ID
695
+							s.AdviceType = 2
696
+							s.AdviceDoctor = adminInfo.AdminUser.Id
697
+							s.StopState = 2
698
+							s.ExecutionState = 2
699
+							s.AdviceDate = recordDateTime
700
+							s.Status = 1
701
+							s.UserOrgId = adminInfo.CurrentOrgId
702
+							s.RecordDate = recordDateTime
703
+							s.StartTime = prescription.PreTime
704
+							s.Groupno = groupNo
705
+							s.CreatedTime = ctime
706
+							s.UpdatedTime = mtime
707
+							s.PatientId = patient_id
708
+							s.HisPatientId = his_patient_id
709
+							errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
710
+							if errcode > 0 {
711
+								c.ServeFailJSONWithSGJErrorCode(errcode)
712
+								return
713
+							}
714
+							service.CreateHisDoctorAdvice(&s)
715
+
716
+						}
717
+					}
718
+				}
719
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
720
+					projects := items["project"].([]interface{})
721
+					if len(projects) > 0 {
722
+						for _, project := range projects {
723
+							var p models.HisPrescriptionProject
724
+							p.PrescriptionId = prescription.ID
725
+							p.Ctime = time.Now().Unix()
726
+							p.Mtime = time.Now().Unix()
727
+							p.PatientId = patient_id
728
+							p.RecordDate = recordDateTime
729
+							p.UserOrgId = adminInfo.CurrentOrgId
730
+							p.HisPatientId = his_patient_id
731
+							p.Status = 1
732
+							errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
733
+							if errcode > 0 {
734
+								c.ServeFailJSONWithSGJErrorCode(errcode)
735
+								return
736
+							}
737
+							service.CreateHisProjectTwo(&p)
738
+
739
+						}
740
+					}
741
+				}
742
+				if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
743
+					addition := items["addition"].([]interface{})
744
+					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
745
+					ctime := time.Now().Unix()
746
+					mtime := ctime
747
+					if len(addition) > 0 {
748
+						for _, item := range addition {
749
+							var s models.HisAdditionalCharge
750
+							s.PrescriptionId = prescription.ID
751
+							s.Status = 1
752
+							s.UserOrgId = adminInfo.CurrentOrgId
753
+							s.RecordDate = recordDateTime
754
+							s.CreatedTime = ctime
755
+							s.UpdatedTime = mtime
756
+							s.PatientId = patient_id
757
+							s.HisPatientId = his_patient_id
758
+							errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
759
+							if errcode > 0 {
760
+								c.ServeFailJSONWithSGJErrorCode(errcode)
761
+								return
762
+							}
763
+							service.CreateAdditionalCharge(&s)
764
+						}
765
+					}
766
+				}
767
+
768
+			}
769
+		}
770
+	}
771
+	if err == nil {
772
+		c.ServeSuccessJSON(map[string]interface{}{
773
+			"msg": "保存成功",
774
+		})
775
+		return
776
+
777
+	} else {
778
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
779
+		return
780
+	}
781
+}
529 782
 
530 783
 func (c *HisApiController) DeletePrescription() {
531 784
 	prescription_id, _ := c.GetInt64("id")
@@ -745,130 +998,379 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
745 998
 		Diagnose:                diagnose,
746 999
 	}
747 1000
 
748
-	err = service.SaveHisPatientCaseHistory(&caseHistory)
749
-	if err != nil {
750
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
751
-		return
1001
+	err = service.SaveHisPatientCaseHistory(&caseHistory)
1002
+	if err != nil {
1003
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
1004
+		return
1005
+	}
1006
+	c.ServeSuccessJSON(map[string]interface{}{
1007
+		"caseHistory": caseHistory,
1008
+	})
1009
+	return
1010
+
1011
+	//查询该患者是否有病历
1012
+	//_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
1013
+	//if errcode == gorm.ErrRecordNotFound {
1014
+	//	err = service.SaveHisPatientCaseHistory(caseHistory)
1015
+	//	if err != nil {
1016
+	//		c.ServeSuccessJSON(map[string]interface{}{
1017
+	//			"msg": "保存成功",
1018
+	//		})
1019
+	//	}
1020
+	//} else if errcode == nil {
1021
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
1022
+	//	return
1023
+	//}
1024
+
1025
+}
1026
+func (c *HisApiController) GetHisPatientCaseHistoryList() {
1027
+	patient_id, _ := c.GetInt64("patient_id", 0)
1028
+	adminUser := c.GetAdminUserInfo()
1029
+	caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
1030
+	c.ServeSuccessJSON(map[string]interface{}{
1031
+		"list": caseHistorys,
1032
+	})
1033
+
1034
+}
1035
+func (c *HisApiController) GetHisPatientCaseHistory() {
1036
+	record_date, _ := c.GetInt64("record_date", 0)
1037
+	patient_id, _ := c.GetInt64("patient_id", 0)
1038
+	admin := c.GetAdminUserInfo()
1039
+	info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
1040
+	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
1041
+	c.ServeSuccessJSON(map[string]interface{}{
1042
+		"info":         info,
1043
+		"case_history": case_history,
1044
+	})
1045
+
1046
+}
1047
+func (c *HisApiController) CreateCaseHistoryTemplate() {
1048
+	template_name := c.GetString("template_name")
1049
+	fmt.Println("template_name22222222222222", template_name)
1050
+	template_remark := c.GetString("template_remark")
1051
+	doctor := c.GetAdminUserInfo().AdminUser.Id
1052
+	diagnostic := c.GetString("diagnostic")
1053
+	chief_conplaint := c.GetString("chief_conplain")
1054
+	history_of_present_illness := c.GetString("history_of_present_illness")
1055
+	past_history := c.GetString("past_history")
1056
+	personal_history := c.GetString("personal_history")
1057
+	family_history := c.GetString("family_history")
1058
+	user_name := c.GetString("user_name")
1059
+	doctor_advice := c.GetString("doctor_advice")
1060
+	remark := c.GetString("remark")
1061
+	//record_date := c.GetString("record_date")
1062
+	//fmt.Println("record_date--------",record_date)
1063
+	//timeLayout := "2006-01-02"
1064
+	//loc, _ := time.LoadLocation("Local")
1065
+	//
1066
+	//theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
1067
+	//if err != nil {
1068
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1069
+	//	return
1070
+	//}
1071
+	//recordDateTime := theTime.Unix()
1072
+
1073
+	ctime := time.Now().Unix()
1074
+
1075
+	template := models.HisCaseHistoryTemplate{
1076
+		HistoryOfPresentIllness: history_of_present_illness,
1077
+		PastHistory:             past_history,
1078
+		ChiefConplaint:          chief_conplaint,
1079
+		PersonalHistory:         personal_history,
1080
+		FamilyHistory:           family_history,
1081
+		Diagnostic:              diagnostic,
1082
+		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
1083
+		Status:                  1,
1084
+		Ctime:                   ctime,
1085
+		Mtime:                   ctime,
1086
+		RecordDate:              time.Now().Unix(),
1087
+		TemplateName:            template_name,
1088
+		TemplateRemark:          template_remark,
1089
+		Creator:                 doctor,
1090
+		Modifier:                doctor,
1091
+		UserName:                user_name,
1092
+		DoctorAdvice:            doctor_advice,
1093
+		Remark:                  remark,
1094
+	}
1095
+
1096
+	err := service.SaveHisPatientCaseHistoryTemplate(template)
1097
+
1098
+	if err == nil {
1099
+		c.ServeSuccessJSON(map[string]interface{}{
1100
+			"msg": "保存成功",
1101
+		})
1102
+
1103
+	} else {
1104
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1105
+		return
1106
+	}
1107
+
1108
+}
1109
+func (c *HisApiController) GetCaseHistoryTemplate() {
1110
+	timeLayout := "2006-01-02"
1111
+	loc, _ := time.LoadLocation("Local")
1112
+	keyword := c.GetString("keyword")
1113
+	start_time := c.GetString("start_time")
1114
+	end_time := c.GetString("end_time")
1115
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1116
+	endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
1117
+	admin := c.GetAdminUserInfo()
1118
+	template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
1119
+	//history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
1120
+	c.ServeSuccessJSON(map[string]interface{}{
1121
+		"template": template,
1122
+		//"history":  history,
1123
+	})
1124
+
1125
+}
1126
+
1127
+func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
1128
+
1129
+	if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
1130
+		utils.ErrorLog("drug_name")
1131
+		return enums.ErrorCodeParamWrong
1132
+	}
1133
+	adviceName, _ := json["drug_name"].(string)
1134
+	if len(adviceName) == 0 {
1135
+		utils.ErrorLog("len(advice_name) == 0")
1136
+		return enums.ErrorCodeParamWrong
1137
+	}
1138
+	advice.AdviceName = adviceName
1139
+	adviceDesc, _ := json["advice_desc"].(string)
1140
+	advice.AdviceDesc = adviceDesc
1141
+	if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
1142
+		drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
1143
+		advice.DrugSpec = drugSpec
1144
+	}
1145
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
1146
+		remark, _ := json["remark"].(string)
1147
+		advice.Remark = remark
1148
+	}
1149
+	if json["id"] == nil {
1150
+		advice.DrugId = 0
1151
+	} else {
1152
+		if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
1153
+			drug_id := int64(json["id"].(float64))
1154
+			advice.DrugId = drug_id
1155
+		}
1156
+	}
1157
+	if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
1158
+		advice_id := int64(json["advice_id"].(float64))
1159
+		advice.ID = advice_id
1160
+		if advice.ID > 0 {
1161
+			hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
1162
+			if err == nil {
1163
+				if hisAdvice.ID > 0 {
1164
+					advice.ExecutionTime = hisAdvice.ExecutionTime
1165
+					advice.ExecutionStaff = hisAdvice.ExecutionStaff
1166
+					advice.ExecutionState = hisAdvice.ExecutionState
1167
+					advice.CheckTime = hisAdvice.CheckTime
1168
+					advice.Checker = hisAdvice.Checker
1169
+					advice.CheckState = hisAdvice.CheckState
1170
+					advice.StartTime = hisAdvice.StartTime
1171
+					advice.FeedetlSn = hisAdvice.FeedetlSn
1172
+
1173
+				}
1174
+			}
1175
+		}
1176
+	}
1177
+
1178
+	//
1179
+	//if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
1180
+	//	execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
1181
+	//	advice.ExecutionTime = execution_time
1182
+	//}
1183
+	//
1184
+	//
1185
+	//
1186
+	//if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
1187
+	//	execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
1188
+	//	advice.ExecutionStaff = execution_staff
1189
+	//}
1190
+	//
1191
+	//
1192
+	//
1193
+	//if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
1194
+	//	execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
1195
+	//	advice.ExecutionState = execution_state
1196
+	//}
1197
+	//
1198
+	//
1199
+	//if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
1200
+	//	check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
1201
+	//	advice.CheckTime = check_time
1202
+	//}
1203
+	//
1204
+	//
1205
+	//if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
1206
+	//	check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
1207
+	//	advice.CheckState = check_state
1208
+	//}
1209
+	//
1210
+	//
1211
+	//if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
1212
+	//	checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
1213
+	//	advice.Checker = checker
1214
+	//}
1215
+	//
1216
+	//if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
1217
+	//	start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
1218
+	//	advice.StartTime = start_time
1219
+	//}
1220
+
1221
+	if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
1222
+		drugSpecUnit, _ := json["min_unit"].(string)
1223
+		advice.DrugSpecUnit = drugSpecUnit
1224
+	}
1225
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
1226
+		singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
1227
+		advice.SingleDose = singleDose
1228
+	}
1229
+	if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
1230
+		singleDoseUnit, _ := json["single_dose_unit"].(string)
1231
+		advice.SingleDoseUnit = singleDoseUnit
1232
+	}
1233
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
1234
+		prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
1235
+		advice.PrescribingNumber = prescribingNumber
1236
+	}
1237
+	if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
1238
+		prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
1239
+		advice.PrescribingNumberUnit = prescribingNumberUnit
1240
+	}
1241
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
1242
+		deliveryWay, _ := json["delivery_way"].(string)
1243
+		advice.DeliveryWay = deliveryWay
1244
+	}
1245
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
1246
+		executionFrequency, _ := json["execution_frequency"].(string)
1247
+		advice.ExecutionFrequency = executionFrequency
1248
+	}
1249
+
1250
+	if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
1251
+		price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
1252
+		advice.Price = price
1253
+	}
1254
+	if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
1255
+		med_list_codg, _ := json["medical_insurance_number"].(string)
1256
+		advice.MedListCodg = med_list_codg
1257
+	}
1258
+	if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
1259
+		day := int64(json["day"].(float64))
1260
+		advice.Day = day
1261
+	}
1262
+	return 0
1263
+}
1264
+
1265
+func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
1266
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
1267
+		id := int64(json["id"].(float64))
1268
+		project.ID = id
1269
+		historyProject, _ := service.GetHisProjectByID(id)
1270
+		project.FeedetlSn = historyProject.FeedetlSn
1271
+
1272
+	}
1273
+	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
1274
+		project_id := int64(json["project_id"].(float64))
1275
+		project.ProjectId = project_id
1276
+
1277
+	}
1278
+	// if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
1279
+	// 	price := int64(json["price"].(float64))
1280
+	// 	formatInt_price := strconv.FormatInt(price, 10)
1281
+	// 	float_price, _ := strconv.ParseFloat(formatInt_price, 64)
1282
+	// 	project.Price = float_price
1283
+	// }
1284
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
1285
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
1286
+		project.Price = price
752 1287
 	}
753
-	c.ServeSuccessJSON(map[string]interface{}{
754
-		"caseHistory": caseHistory,
755
-	})
756
-	return
757 1288
 
758
-	//查询该患者是否有病历
759
-	//_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
760
-	//if errcode == gorm.ErrRecordNotFound {
761
-	//	err = service.SaveHisPatientCaseHistory(caseHistory)
762
-	//	if err != nil {
763
-	//		c.ServeSuccessJSON(map[string]interface{}{
764
-	//			"msg": "保存成功",
765
-	//		})
766
-	//	}
767
-	//} else if errcode == nil {
768
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
769
-	//	return
770
-	//}
1289
+	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
1290
+		total, _ := json["total"].(string)
1291
+		totals, _ := strconv.ParseInt(total, 10, 64)
1292
+		project.Count = totals
1293
+	}
771 1294
 
772
-}
773
-func (c *HisApiController) GetHisPatientCaseHistoryList() {
774
-	patient_id, _ := c.GetInt64("patient_id", 0)
775
-	adminUser := c.GetAdminUserInfo()
776
-	caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
777
-	c.ServeSuccessJSON(map[string]interface{}{
778
-		"list": caseHistorys,
779
-	})
1295
+	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
1296
+		medical_code, _ := json["medical_code"].(string)
1297
+		project.MedListCodg = medical_code
1298
+	}
1299
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
1300
+		single_dose, _ := json["single_dose"].(string)
1301
+		project.SingleDose = single_dose
1302
+	}
780 1303
 
781
-}
782
-func (c *HisApiController) GetHisPatientCaseHistory() {
783
-	record_date, _ := c.GetInt64("record_date", 0)
784
-	patient_id, _ := c.GetInt64("patient_id", 0)
785
-	admin := c.GetAdminUserInfo()
786
-	info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
787
-	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
788
-	c.ServeSuccessJSON(map[string]interface{}{
789
-		"info":         info,
790
-		"case_history": case_history,
791
-	})
1304
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
1305
+		delivery_way, _ := json["delivery_way"].(string)
1306
+		project.DeliveryWay = delivery_way
1307
+	}
1308
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
1309
+		execution_frequency, _ := json["execution_frequency"].(string)
1310
+		project.ExecutionFrequency = execution_frequency
1311
+	}
1312
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
1313
+		remark, _ := json["remark"].(string)
1314
+		project.Remark = remark
1315
+	}
1316
+	if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
1317
+		day, _ := json["number_days"].(string)
1318
+		project.Day = day
1319
+	}
792 1320
 
1321
+	if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
1322
+		unit, _ := json["unit"].(string)
1323
+		project.Unit = unit
1324
+	}
1325
+	return 0
793 1326
 }
794
-func (c *HisApiController) CreateCaseHistoryTemplate() {
795
-	template_name := c.GetString("template_name")
796
-	fmt.Println("template_name22222222222222", template_name)
797
-	template_remark := c.GetString("template_remark")
798
-	doctor := c.GetAdminUserInfo().AdminUser.Id
799
-	diagnostic := c.GetString("diagnostic")
800
-	chief_conplaint := c.GetString("chief_conplain")
801
-	history_of_present_illness := c.GetString("history_of_present_illness")
802
-	past_history := c.GetString("past_history")
803
-	personal_history := c.GetString("personal_history")
804
-	family_history := c.GetString("family_history")
805
-	user_name := c.GetString("user_name")
806
-	doctor_advice := c.GetString("doctor_advice")
807
-	remark := c.GetString("remark")
808
-	//record_date := c.GetString("record_date")
809
-	//fmt.Println("record_date--------",record_date)
810
-	//timeLayout := "2006-01-02"
811
-	//loc, _ := time.LoadLocation("Local")
812
-	//
813
-	//theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
814
-	//if err != nil {
815
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
816
-	//	return
817
-	//}
818
-	//recordDateTime := theTime.Unix()
819 1327
 
820
-	ctime := time.Now().Unix()
821
-
822
-	template := models.HisCaseHistoryTemplate{
823
-		HistoryOfPresentIllness: history_of_present_illness,
824
-		PastHistory:             past_history,
825
-		ChiefConplaint:          chief_conplaint,
826
-		PersonalHistory:         personal_history,
827
-		FamilyHistory:           family_history,
828
-		Diagnostic:              diagnostic,
829
-		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
830
-		Status:                  1,
831
-		Ctime:                   ctime,
832
-		Mtime:                   ctime,
833
-		RecordDate:              time.Now().Unix(),
834
-		TemplateName:            template_name,
835
-		TemplateRemark:          template_remark,
836
-		Creator:                 doctor,
837
-		Modifier:                doctor,
838
-		UserName:                user_name,
839
-		DoctorAdvice:            doctor_advice,
840
-		Remark:                  remark,
1328
+func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
1329
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
1330
+		id := int64(json["id"].(float64))
1331
+		historyAddtions, _ := service.GetHisAdditionByID(id)
1332
+		additionalCharge.ID = id
1333
+		additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
841 1334
 	}
1335
+	if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
1336
+		item_id := int64(json["item_id"].(float64))
1337
+		additionalCharge.ItemId = item_id
1338
+		config, _ := service.GetAdditionChargeByID(org_id, item_id)
1339
+		if config.ID > 0 {
1340
+			if len(config.Code) > 0 {
1341
+				additionalCharge.MedListCodg = config.Code
1342
+			}
1343
+		}
1344
+	}
1345
+	// if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
1346
+	// 	price := int64(json["price"].(float64))
1347
+	// 	formatInt_price := strconv.FormatInt(price, 10)
1348
+	// 	float_price, _ := strconv.ParseFloat(formatInt_price, 64)
1349
+	// 	additionalCharge.Price = float_price
1350
+	// }
842 1351
 
843
-	err := service.SaveHisPatientCaseHistoryTemplate(template)
844
-
845
-	if err == nil {
846
-		c.ServeSuccessJSON(map[string]interface{}{
847
-			"msg": "保存成功",
848
-		})
1352
+	//if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
1353
+	//	price := int64(json["price"].(float64))
1354
+	//	formatInt_price := strconv.FormatInt(price, 10)
1355
+	//	float_price, _ := strconv.ParseFloat(formatInt_price, 64)
1356
+	//	additionalCharge.Price = float_price
1357
+	//}
849 1358
 
850
-	} else {
851
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
852
-		return
1359
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
1360
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
1361
+		additionalCharge.Price = price
1362
+	}
1363
+	if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
1364
+		count, _ := json["count"].(string)
1365
+		counts, _ := strconv.ParseInt(count, 10, 64)
1366
+		additionalCharge.Count = counts
1367
+	}
1368
+	if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
1369
+		item_name, _ := json["item_name"].(string)
1370
+		additionalCharge.ItemName = item_name
853 1371
 	}
854 1372
 
855
-}
856
-func (c *HisApiController) GetCaseHistoryTemplate() {
857
-	timeLayout := "2006-01-02"
858
-	loc, _ := time.LoadLocation("Local")
859
-	keyword := c.GetString("keyword")
860
-	start_time := c.GetString("start_time")
861
-	end_time := c.GetString("end_time")
862
-	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
863
-	endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
864
-	admin := c.GetAdminUserInfo()
865
-	template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
866
-	//history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
867
-	c.ServeSuccessJSON(map[string]interface{}{
868
-		"template": template,
869
-		//"history":  history,
870
-	})
871
-
1373
+	return 0
872 1374
 }
873 1375
 
874 1376
 func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
@@ -1520,6 +2022,8 @@ func (c *HisApiController) GetRegisterInfo() {
1520 2022
 	settlementValue, _ := c.GetInt64("settlement_value")
1521 2023
 	social_type, _ := c.GetInt64("social_type")
1522 2024
 	medical_insurance_card := c.GetString("medical_insurance_card")
2025
+	id_card_type, _ := c.GetInt64("id_card_type")
2026
+
1523 2027
 	timeLayout := "2006-01-02"
1524 2028
 	loc, _ := time.LoadLocation("Local")
1525 2029
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
@@ -1770,6 +2274,7 @@ func (c *HisApiController) GetRegisterInfo() {
1770 2274
 				Ctime:                  time.Now().Unix(),
1771 2275
 				Mtime:                  time.Now().Unix(),
1772 2276
 				Number:                 str,
2277
+				IdCardType:             id_card_type,
1773 2278
 			}
1774 2279
 			service.CreateHisPatient(&hisPatient)
1775 2280
 
@@ -2411,3 +2916,77 @@ func (this *DialysisApiController) GetCallHisPrescription() {
2411 2916
 		return
2412 2917
 	}
2413 2918
 }
2919
+
2920
+func (this *HisApiController) GetHisDayPrescription() {
2921
+	timeLayout := "2006-01-02"
2922
+	loc, _ := time.LoadLocation("Local")
2923
+	start_time := this.GetString("start_time")
2924
+	patient_id, _ := this.GetInt64("patient_id", 0)
2925
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
2926
+	end_time := this.GetString("end_time")
2927
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2928
+	adminUserInfo := this.GetAdminUserInfo()
2929
+	dayHisPrescription, err := service.GetMonthHisPrescription(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix())
2930
+	if err == nil {
2931
+		this.ServeSuccessJSON(map[string]interface{}{
2932
+			"day_prescription": dayHisPrescription,
2933
+		})
2934
+		return
2935
+	} else {
2936
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2937
+		return
2938
+	}
2939
+}
2940
+
2941
+func (c *HisApiController) GetHisChargePatientList() {
2942
+	record_date := c.GetString("record_date")
2943
+	timeLayout := "2006-01-02"
2944
+	loc, _ := time.LoadLocation("Local")
2945
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2946
+	if err != nil {
2947
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2948
+		return
2949
+	}
2950
+	recordDateTime := theTime.Unix()
2951
+	adminInfo := c.GetAdminUserInfo()
2952
+	patients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2953
+	//var patients []*service.Patients
2954
+	//for _, item := range tempPatients{
2955
+	//	if len(item.HisPrescription) > 0 {
2956
+	//		patients = append(patients, item)
2957
+	//	}
2958
+	//}
2959
+	//patients_two, _ := service.GetChargeHisPatientListTwo(adminInfo.CurrentOrgId, "", recordDateTime)
2960
+	c.ServeSuccessJSON(map[string]interface{}{
2961
+		"list": patients,
2962
+		//"list_two":	patients_two,
2963
+	})
2964
+}
2965
+
2966
+func (c *HisApiController) GetHisUnRegisterPatientList() {
2967
+	record_date := c.GetString("record_date")
2968
+	timeLayout := "2006-01-02"
2969
+	loc, _ := time.LoadLocation("Local")
2970
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2971
+	if err != nil {
2972
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2973
+		return
2974
+	}
2975
+	recordDateTime := theTime.Unix()
2976
+	adminUser := c.GetAdminUserInfo()
2977
+
2978
+	tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
2979
+
2980
+	var patients []*service.Patients
2981
+	for _, item := range tempPatients {
2982
+		if item.HisPatient.ID == 0 {
2983
+			patients = append(patients, item)
2984
+		}
2985
+	}
2986
+
2987
+	c.ServeSuccessJSON(map[string]interface{}{
2988
+		"list": patients,
2989
+		//"list_two":	patients_two,
2990
+	})
2991
+
2992
+}

+ 32 - 28
controllers/his_project_api_controller.go View File

@@ -746,6 +746,8 @@ func (this *HisProjectApiController) SaveHisPatient() {
746 746
 	nowtime := recordDate.Unix()
747 747
 	phone := this.GetString("phone")
748 748
 	social_type, _ := this.GetInt64("social_type")
749
+	id_card_type, _ := this.GetInt64("id_card_type")
750
+
749 751
 	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
750 752
 	if errcode == gorm.ErrRecordNotFound {
751 753
 		patient := models.XtHisPatient{
@@ -761,19 +763,20 @@ func (this *HisProjectApiController) SaveHisPatient() {
761 763
 			IsNeedCostOfProduction: cost_checked,
762 764
 			TreatmentCost:          medicalExpense_float,
763 765
 			MedicalInsuranceNumber: medicalinsurancecard,
764
-			Name:                   name,
765
-			RegisterType:           register,
766
-			RegisterCost:           registrationfees_float,
767
-			BalanceAccountsType:    settlementValue,
768
-			Gender:                 sex,
769
-			Total:                  totals_float,
770
-			UserOrgId:              orgId,
771
-			Status:                 1,
772
-			RecordDate:             nowtime,
773
-			IsReturn:               1,
774
-			Ctime:                  time.Now().Unix(),
775
-			Phone:                  phone,
776
-			SocialType:             social_type,
766
+			Name:                name,
767
+			RegisterType:        register,
768
+			RegisterCost:        registrationfees_float,
769
+			BalanceAccountsType: settlementValue,
770
+			Gender:              sex,
771
+			Total:               totals_float,
772
+			UserOrgId:           orgId,
773
+			Status:              1,
774
+			RecordDate:          nowtime,
775
+			IsReturn:            1,
776
+			Ctime:               time.Now().Unix(),
777
+			Phone:               phone,
778
+			SocialType:          social_type,
779
+			IdCardType:          id_card_type,
777 780
 		}
778 781
 
779 782
 		err := service.CreateHisPatient(&patient)
@@ -807,20 +810,21 @@ func (this *HisProjectApiController) SaveHisPatient() {
807 810
 			IsNeedCostOfProduction: cost_checked,
808 811
 			TreatmentCost:          medicalExpense_float,
809 812
 			MedicalInsuranceNumber: medicalinsurancecard,
810
-			Name:                   name,
811
-			RegisterType:           register,
812
-			RegisterCost:           registrationfees_float,
813
-			BalanceAccountsType:    settlementValue,
814
-			Gender:                 sex,
815
-			Total:                  totals_float,
816
-			UserOrgId:              orgId,
817
-			PatientId:              bloodPatient.ID,
818
-			Ctime:                  time.Now().Unix(),
819
-			Phone:                  phone,
820
-			SocialType:             social_type,
821
-			RecordDate:             nowtime,
822
-			Status:                 1,
823
-			IsReturn:               1,
813
+			Name:                name,
814
+			RegisterType:        register,
815
+			RegisterCost:        registrationfees_float,
816
+			BalanceAccountsType: settlementValue,
817
+			Gender:              sex,
818
+			Total:               totals_float,
819
+			UserOrgId:           orgId,
820
+			PatientId:           bloodPatient.ID,
821
+			Ctime:               time.Now().Unix(),
822
+			Phone:               phone,
823
+			SocialType:          social_type,
824
+			IdCardType:          id_card_type,
825
+			RecordDate:          nowtime,
826
+			Status:              1,
827
+			IsReturn:            1,
824 828
 		}
825 829
 
826 830
 		//查询今日没有退号的患者是否已挂号
@@ -1304,7 +1308,7 @@ func (this *HisProjectApiController) GetAllHisPatient() {
1304 1308
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
1305 1309
 	recordDateTime := theTime.Unix()
1306 1310
 	adminUserInfo := this.GetAdminUserInfo()
1307
-	patients, err := service.GetHisPatientList(adminUserInfo.CurrentOrgId, "", recordDateTime)
1311
+	patients, err := service.GetScheduleHisPatientList(adminUserInfo.CurrentOrgId, "", recordDateTime)
1308 1312
 	if err != nil {
1309 1313
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
1310 1314
 		return

+ 16 - 16
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -619,26 +619,27 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
619 619
 			}
620 620
 
621 621
 			if lastPredialysisEvaluation != nil {
622
-				evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId           //血管通路部位
623
-				evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId //血管通路
624
-				evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight             //衣物重
625
-				evaluation.Temperature = lastPredialysisEvaluation.Temperature                       //温度
626
-				evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate                   //呼吸
627
-				evaluation.Catheter = lastPredialysisEvaluation.Catheter                             //导管
628
-				evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula               //内瘘
629
-				evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency                 //脉搏
630
-				evaluation.Complication = lastPredialysisEvaluation.Complication                     //并发症
631
-				evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis             //前次透析后症状
632
-				evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase         //透析期间
633
-				evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis   //透析前症状
634
-				evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle                 //穿刺针
635
-				evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay                       //穿刺方法
622
+				evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
623
+				evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
624
+				evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
625
+				evaluation.Temperature = lastPredialysisEvaluation.Temperature
626
+				evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
627
+				evaluation.Catheter = lastPredialysisEvaluation.Catheter
628
+				evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
629
+				evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
630
+				evaluation.Complication = lastPredialysisEvaluation.Complication
631
+				evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
632
+				evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
633
+				evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
634
+				evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
635
+				evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
636 636
 
637 637
 				evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
638 638
 				evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend               //导管打折
639 639
 				evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage               //出血
640 640
 				evaluation.IsInfect = lastPredialysisEvaluation.IsInfect                       //感染
641 641
 				evaluation.Exposed = lastPredialysisEvaluation.Exposed                         // 外漏
642
+				evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount             //呼吸频次
642 643
 
643 644
 			}
644 645
 		} else {
@@ -736,9 +737,8 @@ func (c *CheckWeightApiController) GetPatientList() {
736 737
 	adminUserInfo := c.GetMobileAdminUserInfo()
737 738
 
738 739
 	patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
739
-	if len(patientList) > 0 {
740 740
 	need_update := 0
741
-	if syncTime ==  0 {
741
+	if syncTime == 0 {
742 742
 		need_update = 1
743 743
 	}
744 744
 	if error != nil {

+ 24 - 0
models/his_models.go View File

@@ -117,6 +117,7 @@ type HisPatient struct {
117 117
 	IptOtpNo               string  `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
118 118
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
119 119
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
120
+	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
120 121
 }
121 122
 
122 123
 func (HisPatient) TableName() string {
@@ -218,6 +219,28 @@ type HisDoctorAdviceInfo struct {
218 219
 	FeedetlSn             string                 `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
219 220
 	Day                   int64                  `gorm:"column:day" json:"day" form:"day"`
220 221
 	ChildDoctorAdvice     []*HisDoctorAdviceInfo `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
222
+	Drug                  Drug                   `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
223
+}
224
+
225
+type Drug struct {
226
+	ID                     int64  `gorm:"column:id" json:"id" form:"id"`
227
+	DrugName               string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
228
+	DrugSpec               string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
229
+	DrugType               int64  `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
230
+	DrugStockLimit         string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
231
+	DrugOriginPlace        string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
232
+	DrugDosageForm         int64  `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
233
+	Manufacturer           int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
234
+	Status                 int64  `gorm:"column:status" json:"status" form:"status"`
235
+	Ctime                  int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
236
+	Mtime                  int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
237
+	OrgId                  int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
238
+	DrugCode               string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
239
+	MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
240
+}
241
+
242
+func (Drug) TableName() string {
243
+	return "xt_base_drug"
221 244
 }
222 245
 
223 246
 func (HisDoctorAdviceInfo) TableName() string {
@@ -576,6 +599,7 @@ type XtHisPatient struct {
576 599
 	IsReturn               int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
577 600
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
578 601
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
602
+	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
579 603
 }
580 604
 
581 605
 func (XtHisPatient) TableName() string {

+ 130 - 21
service/his_service.go View File

@@ -6,6 +6,22 @@ import (
6 6
 	"time"
7 7
 )
8 8
 
9
+type VMSchedule struct {
10
+	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
11
+	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
12
+	PatientId             int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
13
+	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
14
+	ScheduleDate          int64                 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
15
+	Patients              Patients              `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
16
+	HisPatient            HisPatient            `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
17
+	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
18
+	VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
19
+}
20
+
21
+func (VMSchedule) TableName() string {
22
+	return "xt_schedule"
23
+}
24
+
9 25
 type HisPatient struct {
10 26
 	ID              int64              `gorm:"column:id" json:"id" form:"id"`
11 27
 	Name            string             `gorm:"column:name" json:"name" form:"name"`
@@ -24,15 +40,11 @@ func (HisPatient) TableName() string {
24 40
 }
25 41
 
26 42
 type Schedule struct {
27
-	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
28
-	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
29
-	PatientId             int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
30
-	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
31
-	ScheduleDate          int64                 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
32
-	Patients              Patients              `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
33
-	HisPatient            HisPatient            `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
34
-	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
35
-	VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
43
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
44
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
45
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
46
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
47
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36 48
 }
37 49
 
38 50
 func (Schedule) TableName() string {
@@ -67,11 +79,43 @@ func (VMHisPrescriptionInfo) TableName() string {
67 79
 	return "his_prescription_info"
68 80
 }
69 81
 
82
+type VMHisOrder struct {
83
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
84
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
85
+	HisPatientId          int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
86
+	SettleAccountsDate    int64   `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
87
+	Ctime                 int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
88
+	Mtime                 int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
89
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
90
+	Number                string  `gorm:"column:number" json:"number" form:"number"`
91
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
92
+	MedfeeSumamt          float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
93
+	OrderStatus           float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
94
+	PayWay                int64   `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
95
+	PayPrice              float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
96
+	PayCardNo             string  `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
97
+	DiscountPrice         float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
98
+	PreferentialPrice     float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
99
+	RealityPrice          float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
100
+	FoundPrice            float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
101
+	MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
102
+	PrivatePrice          float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
103
+}
104
+
105
+func (VMHisOrder) TableName() string {
106
+	return "his_order"
107
+}
108
+
70 109
 type Patients struct {
71
-	ID        int64  `gorm:"column:id" json:"id" form:"id"`
72
-	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
73
-	Name      string `gorm:"column:name" json:"name" form:"name"`
74
-	Status    int64  `gorm:"column:status" json:"status" form:"status"`
110
+	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
111
+	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
112
+	Name                  string                `gorm:"column:name" json:"name" form:"name"`
113
+	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
114
+	Schedule              Schedule              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
115
+	HisPatient            HisPatient            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
116
+	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
117
+	VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
118
+	VMHisOrder            VMHisOrder            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
75 119
 }
76 120
 
77 121
 func (Patients) TableName() string {
@@ -91,11 +135,45 @@ func (HisPrescription) TableName() string {
91 135
 	return "his_prescription"
92 136
 }
93 137
 
94
-func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
95
-	db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
96
-	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
97
-	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
98
-	err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
138
+func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
139
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
140
+		Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ?", record_date, org_id)
141
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
142
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
143
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
144
+	return
145
+}
146
+
147
+func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
148
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
149
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
150
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
151
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
152
+	return
153
+}
154
+
155
+func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
156
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
157
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
158
+	db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
159
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
160
+	return
161
+}
162
+
163
+func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
164
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
165
+		Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
166
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
167
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
168
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
169
+	return
170
+}
171
+
172
+func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
173
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
174
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
175
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
176
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
99 177
 	return
100 178
 }
101 179
 
@@ -195,13 +273,29 @@ func DelelteProject(id int64, user_org_id int64) (err error) {
195 273
 }
196 274
 
197 275
 func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
276
+	err = readDb.Model(&models.HisPrescription{}).
277
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
278
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
279
+		}).
280
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
281
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
282
+		}).
283
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
284
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
285
+		}).
286
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
287
+		Find(&prescription).Error
288
+	return
289
+}
290
+
291
+func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
198 292
 	err = readDb.Model(&models.HisPrescription{}).
199 293
 		Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
200 294
 		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
201 295
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
202 296
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
203 297
 		}).
204
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
298
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_date, end_date, patient_id).
205 299
 		Find(&prescription).Error
206 300
 	return
207 301
 }
@@ -700,9 +794,9 @@ func DelelteAddition(id int64, user_org_id int64) (err error) {
700 794
 	return
701 795
 }
702 796
 
703
-func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
797
+func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
704 798
 	offset := (page - 1) * limit
705
-	db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
799
+	db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
706 800
 	if len(keywords) > 0 {
707 801
 		keywords = "%" + keywords + "%"
708 802
 		db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
@@ -828,3 +922,18 @@ func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtion
828 922
 	return
829 923
 
830 924
 }
925
+
926
+func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
927
+	err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
928
+	return
929
+}
930
+
931
+func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
932
+	err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1  AND id = ?", id).First(&project).Error
933
+	return
934
+}
935
+
936
+func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
937
+	err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1  AND id = ?", id).First(&addition).Error
938
+	return
939
+}