Przeglądaj źródła

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

csx 4 lat temu
rodzic
commit
6de492bc68

+ 65 - 14
controllers/his_api_controller.go Wyświetl plik

@@ -6,6 +6,7 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
+	"fmt"
9 10
 	"github.com/astaxie/beego"
10 11
 	"reflect"
11 12
 	"strconv"
@@ -118,23 +119,26 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
118 119
 	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
119 120
 
120 121
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
121
-
122
+	//获取所有科室信息
123
+	department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
122 124
 	c.ServeSuccessJSON(map[string]interface{}{
123 125
 		"drugs":            drugs,
124 126
 		"advices_template": advices,
125 127
 		"drugways":         drugways,
126 128
 		"efs":              efs,
127 129
 		"doctors":          doctors,
130
+		"department":       department,
128 131
 	})
129 132
 }
130 133
 func (c *HisApiController) CreateHisPrescription() {
131 134
 	record_date := c.GetString("record_date")
135
+	fmt.Println("record_date", record_date)
132 136
 	patient_id, _ := c.GetInt64("patient_id")
133 137
 	//diagnose := c.GetString("diagnose")
134 138
 	//sick_history := c.GetString("sick_history")
135 139
 	doctor, _ := c.GetInt64("doctor")
136 140
 	//departm/**/ent, _ := c.GetInt64("department")
137
-
141
+	his_patient_id, _ := c.GetInt64("his_patient_id")
138 142
 	dataBody := make(map[string]interface{}, 0)
139 143
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
140 144
 	if err != nil {
@@ -169,16 +173,17 @@ func (c *HisApiController) CreateHisPrescription() {
169 173
 
170 174
 				ctime := time.Now().Unix()
171 175
 				prescription := &models.HisPrescription{
172
-					PatientId:  patient_id,
173
-					UserOrgId:  adminInfo.CurrentOrgId,
174
-					RecordDate: recordDateTime,
175
-					Ctime:      ctime,
176
-					Mtime:      ctime,
177
-					Type:       types,
178
-					Modifier:   adminInfo.AdminUser.Id,
179
-					Creator:    adminInfo.AdminUser.Id,
180
-					Status:     1,
181
-					Doctor:     doctor,
176
+					PatientId:    patient_id,
177
+					UserOrgId:    adminInfo.CurrentOrgId,
178
+					RecordDate:   recordDateTime,
179
+					Ctime:        ctime,
180
+					Mtime:        ctime,
181
+					Type:         types,
182
+					Modifier:     adminInfo.AdminUser.Id,
183
+					Creator:      adminInfo.AdminUser.Id,
184
+					Status:       1,
185
+					Doctor:       doctor,
186
+					HisPatientId: his_patient_id,
182 187
 				}
183 188
 				service.SaveHisPrescription(prescription)
184 189
 
@@ -205,7 +210,7 @@ func (c *HisApiController) CreateHisPrescription() {
205 210
 							s.CreatedTime = ctime
206 211
 							s.UpdatedTime = mtime
207 212
 							s.PatientId = patient_id
208
-
213
+							s.HisPatientId = his_patient_id
209 214
 							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
210 215
 							if errcode > 0 {
211 216
 								c.ServeFailJSONWithSGJErrorCode(errcode)
@@ -215,9 +220,37 @@ func (c *HisApiController) CreateHisPrescription() {
215 220
 						}
216 221
 					}
217 222
 				}
218
-
223
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
224
+					projects := items["project"].([]interface{})
225
+					if len(projects) > 0 {
226
+						for _, project := range projects {
227
+							var p models.HisPrescriptionProject
228
+							p.PrescriptionId = prescription.ID
229
+							p.Ctime = time.Now().Unix()
230
+							p.Mtime = time.Now().Unix()
231
+							p.PatientId = patient_id
232
+							p.RecordDate = recordDateTime
233
+							p.UserOrgId = adminInfo.CurrentOrgId
234
+							p.HisPatientId = his_patient_id
235
+							errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
236
+							if errcode > 0 {
237
+								c.ServeFailJSONWithSGJErrorCode(errcode)
238
+								return
239
+							}
240
+							service.CreateHisProjectTwo(&p)
241
+						}
242
+					}
243
+				}
219 244
 			}
220 245
 		}
246
+
247
+		//查询患者今日处方信息
248
+		//_, errcode := service.GetHisPrescriptionTwo(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
249
+		//if errcode == nil{
250
+		//    //改变患者信息状态
251
+		//   service.UpdatedHisPatient(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
252
+		//
253
+		//}
221 254
 	}
222 255
 
