mainqaq 2 years ago
parent
commit
742436d34d
4 changed files with 241 additions and 9 deletions
  1. 1 1
      conf/app.conf
  2. 84 8
      controllers/pharmacy_controller.go
  3. 3 0
      models/pharmacy_models.go
  4. 153 0
      service/pharmacy_service.go

+ 1 - 1
conf/app.conf View File

1
 appname = 血透
1
 appname = 血透
2
 httpport = 9531
2
 httpport = 9531
3
-runmode =prod
3
+runmode =dev
4
 #dev/prod
4
 #dev/prod
5
 
5
 
6
 #
6
 #

+ 84 - 8
controllers/pharmacy_controller.go View File

118
 	keyword := this.GetString("keyword", "")
118
 	keyword := this.GetString("keyword", "")
119
 	times := this.GetString("time", "")
119
 	times := this.GetString("time", "")
120
 	orgid := this.GetAdminUserInfo().CurrentOrgId
120
 	orgid := this.GetAdminUserInfo().CurrentOrgId
121
+	shift, err := this.GetInt64("shift", 0) //班次
122
+	if err != nil {
123
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
124
+		return
125
+	}
126
+	partition, err := this.GetInt64("partition", 0) //分区
127
+	if err != nil {
128
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
129
+		return
130
+	}
121
 	timeLayout := "2006-01-02"
131
 	timeLayout := "2006-01-02"
122
 	loc, _ := time.LoadLocation("Local")
132
 	loc, _ := time.LoadLocation("Local")
123
 	var stime, etime int64
133
 	var stime, etime int64
136
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
146
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
137
 		return
147
 		return
138
 	}
148
 	}
149
+	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
150
+	if err != nil {
151
+		utils.ErrorLog(err.Error())
152
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
153
+		return
154
+	}
139
 	this.ServeSuccessJSON(map[string]interface{}{
155
 	this.ServeSuccessJSON(map[string]interface{}{
140
-		"list": flist,
156
+		"list": listt,
141
 	})
157
 	})
142
 	return
158
 	return
143
 }
159
 }
153
 	}()
169
 	}()
154
 	keyword := this.GetString("keyword", "")
170
 	keyword := this.GetString("keyword", "")
155
 	times := this.GetString("time", "")
171
 	times := this.GetString("time", "")
172
+	shift, err := this.GetInt64("shift", 0) //班次
173
+	if err != nil {
174
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
175
+		return
176
+	}
177
+	partition, err := this.GetInt64("partition", 0) //分区
178
+	if err != nil {
179
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
180
+		return
181
+	}
156
 	orgid := this.GetAdminUserInfo().CurrentOrgId
182
 	orgid := this.GetAdminUserInfo().CurrentOrgId
157
 	timeLayout := "2006-01-02"
183
 	timeLayout := "2006-01-02"
158
 	loc, _ := time.LoadLocation("Local")
184
 	loc, _ := time.LoadLocation("Local")
172
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
198
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
173
 		return
199
 		return
174
 	}
200
 	}
201
+	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
202
+	if err != nil {
203
+		utils.ErrorLog(err.Error())
204
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
205
+		return
206
+	}
175
 	this.ServeSuccessJSON(map[string]interface{}{
207
 	this.ServeSuccessJSON(map[string]interface{}{
176
-		"list": flist,
208
+		"list": listt,
177
 	})
209
 	})
178
 	return
210
 	return
179
 }
211
 }
392
 	orgid := this.GetAdminUserInfo().CurrentOrgId
424
 	orgid := this.GetAdminUserInfo().CurrentOrgId
393
 	timeLayout := "2006-01-02"
425
 	timeLayout := "2006-01-02"
394
 	loc, _ := time.LoadLocation("Local")
426
 	loc, _ := time.LoadLocation("Local")
427
+	deliveryway := this.GetString("deliveryway", "")
395
 	var stime, etime int64
428
 	var stime, etime int64
396
 	if times == "" {
429
 	if times == "" {
397
 		stime, etime = service.GetNowTime()
430
 		stime, etime = service.GetNowTime()
408
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
441
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
409
 		return
442
 		return
410
 	}
443
 	}
444
+	llist, err := service.Administration(deliveryway, orgid, flist)
445
+	if err != nil {
446
+		utils.ErrorLog(err.Error())
447
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
448
+		return
449
+	}
411
 	this.ServeSuccessJSON(map[string]interface{}{
450
 	this.ServeSuccessJSON(map[string]interface{}{
412
-		"list": flist,
451
+		"list": llist,
413
 	})
452
 	})
414
 	return
453
 	return
415
 }
454
 }
