Browse Source

医保对接

csx 3 years ago
parent
commit
af67cbca64

+ 118 - 109
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -849,6 +849,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
849 849
 		})
850 850
 		return
851 851
 	} else if origin == 2 {
852
+		var ids []string
853
+		advice_ids := c.GetString("advice_id")
854
+		ids = strings.Split(advice_ids, ",")
852 855
 
853 856
 		if len(execution_time) <= 0 {
854 857
 			utils.ErrorLog("execution_time")
@@ -865,107 +868,117 @@ func (c *PatientApiController) ExecDoctorAdvice() {
865 868
 		}
866 869
 		adminInfo := c.GetMobileAdminUserInfo()
867 870
 		creater := c.GetMobileAdminUserInfo().AdminUser.Id
868
-		advice_id, _ := c.GetInt64("advice_id")
869
-		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
870
-		if advices.ExecutionState == 1 {
871
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
872
-			return
873
-		}
874
-		if advices.Checker >= 0 && advices.Checker == adminInfo.AdminUser.Id {
875
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
876
-			return
877
-		}
878
-		if advices.StartTime > theTime.Unix() {
879
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
880
-			return
871
+		advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
872
+		var err error
873
+		for _, item := range advices {
874
+			if item.ExecutionState == 1 {
875
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
876
+				return
877
+			}
878
+
879
+			if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
880
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
881
+				return
882
+			}
883
+
884
+			if item.StartTime > theTime.Unix() {
885
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
886
+				return
887
+			}
888
+
889
+			item.ExecutionState = 1
890
+			item.ExecutionStaff = adminInfo.AdminUser.Id
891
+			item.ExecutionTime = theTime.Unix()
892
+			err = service.SaveHisDoctorAdvice(item)
881 893
 		}
882
-		advices.ExecutionState = 1
883
-		advices.ExecutionStaff = adminInfo.AdminUser.Id
884
-		advices.ExecutionTime = theTime.Unix()
885
-		err := service.SaveHisDoctorAdvice(&advices)
886
-		var ids []string
887
-		ids = append(ids, strconv.FormatInt(advices.ID, 10))
894
+
888 895
 		if err == nil {
896
+
889 897
 			//药品管理信息
890 898
 			_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
891 899
 			if drugStockConfig.IsOpen == 1 {
892
-				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
893
-				//查询该药品是否有库存
894
-				//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
895
-				//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
896
-				//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
897
-				//  if list.Count == 0 {
898
-				//    c.ServeSuccessJSON(map[string]interface{}{
899
-				//      "msg":    "1",
900
-				//      "advice": advice,
901
-				//      "ids":    ids,
902
-				//    })
903
-				//    return
904
-				//  }
905
-				//  if count > list.Count {
906
-				//    c.ServeSuccessJSON(map[string]interface{}{
907
-				//      "msg":    "2",
908
-				//      "advice": advice,
909
-				//      "ids":    ids,
910
-				//    })
911
-				//    return
912
-				//}
913
-				var total int64
914
-				var prescribing_number_total int64
915
-				//查询该药品是否有库存
916
-				list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
917
-
918
-				//查询改药品信息
919
-				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
920
-				//判断单位是否相等
921
-				if medical.MaxUnit == advice.PrescribingNumberUnit {
922
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
923
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
924
-					//转化为最小单位
925
-					total = list.Count * medical.MinNumber
926
-					prescribing_number_total = count * medical.MinNumber
927
-				}
928
-				if medical.MinUnit == advice.PrescribingNumberUnit {
929
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
930
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
931
-					total = list.Count*medical.MinNumber + list.StockMinNumber
932
-					prescribing_number_total = count
933
-				}
900
+				for _, item := range advices {
901
+
902
+					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
903
+					//查询该药品是否有库存
904
+					//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
905
+					//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
906
+					//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
907
+					//  if list.Count == 0 {
908
+					//    c.ServeSuccessJSON(map[string]interface{}{
909
+					//      "msg":    "1",
910
+					//      "advice": advice,
911
+					//      "ids":    ids,
912
+					//    })
913
+					//    return
914
+					//  }
915
+					//  if count > list.Count {
916
+					//    c.ServeSuccessJSON(map[string]interface{}{
917
+					//      "msg":    "2",
918
+					//      "advice": advice,
919
+					//      "ids":    ids,
920
+					//    })
921
+					//    return
922
+					//}
923
+					var total int64
924
+					var prescribing_number_total int64
925
+					//查询该药品是否有库存
926
+					list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
927
+
928
+					//查询改药品信息
929
+					medical, _ := service.GetBaseDrugMedical(advice.DrugId)
930
+					//判断单位是否相等
931
+					if medical.MaxUnit == advice.PrescribingNumberUnit {
932
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
933
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
934
+						//转化为最小单位
935
+						total = list.Count * medical.MinNumber
936
+						prescribing_number_total = count * medical.MinNumber
937
+					}
938
+					if medical.MinUnit == advice.PrescribingNumberUnit {
939
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
940
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
941
+						total = list.Count*medical.MinNumber + list.StockMinNumber
942
+						prescribing_number_total = count
943
+					}
934 944
 
935
-				fmt.Println("数量一", prescribing_number_total)
936
-				fmt.Println("数量二", total)
945
+					fmt.Println("数量一", prescribing_number_total)
946
+					fmt.Println("数量二", total)
937 947
 
938
-				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
939
-					c.ServeSuccessJSON(map[string]interface{}{
940
-						"msg":    "3",
941
-						"advice": advice,
942
-						"ids":    ids,
943
-					})
944
-					return
945
-				}
946
-				if prescribing_number_total > total {
947
-					c.ServeSuccessJSON(map[string]interface{}{
948
-						"msg":    "2",
949
-						"advice": advice,
950
-						"ids":    ids,
951
-					})
952
-					return
953
-				}
954
-				if prescribing_number_total <= total {
955
-					service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
956
-					c.ServeSuccessJSON(map[string]interface{}{
957
-						"msg":    "1",
958
-						"advice": advice,
959
-						"ids":    ids,
960
-					})
961
-					return
948
+					if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
949
+						c.ServeSuccessJSON(map[string]interface{}{
950
+							"msg":    "3",
951
+							"advice": advice,
952
+							"ids":    ids,
953
+						})
954
+						return
955
+					}
956
+					if prescribing_number_total > total {
957
+						c.ServeSuccessJSON(map[string]interface{}{
958
+							"msg":    "2",
959
+							"advice": advice,
960
+							"ids":    ids,
961
+						})
962
+						return
963
+					}
964
+					if prescribing_number_total <= total {
965
+						service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
966
+						c.ServeSuccessJSON(map[string]interface{}{
967
+							"msg":    "1",
968
+							"advice": advice,
969
+							"ids":    ids,
970
+						})
971
+						return
972
+					}
962 973
 				}
963 974
 			}
975
+
964 976
 			c.ServeSuccessJSON(map[string]interface{}{
965 977
 				"msg":    "ok",
966 978
 				"advice": advices,
967 979
 				"ids":    ids,
968 980
 			})
981
+
969 982
 		} else {
970 983
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
971 984
 		}
@@ -1176,41 +1189,37 @@ func (c *PatientApiController) CheckDoctorAdvice() {
1176 1189
 			"advice": advice,
1177 1190
 		})
