Browse Source

修改redis清除数据时间

csx 4 years ago
parent
commit
ba5c13ab47

+ 229 - 216
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)
@@ -1577,16 +1577,46 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1577 1577
 	fmt.Println("adviceName", adviceName.Way)
1578 1578
 	timeStr := time.Now().Format("2006-01-02")
1579 1579
 	fmt.Println("timestr", timeStr)
1580
+
1580 1581
 	//如果医嘱已执行,生成自备药出库单
1581 1582
 	//来自药品库
1582 1583
 	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 {
1584
+
1585
+		//查询是否开启药品库
1586
+		stockConfig, _ := service.GetDrugStockConfig(adminUserInfo.CurrentOrgId)
1587
+		//开启药品库
1588
+		if stockConfig.IsOpen == 1 {
1589
+			timeLayout := "2006-01-02"
1590
+			loc, _ := time.LoadLocation("Local")
1591
+			//产询今日是否存在出库单
1592
+			timeStr := time.Now().Format("2006-01-02")
1593
+			theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", timeStr+" 00:00:00", loc)
1594
+			_, errcode := service.GetDrugWareseOut(theTime.Unix(), adminUserInfo.CurrentOrgId)
1595
+			if errcode == gorm.ErrRecordNotFound {
1596
+				timeArr := strings.Split(timeStr, "-")
1597
+				total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1598
+
1599
+				total = total + 1
1600
+				warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1601
+				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1602
+				number = number + total
1603
+				warehousing_out_order = "YPRKD" + strconv.FormatInt(number, 10)
1604
+				//查询厂家
1605
+				drug, _ := service.GetManufacturer(adviceName.DrugId)
1606
+				//创建
1607
+				warehouse := models.XtDrugWarehouse{
1608
+					WarehousingOrder: warehousing_out_order,
1609
+					OperationTime:    theTime.Unix(),
1610
+					Creater:          adminUserInfo.AdminUser.Id,
1611
+					OrgId:            adminUserInfo.CurrentOrgId,
1612
+					Status:           1,
1613
+					WarehousingTime:  theTime.Unix(),
1614
+					Manufacturer:     drug.Manufacturer,
1615
+					Type:             1,
1616
+				}
1617
+				service.CreateDrugWarehoue(&warehouse)
1618
+			}
1619
+
1590 1620
 			timeArr := strings.Split(timeStr, "-")
1591 1621
 			total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1592 1622
 
@@ -1595,144 +1625,127 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1595 1625
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1596 1626
 			number = number + total
1597 1627
 			warehousing_out_order = "YPRKD" + strconv.FormatInt(number, 10)
1598
-			//查询厂家
1599 1628
 			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,
1629
+			out := models.XtDrugWarehouseOut{
1630
+				WarehouseOutOrderNumber: warehousing_out_order,
1631
+				OperationTime:           theTime.Unix(),
1632
+				Creater:                 adminUserInfo.AdminUser.Id,
1633
+				OrgId:                   adminUserInfo.CurrentOrgId,
1634
+				Ctime:                   time.Now().Unix(),
1635
+				Status:                  1,
1636
+				WarehouseOutTime:        theTime.Unix(),
1637
+				Manufacturer:            drug.Manufacturer,
1638
+				Type:                    1,
1639
+				IsSys:                   1,
1610 1640
 			}
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,
1641
+			service.CreateDrugWareHouseOut(&out)
1642
+
1643
+			//查询今日的出库单号
1644
+			orderOut, _ := service.GetTodayWareHousringOrder(theTime.Unix(), adminUserInfo.CurrentOrgId)
1645
+			prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1646
+			outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1647
+			timeArrs := strings.Split(timeStr, "-")
1648
+			totals, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1649
+
1650
+			totals = totals + 1
1651
+			warehousing_out_orders := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArrs[0] + timeArrs[1] + timeArrs[2] + "000"
1652
+			numbers, _ := strconv.ParseInt(warehousing_out_orders, 10, 64)
1653
+			number = numbers + totals
1654
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(numbers, 10)
1655
+			info := models.XtDrugWarehouseOutInfo{
1656
+				WarehouseOutId:          orderOut.ID,
1657
+				DrugId:                  adviceName.DrugId,
1658
+				Count:                   outStoreNumber,
1659
+				Price:                   drug.RetailPrice,
1660
+				TotalPrice:              drug.RetailPrice,
1661
+				ProductDate:             theTime.Unix(),
1662
+				Ctime:                   time.Now().Unix(),
1663
+				Status:                  1,
1664
+				OrgId:                   adminUserInfo.CurrentOrgId,
1665
+				IsCancel:                2,
1666
+				WarehouseOutOrderNumber: warehousing_out_order,
1667
+				Type:          1,
1668
+				Manufacturer:  orderOut.Manufacturer,
1669
+				IsSys:         1,
1670
+				SysRecordTime: theTime.Unix(),
1671
+			}
1672
+			service.CreateWareHouseOutInfo(&info)
1673
+
1674
+			timeArrss := strings.Split(timeStr, "-")
1675
+			totalss, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1676
+
1677
+			totalss = totalss + 1
1678
+			warehousing_out_orderss := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArrss[0] + timeArrss[1] + timeArrss[2] + "000"
1679
+			numberss, _ := strconv.ParseInt(warehousing_out_orderss, 10, 64)
1680
+			number = numberss + totalss
1681
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(numberss, 10)
1682
+			detail := models.XtDrugAutomaticReduceDetail{
1683
+				WarehouseOutOrderNumber: warehousing_out_order,
1684
+				WarehouseOutId:          orderOut.ID,
1685
+				PatientId:               adviceName.PatientId,
1686
+				Ctime:                   time.Now().Unix(),
1687
+				RecordTime:              theTime.Unix(),
1688
+				OrgId:                   adminUserInfo.CurrentOrgId,
1689
+				GoodId:                  adviceName.DrugId,
1690
+				Count:                   outStoreNumber,
1691
+				Status:                  1,
1692
+			}
1693
+			service.CreateAotoMaticReduceDetail(&detail)
1686 1694
 		}
1687
-		service.CreateAotoMaticReduceDetail(&detail)
1688 1695
 	}
