csx преди 3 години
родител
ревизия
c54463c3ea

+ 134 - 118
controllers/his_api_controller.go Целия файл

@@ -230,6 +230,9 @@ func (c *HisApiController) GetHisPatientInfo() {
230 230
 
231 231
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
232 232
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
233
+
234
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
235
+
233 236
 	//获取所有科室信息
234 237
 	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
235 238
 	c.ServeSuccessJSON(map[string]interface{}{
@@ -246,6 +249,7 @@ func (c *HisApiController) GetHisPatientInfo() {
246 249
 		"last_prescriptions":  last_prescriptions,
247 250
 		"schedule":            sch,
248 251
 		"count":               count,
252
+		"drugStockConfig":     drugStockConfig,
249 253
 	})
250 254
 	return
251 255
 
@@ -318,54 +322,59 @@ func (c *HisApiController) CreateHisPrescription() {
318 322
 		if len(lists) == 1 {
319 323
 			his_patient_id = lists[0].ID
320 324
 		}
325
+
321 326
 	}
322 327
 
323
-	//校验库存总量
324
-	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
325
-		prescriptions, _ := dataBody["prescriptions"].([]interface{})
326
-		if len(prescriptions) > 0 {
327
-			for _, item := range prescriptions {
328
-				items := item.(map[string]interface{})
329
-				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
330
-					advices := items["advices"].([]interface{})
331
-					if len(advices) > 0 {
332
-						for _, advice := range advices {
333
-							var drug_id int64
334
-							var prescribing_number float64
335
-							var prescribingNumberUnit string
328
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
336 329
 
337
-							if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
338
-								drug_id = int64(advice.(map[string]interface{})["id"].(float64))
339
-							}
340
-							if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
341
-								//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
342
-								prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
343
-								prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
330
+	if drugStockConfig.IsOpen == 1 {
331
+		//校验库存总量
332
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
333
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
334
+			if len(prescriptions) > 0 {
335
+				for _, item := range prescriptions {
336
+					items := item.(map[string]interface{})
337
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
338
+						advices := items["advices"].([]interface{})
339
+						if len(advices) > 0 {
340
+							for _, advice := range advices {
341
+								var drug_id int64
342
+								var prescribing_number float64
343
+								var prescribingNumberUnit string
344 344
 
345
-							}
345
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
346
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
347
+								}
348
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
349
+									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
350
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
351
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
346 352
 
347
-							if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
348
-								prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
349
-							}
353
+								}
350 354
 
351
-							drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
352
-							if drug.ID == 0 {
353
-								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
354
-								return
355
-							}
355
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
356
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
357
+								}
356 358
 
357
-							if prescribingNumberUnit == drug.MinUnit {
358
-								if prescribing_number > drug.Total {
359
-									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
359
+								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
360
+								if drug.ID == 0 {
361
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
360 362
 									return
361 363
 								}
362
-							} else {
363
-								if prescribingNumberUnit == drug.MaxUnit {
364
-									num := prescribing_number * float64(drug.MinNumber)
365
-									if num > drug.Total {
364
+
365
+								if prescribingNumberUnit == drug.MinUnit {
366
+									if prescribing_number > drug.Total {
366 367
 										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
367 368
 										return
368 369
 									}
370
+								} else {
371
+									if prescribingNumberUnit == drug.MaxUnit {
372
+										num := prescribing_number * float64(drug.MinNumber)
373
+										if num > drug.Total {
374
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
375
+											return
376
+										}
377
+									}
369 378
 								}
370 379
 							}
371 380
 						}
@@ -484,7 +493,7 @@ func (c *HisApiController) CreateHisPrescription() {
484 493
 
485 494
 				if tempPrescription.ID == 0 {
486 495
 					prescription := &models.HisPrescription{
487
-						ID:                 id,
496
+						ID:                 0,
488 497
 						PatientId:          patient_id,
489 498
 						UserOrgId:          adminInfo.CurrentOrgId,
490 499
 						RecordDate:         recordDateTime,
@@ -506,6 +515,7 @@ func (c *HisApiController) CreateHisPrescription() {
506 515
 					service.SaveHisPrescription(tempPrescription)
507 516
 
508 517
 				} else {
518
+					tempPrescription.ID = id
509 519
 					tempPrescription.Type = types
510 520
 					tempPrescription.Modifier = adminInfo.AdminUser.Id
511 521
 					tempPrescription.Mtime = time.Now().Unix()
@@ -513,9 +523,7 @@ func (c *HisApiController) CreateHisPrescription() {
513 523
 					tempPrescription.OrderStatus = order_status
514 524
 					tempPrescription.PreTime = pTime
515 525
 					service.SaveHisPrescription(tempPrescription)
516
-
517 526
 				}
518
-
519 527
 				//service.SaveHisPrescription(prescription)
520 528
 				//更改患者挂号状态
521 529
 				_, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
@@ -893,6 +901,7 @@ func (c *HisApiController) DeletePrescription() {
893 901
 	prescription_id, _ := c.GetInt64("id")
894 902
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
895 903
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
904
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
896 905
 
897 906
 	err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
898 907
 	if err == nil {
@@ -908,17 +917,19 @@ func (c *HisApiController) DeletePrescription() {
908 917
 			}
909 918
 		}
910 919
 
911
-		if len(advices) > 0 {
912
-			for _, item := range advices {
913
-				drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
914
-				if item.PrescribingNumberUnit == drug.MinUnit {
915
-					drug.Total = drug.Total + item.PrescribingNumber
916
-					service.UpdateBaseDrugLib(&drug)
917
-				} else {
918
-					if item.PrescribingNumberUnit == drug.MaxUnit {
919
-						item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
920
+		if drugStockConfig.IsOpen == 1 {
921
+			if len(advices) > 0 {
922
+				for _, item := range advices {
923
+					drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
924
+					if item.PrescribingNumberUnit == drug.MinUnit {
920 925
 						drug.Total = drug.Total + item.PrescribingNumber
921 926
 						service.UpdateBaseDrugLib(&drug)
927
+					} else {
928
+						if item.PrescribingNumberUnit == drug.MaxUnit {
929
+							item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
930
+							drug.Total = drug.Total + item.PrescribingNumber
931
+							service.UpdateBaseDrugLib(&drug)
932
+						}
922 933
 					}
923 934
 				}
924 935
 			}
@@ -936,20 +947,20 @@ func (c *HisApiController) DeletePrescription() {
936 947
 func (c *HisApiController) DeleteDoctorAdvice() {
937 948
 	id, _ := c.GetInt64("id")
938 949
 	advice, _ := service.GetHisDoctorAdvicesById(id)
950
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
939 951
 	err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
940 952
 	if err == nil {
941
-		drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
942
-
943
-		if advice.PrescribingNumberUnit == drug.MinUnit {
944
-			drug.Total = drug.Total + advice.PrescribingNumber
945
-			service.UpdateBaseDrugLib(&drug)
946
-
947
-		} else {
948
-
949
-			if advice.PrescribingNumberUnit == drug.MaxUnit {
950
-				advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
953
+		if drugStockConfig.IsOpen == 1 {
954
+			drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
955
+			if advice.PrescribingNumberUnit == drug.MinUnit {
951 956
 				drug.Total = drug.Total + advice.PrescribingNumber
952 957
 				service.UpdateBaseDrugLib(&drug)
958
+			} else {
959
+				if advice.PrescribingNumberUnit == drug.MaxUnit {
960
+					advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
961
+					drug.Total = drug.Total + advice.PrescribingNumber
962
+					service.UpdateBaseDrugLib(&drug)
963
+				}
953 964
 			}
954 965
 		}
955 966
 
@@ -1612,74 +1623,79 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
1612 1623
 		}
1613 1624
 	}
1614 1625
 
1615
-	drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
1616
-	if advice.ID == 0 { //医嘱不存在
1617
-		if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
1618
-			drug.Total = drug.Total - advice.PrescribingNumber
1619
-			service.UpdateBaseDrugLib(&drug)
1620
-
1621
-		} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
1622
-			num := advice.PrescribingNumber * float64(drug.MinNumber)
1623
-			drug.Total = drug.Total - num
1624
-			service.UpdateBaseDrugLib(&drug)
1625
-		}
1626
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
1626 1627
 
1627
-	} else if advice.ID > 0 { //医嘱存在
1628
-		hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
1629
-		var num float64
1628
+	if drugStockConfig.IsOpen == 1 {
1630 1629
 
1631
-		if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
1632
-			if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
1633
-				if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
1634
-					num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
1635
-					drug.Total = drug.Total + num
1636
-					service.UpdateBaseDrugLib(&drug)
1637
-				} else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
1638
-					num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
1639
-					drug.Total = drug.Total - num
1640
-					service.UpdateBaseDrugLib(&drug)
1641
-				}
1642
-			} else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
1643
-				num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
1644
-				if num2 > advice.PrescribingNumber {
1645
-					num = num2 - advice.PrescribingNumber
1646
-					drug.Total = drug.Total + num
1647
-					service.UpdateBaseDrugLib(&drug)
1648
-				} else if num2 < advice.PrescribingNumber {
1649
-					num = advice.PrescribingNumber - num2
1650
-					drug.Total = drug.Total - num
1651
-					service.UpdateBaseDrugLib(&drug)
1652
-				}
1630
+		drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
1631
+		if advice.ID == 0 { //医嘱不存在
1632
+			if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
1633
+				drug.Total = drug.Total - advice.PrescribingNumber
1634
+				service.UpdateBaseDrugLib(&drug)
1653 1635
 
1636
+			} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
1637
+				num := advice.PrescribingNumber * float64(drug.MinNumber)
1638
+				drug.Total = drug.Total - num
1639
+				service.UpdateBaseDrugLib(&drug)
1654 1640
 			}
1655 1641
 
1656
-		} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
1657
-			if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
1658
-				num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
1659
-				num2 := advice.PrescribingNumber * float64(drug.MinNumber)
1660
-				if num1 > num2 {
1661
-					num = num1 - num2
1662
-					drug.Total = drug.Total + num
1663
-					service.UpdateBaseDrugLib(&drug)
1664
-				} else if num1 < num2 {
1665
-					num = num2 - num1
1666
-					drug.Total = drug.Total - num
1667
-					service.UpdateBaseDrugLib(&drug)
1668
-				}
1642
+		} else if advice.ID > 0 { //医嘱存在
1643
+			hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
1644
+			var num float64
1645
+
1646
+			if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
1647
+				if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
1648
+					if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
1649
+						num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
1650
+						drug.Total = drug.Total + num
1651
+						service.UpdateBaseDrugLib(&drug)
1652
+					} else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
1653
+						num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
1654
+						drug.Total = drug.Total - num
1655
+						service.UpdateBaseDrugLib(&drug)
1656
+					}
1657
+				} else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
1658
+					num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
1659
+					if num2 > advice.PrescribingNumber {
1660
+						num = num2 - advice.PrescribingNumber
1661
+						drug.Total = drug.Total + num
1662
+						service.UpdateBaseDrugLib(&drug)
1663
+					} else if num2 < advice.PrescribingNumber {
1664
+						num = advice.PrescribingNumber - num2
1665
+						drug.Total = drug.Total - num
1666
+						service.UpdateBaseDrugLib(&drug)
1667
+					}
1669 1668
 
1670
-			} else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
1671
-				num2 := advice.PrescribingNumber * float64(drug.MinNumber)
1672
-				//num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
1673
-				if hisAdvice.PrescribingNumber > num2 {
1674
-					num = hisAdvice.PrescribingNumber - num2
1675
-					drug.Total = drug.Total + num
1676
-					service.UpdateBaseDrugLib(&drug)
1677
-				} else if num2 < advice.PrescribingNumber {
1678
-					num = num2 - hisAdvice.PrescribingNumber
1679
-					drug.Total = drug.Total - num
1680
-					service.UpdateBaseDrugLib(&drug)
1681 1669
 				}
1682 1670
 
1671
+			} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
1672
+				if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
1673
+					num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
1674
+					num2 := advice.PrescribingNumber * float64(drug.MinNumber)
1675
+					if num1 > num2 {
1676
+						num = num1 - num2
1677
+						drug.Total = drug.Total + num
1678
+						service.UpdateBaseDrugLib(&drug)
1679
+					} else if num1 < num2 {
1680
+						num = num2 - num1
1681
+						drug.Total = drug.Total - num
1682
+						service.UpdateBaseDrugLib(&drug)
1683
+					}
1684
+
1685
+				} else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
1686
+					num2 := advice.PrescribingNumber * float64(drug.MinNumber)
1687
+					//num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
1688
+					if hisAdvice.PrescribingNumber > num2 {
1689
+						num = hisAdvice.PrescribingNumber - num2
1690
+						drug.Total = drug.Total + num
1691
+						service.UpdateBaseDrugLib(&drug)
1692
+					} else if num2 < advice.PrescribingNumber {
1693
+						num = num2 - hisAdvice.PrescribingNumber
1694
+						drug.Total = drug.Total - num
1695
+						service.UpdateBaseDrugLib(&drug)
1696
+					}
1697
+
1698
+				}
1683 1699
 			}
1684 1700
 		}
1685 1701
 	}

+ 1 - 1
controllers/his_project_api_controller.go Целия файл

@@ -452,7 +452,7 @@ func (this *HisProjectApiController) GetProjectTeamDetail() {
452 452
 	//orgId := adminUserInfo.CurrentOrgId
453 453
 	projectTeamDetail, err := service.GetProjectTeamDetail(id)
454 454
 
455
-	ids := strings.Split(projectTeamDetail.ProjectId, ",")
455
+	ids := strings.Split(projectTeamDetail.ItemId, ",")
456 456
 	hisList, err := service.GetProjectHisListByIds(ids)
457 457
 
458 458
 	//list, err := service.GetAllProjectList(orgId)

+ 128 - 114
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Целия файл

@@ -139,6 +139,7 @@ func (c *MobileHisApiController) DeletePrescription() {
139 139
 	prescription_id, _ := c.GetInt64("id")
140 140
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
141 141
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
142
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
142 143
 
143 144
 	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
144 145
 	if err == nil {
@@ -153,22 +154,23 @@ func (c *MobileHisApiController) DeletePrescription() {
153 154
 				}
154 155
 			}
155 156
 		}
156
-		if len(advices) > 0 {
157
-			for _, item := range advices {
158
-				drug, _ := service.FindBaseDrugLibRecord(c.GetMobileAdminUserInfo().Org.Id, item.DrugId)
159
-				if item.PrescribingNumberUnit == drug.MinUnit {
160
-					drug.Total = drug.Total + item.PrescribingNumber
161
-					service.UpdateBaseDrugLib(&drug)
162
-				} else {
163
-					if item.PrescribingNumberUnit == drug.MaxUnit {
164
-						item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
157
+		if drugStockConfig.IsOpen == 1 {
158
+			if len(advices) > 0 {
159
+				for _, item := range advices {
160
+					drug, _ := service.FindBaseDrugLibRecord(c.GetMobileAdminUserInfo().Org.Id, item.DrugId)
161
+					if item.PrescribingNumberUnit == drug.MinUnit {
165 162
 						drug.Total = drug.Total + item.PrescribingNumber
166 163
 						service.UpdateBaseDrugLib(&drug)
164
+					} else {
165
+						if item.PrescribingNumberUnit == drug.MaxUnit {
166
+							item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
167
+							drug.Total = drug.Total + item.PrescribingNumber
168
+							service.UpdateBaseDrugLib(&drug)
169
+						}
167 170
 					}
168 171
 				}
169 172
 			}
170 173
 		}
171
-
172 174
 		c.ServeSuccessJSON(map[string]interface{}{
173 175
 			"msg": "删除成功",
174 176
 		})
@@ -182,16 +184,20 @@ func (c *MobileHisApiController) DeleteDoctorAdvice() {
182 184
 	id, _ := c.GetInt64("id")
183 185
 	advice, _ := service.GetHisDoctorAdvicesById(id)
184 186
 	err := service.DelelteDoctorAdvice(id, c.GetMobileAdminUserInfo().Org.Id)
187
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
188
+
185 189
 	if err == nil {
186
-		drug, _ := service.FindBaseDrugLibRecord(c.GetMobileAdminUserInfo().Org.Id, advice.DrugId)
187
-		if advice.PrescribingNumberUnit == drug.MinUnit {
188
-			drug.Total = drug.Total + advice.PrescribingNumber
189
-			service.UpdateBaseDrugLib(&drug)
190
-		} else {
191
-			if advice.PrescribingNumberUnit == drug.MaxUnit {
192
-				advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
190
+		if drugStockConfig.IsOpen == 1 {
191
+			drug, _ := service.FindBaseDrugLibRecord(c.GetMobileAdminUserInfo().Org.Id, advice.DrugId)
192
+			if advice.PrescribingNumberUnit == drug.MinUnit {
193 193
 				drug.Total = drug.Total + advice.PrescribingNumber
194 194
 				service.UpdateBaseDrugLib(&drug)
195
+			} else {
196
+				if advice.PrescribingNumberUnit == drug.MaxUnit {
197
+					advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
198
+					drug.Total = drug.Total + advice.PrescribingNumber
199
+					service.UpdateBaseDrugLib(&drug)
200
+				}
195 201
 			}
196 202
 		}
197 203
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -258,51 +264,55 @@ func (c *MobileHisApiController) CreateHisPrescription() {
258 264
 
259 265
 	//校验库存总量
260 266
 
261
-	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
262
-		prescriptions, _ := dataBody["prescriptions"].([]interface{})
263
-		if len(prescriptions) > 0 {
264
-			for _, item := range prescriptions {
265
-				items := item.(map[string]interface{})
266
-				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
267
-					advices := items["advices"].([]interface{})
268
-					if len(advices) > 0 {
269
-						for _, advice := range advices {
270
-							var drug_id int64
271
-							var prescribing_number float64
272
-							var prescribingNumberUnit string
273
-
274
-							if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
275
-								drug_id = int64(advice.(map[string]interface{})["id"].(float64))
276
-							}
277
-							if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "float64" {
278
-								//presc ribing_number = advice.(map[string]interface{})["prescribing_number"].(float64)
279
-								prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
280
-								prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
281
-
282
-							}
267
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
268
+
269
+	if drugStockConfig.IsOpen == 1 {
270
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
271
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
272
+			if len(prescriptions) > 0 {
273
+				for _, item := range prescriptions {
274
+					items := item.(map[string]interface{})
275
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
276
+						advices := items["advices"].([]interface{})
277
+						if len(advices) > 0 {
278
+							for _, advice := range advices {
279
+								var drug_id int64
280
+								var prescribing_number float64
281
+								var prescribingNumberUnit string
282
+
283
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
284
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
285
+								}
286
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "float64" {
287
+									//presc ribing_number = advice.(map[string]interface{})["prescribing_number"].(float64)
288
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
289
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
283 290
 
284
-							if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
285
-								prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
286
-							}
291
+								}
287 292
 
288
-							drug, _ := service.FindBaseDrugLibRecord(adminInfo.Org.Id, drug_id)
289
-							if drug.ID == 0 {
290
-								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
291
-								return
292
-							}
293
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
294
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
295
+								}
293 296
 
294
-							if prescribingNumberUnit == drug.MinUnit {
295
-								if prescribing_number > drug.Total {
296
-									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
297
+								drug, _ := service.FindBaseDrugLibRecord(adminInfo.Org.Id, drug_id)
298
+								if drug.ID == 0 {
299
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
297 300
 									return
298 301
 								}
299
-							} else {
300
-								if prescribingNumberUnit == drug.MaxUnit {
301
-									num := prescribing_number * float64(drug.MinNumber)
302
-									if num > drug.Total {
302
+
303
+								if prescribingNumberUnit == drug.MinUnit {
304
+									if prescribing_number > drug.Total {
303 305
 										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
304 306
 										return
305 307
 									}
308
+								} else {
309
+									if prescribingNumberUnit == drug.MaxUnit {
310
+										num := prescribing_number * float64(drug.MinNumber)
311
+										if num > drug.Total {
312
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
313
+											return
314
+										}
315
+									}
306 316
 								}
307 317
 							}
308 318
 						}
@@ -637,74 +647,78 @@ func (c *MobileHisApiController) setAdviceWithJSON(advice *models.HisDoctorAdvic
637 647
 		advice.PrescribingNumberUnit = prescribingNumberUnit
638 648
 	}
639 649
 
640
-	drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
641
-	if advice.ID == 0 { //医嘱不存在
642
-		if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
643
-			drug.Total = drug.Total - advice.PrescribingNumber
644
-			service.UpdateBaseDrugLib(&drug)
650
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
645 651
 
646
-		} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
647
-			num := advice.PrescribingNumber * float64(drug.MinNumber)
648
-			drug.Total = drug.Total - num
649
-			service.UpdateBaseDrugLib(&drug)
650
-		}
652
+	if drugStockConfig.IsOpen == 1 {
653
+		drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
654
+		if advice.ID == 0 { //医嘱不存在
655
+			if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
656
+				drug.Total = drug.Total - advice.PrescribingNumber
657
+				service.UpdateBaseDrugLib(&drug)
651 658
 
652
-	} else if advice.ID > 0 { //医嘱存在
653
-		hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
654
-		var num float64
659
+			} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
660
+				num := advice.PrescribingNumber * float64(drug.MinNumber)
661
+				drug.Total = drug.Total - num
662
+				service.UpdateBaseDrugLib(&drug)
663
+			}
655 664
 
656
-		if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
657
-			if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
658
-				if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
659
-					num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
660
-					drug.Total = drug.Total + num
661
-					service.UpdateBaseDrugLib(&drug)
662
-				} else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
663
-					num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
664
-					drug.Total = drug.Total - num
665
-					service.UpdateBaseDrugLib(&drug)
666
-				}
667
-			} else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
668
-				num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
669
-				if num2 > advice.PrescribingNumber {
670
-					num = num2 - advice.PrescribingNumber
671
-					drug.Total = drug.Total + num
672
-					service.UpdateBaseDrugLib(&drug)
673
-				} else if num2 < advice.PrescribingNumber {
674
-					num = advice.PrescribingNumber - num2
675
-					drug.Total = drug.Total - num
676
-					service.UpdateBaseDrugLib(&drug)
677
-				}
665
+		} else if advice.ID > 0 { //医嘱存在
666
+			hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
667
+			var num float64
678 668
 
679
-			}
669
+			if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
670
+				if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
671
+					if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
672
+						num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
673
+						drug.Total = drug.Total + num
674
+						service.UpdateBaseDrugLib(&drug)
675
+					} else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
676
+						num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
677
+						drug.Total = drug.Total - num
678
+						service.UpdateBaseDrugLib(&drug)
679
+					}
680
+				} else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
681
+					num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
682
+					if num2 > advice.PrescribingNumber {
683
+						num = num2 - advice.PrescribingNumber
684
+						drug.Total = drug.Total + num
685
+						service.UpdateBaseDrugLib(&drug)
686
+					} else if num2 < advice.PrescribingNumber {
687
+						num = advice.PrescribingNumber - num2
688
+						drug.Total = drug.Total - num
689
+						service.UpdateBaseDrugLib(&drug)
690
+					}
680 691
 
681
-		} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
682
-			if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
683
-				num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
684
-				num2 := advice.PrescribingNumber * float64(drug.MinNumber)
685
-				if num1 > num2 {
686
-					num = num1 - num2
687
-					drug.Total = drug.Total + num
688
-					service.UpdateBaseDrugLib(&drug)
689
-				} else if num1 < num2 {
690
-					num = num2 - num1
691
-					drug.Total = drug.Total - num
692
-					service.UpdateBaseDrugLib(&drug)
693 692
 				}
694 693
 
695
-			} else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
696
-				num2 := advice.PrescribingNumber * float64(drug.MinNumber)
697
-				//num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
698
-				if hisAdvice.PrescribingNumber > num2 {
699
-					num = hisAdvice.PrescribingNumber - num2
700
-					drug.Total = drug.Total + num
701
-					service.UpdateBaseDrugLib(&drug)
702
-				} else if num2 < advice.PrescribingNumber {
703
-					num = num2 - hisAdvice.PrescribingNumber
704
-					drug.Total = drug.Total - num
705
-					service.UpdateBaseDrugLib(&drug)
706
-				}
694
+			} else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
695
+				if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
696
+					num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
697
+					num2 := advice.PrescribingNumber * float64(drug.MinNumber)
698
+					if num1 > num2 {
699
+						num = num1 - num2
700
+						drug.Total = drug.Total + num
701
+						service.UpdateBaseDrugLib(&drug)
702
+					} else if num1 < num2 {
703
+						num = num2 - num1
704
+						drug.Total = drug.Total - num
705
+						service.UpdateBaseDrugLib(&drug)
706
+					}
707 707
 
708
+				} else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
709
+					num2 := advice.PrescribingNumber * float64(drug.MinNumber)
710
+					//num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
711
+					if hisAdvice.PrescribingNumber > num2 {
712
+						num = hisAdvice.PrescribingNumber - num2
713
+						drug.Total = drug.Total + num
714
+						service.UpdateBaseDrugLib(&drug)
715
+					} else if num2 < advice.PrescribingNumber {
716
+						num = num2 - hisAdvice.PrescribingNumber
717
+						drug.Total = drug.Total - num
718
+						service.UpdateBaseDrugLib(&drug)
719
+					}
720
+
721
+				}
708 722
 			}
709 723
 		}
710 724
 	}

+ 1 - 2
service/his_project_service.go Целия файл

@@ -595,8 +595,7 @@ func GetPrscriptionInfo(patientid int64, recorddata int64) (info []*models.HisPr
595 595
 }
596 596
 
597 597
 func GetPrescriptionByPatientId(patient_id int64, startime int64, p_type int64) (prescritpion []*models.HisPrescription, err error) {
598
-
599
-	err = XTReadDB().Model(&prescritpion).Where("patient_id = ? and record_date =? AND p_type = ?", patient_id, startime, p_type).Find(&prescritpion).Error
598
+	err = XTReadDB().Model(&prescritpion).Where("patient_id = ? AND record_date =? AND p_type = ? AND status = 1", patient_id, startime, p_type).Find(&prescritpion).Error
600 599
 	return prescritpion, err
601 600
 }
602 601
 

+ 1 - 1
service/patient_service.go Целия файл

@@ -74,7 +74,7 @@ func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bind
74 74
 //GetAllPatientList 返回全部患者的列表
75 75
 func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, err error) {
76 76
 
77
-	db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1", orgID)
77
+	db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1 and p.lapseto = 1", orgID)
78 78
 
79 79
 	err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Count(&total).Find(&patients).Error
80 80
 	return