|
@@ -85,6 +85,8 @@ func ScheduleApiRegistRouters() {
|
85
|
85
|
beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
|
86
|
86
|
beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
|
87
|
87
|
|
|
88
|
+ beego.Router("/api/schedule/create_two", &ScheduleApiController{}, "Post:CreateScheduleTwo")
|
|
89
|
+
|
88
|
90
|
}
|
89
|
91
|
func (c *ScheduleApiController) CoverSch() {
|
90
|
92
|
id_one, _ := c.GetInt64("id_one")
|
|
@@ -1581,6 +1583,269 @@ func (c *ScheduleApiController) CreateSchedule() {
|
1581
|
1583
|
return
|
1582
|
1584
|
}
|
1583
|
1585
|
|
|
1586
|
+func (c *ScheduleApiController) CreateScheduleTwo() {
|
|
1587
|
+ patientID, _ := c.GetInt64("patient_id", 0)
|
|
1588
|
+ id, _ := c.GetInt64("id_two", 0)
|
|
1589
|
+
|
|
1590
|
+ if id <= 0 {
|
|
1591
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1592
|
+ return
|
|
1593
|
+ }
|
|
1594
|
+
|
|
1595
|
+ adminINfo := c.GetAdminUserInfo()
|
|
1596
|
+ schedule_two, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
|
|
1597
|
+ timeNow := time.Now().Format("2006-01-02")
|
|
1598
|
+ timeTemplate := "2006-01-02"
|
|
1599
|
+
|
|
1600
|
+ tm := time.Unix(int64(schedule_two.ScheduleDate), 0)
|
|
1601
|
+ timeStr := tm.Format(timeTemplate)
|
|
1602
|
+ if timeNow > timeStr {
|
|
1603
|
+ utils.ErrorLog(timeNow)
|
|
1604
|
+ utils.ErrorLog(timeStr)
|
|
1605
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
|
|
1606
|
+ return
|
|
1607
|
+ }
|
|
1608
|
+ if schedule_two == nil {
|
|
1609
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
|
|
1610
|
+ return
|
|
1611
|
+ }
|
|
1612
|
+
|
|
1613
|
+ order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule_two.ScheduleDate, schedule_two.PatientId)
|
|
1614
|
+ if err != nil {
|
|
1615
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
1616
|
+ return
|
|
1617
|
+ }
|
|
1618
|
+
|
|
1619
|
+ if order != nil {
|
|
1620
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
|
|
1621
|
+ return
|
|
1622
|
+ }
|
|
1623
|
+
|
|
1624
|
+ schedule_two.Status = 0
|
|
1625
|
+ schedule_two.UpdatedTime = time.Now().Unix()
|
|
1626
|
+
|
|
1627
|
+ if patientID <= 0 {
|
|
1628
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1629
|
+ return
|
|
1630
|
+ }
|
|
1631
|
+
|
|
1632
|
+ adminUserInfo := c.GetAdminUserInfo()
|
|
1633
|
+ patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
|
|
1634
|
+ if patientInfo.ID == 0 {
|
|
1635
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
|
|
1636
|
+ return
|
|
1637
|
+ }
|
|
1638
|
+
|
|
1639
|
+ var schedule models.Schedule
|
|
1640
|
+ dataBody := make(map[string]interface{}, 0)
|
|
1641
|
+
|
|
1642
|
+ err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
|
|
1643
|
+ if err != nil {
|
|
1644
|
+ utils.ErrorLog(err.Error())
|
|
1645
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1646
|
+ return
|
|
1647
|
+ }
|
|
1648
|
+
|
|
1649
|
+ if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
|
|
1650
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1651
|
+ return
|
|
1652
|
+ }
|
|
1653
|
+ scheduleDate, _ := dataBody["schedule_date"].(string)
|
|
1654
|
+ if len(scheduleDate) == 0 {
|
|
1655
|
+ utils.ErrorLog("len(schedule_date) == 0")
|
|
1656
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1657
|
+ return
|
|
1658
|
+ }
|
|
1659
|
+ timeLayout := "2006-01-02"
|
|
1660
|
+ loc, _ := time.LoadLocation("Local")
|
|
1661
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
|
|
1662
|
+ if err != nil {
|
|
1663
|
+ utils.ErrorLog(err.Error())
|
|
1664
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1665
|
+ return
|
|
1666
|
+ }
|
|
1667
|
+ schedule.ScheduleDate = theTime.Unix()
|
|
1668
|
+
|
|
1669
|
+ timeNow = time.Now().Format("2006-01-02")
|
|
1670
|
+ if timeNow > scheduleDate {
|
|
1671
|
+ utils.ErrorLog(timeNow)
|
|
1672
|
+ utils.ErrorLog(scheduleDate)
|
|
1673
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
|
|
1674
|
+ return
|
|
1675
|
+ }
|
|
1676
|
+
|
|
1677
|
+ if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
|
|
1678
|
+ utils.ErrorLog("schedule_type")
|
|
1679
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1680
|
+ return
|
|
1681
|
+ }
|
|
1682
|
+ scheduleType := int64(dataBody["schedule_type"].(float64))
|
|
1683
|
+ if scheduleType < 1 || scheduleType > 3 {
|
|
1684
|
+ utils.ErrorLog("scheduleType < 3")
|
|
1685
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1686
|
+ return
|
|
1687
|
+ }
|
|
1688
|
+ schedule.ScheduleType = scheduleType
|
|
1689
|
+
|
|
1690
|
+ if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
|
|
1691
|
+ utils.ErrorLog("bed_id")
|
|
1692
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1693
|
+ return
|
|
1694
|
+ }
|
|
1695
|
+ bedId := int64(dataBody["bed_id"].(float64))
|
|
1696
|
+ if bedId < 1 {
|
|
1697
|
+ utils.ErrorLog("bedId < 1")
|
|
1698
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1699
|
+ return
|
|
1700
|
+ }
|
|
1701
|
+ schedule.BedId = bedId
|
|
1702
|
+
|
|
1703
|
+ if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
|
|
1704
|
+ utils.ErrorLog("partition_id")
|
|
1705
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1706
|
+ return
|
|
1707
|
+ }
|
|
1708
|
+ partitionId := int64(dataBody["partition_id"].(float64))
|
|
1709
|
+ if partitionId < 1 {
|
|
1710
|
+ utils.ErrorLog("partitionId < 1")
|
|
1711
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1712
|
+ return
|
|
1713
|
+ }
|
|
1714
|
+ schedule.PartitionId = partitionId
|
|
1715
|
+
|
|
1716
|
+ if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
|
|
1717
|
+ utils.ErrorLog("schedule_week")
|
|
1718
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1719
|
+ return
|
|
1720
|
+ }
|
|
1721
|
+ scheduleWeek := int64(dataBody["schedule_week"].(float64))
|
|
1722
|
+ if scheduleWeek < 1 || scheduleWeek > 7 {
|
|
1723
|
+ utils.ErrorLog("scheduleWeek < 1")
|
|
1724
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1725
|
+ return
|
|
1726
|
+ }
|
|
1727
|
+ schedule.ScheduleWeek = scheduleWeek
|
|
1728
|
+
|
|
1729
|
+ if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
|
|
1730
|
+ utils.ErrorLog("mode_id")
|
|
1731
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1732
|
+ return
|
|
1733
|
+ }
|
|
1734
|
+ modeId := int64(dataBody["mode_id"].(float64))
|
|
1735
|
+ if modeId < 1 && modeId > 14 {
|
|
1736
|
+ utils.ErrorLog("modeId < 1")
|
|
1737
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1738
|
+ return
|
|
1739
|
+ }
|
|
1740
|
+ schedule.ModeId = modeId
|
|
1741
|
+
|
|
1742
|
+ schedule.PatientId = patientID
|
|
1743
|
+ schedule.CreatedTime = time.Now().Unix()
|
|
1744
|
+ schedule.UpdatedTime = time.Now().Unix()
|
|
1745
|
+ schedule.Status = 1
|
|
1746
|
+ schedule.UserOrgId = adminUserInfo.CurrentOrgId
|
|
1747
|
+ schedule.IsExport = 5
|
|
1748
|
+
|
|
1749
|
+ var DialysisMachineName string
|
|
1750
|
+ so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
|
|
1751
|
+ filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
|
|
1752
|
+ filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
|
|
1753
|
+ filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
|
|
1754
|
+
|
|
1755
|
+ if filedRecordOne.IsShow == 1 {
|
|
1756
|
+ DialysisMachineName = so.DialysisDialyszers
|
|
1757
|
+ }
|
|
1758
|
+ if filedRecordThree.IsShow == 1 {
|
|
1759
|
+ if len(DialysisMachineName) > 0 {
|
|
1760
|
+ DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
|
|
1761
|
+
|
|
1762
|
+ } else {
|
|
1763
|
+ DialysisMachineName = so.DialyzerPerfusionApparatus
|
|
1764
|
+
|
|
1765
|
+ }
|
|
1766
|
+ }
|
|
1767
|
+ if filedRecordTwo.IsShow == 1 {
|
|
1768
|
+ if len(DialysisMachineName) > 0 {
|
|
1769
|
+ DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
|
|
1770
|
+
|
|
1771
|
+ } else {
|
|
1772
|
+ DialysisMachineName = so.DialysisIrrigation
|
|
1773
|
+
|
|
1774
|
+ }
|
|
1775
|
+ }
|
|
1776
|
+ schedule.DialysisMachineName = DialysisMachineName
|
|
1777
|
+
|
|
1778
|
+ bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
|
|
1779
|
+ if bed == nil {
|
|
1780
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
|
|
1781
|
+ return
|
|
1782
|
+ }
|
|
1783
|
+ if bed.ZoneID != schedule.PartitionId {
|
|
1784
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
|
|
1785
|
+ return
|
|
1786
|
+ }
|
|
1787
|
+
|
|
1788
|
+ //scheduleDateStart := scheduleDate + " 00:00:00"
|
|
1789
|
+ //scheduleDateEnd := scheduleDate + " 23:59:59"
|
|
1790
|
+ timeLayout = "2006-01-02 15:04:05"
|
|
1791
|
+ //theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
|
|
1792
|
+ //theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
|
|
1793
|
+ //startTime := theStartTime.Unix()
|
|
1794
|
+ //endTime := theEndTime.Unix()
|
|
1795
|
+
|
|
1796
|
+ ////一天只有排班一次
|
|
1797
|
+ //daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
|
|
1798
|
+ //if daySchedule.ID > 0 {
|
|
1799
|
+ // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
|
|
1800
|
+ // return
|
|
1801
|
+ //}
|
|
1802
|
+ //同天同位置只能排一个
|
|
1803
|
+ pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
|
|
1804
|
+ if err != nil {
|
|
1805
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
1806
|
+ return
|
|
1807
|
+ }
|
|
1808
|
+ if pointSchedule.ID > 0 {
|
|
1809
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
|
|
1810
|
+ return
|
|
1811
|
+ }
|
|
1812
|
+ schedule.IsExport = 1000
|
|
1813
|
+ err = service.CreateSchedule(&schedule, id)
|
|
1814
|
+ if err == nil {
|
|
1815
|
+ redis := service.RedisClient()
|
|
1816
|
+ key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
|
|
1817
|
+ redis.Set(key, "", time.Second)
|
|
1818
|
+ //处方
|
|
1819
|
+ keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
|
|
1820
|
+ redis.Set(keyOne, "", time.Second)
|
|
1821
|
+ //医嘱
|
|
1822
|
+ keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
|
|
1823
|
+ redis.Set(keyTwo, "", time.Second)
|
|
1824
|
+ keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
|
|
1825
|
+ redis.Set(keySix, "", time.Second)
|
|
1826
|
+ keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
|
|
1827
|
+ redis.Set(keyThree, "", time.Second)
|
|
1828
|
+ keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
|
|
1829
|
+ redis.Set(keyFour, "", time.Second)
|
|
1830
|
+ keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
|
|
1831
|
+ redis.Set(keyFive, "", time.Second)
|
|
1832
|
+ keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
|
|
1833
|
+ redis.Set(keySeven, "", time.Second)
|
|
1834
|
+ defer redis.Close()
|
|
1835
|
+ schedule.Patient = patientInfo.Name
|
|
1836
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
1837
|
+ "msg": "ok",
|
|
1838
|
+ "schedule": schedule,
|
|
1839
|
+ "schedule_two": schedule_two,
|
|
1840
|
+ })
|
|
1841
|
+ return
|
|
1842
|
+ } else {
|
|
1843
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
|
|
1844
|
+ return
|
|
1845
|
+ }
|
|
1846
|
+
|
|
1847
|
+}
|
|
1848
|
+
|
1584
|
1849
|
func (c *ScheduleApiController) DeleteSchedule() {
|
1585
|
1850
|
id, _ := c.GetInt64("id", 0)
|
1586
|
1851
|
if id <= 0 {
|