123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers/mobile_api_controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
- )
-
- type StaffScheduleApiController struct {
- mobile_api_controllers.MobileBaseAPIAuthController
- }
-
- func (this *StaffScheduleApiController) GetMobileDoctorList() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- appId := this.GetMobileAdminUserInfo().App.Id
- staffList, err := service.GetDoctorList(orgId, appId)
- //获取所有的医生
- doctorList, err := service.GetAllDoctorList(orgId, appId)
-
- //获取所有的护士
- nurseList, err := service.GetAllNurseList(orgId, appId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "staffList": staffList,
- "doctorList": doctorList,
- "nurseList": nurseList,
- })
- }
-
- func (this *StaffScheduleApiController) GetMobileStaffScheduleList() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- //start_time, _ := this.GetInt64("start_time")
- //fmt.Println("staft_time", start_time)
- //end_time, _ := this.GetInt64("end_time")
- //fmt.Println("start_time",start_time)
- //fmt.Println("end_time",end_time)
- start_time_one := this.GetString("start_time_one")
- end_time_one := this.GetString("end_time_one")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- staffList, err := service.GetStaffScheduleList(orgId, startTime, endTime)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "staffList": staffList,
- })
- }
-
- func (this *StaffScheduleApiController) GetMobileNextWeekScheduleLIst() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- //start_time, _ := this.GetInt64("start_time")
- //end_time, _ := this.GetInt64("end_time")
- start_time_one := this.GetString("start_time_one")
- end_time_one := this.GetString("end_time_one")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- staffList, err := service.GetStaffScheduleList(orgId, startTime, endTime)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "staffList": staffList,
- })
- }
-
- func (this *StaffScheduleApiController) GetScheduleByUserType() {
- doctor_id, _ := this.GetInt64("doctor_id")
- //start_time, _ := this.GetInt64("start_time")
- //end_time, _ := this.GetInt64("end_time")
- start_time_one := this.GetString("start_time_one")
- end_time_one := this.GetString("end_time_one")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- orgId := this.GetMobileAdminUserInfo().Org.Id
- staffList, err := service.GetScheduleByDoctorId(doctor_id, startTime, endTime, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "staffList": staffList,
- })
- }
-
- func (this *StaffScheduleApiController) GetSearchPatientByDoctorId() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- user_name := this.GetString("user_name")
- //start_time, _ := this.GetInt64("start_time")
- //end_time, _ := this.GetInt64("end_time")
-
- start_time_one := this.GetString("start_time_one")
- end_time_one := this.GetString("end_time_one")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- //
- staffList, err := service.ToSearchSeacheduleList(user_name, startTime, endTime, orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "staffList": staffList,
- })
- }
-
- func (this *StaffScheduleApiController) GetMobileSchedulelist() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- list, err := service.GetScheduleList(orgId)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StaffScheduleApiController) GetMobileScheduleListTotal() {
-
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- //统计班次
- scheudletotal, err := service.GetScheduleListTotal(orgId, start_time, end_time)
- //统计总工时
- list, err := service.GetTotalMinutes(orgId, start_time, end_time)
- //统计出勤天数
- workDay, err := service.GetTotalWorkDay(orgId, start_time, end_time)
- //统计缺勤天数
- noWorkDay, err := service.GetTotalNoWorkDay(orgId, start_time, end_time)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheudletotal": scheudletotal,
- "list": list,
- "workDay": workDay,
- "noWorkDay": noWorkDay,
- })
- }
-
- func (this *StaffScheduleApiController) GetMySchedule() {
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- creator, _ := this.GetInt64("creator")
- schedule, err := service.GetMySchedule(start_time, end_time, orgId, creator)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (this *StaffScheduleApiController) GetMobileChartList() {
-
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- //统计总工时
- list, err := service.GetTotalMinutesOne(orgId, start_time, end_time)
- //统计出勤的总工时
- workDaylist, err := service.GetTotalMinutesTwo(orgId, start_time, end_time)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "workDaylist": workDaylist,
- })
- }
-
- func (this *StaffScheduleApiController) ToSearchMobileTotal() {
-
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- keyword := this.GetString("keyword")
- //统计表
- scheduletotal, err := service.GetSearchScheduleListTotal(orgId, start_time, end_time, keyword)
- list, err := service.GeSearchtTotalMinutes(orgId, start_time, end_time, keyword)
- workDay, err := service.GetSearchWorkDay(orgId, start_time, end_time, keyword)
- noWorkDay, err := service.GetSearchWorkNoDay(orgId, start_time, end_time, keyword)
-
- //统计图
- chartTotalMinute, err := service.GetChartTotalMinutesOne(orgId, start_time, end_time, keyword)
- chartWorkDayMinute, err := service.GetChartTotalMinutesTwo(orgId, start_time, end_time, keyword)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduletotal": scheduletotal,
- "list": list,
- "workDay": workDay,
- "noWorkDay": noWorkDay,
- "chartTotalMinute": chartTotalMinute,
- "chartWorkDayMinute": chartWorkDayMinute,
- })
- }
-
- func (this *StaffScheduleApiController) ChangeMobileOption() {
-
- start_time, _ := this.GetInt64("start_time")
- end_time, _ := this.GetInt64("end_time")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- doctor_type, _ := this.GetInt64("doctor_type")
- //统计图
- scheduletotal, err := service.ChagneScheduleListTotal(orgId, start_time, end_time, doctor_type)
- list, err := service.ChangeScheduleMinute(orgId, start_time, end_time, doctor_type)
- workday, err := service.ChangeWorkDay(orgId, start_time, end_time, doctor_type)
- worknoday, err := service.ChangeNoWorkDay(orgId, start_time, end_time, doctor_type)
-
- //统计表
- chartotalminute, err := service.ChartTotalMinute(orgId, start_time, end_time, doctor_type)
- chartworkdayminute, err := service.ChartWorkDayMinute(orgId, start_time, end_time, doctor_type)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduletotal": scheduletotal,
- "list": list,
- "workday": workday,
- "worknoday": worknoday,
- "chartotalminute": chartotalminute,
- "chartworkdayminute": chartworkdayminute,
- })
- }
-
- func (this *StaffScheduleApiController) GetAllZone() {
-
- id := this.GetMobileAdminUserInfo().Org.Id
- zone, err := service.GetAllMobileZone(id)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "zone": zone,
- })
- }
-
- func (this *StaffScheduleApiController) GetAllZonePb() {
- orgid := this.GetMobileAdminUserInfo().Org.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- zoneid, _ := this.GetInt64("zoneid")
- classtype, _ := this.GetInt64("classtype")
-
- // is_open, _ := this.GetInt64("is_open")
-
- //获取空床位的排班数据
- list, _ := service.GetPatientScheduleByPd(startTime, zoneid, orgid, classtype)
- if len(list) > 0 {
- for _, item := range list {
- for _, device := range item.DeviceNumber {
- item.TotalBed += 1
- for _, schedule := range device.Schedule {
- if schedule.ScheduleType == 1 {
- item.SwBed += 1
- }
- if schedule.ScheduleType == 2 {
- item.XwBed += 1
- }
- if schedule.ScheduleType == 3 {
- item.WsBed += 1
- }
- }
- }
- }
- }
-
- //针对百霖和贝尔
- if orgid == 10138 || orgid == 10278 || orgid == 3877 {
- //获取今日的排班数据
- list, _ := service.GetMobileScheduleListByScheduleDate(orgid, startTime)
- for _, item := range list {
- solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
- var str = solution.DialysisDialyszers + "/" + solution.DialysisIrrigation
- service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, str, item.ScheduleType)
- }
- }
-
- if orgid == 10585 {
- //获取今日的排班数据
- list, _ := service.GetMobileScheduleListByScheduleDate(orgid, startTime)
- for _, item := range list {
- solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
- var str = solution.DialyzerPerfusionApparatus
- service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, str, item.ScheduleType)
- }
- }
-
- //查询排班里面的空透析器
- if orgid == 10375 {
-
- schedulesFive, _ := service.GetMobileScheduleListByScheduleDateOne(orgid, startTime)
-
- for _, item := range schedulesFive {
- solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
- var DialysisMachineName string
- if len(solution.DialysisDialyszers) > 0 {
- DialysisMachineName = solution.DialysisDialyszers
- }
- if len(solution.DialyzerPerfusionApparatus) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
- }
-
- if len(solution.DialysisIrrigation) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
- }
- item.DialysisMachineName = DialysisMachineName
- service.UpdateSchOne(item.ID, item.DialysisMachineName)
- }
-
- }
-
- // stockType, _ := service.GetStockType(orgid)
- //zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- // return
- // }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": list,
- // "stockType": stockType,
- //"zonelist": zonelist,
- })
-
- // id := this.GetMobileAdminUserInfo().Org.Id
- // zone, err := service.GetAllMobileZonePb(id)
-
- // if err != nil {
- // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- // return
- // }
- // this.ServeSuccessJSON(map[string]interface{}{
- // "zone": zone,
- // })
- }
-
- func (this *StaffScheduleApiController) GetPatientScheduleList() {
- orgid := this.GetMobileAdminUserInfo().Org.Id
- fmt.Println("orgid", orgid)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- zoneid, _ := this.GetInt64("zoneid")
- fmt.Println(zoneid)
- classtype, _ := this.GetInt64("classtype")
-
- is_open, _ := this.GetInt64("is_open")
-
- if is_open == 0 {
- //获取当天排班的病人情况
- schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
-
- zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- "zonelist": zonelist,
- })
- }
- if is_open == 1 {
- //获取空床位的排班数据
- list, err := service.GetPatientScheduleByBed(startTime, zoneid, orgid, classtype)
- stockType, _ := service.GetStockType(orgid)
- zonelist, _ := service.GetPatientScheduleListByZone(startTime, classtype, orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": list,
- "stockType": stockType,
- "zonelist": zonelist,
- })
- }
- }
-
- func (this *StaffScheduleApiController) DeleteSchedule() {
- id, _ := this.GetInt64("id")
- org_id := this.GetMobileAdminUserInfo().Org.Id
- err := service.DeleteSchedule(id)
-
- if err == nil {
- schedule, _ := service.GetScheduleNight(org_id, id)
-
- //记录日志
- byterequest, _ := json.Marshal(schedule)
- xtScheduleLog := models.XtScheduleLog{
- UserOrgId: org_id,
- RecordDate: schedule.ScheduleDate,
- Status: 1,
- PatientId: schedule.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- Source: "手机端删除排班",
- Module: 5,
- AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
- }
- service.CreateScheduleLog(xtScheduleLog)
-
- //针对凤凰医院
- if org_id == 10579 || org_id == 10344 || org_id == 10206 {
- advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
- if len(advice) > 0 {
- service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
- }
- }
-
- if org_id == 10206 {
- advice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, org_id)
- if len(advice) > 0 {
- service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, org_id)
- }
- project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, org_id)
- if len(project) > 0 {
- service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, org_id)
- }
- }
- redis := service.RedisClient()
- //处方
- keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
- redis.Set(keyOne, "", time.Second)
-
- //医嘱
- keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
- redis.Set(keySix, "", time.Second)
- keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
- redis.Set(keyFive, "", time.Second)
-
- keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keySeven, "", time.Second)
-
- defer redis.Close()
- fmt.Println(err)
-
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
-
- } else {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除失败")
- return
- }
- }
-
- func (this *StaffScheduleApiController) SearchPatient() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- keyword := this.GetString("keyword")
- fmt.Println(keyword)
- orgId := this.GetMobileAdminUserInfo().Org.Id
- start_time := this.GetString("start_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- schedule, err := service.GetSearchPatient(keyword, orgId, startTime)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- var err error
- //查询患者信息
- list, _ := service.GetStaffScheduleById(idSplit)
- if len(list) > 0 {
- for index, _ := range list {
- fmt.Println("index2322332", index)
- schedule := models.XtSchedule{
- PatientId: list[0].PatientId,
- ModeId: list[0].ModeId,
- DialysisMachineName: list[0].DialysisMachineName,
- }
- xtSchedule := models.WeekSchedule{
- PatientId: list[1].PatientId,
- ModeId: list[1].ModeId,
- DialysisMachineName: list[1].DialysisMachineName,
- }
- err = service.UpdateStaffSchedule(list[1].ID, schedule)
- fmt.Println("errrrrrrr2323323232323", err)
- service.UpdateStaffScheduleOne(list[0].ID, xtSchedule)
- }
- }
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "切换成功",
- })
- }
- func (this *StaffScheduleApiController) UpdateDialysisPrescription() {
- patient_id, _ := this.GetInt64("patient_id")
- start_time, _ := this.GetInt64("start_time")
- mode_id, _ := this.GetInt64("mode_id")
- dialyzer_perfusion_apparatus := this.GetString("dialyzer_perfusion_apparatus")
- dialysis_irrigation := this.GetString("dialysis_irrigation")
- //更改透析模式
- _, errcode := service.GetDialyisSolution(patient_id, start_time)
- if errcode == gorm.ErrRecordNotFound {
- orgId := this.GetMobileAdminUserInfo().Org.Id
- prescription := models.DialysisPrescription{
- DialysisDialyszers: dialyzer_perfusion_apparatus,
- DialysisIrrigation: dialysis_irrigation,
- PatientId: patient_id,
- UserOrgId: orgId,
- Status: 1,
- RecordDate: start_time,
- CreatedTime: time.Now().Unix(),
- ModeId: mode_id,
- }
- err := service.CreateDialysisPrescription(&prescription)
-
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- } else if errcode == nil {
- prescription := models.DialysisPrescription{
- DialysisDialyszers: dialyzer_perfusion_apparatus,
- DialysisIrrigation: dialysis_irrigation,
- ModeId: mode_id,
- }
- err := service.UpdateDialysisPrescriptionOne(prescription, patient_id, start_time, mode_id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- }
- }
-
- func (this *StaffScheduleApiController) UpdateBloodScheduleMode() {
-
- id, _ := this.GetInt64("id")
- mode_id, _ := this.GetInt64("mode_id")
- schedule := models.XtSchedule{
- ModeId: mode_id,
- }
- service.UpdatedScheduleMode(schedule, id)
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
- //记录日志
- byterequest, _ := json.Marshal(schedule)
- scheduleLog := models.XtScheduleLog{
- UserOrgId: orgId,
- RecordDate: schedule.ScheduleDate,
- Status: 1,
- PatientId: schedule.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- Source: "手机端修改排班模式",
- Module: 5,
- AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
- }
-
- service.CreateScheduleLog(scheduleLog)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- })
- }
-
- func (this *StaffScheduleApiController) UpdateBloodSchedule() {
-
- patient_id, _ := this.GetInt64("patient_id")
- mode_id, _ := this.GetInt64("mode_id")
- schedule_type, _ := this.GetInt64("schedule_type")
- start_time, _ := this.GetInt64("start_time")
- bed_id, _ := this.GetInt64("bed_id")
- orgid := this.GetMobileAdminUserInfo().Org.Id
- //更改排班
- schedule := models.XtSchedule{
- ScheduleType: schedule_type,
- ModeId: mode_id,
- }
-
- //查询该床位该班次是否存在排班
- _, errschedulecode := service.GetPatientScheduleIsExist(start_time, schedule_type, bed_id, orgid)
- if errschedulecode == gorm.ErrRecordNotFound {
- service.UpdatedSchedule(schedule, patient_id, start_time, schedule_type, bed_id)
-
- //记录日志
- byterequest, _ := json.Marshal(schedule)
- scheduleLog := models.XtScheduleLog{
- UserOrgId: orgid,
- RecordDate: schedule.ScheduleDate,
- Status: 1,
- PatientId: schedule.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- Source: "手机修改排班班次",
- Module: 5,
- AdminUserId: this.GetMobileAdminUserInfo().AdminUser.Id,
- }
-
- service.CreateScheduleLog(scheduleLog)
- this.ServeSuccessJSON(map[string]interface{}{
- "msgerr": "保存成功",
- })
- } else if errschedulecode == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "msgerr": "排班已存在",
- })
- }
-
- }
-
- func (this *StaffScheduleApiController) GetSchedulePatient() {
-
- schedule, _ := this.GetInt64("schedule", 0) //1已2未
- contagion, _ := this.GetInt64("contagion", 0)
- keywords := this.GetString("keywords", "")
- adminInfo := this.GetMobileAdminUserInfo()
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- thisWeekEnd := 7 - weekDay
- weekStartPoint := thisWeekEnd - 6
- weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
- weekEndPoint := thisWeekEnd + 7
- weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
- fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
-
- weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
- weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
- fmt.Println(weekStartTime, weekEndTime)
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
- weekStart := theStarTime.Unix()
- weekEnd := theEndTime.Unix()
- patients, _ := service.GetPatientWithScheduleAndSolutionTwo(adminInfo.Org.Id, keywords, weekStart, weekEnd, schedule, contagion)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- return
- }
-
- func (c *StaffScheduleApiController) CreateMobileSchedulePatient() {
-
- patientID, _ := c.GetInt64("patient_id", 0)
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patientID)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var schedule models.Schedule
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleDate, _ := dataBody["schedule_date"].(string)
- if len(scheduleDate) == 0 {
- utils.ErrorLog("len(schedule_date) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleDate = theTime.Unix()
-
- timeNow := time.Now().Format("2006-01-02")
- if timeNow > scheduleDate {
- utils.ErrorLog(timeNow)
- utils.ErrorLog(scheduleDate)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- return
- }
-
- if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
- utils.ErrorLog("schedule_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleType := int64(dataBody["schedule_type"].(float64))
- if scheduleType < 1 || scheduleType > 3 {
- utils.ErrorLog("scheduleType < 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleType = scheduleType
-
- if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
- utils.ErrorLog("bed_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- bedId := int64(dataBody["bed_id"].(float64))
- if bedId < 1 {
- utils.ErrorLog("bedId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.BedId = bedId
-
- if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
- utils.ErrorLog("partition_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partitionId := int64(dataBody["partition_id"].(float64))
- if partitionId < 1 {
- utils.ErrorLog("partitionId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.PartitionId = partitionId
-
- if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
- utils.ErrorLog("schedule_week")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- scheduleWeek := int64(dataBody["schedule_week"].(float64))
- if scheduleWeek < 1 || scheduleWeek > 7 {
- utils.ErrorLog("scheduleWeek < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ScheduleWeek = scheduleWeek
-
- if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
- utils.ErrorLog("mode_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- modeId := int64(dataBody["mode_id"].(float64))
- if modeId < 1 && modeId > 14 {
- utils.ErrorLog("modeId < 1")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedule.ModeId = modeId
-
- schedule.PatientId = patientID
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- schedule.Status = 1
- schedule.IsExport = 6000
- schedule.UserOrgId = adminUserInfo.Org.Id
-
- bed, _ := service.GetDeviceNumberByID(adminUserInfo.Org.Id, schedule.BedId)
- if bed == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
- return
- }
- if bed.ZoneID != schedule.PartitionId {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
- return
- }
-
- scheduleDateStart := scheduleDate + " 00:00:00"
- scheduleDateEnd := scheduleDate + " 23:59:59"
- timeLayout = "2006-01-02 15:04:05"
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- startTime := theStartTime.Unix()
- endTime := theEndTime.Unix()
-
- //一天只有排班一次
- daySchedule, err := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, patientID)
- if daySchedule.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
- return
- }
-
- //同天同位置只能排一个
- pointSchedule, err := service.GetPointSchedule(adminUserInfo.Org.Id, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if pointSchedule.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
- return
- }
-
- redis := service.RedisClient()
- err = service.CreateScheduleTwo(&schedule)
- service.UpdateRepeatSchStatus(adminUserInfo.Org.Id, schedule.ScheduleDate)
- key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(key, "", time.Second)
- defer redis.Close()
- fmt.Println(err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
- return
- }
- schedule.Patient = patientInfo.Name
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "schedule": schedule,
- })
- return
-
- }
-
- func (c *StaffScheduleApiController) GetSolutionSchedule() {
-
- orgId := c.GetMobileAdminUserInfo().Org.Id
- scheduleDate := c.GetString("start_time")
- zoneid, _ := c.GetInt64("zoneid")
- classtype, _ := c.GetInt64("classtype")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
- schedule, _ := service.GetSolutionScheduleBySchedule(orgId, zoneid, classtype, theTime.Unix())
-
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
- }
-
- func (c *StaffScheduleApiController) GetAllBedList() {
-
- orgId := c.GetMobileAdminUserInfo().Org.Id
- partition_id, _ := c.GetInt64("partition_id")
- list, _ := service.GetAllBedNumberTen(orgId, partition_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *StaffScheduleApiController) ChangeScheduleById() {
-
- id, _ := c.GetInt64("id")
- mode_id, _ := c.GetInt64("mode_id")
- schedule_date, _ := c.GetInt64("schedule_date")
- patient_id, _ := c.GetInt64("patient_id")
- org_id := c.GetMobileAdminUserInfo().Org.Id
- err := service.ChangeScheduleById(id, mode_id)
- fmt.Println("err", err)
- err = service.ChangeDialysisSolution(patient_id, schedule_date, org_id, mode_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- }
-
- func (c *StaffScheduleApiController) ChangeScheduleType() {
- schedule_type, _ := c.GetInt64("schedule_type")
- schedule_date, _ := c.GetInt64("schedule_date")
- patient_id, _ := c.GetInt64("patient_id")
- bed_id, _ := c.GetInt64("bed_id")
- //schedule_week, _ := c.GetInt64("schedule_week")
- mode_id, _ := c.GetInt64("mode_id")
- id, _ := c.GetInt64("id")
- org_id := c.GetMobileAdminUserInfo().Org.Id
- //查询该班次该床位是否已经存在患者
- schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
- //查询该床位所属分区
- //numberlist, _ := service.GetPartionId(bed_id, org_id)
- //存在
- if schedule.ID > 0 {
- order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
- if order.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
- return
- }
- //调换位置
- sch := models.Schedule{
- PatientId: schedule.PatientId,
- ModeId: schedule.ModeId,
- }
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
- filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- sch.DialysisMachineName = DialysisMachineName
- schedu := models.Schedule{
- PatientId: patient_id,
- ModeId: mode_id,
- }
- var DialysisMachineName1 string
- so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
- filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
- filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
- filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
- if filedRecordOne1.IsShow == 1 {
- DialysisMachineName1 = so1.DialysisDialyszers
- }
- if filedRecordThree1.IsShow == 1 {
- if len(DialysisMachineName1) > 0 {
- DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName1 = so1.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo1.IsShow == 1 {
- if len(DialysisMachineName1) > 0 {
- DialysisMachineName1 = DialysisMachineName1 + "*" + so1.DialysisIrrigation
- } else {
- DialysisMachineName1 = so1.DialysisIrrigation
- }
- }
- schedu.DialysisMachineName = DialysisMachineName1
- err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- } else {
- xtSchedule := models.Schedule{
- ScheduleDate: schedule_date,
- ScheduleType: schedule_type,
- PatientId: patient_id,
- UserOrgId: org_id,
- }
-
- err := service.ChangeScheduleClass(xtSchedule)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
- func (c *StaffScheduleApiController) ChangeScheduleBed() {
- schedule_type, _ := c.GetInt64("schedule_type")
- schedule_date, _ := c.GetInt64("schedule_date")
- patient_id, _ := c.GetInt64("patient_id")
- bed_id, _ := c.GetInt64("bed_id")
- schedule_week, _ := c.GetInt64("schedule_week")
- mode_id, _ := c.GetInt64("mode_id")
- id, _ := c.GetInt64("id")
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- temp_schedule, _ := service.GetScheduleByClassTypeTwo(schedule_type, schedule_date, patient_id, org_id)
- id = temp_schedule.ID
-
- //查询该班次该床位是否已经存在患者
- schedule, _ := service.GetScheduleByClassType(schedule_type, schedule_date, bed_id, org_id)
- //查询该床位所属分区
- numberlist, _ := service.GetPartionId(bed_id, org_id)
- //存在
- if schedule.ID > 0 {
-
- order, _ := service.GetDialysisOrder(schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
- if order.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSchedule)
- return
- }
- //调换位置
- sch := models.Schedule{
- PatientId: schedule.PatientId,
- ModeId: schedule.ModeId,
- DialysisMachineName: schedule.DialysisMachineName,
- }
-
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
- filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(org_id, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(org_id, "透析器/灌流器")
-
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "-" + so.DialyzerPerfusionApparatus
-
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
-
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "-" + so.DialysisIrrigation
-
- } else {
- DialysisMachineName = so.DialysisIrrigation
-
- }
- }
- sch.DialysisMachineName = DialysisMachineName
-
- schedu := models.Schedule{
- PatientId: patient_id,
- ModeId: mode_id,
- DialysisMachineName: schedule.DialysisMachineName,
- }
- var DialysisMachineName1 string
- so1, _ := service.GetDialysisSolutionTwo(org_id, schedu.PatientId, schedu.ModeId)
- filedRecordOne1, _ := service.FindFiledBy(org_id, "透析器")
- filedRecordTwo1, _ := service.FindFiledBy(org_id, "灌流器")
- filedRecordThree1, _ := service.FindFiledBy(org_id, "透析器/灌流器")
-
- if filedRecordOne1.IsShow == 1 {
- DialysisMachineName1 = so1.DialysisDialyszers
- }
- if filedRecordThree1.IsShow == 1 {
- if len(DialysisMachineName1) > 0 {
- DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName1 = so1.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo1.IsShow == 1 {
- if len(DialysisMachineName1) > 0 {
- DialysisMachineName1 = DialysisMachineName1 + "-" + so1.DialysisIrrigation
- } else {
- DialysisMachineName1 = so1.DialysisIrrigation
- }
- }
- schedu.DialysisMachineName = DialysisMachineName1
- err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
- //记录日志
- byterequest, _ := json.Marshal(schedule)
- scheduleLog := models.XtScheduleLog{
- UserOrgId: org_id,
- RecordDate: schedule.ScheduleDate,
- Status: 1,
- PatientId: schedule.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- Source: "手机端修改调班",
- Module: 4,
- AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
- }
- service.UpdateRepeatSchStatus(org_id, schedule_date)
- service.CreateScheduleLog(scheduleLog)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- } else {
- var str string
- //查找该机构用的是什么透析器
- filedConfig, _ := service.GetFiledConfig(org_id)
- if filedConfig.ID > 0 {
- solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
- str = solutionType.DialyzerPerfusionApparatus
- } else {
- solutionType, _ := service.GetLastDialysisSolutionType(org_id, patient_id, mode_id)
- str = solutionType.DialysisDialyszers + "/" + solutionType.DialysisIrrigation
- }
- xtSchedule := models.Schedule{
- UserOrgId: org_id,
- PartitionId: numberlist.ZoneId,
- BedId: bed_id,
- PatientId: patient_id,
- ScheduleDate: schedule_date,
- ScheduleType: schedule_type,
- ScheduleWeek: schedule_week,
- ModeId: mode_id,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: 0,
- IsExport: 20000,
- DialysisMachineName: str,
- }
- var err error
- err = service.CreateSchedule(&xtSchedule, id)
- service.UpdateRepeatSchStatus(org_id, schedule_date)
- //记录日志
- byterequest, _ := json.Marshal(schedule)
- scheduleLog := models.XtScheduleLog{
- UserOrgId: org_id,
- RecordDate: schedule.ScheduleDate,
- Status: 1,
- PatientId: schedule.PatientId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- Source: "手机端新建调班",
- Module: 1,
- AdminUserId: c.GetMobileAdminUserInfo().AdminUser.Id,
- }
-
- service.CreateScheduleLog(scheduleLog)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
- }
-
- func (c *StaffScheduleApiController) UpdateMobileSchedule() {
-
- id_one, _ := c.GetInt64("id_one")
- id_two, _ := c.GetInt64("id_two")
- schedule_date, _ := c.GetInt64("schedule_date")
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
-
- mode_id, _ := c.GetInt64("mode_id")
- bed_id, _ := c.GetInt64("bed_id")
- zone_id, _ := c.GetInt64("zone_id")
- schedule_type, _ := c.GetInt64("schedule_type")
- orgId := c.GetMobileAdminUserInfo().Org.Id
-
- schedule, _ := service.GetSchedulePatientIdByPatient(id_one, schedule_date, orgId)
-
- if schedule.ID > 0 {
- service.UpdateMobileSchedule(id_two, mode_id, bed_id, zone_id, schedule_type, schedule.ID)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
|