430
 	orgid := this.GetAdminUserInfo().CurrentOrgId
469
 	orgid := this.GetAdminUserInfo().CurrentOrgId
431
 	timeLayout := "2006-01-02"
470
 	timeLayout := "2006-01-02"
432
 	loc, _ := time.LoadLocation("Local")
471
 	loc, _ := time.LoadLocation("Local")
472
+	deliveryway := this.GetString("deliveryway", "")
433
 	var stime, etime int64
473
 	var stime, etime int64
434
 	if times == "" {
474
 	if times == "" {
435
 		stime, etime = service.GetNowTime()
475
 		stime, etime = service.GetNowTime()
446
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
486
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
447
 		return
487
 		return
448
 	}
488
 	}
489
+	llist, err := service.Administration(deliveryway, orgid, flist)
490
+	if err != nil {
491
+		utils.ErrorLog(err.Error())
492
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
493
+		return
494
+	}
449
 	this.ServeSuccessJSON(map[string]interface{}{
495
 	this.ServeSuccessJSON(map[string]interface{}{
450
-		"list": flist,
496
+		"list": llist,
451
 	})
497
 	})
452
 	return
498
 	return
453
 }
499
 }
467
 	is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
513
 	is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
468
 	times := this.GetString("time", "")
514
 	times := this.GetString("time", "")
469
 	orgid := this.GetAdminUserInfo().CurrentOrgId
515
 	orgid := this.GetAdminUserInfo().CurrentOrgId
516
+	deliveryway := this.GetString("deliveryway", "")
517
+	if deliveryway == "" {
518
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
519
+		return
520
+	}
521
+	shift, err := this.GetInt64("shift", 0) //班次
522
+	if err != nil {
523
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
524
+		return
525
+	}
526
+	partition, err := this.GetInt64("partition", 0) //分区
527
+	if err != nil {
528
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
529
+		return
530
+	}
470
 	timeLayout := "2006-01-02"
531
 	timeLayout := "2006-01-02"
471
 	loc, _ := time.LoadLocation("Local")
532
 	loc, _ := time.LoadLocation("Local")
472
 	var stime, etime int64
533
 	var stime, etime int64
484
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
545
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
485
 		return
546
 		return
486
 	}
547
 	}
548
+	listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
549
+	if err != nil {
550
+		utils.ErrorLog(err.Error())
551
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
552
+		return
553
+	}
554
+	total, err := service.CalculateTheTotalAmount(listll, drug_id)
555
+	if err != nil {
556
+		utils.ErrorLog(err.Error())
557
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
558
+		return
559
+	}
487
 	this.ServeSuccessJSON(map[string]interface{}{
560
 	this.ServeSuccessJSON(map[string]interface{}{
488
-		"list": list,
561
+		"list":  listll,
562
+		"total": total,
489
 	})
563
 	})
490
 	return
564
 	return
491
 }
565
 }
530
 		}
604
 		}
531
 	}()
605
 	}()
532
 	orgid := this.GetAdminUserInfo().CurrentOrgId
606
 	orgid := this.GetAdminUserInfo().CurrentOrgId
533
-	list, err := service.GetAllValidDeviceZones(orgid)
607
+	tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
608
+	list, err := service.GetAllValidDeviceZones02(orgid)
534
 	if err != nil {
609
 	if err != nil {
535
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
610
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
536
 		return
611
 		return
537
 	}
612
 	}
538
 	this.ServeSuccessJSON(map[string]interface{}{
613
 	this.ServeSuccessJSON(map[string]interface{}{
539
-		"list": list,
614
+		"list": append(tmp, list...),
540
 	})
615
 	})
541
 	return
616
 	return
542
 }
617
 }
552
 		}
627
 		}
553
 	}()
628
 	}()
554
 	orgid := this.GetAdminUserInfo().CurrentOrgId
629
 	orgid := this.GetAdminUserInfo().CurrentOrgId
630
+	tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
555
 	list, _, err := service.GetDrugWayDics(orgid)
631
 	list, _, err := service.GetDrugWayDics(orgid)
556
 	if err != nil {
632
 	if err != nil {
557
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
633
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
558
 		return
634
 		return
559
 	}
635
 	}
560
 	this.ServeSuccessJSON(map[string]interface{}{
636
 	this.ServeSuccessJSON(map[string]interface{}{
561
-		"list": list,
637
+		"list": append(tmp, list...),
562
 	})
638
 	})
563
 	return
639
 	return
564
 }
640
 }

+ 3 - 0
models/pharmacy_models.go View File

118
 //病人信息
118
 //病人信息