1178 1191
 	} else if origin == 2 {
1179
-		fmt.Println("金鳌地方 大房贷首付地方阿凡达阿方")
1180 1192
 		adminInfo := c.GetMobileAdminUserInfo()
1181
-		advice_id, _ := c.GetInt64("advice_id")
1182
-		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
1183
-
1184
-		if advices.CheckState == 1 {
1185
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
1186
-			return
1187
-		}
1188
-		if advices.ExecutionStaff >= 0 && advices.ExecutionStaff == adminInfo.AdminUser.Id {
1189
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
1190
-			return
1193
+		var ids []string
1194
+		advice_ids := c.GetString("advice_id")
1195
+		ids = strings.Split(advice_ids, ",")
1196
+		advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
1197
+		var err error
1198
+		for _, item := range advices {
1199
+			if item.CheckState == 1 {
1200
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
1201
+				return
1202
+			}
1203
+			if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
1204
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
1205
+				return
1206
+			}
1207
+			item.Checker = adminInfo.AdminUser.Id
1208
+			item.CheckTime = time.Now().Unix()
1209
+			item.CheckState = 1
1210
+			err = service.SaveHisDoctorAdvice(item)
1191 1211
 		}
1192
-
1193
-		advices.Checker = adminInfo.AdminUser.Id
1194
-		advices.CheckTime = time.Now().Unix()
1195
-		advices.CheckState = 1
1196
-
1197
-		err := service.SaveHisDoctorAdvice(&advices)
1198
-
1199 1212
 		if err == nil {
1200 1213
 			c.ServeSuccessJSON(map[string]interface{}{
1201 1214
 				"msg":    "ok",
1202 1215
 				"advice": advices,
1203 1216
 			})
1204
-
1205 1217
 		} else {
1206 1218
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1207 1219
 			return
1208
-
1209 1220
 		}
1210
-
1211 1221
 	}
1212 1222
 	return
1213
-
1214 1223
 }
1215 1224
 
1216 1225
 func (c *PatientApiController) EditAssessmentBeforeDislysis() {

+ 7 - 0
enums/error_code.go View File

@@ -489,6 +489,13 @@ func MakeFailResponseJSON(errMsg string, errCode int) map[string]interface{} {
489 489
 	return json
490 490
 }
491 491
 
492
+func MakeDynamicFailResponseJSON(errMsg string) map[string]interface{} {
493
+	json := make(map[string]interface{})
494
+	json["msg"] = errMsg
495
+	json["state"] = 0
496
+	return json
497
+}
498
+
492 499
 func MakeFailResponseJSONWithSGJError(err *SGJError) map[string]interface{} {
493 500
 	if err == nil {
494 501
 		utils.WarningLog("MakeFailResponseJSONWithSGJError 参数err 不能为空")

+ 5 - 0
service/dialysis_service.go View File

@@ -1150,6 +1150,11 @@ func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdvi
1150 1150
 	return
1151 1151
 }
1152 1152
 
1153
+func FindHisDoctorAdviceByIds(orgID int64, ids []string) (advice []*models.HisDoctorAdviceInfo, err error) {
1154
+	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id in (?)", orgID, ids).Find(&advice).Error
1155
+	return
1156
+}
1157
+
1153 1158
 func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
1154 1159
 	err = writeDb.Save(&advice).Error
1155 1160
 	return