223 256
 	if err == nil {
@@ -536,3 +569,21 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
536 569
 	}
537 570
 	return 0
538 571
 }
572
+
573
+func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
574
+
575
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
576
+		project_id := int64(json["id"].(float64))
577
+		project.ProjectId = project_id
578
+	}
579
+
580
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
581
+		price := int64(json["price"].(float64))
582
+		formatInt_price := strconv.FormatInt(price, 10)
583
+		float_price, _ := strconv.ParseFloat(formatInt_price, 64)
584
+		project.Price = float_price
585
+	}
586
+
587
+	return 0
588
+
589
+}

+ 41 - 6
controllers/his_project_api_controller.go Wyświetl plik

@@ -54,6 +54,7 @@ func HisProjectRouters() {
54 54
 	beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
55 55
 	beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
56 56
 	beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
57
+	beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
57 58
 }
58 59
 
59 60
 func (this *HisProjectApiController) SaveProject() {
@@ -727,7 +728,6 @@ func (this *HisProjectApiController) SaveHisPatient() {
727 728
 	timeLayout := "2006-01-02"
728 729
 	loc, _ := time.LoadLocation("Local")
729 730
 	age, _ := this.GetInt64("age")
730
-
731 731
 	birthday := this.GetString("birthDay")
732 732
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
733 733
 	birthUnix := birthdays.Unix()
@@ -757,9 +757,10 @@ func (this *HisProjectApiController) SaveHisPatient() {
757 757
 	totals_float, _ := strconv.ParseFloat(totals, 64)
758 758
 	adminUserInfo := this.GetAdminUserInfo()
759 759
 	orgId := adminUserInfo.CurrentOrgId
760
-	timeStr := time.Now().Format("2006-01-02")
761
-	fmt.Println("timeStr:", timeStr)
762
-	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
760
+	recordDateStr := time.Now().Format("2006-01-02")
761
+	recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
762
+	fmt.Println("parseDateErr", parseDateErr)
763
+	nowtime := recordDate.Unix()
763 764
 
764 765
 	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
765 766
 	if errcode == gorm.ErrRecordNotFound {
@@ -769,7 +770,8 @@ func (this *HisProjectApiController) SaveHisPatient() {
769 770
 			IdType:                 certificates,
770 771
 			CostOfProduction:       cost_float,
771 772
 			Departments:            department,
772
-			AdminUserId:            doctor,
773
+			Doctor:                 doctor,
774
+			AdminUserId:            adminUserInfo.AdminUser.Id,
773 775
 			MedicalTreatmentType:   medicalcare,
774 776
 			IdCardNo:               idcard,
775 777
 			IsNeedCostOfProduction: cost_checked,
@@ -783,7 +785,8 @@ func (this *HisProjectApiController) SaveHisPatient() {
783 785
 			Total:                  totals_float,
784 786
 			UserOrgId:              orgId,
785 787
 			Status:                 1,
786
-			RecordDate:             timeStringToTime.Unix(),
788
+			RecordDate:             nowtime,
789
+			IsReturn:               1,
787 790
 		}
788 791
 		err := service.CreateHisPatient(&patient)
789 792
 		if err != nil {
@@ -872,7 +875,10 @@ func (this *HisProjectApiController) GetHisPatientHistory() {
872 875
 	adminUserInfo := this.GetAdminUserInfo()
873 876
 	orgId := adminUserInfo.CurrentOrgId
874 877
 	history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
878
+
875 879
 	department, err := service.GetAllDepartMent(orgId)
880
+	appId := adminUserInfo.CurrentAppId
881
+	doctor, err := service.GetAllDoctor(orgId, appId)
876 882
 	if err != nil {
877 883
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
878 884
 		return
@@ -881,5 +887,34 @@ func (this *HisProjectApiController) GetHisPatientHistory() {
881 887
 		"history":    history,
882 888
 		"total":      total,
883 889
 		"department": department,
890
+		"doctor":     doctor,
884 891
 	})
885 892
 }
893
+
894
+func (this *HisProjectApiController) ChangePatient() {
895
+
896
+	id, _ := this.GetInt64("id")
897
+	//查询该患者今日是否已经就诊
898
+	recordDateStr := time.Now().Format("2006-01-02")
899
+	recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
900
+	fmt.Println("parseDateErr", parseDateErr)
901
+	nowtime := recordDate.Unix()
902
+	adminUserInfo := this.GetAdminUserInfo()
903
+	orgId := adminUserInfo.CurrentOrgId
904
+	_, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
905
+	if errcode == gorm.ErrRecordNotFound {
906
+		err := service.ChangePatient(id)
907
+		if err != nil {
908
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
909
+			return
910
+		}
911
+		returnData := make(map[string]interface{}, 0)
912
+		returnData["msg"] = "ok"
913
+		this.ServeSuccessJSON(returnData)
914
+		return
915
+	} else if errcode == nil {
916
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
917
+		return
918
+	}
919
+
920
+}

+ 1 - 1
controllers/mobile_api_controllers/check_weight_api_controller.go Wyświetl plik

@@ -354,7 +354,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
354 354
 		var system_dialysisPrescribe *models.SystemPrescription
355 355
 
356 356
 		var mode_id int64
357
-		weightfirst, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
357
+		weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
358 358
 		if weightfirst.DryWeight > weighing_before {
359 359
 			return
360 360
 		}

+ 14 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Wyświetl plik

@@ -1685,6 +1685,20 @@ func (this *DialysisAPIController) StartDialysis() {
1685 1685
 		UpdatedTime:           time.Now().Unix(),
1686 1686
 	}
1687 1687
 
1688
+	//只针对广慈医院
1689
+	if template.TemplateId == 26 || template.TemplateId == 25 {
1690
+		// 查询病人是否有透前评估数据
1691
+		befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
1692
+		//如果有数据就插入
1693
+		if errcode == nil {
1694
+			record.SystolicBloodPressure = befor.SystolicBloodPressure
1695
+			record.DiastolicBloodPressure = befor.DiastolicBloodPressure
1696
+			record.BreathingRate = befor.BreathingRate
1697
+			record.PulseFrequency = befor.PulseFrequency
1698
+			record.Temperature = befor.Temperature
1699
+		}
1700
+	}
1701
+
1688 1702
 	// 如果当天有插入数据,则不再往透析纪录里插入数据
1689 1703
 	if newdialysisRecord.ID > 0 {
1690 1704
 		err := service.CreateMonitor(&record)

+ 20 - 2
controllers/mobile_api_controllers/patient_api_controller.go Wyświetl plik

@@ -982,7 +982,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
982 982
 						MedicId:        item.DrugId,
983 983
 						StockOutNumber: warehousing_out_order,
984 984
 					}
985
-					service.CreateOutStock(&outStock)
985
+					//查询 该患者是否已出库
986
+					out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
987
+					fmt.Println("errcode ------------------22222", errcode)
988
+					if errcode == gorm.ErrRecordNotFound {
989
+						service.CreateOutStock(&outStock)
990
+					} else if errcode == nil {
991
+						err := service.UpdatedSelfOutSatock(out.ID, &outStock)
992
+						fmt.Println("err", err)
993
+					}
986 994
 				}
987 995
 			}
988 996
 		} else {
@@ -1004,6 +1012,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1004 1012
 					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1005 1013
 					number = number + total
1006 1014
 					warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1015
+
1007 1016
 					//插入自备药出库单
1008 1017
 					outStock := models.XtSelfOutStock{
1009 1018
 						DrugName:       item.AdviceName,
@@ -1020,7 +1029,16 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1020 1029
 						MedicId:        item.DrugId,
1021 1030
 						StockOutNumber: warehousing_out_order,
1022 1031
 					}
1023
-					service.CreateOutStock(&outStock)
1032
+
1033
+					//查询 该患者是否已出库
1034
+					out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1035
+					fmt.Println("errcode ------------------", errcode)
1036
+					if errcode == gorm.ErrRecordNotFound {
1037
+						service.CreateOutStock(&outStock)
1038
+					} else if errcode == nil {
1039
+						err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1040
+						fmt.Println("err", err)
1041
+					}
1024 1042
 
1025 1043
 				}
1026 1044
 			}

+ 2 - 0
models/his_models.go Wyświetl plik

@@ -491,6 +491,8 @@ type XtHisPatient struct {
491 491
 	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
492 492
 	PatientId              int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
493 493
 	Number                 string  `gorm:"column:number" json:"number" form:"number"`
494
+	Doctor                 int64   `gorm:"column:doctor" json:"doctor" form:"doctor"`
495
+	IsReturn               int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
494 496
 }
495 497
 
496 498
 func (XtHisPatient) TableName() string {

+ 27 - 1
service/his_project_service.go Wyświetl plik

@@ -304,6 +304,32 @@ func GetHisPatientHistory(keyword string, startime int64, endtime int64, registt
304 304
 	if orgid > 0 {
305 305
 		db = db.Where("x.user_org_id = ?", orgid)
306 306
 	}
307
-	err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number").Count(&total).Offset(offset).Limit(limit).Find(&hisPatient).Error
307
+	err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number,x.doctor,x.is_return").Count(&total).Offset(offset).Limit(limit).Find(&hisPatient).Error
308 308
 	return hisPatient, total, err
309 309
 }
310
+
311
+func ChangePatient(id int64) error {
312
+	patient := models.XtHisPatient{}
313
+
314
+	err := XTWriteDB().Model(&patient).Where("id = ?", id).Updates(map[string]interface{}{"is_return": 2}).Error
315
+	return err
316
+}
317
+
318
+func GetHisPrescriptionTwo(patientid int64, orgid int64, recorddate int64) (*models.HisPrescription, error) {
319
+	prescription := models.HisPrescription{}
320
+	err := XTReadDB().Model(&prescription).Where("his_patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, recorddate).Find(&prescription).Error
321
+	if err != nil {
322
+		if err == gorm.ErrRecordNotFound {
323
+			return nil, err
324
+		} else {
325
+			return nil, err
326
+		}
327
+	}
328
+	return &prescription, nil
329
+}
330
+
331
+func UpdatedHisPatient(hispatientid int64, orgid int64, recorddate int64) error {
332
+	hisPatient := models.HisPatient{}
333
+	err := XTWriteDB().Model(&hisPatient).Where("id = ? and user_org_id = ? and record_date = ?", hispatientid, orgid, recorddate).Updates(map[string]interface{}{"is_return": 3}).Error
334
+	return err
335
+}

+ 5 - 0
service/his_service.go Wyświetl plik

@@ -156,3 +156,8 @@ func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
156 156
 	err = writeDb.Create(s).Error
157 157
 	return
158 158
 }
159
+
160
+func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
161
+	err = writeDb.Create(project).Error
162
+	return
163
+}

+ 1 - 1
service/manage_service.go Wyświetl plik

@@ -253,7 +253,7 @@ func GetPlanDetailById(id int64, orgid int64) (models.DevicePlanss, error) {
253 253
 
254 254
 func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
255 255
 
256
-	err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.MachineDisinfectant, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
256
+	err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.DisinfectanWay, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
257 257
 	return err
258 258
 }
259 259
 

+ 14 - 0
service/mobile_dialysis_service.go Wyświetl plik

@@ -1597,3 +1597,17 @@ func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time
1597 1597
 	}
1598 1598
 	return
1599 1599
 }