1689 1696
 
1690 1697
 	if adviceName.ExecutionState == 1 && adviceName.Way == 2 {
1691 1698
 
1692
-		prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1693
-		outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1694
-
1695
-		timeStr := time.Now().Format("2006-01-02")
1696
-		timeArr := strings.Split(timeStr, "-")
1697
-		total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1698
-
1699
-		total = total + 1
1700
-		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1701
-		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1702
-		number = number + total
1703
-		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1704
-
1705
-		medicalName, errcode := service.GetSelfMedicalByDrugName(adviceName.AdviceName, adviceName.AdviceDesc, adviceName.PatientId)
1706
-		if errcode == gorm.ErrRecordNotFound {
1707
-			c.ServeSuccessJSON(map[string]interface{}{
1708
-				"msg":    "ok",
1709
-				"advice": advice,
1710
-			})
1711
-			return
1712
-		} else if errcode == nil {
1713
-			outStock := models.XtSelfOutStock{
1714
-				DrugName:       adviceName.AdviceName,
1715
-				DrugSpec:       adviceName.AdviceDesc,
1716
-				OutstoreNumber: outStoreNumber,
1717
-				AdminUserId:    adminUserInfo.AdminUser.Id,
1718
-				CreatedTime:    time.Now().Unix(),
1719
-				Status:         1,
1720
-				PatientId:      adviceName.PatientId,
1721
-				StockOutNumber: warehousing_out_order,
1722
-				ExitMode:       2,
1723
-				StorckTime:     adviceName.AdviceDate,
1724
-				MedicId:        medicalName.ID,
1725
-				DrugNameId:     medicalName.DrugNameId,
1726
-				UserOrgId:      adminUserInfo.CurrentOrgId,
1699
+		//是否开启自备药
1700
+		medicalSet, _ := service.GetSetSelfMedical(adminUserInfo.CurrentOrgId)
1701
+		//开启自备药,生成出库单
1702
+		if medicalSet.DrugStart == 1 {
1703
+			prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1704
+			outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1705
+
1706
+			timeStr := time.Now().Format("2006-01-02")
1707
+			timeArr := strings.Split(timeStr, "-")
1708
+			total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1709
+
1710
+			total = total + 1
1711
+			warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1712
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1713
+			number = number + total
1714
+			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1715
+
1716
+			medicalName, errcode := service.GetSelfMedicalByDrugName(adviceName.AdviceName, adviceName.AdviceDesc, adviceName.PatientId)
1717
+			if errcode == gorm.ErrRecordNotFound {
1718
+				c.ServeSuccessJSON(map[string]interface{}{
1719
+					"msg":    "ok",
1720
+					"advice": advice,
1721
+				})
1722
+				return
1723
+			} else if errcode == nil {
1724
+				outStock := models.XtSelfOutStock{
1725
+					DrugName:       adviceName.AdviceName,
1726
+					DrugSpec:       adviceName.AdviceDesc,
1727
+					OutstoreNumber: outStoreNumber,
1728
+					AdminUserId:    adminUserInfo.AdminUser.Id,
1729
+					CreatedTime:    time.Now().Unix(),
1730
+					Status:         1,
1731
+					PatientId:      adviceName.PatientId,
1732
+					StockOutNumber: warehousing_out_order,
1733
+					ExitMode:       2,
1734
+					StorckTime:     adviceName.AdviceDate,
1735
+					MedicId:        medicalName.ID,
1736
+					DrugNameId:     medicalName.DrugNameId,
1737
+					UserOrgId:      adminUserInfo.CurrentOrgId,
1738
+				}
1739
+				//创建出库单,自动出库
1740
+				service.CreateOutStock(&outStock)
1741
+				c.ServeSuccessJSON(map[string]interface{}{
1742
+					"msg":    "ok",
1743
+					"advice": advice,
1744
+				})
1745
+				return
1727 1746
 			}
1728
-			//创建出库单,自动出库
1729
-			service.CreateOutStock(&outStock)
1730
-			c.ServeSuccessJSON(map[string]interface{}{
1731
-				"msg":    "ok",
1732
-				"advice": advice,
1733
-			})
1734
-			return
1735 1747
 		}
1748
+
1736 1749
 	}
1737 1750
 
1738 1751
 }

+ 32 - 4
controllers/self_drug_api_congtroller.go View File

@@ -44,6 +44,7 @@ func SelfDrugRouters() {
44 44
 	beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
45 45
 	beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
46 46
 	beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
47
+	beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
47 48
 }
48 49
 
49 50
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -64,14 +65,22 @@ func (this *SelfDrugApiController) GetAllDrugName() {
64 65
 
65 66
 	adminUserInfo := this.GetAdminUserInfo()
66 67
 	orgId := adminUserInfo.CurrentOrgId
68
+
69
+	//查询药品库是否开启
70
+	//configStock, _ := service.GetDrugStockConfig(orgId)
71
+	//if configStock.IsOpen == 1 {
72
+	//
73
+	//}
74
+
67 75
 	drugName, err := service.GetAllDrugName(orgId)
68 76
 	if err != nil {
69
-		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
77
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
70 78
 		return
71 79
 	}
72 80
 	this.ServeSuccessJSON(map[string]interface{}{
73 81
 		"drugName": drugName,
74 82
 	})
83
+
75 84
 }
76 85
 
77 86
 func (this *SelfDrugApiController) SaveDrugName() {
@@ -515,16 +524,20 @@ func (this *SelfDrugApiController) GetStockList() {
515 524
 	startimeUnix := theTime.Unix()
516 525
 	keyword := this.GetString("keyword")
517 526
 	fmt.Println("keyword", keyword)
527
+	adminUserInfo := this.GetAdminUserInfo()
528
+	orgId := adminUserInfo.CurrentOrgId
529
+	//获取
530
+	medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
518 531
 	//统计总数量
519
-	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword)
520
-
532
+	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
521 533
 	//统计出库数量
522
-	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword)
534
+	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
523 535
 	if err != nil {
524 536
 		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
525 537
 		return
526 538
 	}
527 539
 	this.ServeSuccessJSON(map[string]interface{}{
540
+		"medicalList":  medicalList,
528 541
 		"stocklist":    stocklist,
529 542
 		"outStocklist": outStocklist,
530 543
 	})
@@ -690,3 +703,18 @@ func (this *SelfDrugApiController) GetDrugDescByDrugName() {
690 703
 	}
691 704
 
692 705
 }
