mainqaq преди 2 години
родител
ревизия
742436d34d
променени са 4 файла, в които са добавени 241 реда и са изтрити 9 реда
  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 Целия файл

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

+ 84 - 8
controllers/pharmacy_controller.go Целия файл

@@ -118,6 +118,16 @@ func (this *PharmacyController) IssuedDrug() {
118 118
 	keyword := this.GetString("keyword", "")
119 119
 	times := this.GetString("time", "")
120 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 131
 	timeLayout := "2006-01-02"
122 132
 	loc, _ := time.LoadLocation("Local")
123 133
 	var stime, etime int64
@@ -136,8 +146,14 @@ func (this *PharmacyController) IssuedDrug() {
136 146
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
137 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 155
 	this.ServeSuccessJSON(map[string]interface{}{
140
-		"list": flist,
156
+		"list": listt,
141 157
 	})
142 158
 	return
143 159
 }
@@ -153,6 +169,16 @@ func (this *PharmacyController) WaitingDrug() {
153 169
 	}()
154 170
 	keyword := this.GetString("keyword", "")
155 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 182
 	orgid := this.GetAdminUserInfo().CurrentOrgId
157 183
 	timeLayout := "2006-01-02"
158 184
 	loc, _ := time.LoadLocation("Local")
@@ -172,8 +198,14 @@ func (this *PharmacyController) WaitingDrug() {
172 198
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
173 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 207
 	this.ServeSuccessJSON(map[string]interface{}{
176
-		"list": flist,
208
+		"list": listt,
177 209
 	})
178 210
 	return
179 211
 }
@@ -392,6 +424,7 @@ func (this *PharmacyController) DispenseMedicine() {
392 424
 	orgid := this.GetAdminUserInfo().CurrentOrgId
393 425
 	timeLayout := "2006-01-02"
394 426
 	loc, _ := time.LoadLocation("Local")
427
+	deliveryway := this.GetString("deliveryway", "")
395 428
 	var stime, etime int64
396 429
 	if times == "" {
397 430
 		stime, etime = service.GetNowTime()
@@ -408,8 +441,14 @@ func (this *PharmacyController) DispenseMedicine() {
408 441
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
409 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 450
 	this.ServeSuccessJSON(map[string]interface{}{
412
-		"list": flist,
451
+		"list": llist,
413 452
 	})
414 453
 	return
415 454
 }
@@ -430,6 +469,7 @@ func (this *PharmacyController) WaitingMedicine() {
430 469
 	orgid := this.GetAdminUserInfo().CurrentOrgId
431 470
 	timeLayout := "2006-01-02"
432 471
 	loc, _ := time.LoadLocation("Local")
472
+	deliveryway := this.GetString("deliveryway", "")
433 473
 	var stime, etime int64
434 474
 	if times == "" {
435 475
 		stime, etime = service.GetNowTime()
@@ -446,8 +486,14 @@ func (this *PharmacyController) WaitingMedicine() {
446 486
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
447 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 495
 	this.ServeSuccessJSON(map[string]interface{}{
450
-		"list": flist,
496
+		"list": llist,
451 497
 	})
452 498
 	return
453 499
 }
@@ -467,6 +513,21 @@ func (this *PharmacyController) GetPatientsWithDrugs() {
467 513
 	is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
468 514
 	times := this.GetString("time", "")
469 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 531
 	timeLayout := "2006-01-02"
471 532
 	loc, _ := time.LoadLocation("Local")
472 533
 	var stime, etime int64
@@ -484,8 +545,21 @@ func (this *PharmacyController) GetPatientsWithDrugs() {
484 545
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
485 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 560
 	this.ServeSuccessJSON(map[string]interface{}{
488
-		"list": list,
561
+		"list":  listll,
562
+		"total": total,
489 563
 	})
490 564
 	return
491 565
 }
@@ -530,13 +604,14 @@ func (this *PharmacyController) GetPartitionList() {
530 604
 		}
531 605
 	}()
532 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 609
 	if err != nil {
535 610
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
536 611
 		return
537 612
 	}
538 613
 	this.ServeSuccessJSON(map[string]interface{}{
539
-		"list": list,
614
+		"list": append(tmp, list...),
540 615
 	})
541 616
 	return
542 617
 }
@@ -552,13 +627,14 @@ func (this *PharmacyController) RouteOfAdministration() {
552 627
 		}
553 628
 	}()
554 629
 	orgid := this.GetAdminUserInfo().CurrentOrgId
630
+	tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
555 631
 	list, _, err := service.GetDrugWayDics(orgid)
556 632
 	if err != nil {
557 633
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
558 634
 		return
559 635
 	}
560 636
 	this.ServeSuccessJSON(map[string]interface{}{
561
-		"list": list,
637
+		"list": append(tmp, list...),
562 638
 	})
563 639
 	return
564 640
 }

+ 3 - 0
models/pharmacy_models.go Целия файл

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

+ 153 - 0
service/pharmacy_service.go Целия файл

@@ -529,6 +529,7 @@ func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*
529 529
 		pp = append(pp, &models.PatientInformation{
530 530
 			Id:           "h" + config.ToString(v.ID),
531 531
 			Name:         FindUserName(v.PatientId),
532
+			PatientId:    v.PatientId,
532 533
 			SingleDosage: config.ToString(v.SingleDose) + v.SingleDoseUnit,
533 534
 			Usage:        v.DeliveryWay,
534 535
 			Frequency:    v.ExecutionFrequency,
@@ -536,6 +537,8 @@ func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*
536 537
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
537 538
 			DataSources:  "his处方",
538 539
 			People:       GetUserAdminName(v.People, orgid), //领药人!!!!!!!!!!!!!!!!!!!!!!
540
+			Quantity:     int64(v.PrescribingNumber),
541
+			Unit:         v.PrescribingNumberUnit,
539 542
 		})
540 543
 	}
541 544
 
@@ -556,6 +559,8 @@ func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*
556 559
 			Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
557 560
 			DataSources:  "临时医嘱",
558 561
 			People:       GetUserAdminName(v.People, orgid), //领药人
562
+			Quantity:     int64(v.PrescribingNumber),
563
+			Unit:         v.PrescribingNumberUnit,
559 564
 		})
560 565
 	}
561 566
 	return
@@ -1737,3 +1742,151 @@ func Scavenger(orgid int64) (err error) {
1737 1742
 
1738 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
+}