Browse Source

自备药开发

XMLWAN 4 years ago
parent
commit
9e14822323

+ 205 - 82
controllers/patient_api_controller.go View File

@@ -254,29 +254,29 @@ func (c *PatientApiController) CreatePatient() {
254 254
 	//获取老表的最后一条数据
255 255
 	patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
256 256
 	patientsNew := models.XtPatientsNew{
257
-		UserOrgId:          adminUserInfo.CurrentOrgId,
258
-		UserId:             0,
259
-		Avatar:             patients.Avatar,
260
-		PatientType:        patients.PatientType,
261
-		DialysisNo:         patients.DialysisNo,
262
-		AdmissionNumber:    patients.AdmissionNumber,
263
-		Source:             patients.Source,
264
-		Lapseto:            patients.Lapseto,
265
-		PartitionId:        patients.PartitionId,
266
-		BedId:              patients.BedId,
267
-		Name:               patients.Name,
268
-		Alias:              patients.Alias,
269
-		Gender:             patients.Gender,
270
-		MaritalStatus:      patients.MaritalStatus,
271
-		IdCardNo:           patients.IdCardNo,
272
-		Birthday:           patients.Birthday,
273
-		ReimbursementWayId: patients.ReimbursementWayId,
274
-		HealthCareType:     patients.HealthCareType,
275
-		HealthCareNo:       patients.HealthCareNo,
276
-		HealthCareDueDate:  patients.HealthCareDueDate,
277
-		Height:             patients.Height,
278
-		BloodType:          patients.BloodType,
279
-		Rh:                 patients.Rh,
257
+		UserOrgId:                    adminUserInfo.CurrentOrgId,
258
+		UserId:                       0,
259
+		Avatar:                       patients.Avatar,
260
+		PatientType:                  patients.PatientType,
261
+		DialysisNo:                   patients.DialysisNo,
262
+		AdmissionNumber:              patients.AdmissionNumber,
263
+		Source:                       patients.Source,
264
+		Lapseto:                      patients.Lapseto,
265
+		PartitionId:                  patients.PartitionId,
266
+		BedId:                        patients.BedId,
267
+		Name:                         patients.Name,
268
+		Alias:                        patients.Alias,
269
+		Gender:                       patients.Gender,
270
+		MaritalStatus:                patients.MaritalStatus,
271
+		IdCardNo:                     patients.IdCardNo,
272
+		Birthday:                     patients.Birthday,
273
+		ReimbursementWayId:           patients.ReimbursementWayId,
274
+		HealthCareType:               patients.HealthCareType,
275
+		HealthCareNo:                 patients.HealthCareNo,
276
+		HealthCareDueDate:            patients.HealthCareDueDate,
277
+		Height:                       patients.Height,
278
+		BloodType:                    patients.BloodType,
279
+		Rh:                           patients.Rh,
280 280
 		HealthCareDueAlertDate:       patients.HealthCareDueAlertDate,
281 281
 		EducationLevel:               patients.EducationLevel,
282 282
 		Profession:                   patients.Profession,
@@ -322,28 +322,28 @@ func (c *PatientApiController) CreatePatient() {
322 322
 		Nation:                       patients.Nation,
323 323
 		NativePlace:                  patients.NativePlace,
324 324
 		Age:                          patients.Age,
325
-		InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
326
-		IsInfectious:             patients.IsInfectious,
327
-		RemindCycle:              patients.RemindCycle,
328
-		ResponseResult:           patients.ResponseResult,
329
-		IsOpenRemind:             patients.IsOpenRemind,
330
-		FirstTreatmentDate:       patients.FirstTreatmentDate,
331
-		DialysisAge:              patients.DialysisAge,
332
-		ExpenseKind:              patients.ExpenseKind,
333
-		TellPhone:                patients.TellPhone,
334
-		ContactName:              patients.ContactName,
335
-		BloodPatients:            1,
336
-		SlowPatients:             0,
337
-		MemberPatients:           0,
338
-		EcommerPatients:          "",
339
-		BloodId:                  patients.ID,
340
-		SlowId:                   0,
341
-		MemberId:                 0,
342
-		MemberFistdate:           0,
343
-		MemberPatienttype:        0,
344
-		MemberTreatement:         0,
345
-		EquitmentId:              "",
346
-		UserSysBeforeCount:       patient.UserSysBeforeCount,
325
+		InfectiousNextRecordTime:     patients.InfectiousNextRecordTime,
326
+		IsInfectious:                 patients.IsInfectious,
327
+		RemindCycle:                  patients.RemindCycle,
328
+		ResponseResult:               patients.ResponseResult,
329
+		IsOpenRemind:                 patients.IsOpenRemind,
330
+		FirstTreatmentDate:           patients.FirstTreatmentDate,
331
+		DialysisAge:                  patients.DialysisAge,
332
+		ExpenseKind:                  patients.ExpenseKind,
333
+		TellPhone:                    patients.TellPhone,
334
+		ContactName:                  patients.ContactName,
335
+		BloodPatients:                1,
336
+		SlowPatients:                 0,
337
+		MemberPatients:               0,
338
+		EcommerPatients:              "",
339
+		BloodId:                      patients.ID,
340
+		SlowId:                       0,
341
+		MemberId:                     0,
342
+		MemberFistdate:               0,
343
+		MemberPatienttype:            0,
344
+		MemberTreatement:             0,
345
+		EquitmentId:                  "",
346
+		UserSysBeforeCount:           patient.UserSysBeforeCount,
347 347
 	}
348 348
 
349 349
 	err = service.CreatePatientsNew(&patientsNew)
@@ -481,28 +481,28 @@ func (c *PatientApiController) EditPatient() {
481 481
 		return
482 482
 	}
483 483
 	patientsNew := models.XtPatientsNew{
484
-		UserOrgId:          patient.UserOrgId,
485
-		UserId:             patient.UserId,
486
-		Avatar:             patient.Avatar,
487
-		PatientType:        patient.PatientType,
488
-		DialysisNo:         patient.DialysisNo,
489
-		AdmissionNumber:    patient.AdmissionNumber,
490
-		Source:             patient.Source,
491
-		PartitionId:        patient.PartitionId,
492
-		BedId:              patient.BedId,
493
-		Name:               patient.Name,
494
-		Alias:              patient.Alias,
495
-		Gender:             patient.Gender,
496
-		MaritalStatus:      patient.MaritalStatus,
497
-		IdCardNo:           patient.IdCardNo,
498
-		Birthday:           patient.Birthday,
499
-		ReimbursementWayId: patient.ReimbursementWayId,
500
-		HealthCareType:     patient.HealthCareType,
501
-		HealthCareNo:       patient.HealthCareNo,
502
-		HealthCareDueDate:  patient.HealthCareDueDate,
503
-		Height:             patient.Height,
504
-		BloodType:          patient.BloodType,
505
-		Rh:                 patient.Rh,
484
+		UserOrgId:                 patient.UserOrgId,
485
+		UserId:                    patient.UserId,
486
+		Avatar:                    patient.Avatar,
487
+		PatientType:               patient.PatientType,
488
+		DialysisNo:                patient.DialysisNo,
489
+		AdmissionNumber:           patient.AdmissionNumber,
490
+		Source:                    patient.Source,
491
+		PartitionId:               patient.PartitionId,
492
+		BedId:                     patient.BedId,
493
+		Name:                      patient.Name,
494
+		Alias:                     patient.Alias,
495
+		Gender:                    patient.Gender,
496
+		MaritalStatus:             patient.MaritalStatus,
497
+		IdCardNo:                  patient.IdCardNo,
498
+		Birthday:                  patient.Birthday,
499
+		ReimbursementWayId:        patient.ReimbursementWayId,
500
+		HealthCareType:            patient.HealthCareType,
501
+		HealthCareNo:              patient.HealthCareNo,
502
+		HealthCareDueDate:         patient.HealthCareDueDate,
503
+		Height:                    patient.Height,
504
+		BloodType:                 patient.BloodType,
505
+		Rh:                        patient.Rh,
506 506
 		HealthCareDueAlertDate:    patient.HealthCareDueAlertDate,
507 507
 		EducationLevel:            patient.EducationLevel,
508 508
 		Profession:                patient.Profession,
@@ -544,19 +544,19 @@ func (c *PatientApiController) EditPatient() {
544 544
 		Nation:                    patient.Nation,
545 545
 		NativePlace:               patient.NativePlace,
546 546
 		Age:                       patient.Age,
547
-		InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
548
-		IsInfectious:             patient.IsInfectious,
549
-		RemindCycle:              patient.RemindCycle,
550
-		ResponseResult:           patient.ResponseResult,
551
-		IsOpenRemind:             patient.IsOpenRemind,
552
-		FirstTreatmentDate:       patient.FirstTreatmentDate,
553
-		DialysisAge:              patient.DialysisAge,
554
-		ExpenseKind:              patient.ExpenseKind,
555
-		TellPhone:                patient.TellPhone,
556
-		ContactName:              patient.ContactName,
557
-		UpdatedTime:              time.Now().Unix(),
558
-		BloodPatients:            1,
559
-		Lapseto:                  patient.Lapseto,
547
+		InfectiousNextRecordTime:  patient.InfectiousNextRecordTime,
548
+		IsInfectious:              patient.IsInfectious,
549
+		RemindCycle:               patient.RemindCycle,
550
+		ResponseResult:            patient.ResponseResult,
551
+		IsOpenRemind:              patient.IsOpenRemind,
552
+		FirstTreatmentDate:        patient.FirstTreatmentDate,
553
+		DialysisAge:               patient.DialysisAge,
554
+		ExpenseKind:               patient.ExpenseKind,
555
+		TellPhone:                 patient.TellPhone,
556
+		ContactName:               patient.ContactName,
557
+		UpdatedTime:               time.Now().Unix(),
558
+		BloodPatients:             1,
559
+		Lapseto:                   patient.Lapseto,
560 560
 	}
561 561
 	//	//更新病人ID获取新表病人ID
562 562
 	err = service.UpdatepatientTwo(&patientsNew, id)
@@ -1228,6 +1228,16 @@ func (c *PatientApiController) CreateGroupAdvice() {
1228 1228
 			advice.ExecutionFrequency = executionFrequency
1229 1229
 		}
1230 1230
 
1231
+		if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
1232
+			way := int64(adviceNameM["way"].(float64))
1233
+			advice.Way = way
1234
+		}
1235
+
1236
+		if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
1237
+			drug_id := int64(adviceNameM["drug_id"].(float64))
1238
+			advice.DrugId = drug_id
1239
+		}
1240
+
1231 1241
 		if adviceType == 1 {
1232 1242
 
1233 1243
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
@@ -1493,6 +1503,7 @@ func (c *PatientApiController) ExecGroupAdvice() {
1493 1503
 }
1494 1504
 
1495 1505
 func (c *PatientApiController) ExecDoctorAdvice() {
1506
+
1496 1507
 	patient, _ := c.GetInt64("patient", 0)
1497 1508
 	id, _ := c.GetInt64("id", 0)
1498 1509
 	executionTime := c.GetString("execution_time")
@@ -1563,9 +1574,121 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1563 1574
 	// advice.Checker = checker
1564 1575
 
1565 1576
 	adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
1566
-
1577
+	fmt.Println("adviceName", adviceName.Way)
1578
+	timeStr := time.Now().Format("2006-01-02")
1579
+	fmt.Println("timestr", timeStr)
1567 1580
 	//如果医嘱已执行,生成自备药出库单
1568
-	if adviceName.ExecutionState == 1 {
1581
+	//来自药品库
1582
+	if adviceName.ExecutionState == 1 && adviceName.Way == 1 {
1583
+		timeLayout := "2006-01-02"
1584
+		loc, _ := time.LoadLocation("Local")
1585
+		//产询今日是否存在出库单
1586
+		timeStr := time.Now().Format("2006-01-02")
1587
+		theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeStr+" 00:00:00", loc)
1588
+		_, errcode := service.GetDrugWareseOut(theTime.Unix(), adminUserInfo.CurrentOrgId)
1589
+		if errcode == gorm.ErrRecordNotFound {
1590
+			timeArr := strings.Split(timeStr, "-")
1591
+			total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1592
+
1593
+			total = total + 1
1594
+			warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1595
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1596
+			number = number + total
1597
+			warehousing_out_order = "YPRKD" + strconv.FormatInt(number, 10)
1598
+			//查询厂家
1599
+			drug, _ := service.GetManufacturer(adviceName.DrugId)
1600
+			//创建
1601
+			warehouse := models.XtDrugWarehouse{
1602
+				WarehousingOrder: warehousing_out_order,
1603
+				OperationTime:    theTime.Unix(),
1604
+				Creater:          adminUserInfo.AdminUser.Id,
1605
+				OrgId:            adminUserInfo.CurrentOrgId,
1606
+				Status:           1,
1607
+				WarehousingTime:  theTime.Unix(),
1608
+				Manufacturer:     drug.Manufacturer,
1609
+				Type:             1,
1610
+			}
1611
+			service.CreateDrugWarehoue(&warehouse)
1612
+		}
1613
+
1614
+		timeArr := strings.Split(timeStr, "-")
1615
+		total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1616
+
1617
+		total = total + 1
1618
+		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1619
+		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1620
+		number = number + total
1621
+		warehousing_out_order = "YPRKD" + strconv.FormatInt(number, 10)
1622
+		drug, _ := service.GetManufacturer(adviceName.DrugId)
1623
+		out := models.XtDrugWarehouseOut{
1624
+			WarehouseOutOrderNumber: warehousing_out_order,
1625
+			OperationTime:           theTime.Unix(),
1626
+			Creater:                 adminUserInfo.AdminUser.Id,
1627
+			OrgId:                   adminUserInfo.CurrentOrgId,
1628
+			Ctime:                   time.Now().Unix(),
1629
+			Status:                  1,
1630
+			WarehouseOutTime:        theTime.Unix(),
1631
+			Manufacturer:            drug.Manufacturer,
1632
+			Type:                    1,
1633
+			IsSys:                   1,
1634
+		}
1635
+		service.CreateDrugWareHouseOut(&out)
1636
+
1637
+		//查询今日的出库单号
1638
+		orderOut, _ := service.GetTodayWareHousringOrder(theTime.Unix(), adminUserInfo.CurrentOrgId)
1639
+		prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1640
+		outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1641
+		timeArrs := strings.Split(timeStr, "-")
1642
+		totals, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1643
+
1644
+		totals = totals + 1
1645
+		warehousing_out_orders := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArrs[0] + timeArrs[1] + timeArrs[2] + "000"
1646
+		numbers, _ := strconv.ParseInt(warehousing_out_orders, 10, 64)
1647
+		number = numbers + totals
1648
+		warehousing_out_order = "YPCKD" + strconv.FormatInt(numbers, 10)
1649
+		info := models.XtDrugWarehouseOutInfo{
1650
+			WarehouseOutId:          orderOut.ID,
1651
+			DrugId:                  adviceName.DrugId,
1652
+			Count:                   outStoreNumber,
1653
+			Price:                   drug.RetailPrice,
1654
+			TotalPrice:              drug.RetailPrice,
1655
+			ProductDate:             theTime.Unix(),
1656
+			Ctime:                   time.Now().Unix(),
1657
+			Status:                  1,
1658
+			OrgId:                   adminUserInfo.CurrentOrgId,
1659
+			IsCancel:                2,
1660
+			WarehouseOutOrderNumber: warehousing_out_order,
1661
+			Type:                    1,
1662
+			Manufacturer:            orderOut.Manufacturer,
1663
+			IsSys:                   1,
1664
+			SysRecordTime:           theTime.Unix(),
1665
+		}
1666
+		service.CreateWareHouseOutInfo(&info)
1667
+
1668
+		timeArrss := strings.Split(timeStr, "-")
1669
+		totalss, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1670
+
1671
+		totalss = totalss + 1
1672
+		warehousing_out_orderss := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArrss[0] + timeArrss[1] + timeArrss[2] + "000"
1673
+		numberss, _ := strconv.ParseInt(warehousing_out_orderss, 10, 64)
1674
+		number = numberss + totalss
1675
+		warehousing_out_order = "YPCKD" + strconv.FormatInt(numberss, 10)
1676
+		detail := models.XtDrugAutomaticReduceDetail{
1677
+			WarehouseOutOrderNumber: warehousing_out_order,
1678
+			WarehouseOutId:          orderOut.ID,
1679
+			PatientId:               adviceName.PatientId,
1680
+			Ctime:                   time.Now().Unix(),
1681
+			RecordTime:              theTime.Unix(),
1682
+			OrgId:                   adminUserInfo.CurrentOrgId,
1683
+			GoodId:                  adviceName.DrugId,
1684
+			Count:                   outStoreNumber,
1685
+			Status:                  1,
1686
+		}
1687
+		service.CreateAotoMaticReduceDetail(&detail)
1688
+	}
1689
+
1690
+	if adviceName.ExecutionState == 1 && adviceName.Way == 2 {
1691
+
1569 1692
 		prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1570 1693
 		outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1571 1694
 

+ 40 - 9
controllers/self_drug_api_congtroller.go View File

@@ -629,6 +629,9 @@ func (this *SelfDrugApiController) GetSelfMedicalList() {
629 629
 	orgId := adminUserInfo.CurrentOrgId
630 630
 	//查询该机构是否开启自备药
631 631
 	medical, _ := service.GetSetSelfMedical(orgId)
632
+
633
+	//查询该机构下的药品库
634
+	drugName, _ := service.GetAllDrugName(orgId)
632 635
 	//开启
633 636
 	if medical.DrugStart == 1 {
634 637
 		list, err := service.GetSelfMedicalList(patient_id)
@@ -638,6 +641,11 @@ func (this *SelfDrugApiController) GetSelfMedicalList() {
638 641
 		}
639 642
 		this.ServeSuccessJSON(map[string]interface{}{
640 643
 			"medicalList": list,
644
+			"drugName":    drugName,
645
+		})
646
+	} else {
647
+		this.ServeSuccessJSON(map[string]interface{}{
648
+			"drugName": drugName,
641 649
 		})
642 650
 	}
643 651
 }
@@ -645,17 +653,40 @@ func (this *SelfDrugApiController) GetSelfMedicalList() {
645 653
 func (this *SelfDrugApiController) GetDrugDescByDrugName() {
646 654
 
647 655
 	drug_name := this.GetString("drug_name")
648
-
649 656
 	patient_id, _ := this.GetInt64("patient_id")
650
-	fmt.Println("patient_id", patient_id)
657
+	way, _ := this.GetInt64("way")
651 658
 	adminUserInfo := this.GetAdminUserInfo()
652 659
 	orgId := adminUserInfo.CurrentOrgId
653
-	drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
654
-	if err != nil {
655
-		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
656
-		return
660
+	drug_id, _ := this.GetInt64("id")
661
+	//从基础库查询
662
+	if way == 1 {
663
+		//查询基础库数据
664
+		medcal, err := service.GetBaseMedcal(drug_name, orgId)
665
+		//统计入库数量
666
+		countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
667
+
668
+		//统计出库数量
669
+		countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
670
+		if err != nil {
671
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
672
+			return
673
+		}
674
+		this.ServeSuccessJSON(map[string]interface{}{
675
+			"drugspec":  medcal,
676
+			"countInfo": countInfo,
677
+			"countout":  countout,
678
+		})
657 679
 	}
658
-	this.ServeSuccessJSON(map[string]interface{}{
659
-		"drugspec": drugspec,
660
-	})
680
+	//从自备药库查询
681
+	if way == 2 {
682
+		drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
683
+		if err != nil {
684
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
685
+			return
686
+		}
687
+		this.ServeSuccessJSON(map[string]interface{}{
688
+			"drugspec": drugspec,
689
+		})
690
+	}
691
+
661 692
 }

+ 2 - 0
models/dialysis.go View File

@@ -393,6 +393,8 @@ type DoctorAdvice struct {
393 393
 	TemplateId            string          `gorm:"column:template_id" json:"template_id"`
394 394
 	Modifier              int64           `gorm:"column:modifier" json:"modifier" form:"modifier"`
395 395
 	IsCheck               int64           `gorm:"-" json:"is_check" form:"is_check"`
396
+	Way                   int64           `gorm:"column:way" json:"way" form:"way"`
397
+	DrugId                int64           `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
396 398
 }
397 399
 
398 400
 func (DoctorAdvice) TableName() string {

+ 138 - 10
models/self_drug_models.go View File

@@ -102,16 +102,20 @@ func (XtStandName) TableName() string {
102 102
 }
103 103
 
104 104
 type XtSelfMedical struct {
105
-	DrugName    string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
106
-	ID          int64  `gorm:"column:id" json:"id" form:"id"`
107
-	DrugSpec    string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
108
-	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
109
-	DrugNameId  int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
110
-	Status      int64  `gorm:"column:status" json:"status" form:"status"`
111
-	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
112
-	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
113
-	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
114
-	MinUnit     string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
105
+	DrugName           string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
106
+	ID                 int64   `gorm:"column:id" json:"id" form:"id"`
107
+	DrugSpec           string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
108
+	PatientId          int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
109
+	DrugNameId         int64   `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
110
+	Status             int64   `gorm:"column:status" json:"status" form:"status"`
111
+	UserOrgId          int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
112
+	CreatedTime        int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
113
+	UpdatedTime        int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
114
+	MinUnit            string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
115
+	ExecutionFrequency string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
116
+	PrescribingNumber  float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
117
+	DeliveryWay        string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
118
+	SingleDose         float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
115 119
 }
116 120
 
117 121
 func (XtSelfMedical) TableName() string {
@@ -220,3 +224,127 @@ type XtSelfOutStocks struct {
220 224
 	DialysisNO     string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
221 225
 	Count          int64
222 226
 }
227
+
228
+type XtDrugWarehouse struct {
229
+	ID               int64  `gorm:"column:id" json:"id" form:"id"`
230
+	WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
231
+	OperationTime    int64  `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
232
+	OrgId            int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
233
+	Creater          int64  `gorm:"column:creater" json:"creater" form:"creater"`
234
+	Ctime            int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
235
+	Modifier         int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
236
+	Mtime            int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
237
+	Status           int64  `gorm:"column:status" json:"status" form:"status"`
238
+	WarehousingTime  int64  `gorm:"column:warehousing_time" json:"warehousing_time" form:"warehousing_time"`
239
+	Dealer           int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
240
+	Manufacturer     int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
241
+	Type             int64  `gorm:"column:type" json:"type" form:"type"`
242
+}
243
+
244
+func (XtDrugWarehouse) TableName() string {
245
+	return "xt_drug_warehouse"
246
+}
247
+
248
+type XtDrugWarehouseOut struct {
249
+	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
250
+	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
251
+	OperationTime           int64  `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
252
+	Creater                 int64  `gorm:"column:creater" json:"creater" form:"creater"`
253
+	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
254
+	Modifier                int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
255
+	Remark                  string `gorm:"column:remark" json:"remark" form:"remark"`
256
+	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
257
+	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
258
+	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
259
+	WarehouseOutTime        int64  `gorm:"column:warehouse_out_time" json:"warehouse_out_time" form:"warehouse_out_time"`
260
+	Dealer                  int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
261
+	Manufacturer            int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
262
+	Type                    int64  `gorm:"column:type" json:"type" form:"type"`
263
+	IsSys                   int64  `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
264
+}
265
+
266
+func (XtDrugWarehouseOut) TableName() string {
267
+	return "xt_drug_warehouse_out"
268
+}
269
+
270
+type XtDrugWarehouseOutInfo struct {
271
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
272
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
273
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
274
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
275
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
276
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
277
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
278
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
279
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
280
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
281
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
282
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
283
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
284
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
285
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
286
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
287
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
288
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
289
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
290
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
291
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
292
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
293
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
294
+}
295
+
296
+func (XtDrugWarehouseOutInfo) TableName() string {
297
+	return "xt_drug_warehouse_out_info"
298
+}
299
+
300
+type XtDrugAutomaticReduceDetail struct {
301
+	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
302
+	WarehouseOutId          int64  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
303
+	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
304
+	PatientId               int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
305
+	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
306
+	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
307
+	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
308
+	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
309
+	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
310
+	GoodId                  int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
311
+	GoodTypeId              int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
312
+	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
313
+}
314
+
315
+func (XtDrugAutomaticReduceDetail) TableName() string {
316
+	return "xt_drug_automatic_reduce_detail"
317
+}
318
+
319
+type XtDrugWarehouseInfo struct {
320
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
321
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
322
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
323
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
324
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
325
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
326
+	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
327
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
328
+	TotalPrice       float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
329
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
330
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
331
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
332
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
333
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
334
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
335
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
336
+	IsReturn         int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
337
+	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
338
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
339
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
340
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
341
+}
342
+
343
+func (XtDrugWarehouseInfo) TableName() string {
344
+	return "xt_drug_warehouse_info"
345
+}
346
+
347
+type DrugWarehousingInfo struct {
348
+	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
349
+	Count  int64
350
+}

+ 1 - 1
service/mobile_dialysis_service.go View File

@@ -491,7 +491,7 @@ func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*
491 491
 	err := readDb.
492 492
 		Model(&models.DoctorAdvice{}).
493 493
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
494
-		Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,IF(parent_id>0, parent_id, id) as advice_order,groupno").
494
+		Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
495 495
 		Order("start_time asc, groupno desc, advice_order desc, id").
496 496
 		Scan(&records).Error
497 497
 

+ 68 - 0
service/self_drug_service.go View File

@@ -307,3 +307,71 @@ func GetDrugDescByDrugName(drugname string, patient_id int64, orgid int64) (self
307 307
 	err = XTReadDB().Model(&selfMedical).Where("drug_name = ? and patient_id = ? and user_org_id = ? and status = 1", drugname, patient_id, orgid).Find(&selfMedical).Error
308 308
 	return selfMedical, err
309 309
 }
310
+
311
+func GetBaseMedcal(drugname string, orgid int64) (baseDrug []*models.XtBaseDrug, err error) {
312
+
313
+	err = XTReadDB().Model(&baseDrug).Where("drug_name = ? and org_id = ? and status = 1", drugname, orgid).Find(&baseDrug).Error
314
+	return baseDrug, err
315
+}
316
+
317
+func GetTotalBaseMedicalCount(drug_id int64, orgid int64) (drugInfo []*models.DrugWarehousingInfo, err error) {
318
+
319
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
320
+	err = db.Select("x.drug_id,sum(x.warehousing_count) as count").Where("drug_id = ? and org_id = ?", drug_id, orgid).Scan(&drugInfo).Error
321
+	return drugInfo, err
322
+}
323
+
324
+func GetTotalBaseMedicalCountOut(drug_id int64, orgid int64) (drugOut []*models.DrugWarehousingInfo, err error) {
325
+
326
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
327
+	err = db.Select("x.drug_id,sum(x.count) as count").Where("drug_id = ? and org_id = ?", drug_id, orgid).Scan(&drugOut).Error
328
+	return drugOut, err
329
+}
330
+
331
+func GetDrugWareseOut(startime int64, orgid int64) (*models.XtDrugWarehouse, error) {
332
+	warehouse := models.XtDrugWarehouse{}
333
+	err := XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", startime, orgid).Find(&warehouse).Error
334
+	if err == gorm.ErrRecordNotFound {
335
+		return nil, err
336
+	}
337
+	if err != nil {
338
+		return nil, err
339
+	}
340
+	return &warehouse, nil
341
+}
342
+
343
+func GetManufacturer(id int64) (models.XtBaseDrug, error) {
344
+	drug := models.XtBaseDrug{}
345
+	err := XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
346
+	return drug, err
347
+}
348
+
349
+func CreateDrugWarehoue(warehouse *models.XtDrugWarehouse) error {
350
+
351
+	err := XTWriteDB().Model(&warehouse).Create(&warehouse).Error
352
+	return err
353
+}
354
+
355
+func GetTodayWareHousringOrder(startime int64, orgid int64) (models.XtDrugWarehouseOut, error) {
356
+	warehouse := models.XtDrugWarehouseOut{}
357
+	err := XTReadDB().Model(&warehouse).Where("warehouse_out_time = ? and org_id = ? and status = 1", startime, orgid).Find(&warehouse).Error
358
+	return warehouse, err
359
+}
360
+
361
+func CreateDrugWareHouseOut(out *models.XtDrugWarehouseOut) error {
362
+
363
+	err := XTWriteDB().Model(&out).Create(&out).Error
364
+	return err
365
+}
366
+
367
+func CreateWareHouseOutInfo(info *models.XtDrugWarehouseOutInfo) error {
368
+
369
+	err := XTWriteDB().Model(&info).Create(&info).Error
370
+	return err
371
+}
372
+
373
+func CreateAotoMaticReduceDetail(detail *models.XtDrugAutomaticReduceDetail) error {
374
+
375
+	err := XTWriteDB().Model(&detail).Create(&detail).Error
376
+	return err
377
+}