Parcourir la source

Merge branch '20230223_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20230223_xt_api_new_branch

28169 il y a 1 mois
Parent
révision
035a7ff110
2 fichiers modifiés avec 344 ajouts et 331 suppressions
  1. 343 330
      controllers/his_api_controller.go
  2. 1 1
      service/his_print_service.go

+ 343 - 330
controllers/his_api_controller.go Voir le fichier

@@ -35,7 +35,7 @@ func HisManagerApiRegistRouters() {
35 35
 	beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
36 36
 	beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
37 37
 	beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
38
-	beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
38
+	//beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
39 39
 	beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
40 40
 	beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
41 41
 	beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
@@ -3091,6 +3091,17 @@ func (c *HisApiController) CreateHisPrescription() {
3091 3091
 	var adviceList []models.HisDoctorAdviceInfo
3092 3092
 	var projectList []models.HisPrescriptionProject
3093 3093
 
3094
+	// 开始主事务
3095
+	db := service.XTWriteDB()
3096
+	tx := db.Begin()
3097
+
3098
+	// 在函数结束时处理事务回滚
3099
+	defer func() {
3100
+		if r := recover(); r != nil {
3101
+			tx.Rollback()
3102
+		}
3103
+	}()
3104
+
3094 3105
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3095 3106
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
3096 3107
 
@@ -3098,6 +3109,16 @@ func (c *HisApiController) CreateHisPrescription() {
3098 3109
 
3099 3110
 		if len(prescriptions) > 0 {
3100 3111
 			for _, item := range prescriptions {
3112
+				// 开始外部循环的事务
3113
+				tx := db.Begin()
3114
+
3115
+				// 在函数结束时处理事务回滚
3116
+				defer func() {
3117
+					if r := recover(); r != nil {
3118
+						tx.Rollback()
3119
+					}
3120
+				}()
3121
+
3101 3122
 				items := item.(map[string]interface{})
3102 3123
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
3103 3124
 					utils.ErrorLog("id")
@@ -3168,7 +3189,7 @@ func (c *HisApiController) CreateHisPrescription() {
3168 3189
 						MedType:            med_type,
3169 3190
 					}
3170 3191
 					tempPrescription = prescription
3171
-					service.SaveHisPrescription(tempPrescription)
3192
+					service.SaveHisPrescription(tx, tempPrescription)
3172 3193
 					redis := service.RedisClient()
3173 3194
 					key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
3174 3195
 					redis.Set(key, "", time.Second)
@@ -3187,7 +3208,7 @@ func (c *HisApiController) CreateHisPrescription() {
3187 3208
 					//tempPrescription.OrderStatus = order_status
3188 3209
 					tempPrescription.PreTime = pTime
3189 3210
 					tempPrescription.MedType = med_type
3190
-					service.SaveHisPrescription(tempPrescription)
3211
+					service.SaveHisPrescription(tx, tempPrescription)
3191 3212
 					redis := service.RedisClient()
3192 3213
 					key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
3193 3214
 
@@ -3211,6 +3232,15 @@ func (c *HisApiController) CreateHisPrescription() {
3211 3232
 					mtime := ctime
3212 3233
 					if len(advices) > 0 {
3213 3234
 						for _, advice := range advices {
3235
+							tx := db.Begin()
3236
+
3237
+							// 在函数结束时处理事务回滚
3238
+							defer func() {
3239
+								if r := recover(); r != nil {
3240
+									tx.Rollback()
3241
+								}
3242
+							}()
3243
+
3214 3244
 							var s models.HisDoctorAdviceInfo
3215 3245
 							s.PrescriptionId = tempPrescription.ID
3216 3246
 							s.AdviceType = 2
@@ -3264,7 +3294,7 @@ func (c *HisApiController) CreateHisPrescription() {
3264 3294
 								}
3265 3295
 							}
3266 3296
 
3267
-							service.CreateHisDoctorAdvice(&s)
3297
+							service.CreateHisDoctorAdvice(&s, tx)
3268 3298
 
3269 3299
 							//记录日志
3270 3300
 							byterequest, _ := json.Marshal(s)
@@ -3298,7 +3328,7 @@ func (c *HisApiController) CreateHisPrescription() {
3298 3328
 							tempTime := time.Unix(timestamp, 0)
3299 3329
 							timeFormat := tempTime.Format("20060102150405")
3300 3330
 							s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
3301
-							service.CreateHisDoctorAdvice(&s)
3331
+							service.CreateHisDoctorAdvice(&s, tx)
3302 3332
 							keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
3303 3333
 							redis.Set(keySix, "", time.Second)
3304 3334
 							keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
@@ -3315,6 +3345,14 @@ func (c *HisApiController) CreateHisPrescription() {
3315 3345
 					projects := items["project"].([]interface{})
3316 3346
 					if len(projects) > 0 {
3317 3347
 						for _, project := range projects {
3348
+							tx := db.Begin()
3349
+
3350
+							// 在函数结束时处理事务回滚
3351
+							defer func() {
3352
+								if r := recover(); r != nil {
3353
+									tx.Rollback()
3354
+								}
3355
+							}()
3318 3356
 
3319 3357
 							var p models.HisPrescriptionProject
3320 3358
 							p.PrescriptionId = tempPrescription.ID
@@ -3371,7 +3409,7 @@ func (c *HisApiController) CreateHisPrescription() {
3371 3409
 							//
3372 3410
 							//}
3373 3411
 
3374
-							service.CreateHisProjectTwo(&p)
3412
+							service.CreateHisProjectTwo(&p, tx)
3375 3413
 							//记录日志
3376 3414
 							byterequest, _ := json.Marshal(p)
3377 3415
 							adviceLog := models.XtDoctorAdviceLog{
@@ -3422,7 +3460,7 @@ func (c *HisApiController) CreateHisPrescription() {
3422 3460
 												label.PProjectId = p.ID
3423 3461
 												label.ProjectName = team.ProjectTeam
3424 3462
 												label.PatientName = patient.Name
3425
-												service.CreateHisLabelRecord(&label)
3463
+												service.CreateHisLabelRecord(&label, tx)
3426 3464
 											}
3427 3465
 										} else { //单条检验检查项目
3428 3466
 											label.Number = tempPrescription.PrescriptionNumber
@@ -3440,13 +3478,13 @@ func (c *HisApiController) CreateHisPrescription() {
3440 3478
 											label.ItemId = p.TeamId
3441 3479
 											label.ProjectName = project.ProjectName
3442 3480
 											label.PatientName = patient.Name
3443
-											service.CreateHisLabelRecord(&label)
3481
+											service.CreateHisLabelRecord(&label, tx)
3444 3482
 										}
3445 3483
 									}
3446 3484
 								}
3447 3485
 							}
3448 3486
 
3449
-							service.SaveHisProjectTwo(&p)
3487
+							service.SaveHisProjectTwo(&p, tx)
3450 3488
 
3451 3489
 						}
3452 3490
 					}
@@ -3747,33 +3785,7 @@ func (c *HisApiController) CreateHisPrescription() {
3747 3785
 		}
3748 3786
 	}
3749 3787
 
3750
-	//redisClient := service.RedisClient()
3751
-	//defer redisClient.Close()
3752
-	//
3753
-	//list := models.HisList{
3754
-	//  Patient_id:  patient_id,
3755
-	//  Advice_id:0,
3756
-	//  Record_date: 0,
3757
-	//  Advice:      adviceList,
3758
-	//  Project:     nil,
3759
-	//}
3760
-	//hisLis = append(hisLis, list)
3761
-	//
3762
-	//advice_json, _ := json.Marshal(&hisLis)
3763
-	//redisClient.RPush("111", advice_json).Result()
3764
-	//result, _ := redisClient.RPop("111").Result()
3765
-	//fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
3766
-	//
3767
-	//var dat []map[string]interface{}
3768
-	//json.Unmarshal([]byte(result), &dat)
3769
-	//fmt.Println("hhhh2332323232233223322332322323232323",dat)
3770
-	//
3771
-	//for k,v:=range dat{
3772
-	//  fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
3773
-	//}
3774
-	//project_json, _ := json.Marshal(&projectList)
3775
-	//redisClient.LPush("222", project_json).Result()
3776
-
3788
+	tx.Commit()
3777 3789
 	if err == nil {
3778 3790
 		c.ServeSuccessJSON(map[string]interface{}{
3779 3791
 			"msg": "保存成功",
@@ -3786,299 +3798,300 @@ func (c *HisApiController) CreateHisPrescription() {
3786 3798
 	}
3787 3799
 
3788 3800
 }
3789
-func (c *HisApiController) EditHisPrescription() {
3790
-	record_date := c.GetString("record_date")
3791
-	patient_id, _ := c.GetInt64("patient_id")
3792
-	reg_type, _ := c.GetInt64("reg_type")
3793
-	//diagnose, _ := c.GetInt64("diagnose", 0)
3794
-	diagnose := c.GetString("diagnose")
3795
-	sick_type, _ := c.GetInt64("sick_type")
3796
-	sick_history := c.GetString("sick_history")
3797
-	doctor_id, _ := c.GetInt64("doctor", 0)
3798
-	department, _ := c.GetInt64("department", 0)
3799
-	his_patient_id, _ := c.GetInt64("his_patient_id")
3800
-	p_type, _ := c.GetInt64("p_type")
3801
-
3802
-	dataBody := make(map[string]interface{}, 0)
3803
-	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
3804
-	if err != nil {
3805
-		utils.ErrorLog(err.Error())
3806
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3807
-		return
3808
-	}
3809 3801
 
3810
-	timeLayout := "2006-01-02"
3811
-	loc, _ := time.LoadLocation("Local")
3812
-	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
3813
-	if err != nil {
3814
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3815
-		return
3816
-	}
3817
-	adminInfo := c.GetAdminUserInfo()
3818
-	recordDateTime := theTime.Unix()
3819
-
3820
-	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
3821
-
3822
-	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
3823
-	var hpInfo models.HisPrescriptionInfo
3824
-	if info.ID == 0 {
3825
-		var randNum int
3826
-		randNum = rand.Intn(10000) + 1000
3827
-		timestamp := time.Now().Unix()
3828
-		tempTime := time.Unix(timestamp, 0)
3829
-		timeFormat := tempTime.Format("20060102150405")
3830
-		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
3831
-
3832
-		hpInfo = models.HisPrescriptionInfo{
3833
-			UserOrgId:          adminInfo.CurrentOrgId,
3834
-			RecordDate:         theTime.Unix(),
3835
-			PatientId:          patient_id,
3836
-			Status:             1,
3837
-			Ctime:              time.Now().Unix(),
3838
-			Mtime:              time.Now().Unix(),
3839
-			Creator:            adminInfo.AdminUser.Id,
3840
-			Modifier:           adminInfo.AdminUser.Id,
3841
-			Diagnosis:          diagnose,
3842
-			SickHistory:        sick_history,
3843
-			Departments:        department,
3844
-			RegisterType:       reg_type,
3845
-			PrescriptionNumber: p_number,
3846
-			PrescriptionStatus: 1,
3847
-			Doctor:             role.UserName,
3848
-			DoctorId:           doctor_id,
3849
-			SickType:           sick_type,
3850
-			PType:              p_type,
3851
-		}
3852
-		service.SavePatientPrescriptionInfo(hpInfo)
3853
-
3854
-	} else {
3855
-		hpInfo = models.HisPrescriptionInfo{
3856
-			ID:                 info.ID,
3857
-			UserOrgId:          adminInfo.CurrentOrgId,
3858
-			RecordDate:         info.RecordDate,
3859
-			PatientId:          info.PatientId,
3860
-			Status:             1,
3861
-			Ctime:              info.Ctime,
3862
-			Mtime:              time.Now().Unix(),
3863
-			Creator:            info.Creator,
3864
-			Modifier:           adminInfo.AdminUser.Id,
3865
-			Diagnosis:          diagnose,
3866
-			SickHistory:        sick_history,
3867
-			Departments:        department,
3868
-			RegisterType:       reg_type,
3869
-			PrescriptionNumber: info.PrescriptionNumber,
3870
-			Doctor:             role.UserName,
3871
-			PrescriptionStatus: info.PrescriptionStatus,
3872
-			DoctorId:           doctor_id,
3873
-			SickType:           sick_type,
3874
-			PType:              info.PType,
3875
-		}
3876
-		service.SavePatientPrescriptionInfo(hpInfo)
3877
-	}
3878
-
3879
-	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3880
-		prescriptions, _ := dataBody["prescriptions"].([]interface{})
3881
-
3882
-		if len(prescriptions) > 0 {
3883
-			for _, item := range prescriptions {
3884
-				items := item.(map[string]interface{})
3885
-				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
3886
-					utils.ErrorLog("id")
3887
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3888
-					return
3889
-				}
3890
-				id := int64(items["id"].(float64))
3891
-
3892
-				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
3893
-					utils.ErrorLog("type")
3894
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3895
-					return
3896
-				}
3897
-				types := int64(items["type"].(float64))
3898
-
3899
-				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
3900
-					utils.ErrorLog("med_type")
3901
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3902
-					return
3903
-				}
3904
-				med_type := strconv.Itoa(int(items["med_type"].(float64)))
3905
-
3906
-				historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
3907
-
3908
-				ctime := time.Now().Unix()
3909
-
3910
-				prescription := &models.HisPrescription{
3911
-					ID:                 id,
3912
-					PatientId:          patient_id,
3913
-					UserOrgId:          adminInfo.CurrentOrgId,
3914
-					RecordDate:         recordDateTime,
3915
-					Ctime:              ctime,
3916
-					Mtime:              ctime,
3917
-					Type:               types,
3918
-					Modifier:           adminInfo.AdminUser.Id,
3919
-					Creator:            adminInfo.AdminUser.Id,
3920
-					Status:             1,
3921
-					Doctor:             role.UserName,
3922
-					HisPatientId:       his_patient_id,
3923
-					OrderStatus:        1,
3924
-					BatchNumber:        "",
3925
-					PrescriptionNumber: hpInfo.PrescriptionNumber,
3926
-					PType:              hpInfo.PType,
3927
-					MedType:            med_type,
3928
-				}
3929
-
3930
-				if historyPrescription.ID > 0 {
3931
-					prescription.PreTime = historyPrescription.PreTime
3932
-
3933
-				}
3934
-
3935
-				service.SaveHisPrescription(prescription)
3936
-
3937
-				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
3938
-					advices := items["advices"].([]interface{})
3939
-					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
3940
-					groupNo := int64(0)
3941
-					ctime := time.Now().Unix()
3942
-					mtime := ctime
3943
-					if len(advices) > 0 {
3944
-						for _, advice := range advices {
3945
-							var s models.HisDoctorAdviceInfo
3946
-							s.PrescriptionId = prescription.ID
3947
-							s.AdviceType = 2
3948
-							s.AdviceDoctor = adminInfo.AdminUser.Id
3949
-							s.StopState = 2
3950
-							s.ExecutionState = 2
3951
-							s.AdviceDate = recordDateTime
3952
-							s.Status = 1
3953
-							s.UserOrgId = adminInfo.CurrentOrgId
3954
-							s.RecordDate = recordDateTime
3955
-							s.StartTime = prescription.PreTime
3956
-							s.Groupno = groupNo
3957
-							s.CreatedTime = ctime
3958
-							s.UpdatedTime = mtime
3959
-							s.PatientId = patient_id
3960
-							s.HisPatientId = his_patient_id
3961
-							errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
3962
-							if errcode > 0 {
3963
-								c.ServeFailJSONWithSGJErrorCode(errcode)
3964
-								return
3965
-							}
3966
-
3967
-							if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
3968
-								storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3969
-								lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
3970
-								if s.Price == 0 {
3971
-									s.Price = lastWarehouse.RetailPrice
3972
-								}
3973
-							}
3974
-
3975
-							service.CreateHisDoctorAdvice(&s)
3976
-							//记录日志
3977
-							byterequest, _ := json.Marshal(s)
3978
-							adviceLog := models.XtDoctorAdviceLog{
3979
-								UserOrgId:   s.UserOrgId,
3980
-								PatientId:   s.PatientId,
3981
-								AdminUserId: adminInfo.AdminUser.Id,
3982
-								Module:      1,
3983
-								ErrLog:      string(byterequest),
3984
-								Status:      1,
3985
-								Ctime:       time.Now().Unix(),
3986
-								Mtime:       0,
3987
-								Source:      "电脑端his医嘱修改",
3988
-								RecordDate:  s.AdviceDate,
3989
-							}
3990
-							service.CreateDoctorAdviceLog(adviceLog)
3991
-							redis := service.RedisClient()
3992
-							key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
3993
-							redis.Set(key, "", time.Second)
3994
-							keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
3995
-							fmt.Println("keyOne", keyOne)
3996
-							redis.Set(keyOne, "", time.Second)
3997
-							keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
3998
-							redis.Set(keySeven, "", time.Second)
3999
-							redis.Close()
4000
-
4001
-						}
4002
-					}
4003
-				}
4004
-				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
4005
-					projects := items["project"].([]interface{})
4006
-					if len(projects) > 0 {
4007
-						for _, project := range projects {
4008
-							var p models.HisPrescriptionProject
4009
-							p.PrescriptionId = prescription.ID
4010
-							p.Ctime = time.Now().Unix()
4011
-							p.Mtime = time.Now().Unix()
4012
-							p.PatientId = patient_id
4013
-							p.RecordDate = recordDateTime
4014
-							p.UserOrgId = adminInfo.CurrentOrgId
4015
-							p.HisPatientId = his_patient_id
4016
-							p.Status = 1
4017
-							errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
4018
-							if errcode > 0 {
4019
-								c.ServeFailJSONWithSGJErrorCode(errcode)
4020
-								return
4021
-							}
4022
-							service.CreateHisProjectTwo(&p)
4023
-
4024
-							//记录日志
4025
-							byterequest, _ := json.Marshal(p)
4026
-							adviceLog := models.XtDoctorAdviceLog{
4027
-								UserOrgId:   p.UserOrgId,
4028
-								PatientId:   p.PatientId,
4029
-								AdminUserId: adminInfo.AdminUser.Id,
4030
-								Module:      1,
4031
-								ErrLog:      string(byterequest),
4032
-								Status:      1,
4033
-								Ctime:       time.Now().Unix(),
4034
-								Mtime:       0,
4035
-								Source:      "电脑端his项目修改",
4036
-								RecordDate:  p.RecordDate,
4037
-							}
4038
-							service.CreateDoctorAdviceLog(adviceLog)
4039
-						}
4040
-					}
4041
-				}
4042
-				if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
4043
-					addition := items["addition"].([]interface{})
4044
-					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
4045
-					ctime := time.Now().Unix()
4046
-					mtime := ctime
4047
-					if len(addition) > 0 {
4048
-						for _, item := range addition {
4049
-							var s models.HisAdditionalCharge
4050
-							s.PrescriptionId = prescription.ID
4051
-							s.Status = 1
4052
-							s.UserOrgId = adminInfo.CurrentOrgId
4053
-							s.RecordDate = recordDateTime
4054
-							s.CreatedTime = ctime
4055
-							s.UpdatedTime = mtime
4056
-							s.PatientId = patient_id
4057
-							s.HisPatientId = his_patient_id
4058
-							errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
4059
-							if errcode > 0 {
4060
-								c.ServeFailJSONWithSGJErrorCode(errcode)
4061
-								return
4062
-							}
4063
-							service.CreateAdditionalCharge(&s)
4064
-						}
4065
-					}
4066
-				}
4067
-
4068
-			}
4069
-		}
4070
-	}
4071
-	if err == nil {
4072
-		c.ServeSuccessJSON(map[string]interface{}{
4073
-			"msg": "保存成功",
4074
-		})
4075
-		return
4076
-
4077
-	} else {
4078
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4079
-		return
4080
-	}
4081
-}
3802
+//func (c *HisApiController) EditHisPrescription() {
3803
+//	record_date := c.GetString("record_date")
3804
+//	patient_id, _ := c.GetInt64("patient_id")
3805
+//	reg_type, _ := c.GetInt64("reg_type")
3806
+//	//diagnose, _ := c.GetInt64("diagnose", 0)
3807
+//	diagnose := c.GetString("diagnose")
3808
+//	sick_type, _ := c.GetInt64("sick_type")
3809
+//	sick_history := c.GetString("sick_history")
3810
+//	doctor_id, _ := c.GetInt64("doctor", 0)
3811
+//	department, _ := c.GetInt64("department", 0)
3812
+//	his_patient_id, _ := c.GetInt64("his_patient_id")
3813
+//	p_type, _ := c.GetInt64("p_type")
3814
+//
3815
+//	dataBody := make(map[string]interface{}, 0)
3816
+//	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
3817
+//	if err != nil {
3818
+//		utils.ErrorLog(err.Error())
3819
+//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3820
+//		return
3821
+//	}
3822
+//
3823
+//	timeLayout := "2006-01-02"
3824
+//	loc, _ := time.LoadLocation("Local")
3825
+//	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
3826
+//	if err != nil {
3827
+//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3828
+//		return
3829
+//	}
3830
+//	adminInfo := c.GetAdminUserInfo()
3831
+//	recordDateTime := theTime.Unix()
3832
+//
3833
+//	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
3834
+//
3835
+//	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
3836
+//	var hpInfo models.HisPrescriptionInfo
3837
+//	if info.ID == 0 {
3838
+//		var randNum int
3839
+//		randNum = rand.Intn(10000) + 1000
3840
+//		timestamp := time.Now().Unix()
3841
+//		tempTime := time.Unix(timestamp, 0)
3842
+//		timeFormat := tempTime.Format("20060102150405")
3843
+//		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
3844
+//
3845
+//		hpInfo = models.HisPrescriptionInfo{
3846
+//			UserOrgId:          adminInfo.CurrentOrgId,
3847
+//			RecordDate:         theTime.Unix(),
3848
+//			PatientId:          patient_id,
3849
+//			Status:             1,
3850
+//			Ctime:              time.Now().Unix(),
3851
+//			Mtime:              time.Now().Unix(),
3852
+//			Creator:            adminInfo.AdminUser.Id,
3853
+//			Modifier:           adminInfo.AdminUser.Id,
3854
+//			Diagnosis:          diagnose,
3855
+//			SickHistory:        sick_history,
3856
+//			Departments:        department,
3857
+//			RegisterType:       reg_type,
3858
+//			PrescriptionNumber: p_number,
3859
+//			PrescriptionStatus: 1,
3860
+//			Doctor:             role.UserName,
3861
+//			DoctorId:           doctor_id,
3862
+//			SickType:           sick_type,
3863
+//			PType:              p_type,
3864
+//		}
3865
+//		service.SavePatientPrescriptionInfo(hpInfo)
3866
+//
3867
+//	} else {
3868
+//		hpInfo = models.HisPrescriptionInfo{
3869
+//			ID:                 info.ID,
3870
+//			UserOrgId:          adminInfo.CurrentOrgId,
3871
+//			RecordDate:         info.RecordDate,
3872
+//			PatientId:          info.PatientId,
3873
+//			Status:             1,
3874
+//			Ctime:              info.Ctime,
3875
+//			Mtime:              time.Now().Unix(),
3876
+//			Creator:            info.Creator,
3877
+//			Modifier:           adminInfo.AdminUser.Id,
3878
+//			Diagnosis:          diagnose,
3879
+//			SickHistory:        sick_history,
3880
+//			Departments:        department,
3881
+//			RegisterType:       reg_type,
3882
+//			PrescriptionNumber: info.PrescriptionNumber,
3883
+//			Doctor:             role.UserName,
3884
+//			PrescriptionStatus: info.PrescriptionStatus,
3885
+//			DoctorId:           doctor_id,
3886
+//			SickType:           sick_type,
3887
+//			PType:              info.PType,
3888
+//		}
3889
+//		service.SavePatientPrescriptionInfo(hpInfo)
3890
+//	}
3891
+//
3892
+//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3893
+//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
3894
+//
3895
+//		if len(prescriptions) > 0 {
3896
+//			for _, item := range prescriptions {
3897
+//				items := item.(map[string]interface{})
3898
+//				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
3899
+//					utils.ErrorLog("id")
3900
+//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3901
+//					return
3902
+//				}
3903
+//				id := int64(items["id"].(float64))
3904
+//
3905
+//				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
3906
+//					utils.ErrorLog("type")
3907
+//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3908
+//					return
3909
+//				}
3910
+//				types := int64(items["type"].(float64))
3911
+//
3912
+//				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
3913
+//					utils.ErrorLog("med_type")
3914
+//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3915
+//					return
3916
+//				}
3917
+//				med_type := strconv.Itoa(int(items["med_type"].(float64)))
3918
+//
3919
+//				historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
3920
+//
3921
+//				ctime := time.Now().Unix()
3922
+//
3923
+//				prescription := &models.HisPrescription{
3924
+//					ID:                 id,
3925
+//					PatientId:          patient_id,
3926
+//					UserOrgId:          adminInfo.CurrentOrgId,
3927
+//					RecordDate:         recordDateTime,
3928
+//					Ctime:              ctime,
3929
+//					Mtime:              ctime,
3930
+//					Type:               types,
3931
+//					Modifier:           adminInfo.AdminUser.Id,
3932
+//					Creator:            adminInfo.AdminUser.Id,
3933
+//					Status:             1,
3934
+//					Doctor:             role.UserName,
3935
+//					HisPatientId:       his_patient_id,
3936
+//					OrderStatus:        1,
3937
+//					BatchNumber:        "",
3938
+//					PrescriptionNumber: hpInfo.PrescriptionNumber,
3939
+//					PType:              hpInfo.PType,
3940
+//					MedType:            med_type,
3941
+//				}
3942
+//
3943
+//				if historyPrescription.ID > 0 {
3944
+//					prescription.PreTime = historyPrescription.PreTime
3945
+//
3946
+//				}
3947
+//
3948
+//				service.SaveHisPrescription(prescription)
3949
+//
3950
+//				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
3951
+//					advices := items["advices"].([]interface{})
3952
+//					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
3953
+//					groupNo := int64(0)
3954
+//					ctime := time.Now().Unix()
3955
+//					mtime := ctime
3956
+//					if len(advices) > 0 {
3957
+//						for _, advice := range advices {
3958
+//							var s models.HisDoctorAdviceInfo
3959
+//							s.PrescriptionId = prescription.ID
3960
+//							s.AdviceType = 2
3961
+//							s.AdviceDoctor = adminInfo.AdminUser.Id
3962
+//							s.StopState = 2
3963
+//							s.ExecutionState = 2
3964
+//							s.AdviceDate = recordDateTime
3965
+//							s.Status = 1
3966
+//							s.UserOrgId = adminInfo.CurrentOrgId
3967
+//							s.RecordDate = recordDateTime
3968
+//							s.StartTime = prescription.PreTime
3969
+//							s.Groupno = groupNo
3970
+//							s.CreatedTime = ctime
3971
+//							s.UpdatedTime = mtime
3972
+//							s.PatientId = patient_id
3973
+//							s.HisPatientId = his_patient_id
3974
+//							errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
3975
+//							if errcode > 0 {
3976
+//								c.ServeFailJSONWithSGJErrorCode(errcode)
3977
+//								return
3978
+//							}
3979
+//
3980
+//							if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
3981
+//								storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3982
+//								lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
3983
+//								if s.Price == 0 {
3984
+//									s.Price = lastWarehouse.RetailPrice
3985
+//								}
3986
+//							}
3987
+//
3988
+//							service.CreateHisDoctorAdvice(&s)
3989
+//							//记录日志
3990
+//							byterequest, _ := json.Marshal(s)
3991
+//							adviceLog := models.XtDoctorAdviceLog{
3992
+//								UserOrgId:   s.UserOrgId,
3993
+//								PatientId:   s.PatientId,
3994
+//								AdminUserId: adminInfo.AdminUser.Id,
3995
+//								Module:      1,
3996
+//								ErrLog:      string(byterequest),
3997
+//								Status:      1,
3998
+//								Ctime:       time.Now().Unix(),
3999
+//								Mtime:       0,
4000
+//								Source:      "电脑端his医嘱修改",
4001
+//								RecordDate:  s.AdviceDate,
4002
+//							}
4003
+//							service.CreateDoctorAdviceLog(adviceLog)
4004
+//							redis := service.RedisClient()
4005
+//							key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
4006
+//							redis.Set(key, "", time.Second)
4007
+//							keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
4008
+//							fmt.Println("keyOne", keyOne)
4009
+//							redis.Set(keyOne, "", time.Second)
4010
+//							keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
4011
+//							redis.Set(keySeven, "", time.Second)
4012
+//							redis.Close()
4013
+//
4014
+//						}
4015
+//					}
4016
+//				}
4017
+//				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
4018
+//					projects := items["project"].([]interface{})
4019
+//					if len(projects) > 0 {
4020
+//						for _, project := range projects {
4021
+//							var p models.HisPrescriptionProject
4022
+//							p.PrescriptionId = prescription.ID
4023
+//							p.Ctime = time.Now().Unix()
4024
+//							p.Mtime = time.Now().Unix()
4025
+//							p.PatientId = patient_id
4026
+//							p.RecordDate = recordDateTime
4027
+//							p.UserOrgId = adminInfo.CurrentOrgId
4028
+//							p.HisPatientId = his_patient_id
4029
+//							p.Status = 1
4030
+//							errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
4031
+//							if errcode > 0 {
4032
+//								c.ServeFailJSONWithSGJErrorCode(errcode)
4033
+//								return
4034
+//							}
4035
+//							service.CreateHisProjectTwo(&p)
4036
+//
4037
+//							//记录日志
4038
+//							byterequest, _ := json.Marshal(p)
4039
+//							adviceLog := models.XtDoctorAdviceLog{
4040
+//								UserOrgId:   p.UserOrgId,
4041
+//								PatientId:   p.PatientId,
4042
+//								AdminUserId: adminInfo.AdminUser.Id,
4043
+//								Module:      1,
4044
+//								ErrLog:      string(byterequest),
4045
+//								Status:      1,
4046
+//								Ctime:       time.Now().Unix(),
4047
+//								Mtime:       0,
4048
+//								Source:      "电脑端his项目修改",
4049
+//								RecordDate:  p.RecordDate,
4050
+//							}
4051
+//							service.CreateDoctorAdviceLog(adviceLog)
4052
+//						}
4053
+//					}
4054
+//				}
4055
+//				if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
4056
+//					addition := items["addition"].([]interface{})
4057
+//					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
4058
+//					ctime := time.Now().Unix()
4059
+//					mtime := ctime
4060
+//					if len(addition) > 0 {
4061
+//						for _, item := range addition {
4062
+//							var s models.HisAdditionalCharge
4063
+//							s.PrescriptionId = prescription.ID
4064
+//							s.Status = 1
4065
+//							s.UserOrgId = adminInfo.CurrentOrgId
4066
+//							s.RecordDate = recordDateTime
4067
+//							s.CreatedTime = ctime
4068
+//							s.UpdatedTime = mtime
4069
+//							s.PatientId = patient_id
4070
+//							s.HisPatientId = his_patient_id
4071
+//							errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
4072
+//							if errcode > 0 {
4073
+//								c.ServeFailJSONWithSGJErrorCode(errcode)
4074
+//								return
4075
+//							}
4076
+//							service.CreateAdditionalCharge(&s)
4077
+//						}
4078
+//					}
4079
+//				}
4080
+//
4081
+//			}
4082
+//		}
4083
+//	}
4084
+//	if err == nil {
4085
+//		c.ServeSuccessJSON(map[string]interface{}{
4086
+//			"msg": "保存成功",
4087
+//		})
4088
+//		return
4089
+//
4090
+//	} else {
4091
+//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4092
+//		return
4093
+//	}
4094
+//}
4082 4095
 
4083 4096
 func (c *HisApiController) DeletePrescription() {
4084 4097
 	prescription_id, _ := c.GetInt64("id")
@@ -4809,7 +4822,7 @@ func (c *HisApiController) DeleteProject() {
4809 4822
 	service.DeletePrintInfo(id)
4810 4823
 	label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
4811 4824
 	label.Status = 0
4812
-	service.CreateHisLabelRecord(&label)
4825
+	service.CreateHisLabelRecordTwo(&label)
4813 4826
 
4814 4827
 	fmt.Println(goodOutConfig.IsOpen)
4815 4828
 	if goodOutConfig.IsOpen != 1 {
@@ -11280,7 +11293,7 @@ func (this *HisApiController) ChangeMedType() {
11280 11293
 		id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
11281 11294
 		prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
11282 11295
 		prescription.MedType = med_type
11283
-		err := service.SaveHisPrescription(&prescription)
11296
+		err := service.SaveHisPrescriptionTwo(&prescription)
11284 11297
 
11285 11298
 		if err == nil {
11286 11299
 			this.ServeSuccessJSON(map[string]interface{}{

+ 1 - 1
service/his_print_service.go Voir le fichier

@@ -113,7 +113,7 @@ func GetBatchProjectHisPrescription(ids []string, record_time int64, user_org_id
113 113
 		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
114 114
 			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
115 115
 				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
116
-					return db.Joins("").Joins("Join xt_his_project p On p.id = his_prescription_project.project_id ").Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
116
+					return db.Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
117 117
 				})
118 118
 		}).
119 119
 		Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).