706
+
707
+func (this *SelfDrugApiController) GetDrugSet() {
708
+
709
+	adminUserInfo := this.GetAdminUserInfo()
710
+	orgId := adminUserInfo.CurrentOrgId
711
+	drugSet, err := service.GetDrugSet(orgId)
712
+	if err != nil {
713
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
714
+		return
715
+	}
716
+	this.ServeSuccessJSON(map[string]interface{}{
717
+		"drugSet": drugSet,
718
+	})
719
+
720
+}

+ 45 - 0
models/self_drug_models.go View File

@@ -101,6 +101,23 @@ func (XtStandName) TableName() string {
101 101
 	return "xt_stand_name"
102 102
 }
103 103
 
104
+type XtSelfMedicals 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
+	MinUnit     string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
112
+	StoreNumber int64  `gorm:"column:store_number" json:"store_number" form:"store_number"`
113
+	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
114
+	StorckTime  int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
115
+	MedicId     int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
116
+	Remarks     string `gorm:"column:remarks" json:"remarks" form:"remarks"`
117
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
118
+	Total       int64
119
+}
120
+
104 121
 type XtSelfMedical struct {
105 122
 	DrugName           string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
106 123
 	ID                 int64   `gorm:"column:id" json:"id" form:"id"`
@@ -146,6 +163,21 @@ func (XtSelfStock) TableName() string {
146 163
 	return "xt_self_stock"
147 164
 }
148 165
 
166
+type SelfOutStock struct {
167
+	DrugName       string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
168
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
169
+	DrugSpec       string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
170
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
171
+	DrugNameId     int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
172
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
173
+	Remarks        string `gorm:"column:remarks" json:"remarks" form:"remarks"`
174
+	OutstoreNumber int64  `gorm:"column:outstore_number" json:"outstore_number" form:"outstore_number"`
175
+	AdminUserId    int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
176
+	StorckTime     int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
177
+	MedicId        int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
178
+	Count          int64
179
+}
180
+
149 181
 type XtSelfOutStock struct {
150 182
 	ID             int64  `gorm:"column:id" json:"id" form:"id"`
151 183
 	DrugName       string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
@@ -348,3 +380,16 @@ type DrugWarehousingInfo struct {
348 380
 	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
349 381
 	Count  int64
350 382
 }
383
+
384
+type XtDrugStockConfig struct {
385
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
386
+	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
387
+	IsOpen     int64 `gorm:"column:is_open" json:"is_open" form:"is_open"`
388
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
389
+	CreateTime int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
390
+	UpdateTime int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
391
+}
392
+
393
+func (XtDrugStockConfig) TableName() string {
394
+	return "xt_drug_stock_config"
395
+}

+ 76 - 23
service/self_drug_service.go View File

@@ -14,7 +14,7 @@ func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error)
14 14
 
15 15
 func GetAllDrugName(orgid int64) (baseDrug []*models.XtBaseDrug, err error) {
16 16
 
17
-	err = XTReadDB().Group("drug_name").Where("org_id = ? and status = 1", orgid).Find(&baseDrug).Error
17
+	err = XTReadDB().Group("drug_name").Where("org_id = ? and status = 1 and find_in_set('停用',drug_status) = 0", orgid).Find(&baseDrug).Error
18 18
 	return baseDrug, err
19 19
 
20 20
 }
@@ -177,36 +177,77 @@ func DeleteDrugStand(id int64) error {
177 177
 	return err
178 178
 }
179 179
 
180
-func GetStockList(patientid int64, startime int64, keyword string) (stock []*models.SelfStocks, err error) {
181
-	db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
180
+//func GetStockList(patientid int64, startime int64, keyword string) (stock []*models.SelfStocks, err error) {
181
+//	db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
182
+//	likeKey := "%" + keyword + "%"
183
+//	table := XTReadDB().Table("xt_patients as s")
184
+//	fmt.Println(table)
185
+//	if patientid > 0 {
186
+//		db = db.Where("x.patient_id = ?", patientid)
187
+//	}
188
+//	if startime > 0 {
189
+//		db = db.Where("x.storck_time <= ?", startime)
190
+//	}
191
+//	err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.store_number,x.admin_user_id,x.storck_time,x.user_org_id,x.stock_in_number,x.patient_id,x.min_unit,sum(x.store_number) as total").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
192
+//	return stock, err
193
+//}
194
+
195
+func GetStockList(patientid int64, startime int64, keyword string, orgid int64) (stock []*models.XtSelfMedicals, err error) {
182 196
 	likeKey := "%" + keyword + "%"
183
-	table := XTReadDB().Table("xt_patients as s")
184
-	fmt.Println(table)
197
+	db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
185 198
 	if patientid > 0 {
186 199
 		db = db.Where("x.patient_id = ?", patientid)
187 200
 	}
188
-	//if startime >0 {
189
-	//  db = db.Where("x.storck_time = ?", startime)
190
-	//}
191
-	err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.store_number,x.admin_user_id,x.storck_time,x.user_org_id,x.stock_in_number,x.patient_id,x.min_unit,sum(x.store_number) as total").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
201
+	if orgid > 0 {
202
+		db = db.Where("x.user_org_id = ?", orgid)
203
+	}
204
+	err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.min_unit,sum(t.store_number) as total,t.remarks,x.patient_id,t.stock_in_number,t.storck_time,t.admin_user_id,t.medic_id").Joins("left join xt_self_stock as t on t.medic_id = x.id").Where("t.storck_time<=?", startime).Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
192 205
 	return stock, err
193 206
 }
194 207
 
195
-func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
196
-	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
208
+func GetOutStockList(patientid int64, startime int64, keyword string, orgid int64) (outStock []*models.SelfOutStock, err error) {
209
+
197 210
 	likeKey := "%" + keyword + "%"
198
-	table := XTReadDB().Table("xt_patients as s")
199
-	fmt.Println(table)
211
+	db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
200 212
 	if patientid > 0 {
201 213
 		db = db.Where("x.patient_id = ?", patientid)
202 214
 	}
203
-	//if startime > 0 {
204
-	//  db = db.Where("x.storck_time = ?", startime)
205
-	//}
206
-	err = db.Group("x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
215
+	if orgid > 0 {
216
+		db = db.Where("x.user_org_id = ?", orgid)
217
+	}
218
+	err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.min_unit,sum(t.outstore_number) as count,t.remarks,x.patient_id,t.stock_out_number,t.storck_time,t.admin_user_id,t.medic_id").Joins("left join xt_self_out_stock as t on t.medic_id = x.id").Where("t.storck_time<=?", startime).Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
207 219
 	return outStock, err
208 220
 }
209 221
 
222
+//func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
223
+//	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
224
+//	likeKey := "%" + keyword + "%"
225
+//	table := XTReadDB().Table("xt_patients as s")
226
+//	fmt.Println(table)
227
+//	if patientid > 0 {
228
+//		db = db.Where("x.patient_id = ?", patientid)
229
+//	}
230
+//	if startime > 0 {
231
+//		db = db.Where("x.storck_time <= ?", startime)
232
+//	}
233
+//	err = db.Group("x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
234
+//	return outStock, err
235
+//}
236
+
237
+func GetMedicalList(patientid int64, orgid int64, keyword string) (medical []*models.XtSelfMedicals, err error) {
238
+	likeKey := "%" + keyword + "%"
239
+	db := XTReadDB().Table("xt_self_medical as x").Where("x.status = 1")
240
+	if patientid > 0 {
241
+		db = db.Where("x.patient_id = ?", patientid)
242
+	}
243
+	if orgid > 0 {
244
+		db = db.Where("x.user_org_id = ?", orgid)
245
+	}
246
+	err = db.Select("x.drug_name,x.id,x.drug_spec,x.patient_id,x.min_unit").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Group("x.drug_name,x.drug_spec").Scan(&medical).Error
247
+	//err = XTReadDB().Model(&medical).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Group("drug_name,drug_spec").Find(&medical).Error
248
+	return medical, err
249
+}
250
+
210 251
 func GetStockOutDetail(durgname string, patientid int64) (stock []*models.XtSelfOutStock, err error) {
211 252
 
212 253
 	err = XTReadDB().Model(&stock).Where("drug_name = ? and patient_id = ? and status = 1", durgname, patientid).Find(&stock).Error
@@ -220,16 +261,14 @@ func DeleteDrugStockNumber(drugname string, patientid int64) (models.XtSelfStock
220 261
 }
221 262
 
222 263
 func GetStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (stock []*models.XtSelfStock, err error) {
223
-	fmt.Println("startime", startime)
224
-	fmt.Println("endtime", endtime)
225
-	err = XTReadDB().Model(&stock).Where("drug_name = ? and drug_spec = ? and patient_id =? and user_org_id = ? and status = 1", drugname, drugspec, patientid, orgid).Find(&stock).Error
264
+
265
+	err = XTReadDB().Model(&stock).Where("drug_name = ? and drug_spec = ? and patient_id =? and user_org_id = ? and status = 1 and storck_time>=? and storck_time<=?", drugname, drugspec, patientid, orgid, startime, endtime).Order("storck_time asc").Find(&stock).Error
226 266
 	return stock, err
227 267
 }
228 268
 
229 269
 func GetOutStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (outStock []*models.XtSelfOutStock, err error) {
230
-	fmt.Println(startime)
231
-	fmt.Println(endtime)
232
-	err = XTReadDB().Model(&outStock).Where("drug_name = ? and drug_spec=? and patient_id = ? and user_org_id = ? and status = 1", drugname, drugspec, patientid, orgid).Find(&outStock).Error
270
+
271
+	err = XTReadDB().Model(&outStock).Where("drug_name = ? and drug_spec=? and patient_id = ? and user_org_id = ? and status = 1 and storck_time>=? and storck_time<=?", drugname, drugspec, patientid, orgid, startime, endtime).Order("storck_time asc").Find(&outStock).Error
233 272
 	return outStock, err
234 273
 }
235 274
 
@@ -376,6 +415,20 @@ func CreateAotoMaticReduceDetail(detail *models.XtDrugAutomaticReduceDetail) err
376 415
 	return err
377 416
 }
378 417
 
418
+func GetDrugStockConfig(orgid int64) (models.XtDrugStockConfig, error) {
419
+
420
+	config := models.XtDrugStockConfig{}
421
+	err := XTReadDB().Model(&config).Where("org_id =? and status = 1", orgid).Find(&orgid).Error
422
+	return config, err
423
+}
424
+
425
+func GetDrugSet(orgid int64) (models.XtDrugSet, error) {
426
+
427
+	drugSet := models.XtDrugSet{}
428
+	err := XTReadDB().Model(&drugSet).Where("user_org_id =? and status = 1", orgid).Find(&drugSet).Error
429
+	return drugSet, err
430
+}
431
+
379 432
 type Drugs struct {
380 433
 	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
381 434
 	DrugName           string   `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`