1600
+
1601
+func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
1602
+
1603
+	evaluation := models.PredialysisEvaluation{}
1604
+
1605
+	err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
1606
+	if err == gorm.ErrRecordNotFound {
1607
+		return nil, err
1608
+	}
1609
+	if err != nil {
1610
+		return nil, err
1611
+	}
1612
+	return &evaluation, nil
1613
+}

+ 19 - 0
service/self_drug_service.go Wyświetl plik

@@ -4,6 +4,7 @@ import (
4 4
 	"XT_New/models"
5 5
 	"fmt"
6 6
 	"github.com/jinzhu/gorm"
7
+	"time"
7 8
 )
8 9
 
9 10
 func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error) {
@@ -733,3 +734,21 @@ func GetMedicalDrugNameList(orgid int64) (drugName []*models.DrugName, err error
733 734
 	return drugName, err
734 735
 
735 736
 }
737
+
738
+func GetSelfOutStock(orgid int64, advicedate int64, patientid int64, adivicename string, advicedesc string) (*models.XtSelfOutStock, error) {
739
+	stock := models.XtSelfOutStock{}
740
+	err = XTReadDB().Model(&stock).Where("user_org_id = ? and storck_time = ? and patient_id = ? and drug_name = ? and drug_spec = ? and status = 1", orgid, advicedate, patientid, adivicename, advicedesc).Find(&stock).Error
741
+	if err == gorm.ErrRecordNotFound {
742
+		return nil, err
743
+	}
744
+	if err != nil {
745
+		return nil, err
746
+	}
747
+	return &stock, err
748
+}
749
+
750
+func UpdatedSelfOutSatock(id int64, stock *models.XtSelfOutStock) error {
751
+
752
+	err := XTWriteDB().Model(&stock).Where("id = ?", id).Updates(map[string]interface{}{"drug_name": stock.DrugName, "drug_name_id": stock.DrugNameId, "drug_spec": stock.DrugSpec, "outstore_number": stock.OutstoreNumber, "admin_user_id": stock.AdminUserId, "storck_time": stock.StorckTime, "patient_id": stock.PatientId, "stock_out_number": stock.StockOutNumber, "exit_mode": stock.ExitMode, "medic_id": stock.MedicId, "updated_time": time.Now().Unix()}).Error
753
+	return err
754
+}