28169 преди 2 години
родител
ревизия
8346bb7e3f

+ 3 - 3
controllers/dialysis_api_controller.go Целия файл

3419
 }
3419
 }
3420
 
3420
 
3421
 func (c *DialysisApiController) GetDialysisOrder() {
3421
 func (c *DialysisApiController) GetDialysisOrder() {
3422
-	xtno := c.GetString("xtno")
3422
+	//xtno := c.GetString("xtno")
3423
 	xtdate := c.GetString("xtdate")
3423
 	xtdate := c.GetString("xtdate")
3424
-
3424
+	patient_id, _ := c.GetInt64("patient_id")
3425
 	timeLayout := "2006-01-02"
3425
 	timeLayout := "2006-01-02"
3426
 	loc, _ := time.LoadLocation("Local")
3426
 	loc, _ := time.LoadLocation("Local")
3427
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
3427
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
3438
 
3438
 
3439
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
3439
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
3440
 
3440
 
3441
-	patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
3441
+	patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
3442
 
3442
 
3443
 	//透析单
3443
 	//透析单
3444
 	dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
3444
 	dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)

+ 52 - 7
controllers/mobile_api_controllers/patient_api_controller.go Целия файл

719
 							}
719
 							}
720
 
720
 
721
 							if medical.IsUse == 1 {
721
 							if medical.IsUse == 1 {
722
+								service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
722
 								c.ServeSuccessJSON(map[string]interface{}{
723
 								c.ServeSuccessJSON(map[string]interface{}{
723
 									"msg":    "1",
724
 									"msg":    "1",
724
 									"advice": advice,
725
 									"advice": advice,
729
 
730
 
730
 							if medical.IsUse != 1 {
731
 							if medical.IsUse != 1 {
731
 								if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
732
 								if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
733
+									service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
732
 									c.ServeSuccessJSON(map[string]interface{}{
734
 									c.ServeSuccessJSON(map[string]interface{}{
733
 										"msg":    "3",
735
 										"msg":    "3",
734
 										"advice": advice,
736
 										"advice": advice,
735
 										"ids":    ids,
737
 										"ids":    ids,
736
 									})
738
 									})
737
 									return
739
 									return
740
+
738
 								}
741
 								}
739
 								if prescribing_number_total > total {
742
 								if prescribing_number_total > total {
743
+									service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
740
 									c.ServeSuccessJSON(map[string]interface{}{
744
 									c.ServeSuccessJSON(map[string]interface{}{
741
 										"msg":    "2",
745
 										"msg":    "2",
742
 										"advice": advice,
746
 										"advice": advice,
752
 					//出库
756
 					//出库
753
 					for _, item := range advices {
757
 					for _, item := range advices {
754
 						if item.Way == 1 {
758
 						if item.Way == 1 {
755
-
756
 							//查询是否出库按钮开启
759
 							//查询是否出库按钮开启
757
 							adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
760
 							adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
758
 							//查询改药品信息
761
 							//查询改药品信息
760
 							if adviceSetting.IsAdviceOpen == 1 {
763
 							if adviceSetting.IsAdviceOpen == 1 {
761
 								//查询是否出库按钮开启
764
 								//查询是否出库按钮开启
762
 								prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
765
 								prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
766
+								//患者发药
763
 								pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
767
 								pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
764
 								if prescriptionConfig.IsOpen == 1 {
768
 								if prescriptionConfig.IsOpen == 1 {
765
 									if medical.IsUse == 2 {
769
 									if medical.IsUse == 2 {
766
 										if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
770
 										if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
767
-											service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
771
+											//查询今日是否出库
772
+											drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
773
+											if drugOutInfo.ID == 0 {
774
+												service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
775
+											}
776
+
768
 										}
777
 										}
769
 										if pharmacyConfig.IsOpen != 1 {
778
 										if pharmacyConfig.IsOpen != 1 {
770
-											service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
779
+											drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
780
+											if drugOutInfo.ID == 0 {
781
+												service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
782
+											}
771
 										}
783
 										}
772
 
784
 
773
 										//更新字典里面的库存
785
 										//更新字典里面的库存
788
 								pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
800
 								pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
789
 								if medical.IsUse == 2 {
801
 								if medical.IsUse == 2 {
790
 									if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
802
 									if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
791
-										service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
803
+										drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
804
+										if drugOutInfo.ID == 0 {
805
+											service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
806
+										}
792
 									}
807
 									}
793
 									if pharmacyConfig.IsOpen != 1 {
808
 									if pharmacyConfig.IsOpen != 1 {
794
-										service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
809
+										drugError := models.XtDrugError{
810
+											ID:                    0,
811
+											UserOrgId:             item.UserOrgId,
812
+											DrugId:                item.DrugId,
813
+											RecordDate:            item.AdviceDate,
814
+											PatientId:             item.PatientId,
815
+											Remark:                "恒泰中医院出库开始",
816
+											Status:                1,
817
+											Ctime:                 time.Now().Unix(),
818
+											Mtime:                 0,
819
+											Prescribingnumber:     item.PrescribingNumber,
820
+											PrescribingNumberUnit: item.PrescribingNumberUnit,
821
+											SumCount:              0,
822
+										}
823
+										service.CreateDrugError(drugError)
824
+										drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
825
+										if drugOutInfo.ID == 0 {
826
+
827
+											service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
828
+										}
795
 									}
829
 									}
796
 
830
 
797
 									stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
831
 									stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
855
 							}
889
 							}
856
 
890
 
857
 							if medical.IsUse == 1 {
891
 							if medical.IsUse == 1 {
892
+								service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
858
 								c.ServeSuccessJSON(map[string]interface{}{
893
 								c.ServeSuccessJSON(map[string]interface{}{
859
 									"msg":    "1",
894
 									"msg":    "1",
860
 									"advice": advice,
895
 									"advice": advice,
864
 							}
899
 							}
865
 							if medical.IsUse != 1 {
900
 							if medical.IsUse != 1 {
866
 								if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
901
 								if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
902
+									service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
867
 									c.ServeSuccessJSON(map[string]interface{}{
903
 									c.ServeSuccessJSON(map[string]interface{}{
868
 										"msg":    "3",
904
 										"msg":    "3",
869
 										"advice": advice,
905
 										"advice": advice,
872
 									return
908
 									return
873
 								}
909
 								}
874
 								if prescribing_number_total > total {
910
 								if prescribing_number_total > total {
911
+									service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
875
 									c.ServeSuccessJSON(map[string]interface{}{
912
 									c.ServeSuccessJSON(map[string]interface{}{
876
 										"msg":    "2",
913
 										"msg":    "2",
877
 										"advice": advice,
914
 										"advice": advice,
891
 							pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
928
 							pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
892
 							if medical.IsUse == 2 {
929
 							if medical.IsUse == 2 {
893
 								if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
930
 								if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
894
-									service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
931
+									//查询今日是否出库
932
+									drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
933
+									if drugOutInfo.ID == 0 {
934
+										service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
935
+									}
895
 								}
936
 								}
896
 								if pharmacyConfig.IsOpen != 1 {
937
 								if pharmacyConfig.IsOpen != 1 {
897
-									service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
938
+									//查询今日是否出库
939
+									drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
940
+									if drugOutInfo.ID == 0 {
941
+										service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
942
+									}
898
 								}
943
 								}
899
 
944
 
900
 								//更新字典里面的库存
945
 								//更新字典里面的库存

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

37
 	idStrs := strings.Split(schIDStr, ",")
37
 	idStrs := strings.Split(schIDStr, ",")
38
 	adminUserInfo := this.GetAdminUserInfo()
38
 	adminUserInfo := this.GetAdminUserInfo()
39
 
39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 || this.GetAdminUserInfo().CurrentOrgId == 10340 {
41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42
 		for _, item := range schedules {
42
 		for _, item := range schedules {
43
 
43
 

+ 6 - 0
service/dialysis_service.go Целия файл

2090
 	err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
2090
 	err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
2091
 	return err
2091
 	return err
2092
 }
2092
 }
2093
+
2094
+func UpdateDoctorAdviceByExcecute(id int64, user_org_id int64) error {
2095
+
2096
+	err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id = ? and user_org_id = ? and status =1").Updates(map[string]interface{}{"execution_time": 0, "execution_staff": 0, "execution_state": 0}).Error
2097
+	return err
2098
+}

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

609
 	return
609
 	return
610
 }
610
 }
611
 
611
 
612
+func FindPatientWithDeviceByPatientId(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
613
+	err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
614
+		return db.Preload("DeviceNumber", "org_id = ?", orgID).
615
+			Preload("DeviceZone", "org_id = ?", orgID).
616
+			Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
617
+	}).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and id = ? and status = 1 ", orgID, id).First(&patient).Error
618
+	return
619
+}
620
+
612
 func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
621
 func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
613
 
622
 
614
 	user, _ := GetSgjUserByMobild(patient.Phone)
623
 	user, _ := GetSgjUserByMobild(patient.Phone)

+ 30 - 0
service/warhouse_service.go Целия файл

83
 // 药品自动出库 递归方式
83
 // 药品自动出库 递归方式
84
 func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DoctorAdvice) (err error) {
84
 func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DoctorAdvice) (err error) {
85
 
85
 
86
+	drugError := models.XtDrugError{
87
+		ID:                    0,
88
+		UserOrgId:             advice.UserOrgId,
89
+		DrugId:                advice.DrugId,
90
+		RecordDate:            advice.AdviceDate,
91
+		PatientId:             advice.PatientId,
92
+		Remark:                "恒泰中医院出库进来",
93
+		Status:                1,
94
+		Ctime:                 time.Now().Unix(),
95
+		Mtime:                 0,
96
+		Prescribingnumber:     advice.PrescribingNumber,
97
+		PrescribingNumberUnit: advice.PrescribingNumberUnit,
98
+		SumCount:              0,
99
+	}
100
+	CreateDrugError(drugError)
86
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
101
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
87
 	var deliver_number int64 = 0
102
 	var deliver_number int64 = 0
88
 	var stock_number int64 = 0
103
 	var stock_number int64 = 0
249
 			StorehouseId:            storeConfig.DrugStorehouseOut,
264
 			StorehouseId:            storeConfig.DrugStorehouseOut,
250
 			IsCheck:                 1,
265
 			IsCheck:                 1,
251
 			OverCount:               sum_count,
266
 			OverCount:               sum_count,
267
+			AdviceId:                advice.ID,
252
 		}
268
 		}
253
 
269
 
254
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
270
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
282
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
298
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
283
 			LastPrice:               warehouse.Price,
299
 			LastPrice:               warehouse.Price,
284
 			OverCount:               sum_count,
300
 			OverCount:               sum_count,
301
+			AdviceId:                advice.ID,
285
 		}
302
 		}
286
 
303
 
287
 		CreateDrugFlowOne(drugflow)
304
 		CreateDrugFlowOne(drugflow)
302
 			CountUnit:               drup.MinUnit,
319
 			CountUnit:               drup.MinUnit,
303
 			WarehouseInfoId:         warehouse.ID,
320
 			WarehouseInfoId:         warehouse.ID,
304
 			StorehouseId:            storeConfig.DrugStorehouseOut,
321
 			StorehouseId:            storeConfig.DrugStorehouseOut,
322
+			AdviceId:                advice.ID,
305
 		}
323
 		}
306
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
324
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
307
 		if errTwo != nil {
325
 		if errTwo != nil {
346
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
364
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
347
 			StorehouseId:            storeConfig.DrugStorehouseOut,
365
 			StorehouseId:            storeConfig.DrugStorehouseOut,
348
 			IsCheck:                 1,
366
 			IsCheck:                 1,
367
+			AdviceId:                advice.ID,
349
 		}
368
 		}
350
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
369
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
351
 		if errOne != nil {
370
 		if errOne != nil {
366
 			CountUnit:               drup.MinUnit,
385
 			CountUnit:               drup.MinUnit,
367
 			WarehouseInfoId:         warehouse.ID,
386
 			WarehouseInfoId:         warehouse.ID,
368
 			StorehouseId:            storeConfig.DrugStorehouseOut,
387
 			StorehouseId:            storeConfig.DrugStorehouseOut,
388
+			AdviceId:                advice.ID,
369
 		}
389
 		}
370
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
390
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
371
 		if errTwo != nil {
391
 		if errTwo != nil {
455
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
475
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
456
 			LastPrice:               warehouse.Price,
476
 			LastPrice:               warehouse.Price,
457
 			OverCount:               sum_count,
477
 			OverCount:               sum_count,
478
+			AdviceId:                advice.ID,
458
 		}
479
 		}
459
 
480
 
460
 		CreateDrugFlowOne(drugflow)
481
 		CreateDrugFlowOne(drugflow)
7489
 	err := XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"execution_time": "", "execution_staff": "", "execution_state": 2}).Error
7510
 	err := XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"execution_time": "", "execution_staff": "", "execution_state": 2}).Error
7490
 	return err
7511
 	return err
7491
 }
7512
 }
7513
+
7514
+func GetAdviceIsOut(advice_id int64, user_org_id int64, patient_id int64, advice_date int64, drug_id int64) (models.DrugWarehouseOutInfo, error) {
7515
+
7516
+	advice := models.DrugWarehouseOutInfo{}
7517
+
7518
+	err := XTReadDB().Where("advice_id = ? and org_id = ? and patient_id = ? and sys_record_time = ? and status=1 and drug_id = ?", advice_id, user_org_id, patient_id, advice_date, drug_id).Find(&advice).Error
7519
+
7520
+	return advice, err
7521
+}