119
 type PatientInformation struct {
119
 type PatientInformation struct {
120
 	Id           string `json:"id"`            //hid表示his_doctor_advice_info的id ,xid表示xt_doctor_advice的id
120
 	Id           string `json:"id"`            //hid表示his_doctor_advice_info的id ,xid表示xt_doctor_advice的id
121
+	PatientId    int64  `json:"patient_id"`    //患者id
121
 	Name         string `json:"name"`          //患者姓名
122
 	Name         string `json:"name"`          //患者姓名
122
 	SingleDosage string `json:"single_dosage"` //单次用量
123
 	SingleDosage string `json:"single_dosage"` //单次用量
123
 	Usage        string `json:"usage"`         //用法
124
 	Usage        string `json:"usage"`         //用法
126
 	Total        string `json:"total"`         //总量
127
 	Total        string `json:"total"`         //总量
127
 	DataSources  string `json:"data_sources"`  //数据来源
128
 	DataSources  string `json:"data_sources"`  //数据来源
128
 	People       string `json:"people"`        //领药人
129
 	People       string `json:"people"`        //领药人
130
+	Quantity     int64  `json:"quantity"`      //总量拆分——数据部分
131
+	Unit         string `json:"unit"`          //总量拆分——单位部分
129
 }
132
 }
130
 type HisDoctorAdviceInfoL struct {
133
 type HisDoctorAdviceInfoL struct {
131
 	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
134
 	ID                    int64   `gorm:"column:id" json:"id" form:"id"`

+ 153 - 0
service/pharmacy_service.go View File

529
 		pp = append(pp, &models.PatientInformation{
529
 		pp = append(pp, &models.PatientInformation{
530
 			Id:           "h" + config.ToString(v.ID),
530
 			Id:           "h" + config.ToString(v.ID),
531
 			Name:         FindUserName(v.PatientId),
531
 			Name:         FindUserName(v.PatientId),
532
+			PatientId:    v.PatientId,
532
 			SingleDosage: config.ToString(v.SingleDose) + v.SingleDoseUnit,
533
 			SingleDosage: config.ToString(v.SingleDose) + v.SingleDoseUnit,
533
 			Usage:        v.DeliveryWay,
534
 			Usage:        v.DeliveryWay,
534
 			Frequency:    v.ExecutionFrequency,
535
 			Frequency:    v.ExecutionFrequency,
536
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
537
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
537
 			DataSources:  "his处方",
538
 			DataSources:  "his处方",
538
 			People:       GetUserAdminName(v.People, orgid), //领药人!!!!!!!!!!!!!!!!!!!!!!
539
 			People:       GetUserAdminName(v.People, orgid), //领药人!!!!!!!!!!!!!!!!!!!!!!
540
+			Quantity:     int64(v.PrescribingNumber),
541
+			Unit:         v.PrescribingNumberUnit,
539
 		})
542
 		})
540
 	}
543
 	}
541
 
544
 
556
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
559
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
557
 			DataSources:  "临时医嘱",
560
 			DataSources:  "临时医嘱",
558
 			People:       GetUserAdminName(v.People, orgid), //领药人
561
 			People:       GetUserAdminName(v.People, orgid), //领药人
562
+			Quantity:     int64(v.PrescribingNumber),
563
+			Unit:         v.PrescribingNumberUnit,
559
 		})
564
 		})
560
 	}
565
 	}
561
 	return
566
 	return
1737
 
1742
 
1738
 	return
1743
 	return
1739
 }
1744
 }
