|
@@ -327,6 +327,8 @@ func (c *HisApiController) CreateHisPrescription() {
|
327
|
327
|
|
328
|
328
|
_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
329
|
329
|
|
|
330
|
+ _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
|
331
|
+
|
330
|
332
|
if drugStockConfig.IsOpen == 1 {
|
331
|
333
|
//校验库存总量
|
332
|
334
|
if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
|
@@ -383,6 +385,53 @@ func (c *HisApiController) CreateHisPrescription() {
|
383
|
385
|
}
|
384
|
386
|
}
|
385
|
387
|
}
|
|
388
|
+
|
|
389
|
+ if stockConfig.IsOpen == 1 {
|
|
390
|
+ if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
|
391
|
+ prescriptions, _ := dataBody["prescriptions"].([]interface{})
|
|
392
|
+ if len(prescriptions) > 0 {
|
|
393
|
+ for _, item := range prescriptions {
|
|
394
|
+ items := item.(map[string]interface{})
|
|
395
|
+ if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
|
|
396
|
+ projects := items["project"].([]interface{})
|
|
397
|
+ if len(projects) > 0 {
|
|
398
|
+ for _, project := range projects {
|
|
399
|
+ var project_id int64
|
|
400
|
+ var project_type int64
|
|
401
|
+ var totals float64
|
|
402
|
+ if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
|
|
403
|
+ project_id = int64(project.(map[string]interface{})["id"].(float64))
|
|
404
|
+ }
|
|
405
|
+ if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
|
|
406
|
+ project_type = int64(project.(map[string]interface{})["type"].(float64))
|
|
407
|
+ }
|
|
408
|
+ if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
|
|
409
|
+ total, _ := project.(map[string]interface{})["total"].(string)
|
|
410
|
+
|
|
411
|
+ totals, _ = strconv.ParseFloat(total, 64)
|
|
412
|
+ }
|
|
413
|
+ if project_type == 3 {
|
|
414
|
+ good, _ := service.FindGoodInfoByIdTwo(project_id)
|
|
415
|
+ if good.ID == 0 {
|
|
416
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
417
|
+ return
|
|
418
|
+ }
|
|
419
|
+ if totals > good.Total {
|
|
420
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
|
421
|
+ return
|
|
422
|
+ }
|
|
423
|
+
|
|
424
|
+ }
|
|
425
|
+
|
|
426
|
+ }
|
|
427
|
+ }
|
|
428
|
+ }
|
|
429
|
+ }
|
|
430
|
+ }
|
|
431
|
+ }
|
|
432
|
+
|
|
433
|
+ }
|
|
434
|
+
|
386
|
435
|
info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
|
387
|
436
|
var hpInfo models.HisPrescriptionInfo
|
388
|
437
|
if info.ID == 0 {
|
|
@@ -594,6 +643,7 @@ func (c *HisApiController) CreateHisPrescription() {
|
594
|
643
|
return
|
595
|
644
|
}
|
596
|
645
|
service.CreateHisProjectTwo(&p)
|
|
646
|
+
|
597
|
647
|
var randNum int
|
598
|
648
|
randNum = rand.Intn(10000) + 1000
|
599
|
649
|
timestamp := time.Now().Unix()
|
|
@@ -903,10 +953,21 @@ func (c *HisApiController) DeletePrescription() {
|
903
|
953
|
advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
|
904
|
954
|
_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
905
|
955
|
|
|
956
|
+ _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
|
957
|
+
|
906
|
958
|
err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
|
907
|
959
|
if err == nil {
|
908
|
960
|
if len(projects) > 0 {
|
909
|
961
|
for _, item := range projects {
|
|
962
|
+ if stockConfig.IsOpen == 1 {
|
|
963
|
+ if item.Type == 3 {
|
|
964
|
+ good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
|
|
965
|
+ f_count, _ := strconv.ParseFloat(strconv.FormatInt(item.Count, 10), 64)
|
|
966
|
+ good.Total = good.Total + f_count
|
|
967
|
+ service.UpdateGoodInfo(&good)
|
|
968
|
+ }
|
|
969
|
+ }
|
|
970
|
+
|
910
|
971
|
if item.Type == 3 { //处理透前准备耗材数量数据
|
911
|
972
|
consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
|
912
|
973
|
if consumables.ID > 0 {
|
|
@@ -979,11 +1040,21 @@ func (c *HisApiController) DeleteProject() {
|
979
|
1040
|
adminInfo := c.GetAdminUserInfo()
|
980
|
1041
|
project, _ := service.GetHisProjectByID(id)
|
981
|
1042
|
var consumable models.DialysisBeforePrepare
|
|
1043
|
+ _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
|
1044
|
+
|
982
|
1045
|
if project.ID > 0 && project.Type == 3 {
|
983
|
1046
|
consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
|
984
|
1047
|
}
|
985
|
1048
|
err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
|
986
|
1049
|
if err == nil {
|
|
1050
|
+ if stockConfig.IsOpen == 1 {
|
|
1051
|
+ if project.Type == 3 {
|
|
1052
|
+ good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
|
|
1053
|
+ f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
|
|
1054
|
+ good.Total = good.Total + f_count
|
|
1055
|
+ service.UpdateGoodInfo(&good)
|
|
1056
|
+ }
|
|
1057
|
+ }
|
987
|
1058
|
if consumable.ID > 0 {
|
988
|
1059
|
consumable.Count = 0
|
989
|
1060
|
service.UpdateConsumables(&consumable)
|
|
@@ -1857,6 +1928,41 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
|
1857
|
1928
|
project.Unit = unit
|
1858
|
1929
|
}
|
1859
|
1930
|
|
|
1931
|
+ _, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
|
|
1932
|
+
|
|
1933
|
+ if project.ID == 0 {
|
|
1934
|
+ if stockConfig.IsOpen == 1 {
|
|
1935
|
+ if project.Type == 3 {
|
|
1936
|
+ good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
|
|
1937
|
+ f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
|
|
1938
|
+ good.Total = good.Total - f_count
|
|
1939
|
+ service.UpdateGoodInfo(&good)
|
|
1940
|
+ }
|
|
1941
|
+ }
|
|
1942
|
+
|
|
1943
|
+ } else {
|
|
1944
|
+ temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
|
|
1945
|
+
|
|
1946
|
+ if stockConfig.IsOpen == 1 {
|
|
1947
|
+ if project.Type == 3 {
|
|
1948
|
+ good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
|
|
1949
|
+ if project.Count < temp_project.Count {
|
|
1950
|
+ other_count := temp_project.Count - project.Count
|
|
1951
|
+ other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
|
|
1952
|
+ good.Total = good.Total + other_count_two
|
|
1953
|
+ service.UpdateGoodInfo(&good)
|
|
1954
|
+ } else if project.Count > temp_project.Count {
|
|
1955
|
+ other_count := project.Count - temp_project.Count
|
|
1956
|
+ other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
|
|
1957
|
+ good.Total = good.Total - other_count_two
|
|
1958
|
+ service.UpdateGoodInfo(&good)
|
|
1959
|
+ }
|
|
1960
|
+
|
|
1961
|
+ }
|
|
1962
|
+ }
|
|
1963
|
+
|
|
1964
|
+ }
|
|
1965
|
+
|
1860
|
1966
|
return 0
|
1861
|
1967
|
}
|
1862
|
1968
|
|