1745
+
1746
+//分区和收费(患者发药
1747
+func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1748
+	//获取排班
1749
+	var sch []*models.XtScheduleTwo
1750
+	ma := make(map[int64]int64)
1751
+	s := "user_org_id = ? and status = 1 and schedule_date >= ? and schedule_date <= ?"
1752
+	if shift != 0 {
1753
+		s = s + " and schedule_type = " + config.ToString(shift)
1754
+	}
1755
+	if partition != 0 {
1756
+		s = s + " and partition_id = " + config.ToString(partition)
1757
+	}
1758
+	if shift == 0 && partition == 0 {
1759
+		return flist, nil
1760
+	}
1761
+	err = XTWriteDB().Model(&models.XtScheduleTwo{}).Where(s, orgid, stime, etime).Find(&sch).Error
1762
+	if err != nil {
1763
+		return
1764
+	}
1765
+	for _, v := range sch {
1766
+		ma[v.PatientId] = v.PatientId
1767
+	}
1768
+	for _, v := range flist {
1769
+		if _, ok := ma[v.PatientID]; ok {
1770
+			tmp = append(tmp, v)
1771
+		}
1772
+	}
1773
+	return
1774
+}
1775
+
1776
+//分区和收费(药品发药
1777
+func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1778
+	//获取排班
1779
+	var sch []*models.XtScheduleTwo
1780
+	ma := make(map[int64]int64)
1781
+	s := "user_org_id = ? and status = 1 and schedule_date >= ? and schedule_date <= ?"
1782
+	if shift != 0 {
1783
+		s = s + " and schedule_type = " + config.ToString(shift)
1784
+	}
1785
+	if partition != 0 {
1786
+		s = s + " and partition_id = " + config.ToString(partition)
1787
+	}
1788
+	if shift == 0 && partition == 0 {
1789
+		for _, v := range flist {
1790
+			ma[v.PatientId] = v.PatientId
1791
+		}
1792
+		for _, v := range flist {
1793
+			if _, ok := ma[v.PatientId]; ok && (v.Usage == deliveryway || deliveryway == "全部") {
1794
+				tmp = append(tmp, v)
1795
+			}
1796
+		}
1797
+		return tmp, nil
1798
+	}
1799
+	err = XTWriteDB().Model(&models.XtScheduleTwo{}).Where(s, orgid, stime, etime).Find(&sch).Error
1800
+	if err != nil {
1801
+		return
1802
+	}
1803
+	for _, v := range sch {
1804
+		ma[v.PatientId] = v.PatientId
1805
+	}
1806
+
1807
+	for _, v := range flist {
1808
+		if _, ok := ma[v.PatientId]; ok && (v.Usage == deliveryway || deliveryway == "全部") {
1809
+			tmp = append(tmp, v)
1810
+		}
1811
+	}
1812
+	return
1813
+}
1814
+
1815
+//给药途径
1816
+func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1817
+	//查询药品
1818
+	var pp []*models.PharmacyBaseDrug
1819
+	s := "org_id = ? and status = 1"
1820
+	if deliveryway == "全部" {
1821
+		tmp = flist
1822
+		return
1823
+	} else {
1824
+		s = s + " and delivery_way = '" + deliveryway + "'"
1825
+	}
1826
+	err = XTReadDB().Model(&models.PharmacyBaseDrug{}).Where(s, orgid).Find(&pp).Error
1827
+	if err != nil {
1828
+		return
1829
+	}
1830
+	ma := make(map[int64]int64)
1831
+	for _, v := range pp {
1832
+		ma[v.ID] = v.ID
1833
+	}
1834
+	for _, v := range flist {
1835
+		if _, ok := ma[v.ID]; ok {
1836
+			tmp = append(tmp, v)
1837
+		}
1838
+	}
1839
+	return
1840
+}
1841
+
1842
+//计算总量
1843
+func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1844
+	//获取药品信息
1845
+	var t models.SpBaseDrug
1846
+	err = XTReadDB().Model(&models.SpBaseDrug{}).Where("id = ?", drug_id).Find(&t).Error
1847
+	if err != nil {
1848
+		return
1849
+	}
1850
+	terr, maxunit, minunit := int64(0), int64(0), int64(0) //terr异常的单位数量,maxunit包装单位数量,minunit拆零单位数量
1851
+	minmunber := t.MinNumber                               //拆零数量
1852
+	terrUnit := ""
1853
+	for _, v := range tmp {
1854
+		switch v.Unit {
1855
+		case t.MaxUnit:
1856
+			maxunit = v.Quantity
1857
+		case t.MinUnit:
1858
+			minunit = v.Quantity
1859
+		default:
1860
+			terr = v.Quantity
1861
+			terrUnit = v.Unit
1862
+		}
1863
+	}
1864
+	if minunit > minmunber {
1865
+		if minmunber == 0 {
1866
+			err = fmt.Errorf("拆零数量不能为零")
1867
+			return
1868
+		}
1869
+		maxunit = maxunit + minunit/minmunber
1870
+		minunit = minunit % minmunber
1871
+
1872
+	}
1873
+	if terr > 0 {
1874
+		total = total + config.ToString(terr) + terrUnit
1875
+	}
1876
+	if maxunit > 0 {
1877
+		total = total + config.ToString(maxunit) + t.MaxUnit
1878
+	}
1879
+	if minunit > 0 {
1880
+		total = total + config.ToString(minunit) + t.MinUnit
1881
+	}
1882
+
1883
+	return
1884
+}
1885
+func GetAllValidDeviceZones02(orgID int64) ([]*models.DeviceZone, error) {
1886
+	var zones []*models.DeviceZone
1887
+	err := readDb.Model(&models.DeviceZone{}).Where("org_id = ? and status = 1", orgID).Find(&zones).Error
1888
+	if err != nil {
1889
+		return nil, err
1890
+	}
1891
+	return zones, nil
1892
+}