dialysis_record_api_controller.go 106KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "github.com/jinzhu/gorm"
  6. "math"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "fmt"
  14. "github.com/astaxie/beego"
  15. )
  16. func DialysisRecordAPIControllerRegistRouter() {
  17. beego.Router("/api/dialysis/initdata", &DialysisRecordAPIController{}, "get:RecordInitData")
  18. beego.Router("/api/dialysis/schedules", &DialysisRecordAPIController{}, "get:GetSchedules")
  19. beego.Router("/api/dislysis/schedule", &DialysisRecordAPIController{}, "get:DialysisSchedule")
  20. beego.Router("/api/dislysis/monitor/edit", &DialysisRecordAPIController{}, "post:EditMonitor")
  21. beego.Router("/api/dialysis/start_record", &DialysisRecordAPIController{}, "post:StartDialysis")
  22. beego.Router("/api/dialysis/finish", &DialysisRecordAPIController{}, "post:FinishDialysis")
  23. beego.Router("/api/start_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyStartDialysis")
  24. beego.Router("/api/finish_dialysis/modify", &DialysisRecordAPIController{}, "post:ModifyFinishDialysis")
  25. }
  26. type DialysisRecordAPIController struct {
  27. BaseAuthAPIController
  28. }
  29. // /api/dialysis/initdata [get]
  30. func (this *DialysisRecordAPIController) RecordInitData() {
  31. adminInfo := this.GetAdminUserInfo()
  32. orgID := adminInfo.CurrentOrgId
  33. now := time.Now()
  34. ymdDate, _ := utils.ParseTimeStringToTime("2006-01-02", now.Format("2006-01-02"))
  35. schedules, getSchedulesErr := service.GetDialysisScheduals(orgID, ymdDate.Unix())
  36. if getSchedulesErr != nil {
  37. this.ErrorLog("获取排班信息失败:%v", getSchedulesErr)
  38. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  39. return
  40. }
  41. zones, getZonesErr := service.GetAllValidDeviceZones(orgID)
  42. if getZonesErr != nil {
  43. this.ErrorLog("获取全部分区失败:%v", getZonesErr)
  44. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  45. return
  46. }
  47. this.ServeSuccessJSON(map[string]interface{}{
  48. "schedules": schedules,
  49. "zones": zones,
  50. })
  51. }
  52. // /api/dialysis/schedules [get]
  53. // @param date:string (yyyy-mm-dd)
  54. func (this *DialysisRecordAPIController) GetSchedules() {
  55. schedualDate := this.GetString("date")
  56. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  57. if parseDateErr != nil {
  58. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. adminInfo := this.GetAdminUserInfo()
  62. orgID := adminInfo.CurrentOrgId
  63. schedules, err := service.GetDialysisScheduals(orgID, date.Unix())
  64. if err != nil {
  65. this.ErrorLog("获取排班信息失败:%v", err)
  66. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  67. } else {
  68. this.ServeSuccessJSON(map[string]interface{}{
  69. "schedules": schedules,
  70. })
  71. }
  72. }
  73. // /api/dislysis/schedule [get]
  74. // @param patient_id:int
  75. // @param date:string (yyyy-MM-dd)
  76. func (this *DialysisRecordAPIController) DialysisSchedule() {
  77. patientID, _ := this.GetInt64("patient_id")
  78. recordDateStr := this.GetString("date")
  79. if patientID <= 0 {
  80. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  81. return
  82. }
  83. if len(recordDateStr) == 0 {
  84. recordDateStr = time.Now().Format("2006-01-02")
  85. }
  86. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  87. if parseDateErr != nil {
  88. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. adminInfo := this.GetAdminUserInfo()
  93. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.CurrentOrgId, patientID)
  94. if getPatientErr != nil {
  95. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  96. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  97. return
  98. } else if patient == nil {
  99. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  100. return
  101. }
  102. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.CurrentOrgId, patientID, date.Unix())
  103. if getSchedualErr != nil {
  104. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  106. return
  107. }
  108. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  109. if getRTARErr != nil {
  110. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  112. return
  113. }
  114. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  115. fmt.Println("predialysisEvaluatiotion", predialysisEvaluation)
  116. if getPEErr != nil {
  117. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  119. return
  120. }
  121. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvices(adminInfo.CurrentOrgId, patientID, date.Unix())
  122. if getDoctorAdvicesErr != nil {
  123. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. return
  126. }
  127. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  128. if getDialysisOrderErr != nil {
  129. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  131. return
  132. }
  133. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.CurrentOrgId, patientID, date.Unix())
  134. if getDoubleCheckErr != nil {
  135. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  137. return
  138. }
  139. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.CurrentOrgId, patientID, date.Unix())
  140. if getMonitorRecordsErr != nil {
  141. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  143. return
  144. }
  145. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  146. if getAADErr != nil {
  147. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  149. return
  150. }
  151. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.CurrentOrgId, patientID, date.Unix())
  152. if getTreatmentSummaryErr != nil {
  153. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  155. return
  156. }
  157. admins, getAdminsErr := service.GetAllAdminUsers(adminInfo.CurrentOrgId, adminInfo.CurrentAppId)
  158. if getAdminsErr != nil {
  159. this.ErrorLog("获取医护列表失败:%v", getAdminsErr)
  160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  161. return
  162. }
  163. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, 0, 0)
  164. if getDevicesErr != nil {
  165. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. return
  168. }
  169. deviceNumbers, getDeviceNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  170. if getDeviceNumbersErr != nil {
  171. this.ErrorLog("获取床位号列表失败:%v", getDeviceNumbersErr)
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  173. return
  174. }
  175. lastPredialysisEvaluation, getLPEErr := service.GetLastTimePredialysisEvaluation(adminInfo.CurrentOrgId, patientID, date.Unix())
  176. if getLPEErr != nil {
  177. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  179. return
  180. }
  181. var lastMonitorRecord *models.MonitoringRecord
  182. lastMonitorRecord, getLastErr := service.GetLastMonitorRecord(adminInfo.CurrentOrgId, patientID, date.Unix())
  183. if getLastErr != nil {
  184. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  186. return
  187. }
  188. lastAssessmentAfterDislysis, getLAADErr := service.GetLastTimeAssessmentAfterDislysis(adminInfo.CurrentOrgId, patientID, date.Unix())
  189. if getLAADErr != nil {
  190. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  192. return
  193. }
  194. dialysisPrescribe, getDialysisPrescribeErr := service.GetDialysisPrescribe(adminInfo.CurrentOrgId, patientID, date.Unix())
  195. if getDialysisPrescribeErr != nil {
  196. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  198. return
  199. }
  200. dialysisSolution, getDialysisSolutionErr := service.GetDialysisSolution(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  201. if getDialysisSolutionErr != nil {
  202. this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  204. return
  205. }
  206. lastDialysisPrescribe, getDialysisPrescribeErr := service.GetLastDialysisPrescribeByModeId(adminInfo.CurrentOrgId, patientID, schedual.ModeId)
  207. if getDialysisPrescribeErr != nil {
  208. this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  210. return
  211. }
  212. systemDialysisPrescribe, getSystemDialysisPrescribeErr := service.GetSystemDialysisPrescribeByModeId(adminInfo.CurrentOrgId, schedual.ModeId)
  213. if getSystemDialysisPrescribeErr != nil {
  214. this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  216. return
  217. }
  218. if getLPEErr != nil {
  219. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
  224. if getDryErr != nil {
  225. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  230. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.CurrentOrgId)
  231. if record.IsOpen == 1 {
  232. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  233. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  234. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  235. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  236. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  237. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  238. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  239. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  240. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  241. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  242. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  243. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  244. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  245. niprocart_info, _ := service.FindWarehouseInfoByGoodType(niprocart_good_type_id, adminInfo.CurrentOrgId)
  246. jms_info, _ := service.FindWarehouseInfoByGoodType(jms_good_type_id, adminInfo.CurrentOrgId)
  247. fistula_needle_set_info, _ := service.FindWarehouseInfoByGoodType(fistula_needle_set_good_type_id, adminInfo.CurrentOrgId)
  248. fistula_needle_set_16_info, _ := service.FindWarehouseInfoByGoodType(fistula_needle_set_16_good_type_id, adminInfo.CurrentOrgId)
  249. hemoperfusion_info, _ := service.FindWarehouseInfoByGoodType(hemoperfusion_good_type_id, adminInfo.CurrentOrgId)
  250. dialyser_sterilised_info, _ := service.FindWarehouseInfoByGoodType(dialyser_sterilised_good_type_id, adminInfo.CurrentOrgId)
  251. filtryzer_info, _ := service.FindWarehouseInfoByGoodType(filtryzer_good_type_id, adminInfo.CurrentOrgId)
  252. dialyzers_info, _ := service.FindWarehouseInfoByGoodType(dialyzers_good_type_id, adminInfo.CurrentOrgId)
  253. injector_info, _ := service.FindWarehouseInfoByGoodType(injector_good_type_id, adminInfo.CurrentOrgId)
  254. bloodlines_info, _ := service.FindWarehouseInfoByGoodType(bloodlines_good_type_id, adminInfo.CurrentOrgId)
  255. tubingHemodialysis_info, _ := service.FindWarehouseInfoByGoodType(tubingHemodialysis_good_type_id, adminInfo.CurrentOrgId)
  256. safe_package_info, _ := service.FindWarehouseInfoByGoodType(safe_package_good_type_id, adminInfo.CurrentOrgId)
  257. aliquid_info, _ := service.FindWarehouseInfoByGoodType(aliquid_good_type_id, adminInfo.CurrentOrgId)
  258. returnData := map[string]interface{}{
  259. "patient": patient,
  260. "schedual": schedual,
  261. "prescription": dialysisPrescribe,
  262. "solution": dialysisSolution,
  263. "receiver_treatment_access": receiverTreatmentAccess,
  264. "predialysis_evaluation": predialysisEvaluation,
  265. "doctor_advices": doctorAdvices,
  266. "double_check": doubleCheck,
  267. "assessment_after_dislysis": assessmentAfterDislysis,
  268. "treatment_summary": treatmentSummary,
  269. "monitor_records": monitorRecords,
  270. "dialysis_order": dialysisOrder,
  271. "doctors": admins,
  272. "devices": devices,
  273. "device_numbers": deviceNumbers,
  274. "niprocart_info": niprocart_info,
  275. "jms_info": jms_info,
  276. "fistula_needle_set_info": fistula_needle_set_info,
  277. "fistula_needle_set_16_info": fistula_needle_set_16_info,
  278. "hemoperfusion_info": hemoperfusion_info,
  279. "dialyser_sterilised_info": dialyser_sterilised_info,
  280. "filtryzer_info": filtryzer_info,
  281. "dialyzers_info": dialyzers_info,
  282. "injector_info": injector_info,
  283. "bloodlines_info": bloodlines_info,
  284. "tubingHemodialysis_info": tubingHemodialysis_info,
  285. "safe_package_info": safe_package_info,
  286. "aliquid_info": aliquid_info,
  287. "config": record,
  288. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  289. "lastMonitorRecord": lastMonitorRecord,
  290. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  291. "lastDialysisPrescribe": lastDialysisPrescribe,
  292. "lastDryWeightDislysis": lastDryWeightDislysis,
  293. "headNurses": headNurses,
  294. "system_prescribe": systemDialysisPrescribe,
  295. }
  296. this.ServeSuccessJSON(returnData)
  297. } else {
  298. returnData := map[string]interface{}{
  299. "patient": patient,
  300. "schedual": schedual,
  301. "prescription": dialysisPrescribe,
  302. "solution": dialysisSolution,
  303. "receiver_treatment_access": receiverTreatmentAccess,
  304. "predialysis_evaluation": predialysisEvaluation,
  305. "doctor_advices": doctorAdvices,
  306. "double_check": doubleCheck,
  307. "assessment_after_dislysis": assessmentAfterDislysis,
  308. "treatment_summary": treatmentSummary,
  309. "monitor_records": monitorRecords,
  310. "dialysis_order": dialysisOrder,
  311. "doctors": admins,
  312. "devices": devices,
  313. "device_numbers": deviceNumbers,
  314. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  315. "lastMonitorRecord": lastMonitorRecord,
  316. "lastAssessmentAfterDislysis": lastAssessmentAfterDislysis,
  317. "lastDialysisPrescribe": lastDialysisPrescribe,
  318. "lastDryWeightDislysis": lastDryWeightDislysis,
  319. "headNurses": headNurses,
  320. "system_prescribe": systemDialysisPrescribe,
  321. }
  322. this.ServeSuccessJSON(returnData)
  323. }
  324. }
  325. type EditMonitorParamObject struct {
  326. ID int64 `json:"id"`
  327. MonitoringDate int64 `json:"monitoring_date"`
  328. OperateTime int64 `json:"operate_time"`
  329. // MonitoringTime string `json:"monitoring_time"`
  330. SystolicBP float64 `json:"systolic_bp"`
  331. DiastolicBP float64 `json:"diastolic_bp"`
  332. PulseFrequency float64 `json:"pulse_frequency"`
  333. BreathingRated float64 `json:"breathing_rated"`
  334. BloodFlowVolume float64 `json:"blood_flow_volume"`
  335. VenousPressure float64 `json:"venous_pressure"`
  336. TransmembranePressure float64 `json:"transmembrane_pressure"`
  337. UltrafiltrationVolume float64 `json:"ultrafiltration_volume"`
  338. UltrafiltrationRate float64 `json:"ultrafiltration_rate"`
  339. ArterialPressure float64 `json:"arterial_pressure"`
  340. SodiumConcentration float64 `json:"sodium_concentration"`
  341. DialysateTemperature float64 `json:"dialysate_temperature"`
  342. Temperature float64 `json:"temperature"`
  343. ReplacementRate float64 `json:"replacement_rate"`
  344. DisplacementQuantity float64 `json:"displacement_quantity"`
  345. KTV float64 `json:"ktv"`
  346. Symptom string `json:"symptom"`
  347. Dispose string `json:"dispose"`
  348. Result string `json:"result"`
  349. Conductivity float64 `json:"conductivity"`
  350. DisplacementFlowQuantity float64 `json:"displacement_flow_quantity"`
  351. BloodOxygenSaturation string `gorm:"column:blood_oxygen_saturation" json:"blood_oxygen_saturation" form:"blood_oxygen_saturation"`
  352. }
  353. // /api/dislysis/monitor/edit [post]
  354. // @param patient_id:int 患者id
  355. // @param schedule_date:int 排班日期
  356. // 下面的参数放到 body
  357. // @param id?:int 监测记录ID(id为0时为创建记录,不为0时为修改记录)
  358. // @param monitoring_date:int 排班日期
  359. // @param operate_time:int 实际测量日期
  360. // @param monitoring_time:string (HH:mm) 监测时间 废弃
  361. // @param systolic_bp?:float 收缩压
  362. // @param diastolic_bp?:float 舒张压
  363. // @param pulse_frequency?:float 心率
  364. // @param breathing_rated?:float 呼吸频率
  365. // @param blood_flow_volume?:float 血流量
  366. // @param venous_pressure?:float 静脉压
  367. // @param transmembrane_pressure?:float 跨膜压
  368. // @param ultrafiltration_volume?:float 超滤量
  369. // @param ultrafiltration_rate?:float 超滤率
  370. // @param arterial_pressure?:float 动脉压
  371. // @param sodium_concentration?:float 钠浓度
  372. // @param dialysate_temperature?:float 透析液温度
  373. // @param replacement_rate?:float 置换率
  374. // @param displacement_quantity?:float 置换量
  375. // @param ktv?:float KT/V
  376. // @param symptom?:string 病情变化
  377. // @param dispose?:string 处理
  378. // @param result?:string 结果
  379. func (this *DialysisRecordAPIController) EditMonitor() {
  380. patientID, _ := this.GetInt64("patient_id")
  381. scheduleDate, _ := this.GetInt64("schedule_date")
  382. if patientID <= 0 || scheduleDate <= 0 {
  383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  384. return
  385. }
  386. var monitorParam EditMonitorParamObject
  387. if parseErr := json.Unmarshal(this.Ctx.Input.RequestBody, &monitorParam); parseErr != nil {
  388. this.ErrorLog("参数解析失败:%v", parseErr)
  389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  390. return
  391. }
  392. if monitorParam.MonitoringDate != scheduleDate {
  393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. adminUserInfo := this.GetAdminUserInfo()
  397. schedule, getScheduleErr := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  398. if getScheduleErr != nil {
  399. this.ErrorLog("获取排班信息失败:%v", getScheduleErr)
  400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  401. return
  402. } else if schedule == nil {
  403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  404. return
  405. }
  406. // TODO 其实这里合理的逻辑是“透析记录存在的情况下才能添加监测记录的”
  407. dialysisOrder, getDialysisOrderErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, scheduleDate)
  408. if getDialysisOrderErr != nil {
  409. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  411. return
  412. }
  413. orderID := int64(0)
  414. if dialysisOrder != nil {
  415. orderID = dialysisOrder.ID
  416. }
  417. if monitorParam.ID <= 0 { // 新建记录
  418. monitor := models.MonitoringRecord{
  419. UserOrgId: adminUserInfo.CurrentOrgId,
  420. PatientId: patientID,
  421. DialysisOrderId: orderID,
  422. MonitoringDate: monitorParam.MonitoringDate,
  423. OperateTime: monitorParam.OperateTime,
  424. // MonitoringTime: monitorParam.MonitoringTime,
  425. PulseFrequency: monitorParam.PulseFrequency,
  426. BreathingRate: monitorParam.BreathingRated,
  427. SystolicBloodPressure: monitorParam.SystolicBP,
  428. DiastolicBloodPressure: monitorParam.DiastolicBP,
  429. BloodFlowVolume: monitorParam.BloodFlowVolume,
  430. VenousPressure: monitorParam.VenousPressure,
  431. ArterialPressure: monitorParam.ArterialPressure,
  432. TransmembranePressure: monitorParam.TransmembranePressure,
  433. UltrafiltrationRate: monitorParam.UltrafiltrationRate,
  434. UltrafiltrationVolume: monitorParam.UltrafiltrationVolume,
  435. SodiumConcentration: monitorParam.SodiumConcentration,
  436. DialysateTemperature: monitorParam.DialysateTemperature,
  437. Temperature: monitorParam.Temperature,
  438. ReplacementRate: monitorParam.ReplacementRate,
  439. DisplacementQuantity: monitorParam.DisplacementQuantity,
  440. Ktv: monitorParam.KTV,
  441. Symptom: monitorParam.Symptom,
  442. Dispose: monitorParam.Dispose,
  443. Result: monitorParam.Result,
  444. MonitoringNurse: adminUserInfo.AdminUser.Id,
  445. Conductivity: monitorParam.Conductivity,
  446. DisplacementFlowQuantity: monitorParam.DisplacementFlowQuantity,
  447. Status: 1,
  448. CreatedTime: time.Now().Unix(),
  449. UpdatedTime: time.Now().Unix(),
  450. BloodOxygenSaturation: monitorParam.BloodOxygenSaturation,
  451. Creator: adminUserInfo.AdminUser.Id,
  452. }
  453. createErr := service.CreateMonitor(&monitor)
  454. if createErr != nil {
  455. this.ErrorLog("创建监测记录失败:%v", createErr)
  456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  457. return
  458. }
  459. this.ServeSuccessJSON(map[string]interface{}{
  460. "monitor": monitor,
  461. })
  462. } else { // 修改记录
  463. monitor, getMonitorErr := service.GetMonitor(adminUserInfo.CurrentOrgId, patientID, monitorParam.ID)
  464. if getMonitorErr != nil {
  465. this.ErrorLog("获取透析监测记录失败:%v", getMonitorErr)
  466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  467. return
  468. } else if monitor == nil {
  469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorNotExist)
  470. return
  471. }
  472. //if monitor.MonitoringNurse != adminUserInfo.AdminUser.Id {
  473. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  474. // if getPermissionErr != nil {
  475. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  476. // return
  477. // } else if headNursePermission == nil {
  478. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  479. // return
  480. // }
  481. //}
  482. monitor.OperateTime = monitorParam.OperateTime
  483. monitor.PulseFrequency = monitorParam.PulseFrequency
  484. monitor.BreathingRate = monitorParam.BreathingRated
  485. monitor.SystolicBloodPressure = monitorParam.SystolicBP
  486. monitor.DiastolicBloodPressure = monitorParam.DiastolicBP
  487. monitor.BloodFlowVolume = monitorParam.BloodFlowVolume
  488. monitor.VenousPressure = monitorParam.VenousPressure
  489. monitor.ArterialPressure = monitorParam.ArterialPressure
  490. monitor.TransmembranePressure = monitorParam.TransmembranePressure
  491. monitor.UltrafiltrationRate = monitorParam.UltrafiltrationRate
  492. monitor.UltrafiltrationVolume = monitorParam.UltrafiltrationVolume
  493. monitor.SodiumConcentration = monitorParam.SodiumConcentration
  494. monitor.DialysateTemperature = monitorParam.DialysateTemperature
  495. monitor.Temperature = monitorParam.Temperature
  496. monitor.ReplacementRate = monitorParam.ReplacementRate
  497. monitor.DisplacementQuantity = monitorParam.DisplacementQuantity
  498. monitor.Conductivity = monitorParam.Conductivity
  499. monitor.DisplacementFlowQuantity = monitorParam.DisplacementFlowQuantity
  500. monitor.Ktv = monitorParam.KTV
  501. monitor.Symptom = monitorParam.Symptom
  502. monitor.Dispose = monitorParam.Dispose
  503. monitor.Result = monitorParam.Result
  504. monitor.MonitoringNurse = adminUserInfo.AdminUser.Id
  505. monitor.UpdatedTime = time.Now().Unix()
  506. monitor.Modify = adminUserInfo.AdminUser.Id
  507. monitor.BloodOxygenSaturation = monitorParam.BloodOxygenSaturation
  508. updateErr := service.UpdateMonitor(monitor)
  509. if updateErr != nil {
  510. this.ErrorLog("修改透析监测记录失败:%v", updateErr)
  511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  512. return
  513. }
  514. this.ServeSuccessJSON(map[string]interface{}{
  515. "monitor": monitor,
  516. })
  517. }
  518. }
  519. // /api/dialysis/start_record [post]
  520. // @param patient_id:int
  521. // @param date:string 排班时间 (yyyy-mm-dd)
  522. // @param nurse:int 上机护士
  523. // @param bed:int 上机床位号
  524. func (this *DialysisRecordAPIController) StartDialysis() {
  525. patientID, _ := this.GetInt64("patient_id")
  526. recordDateStr := this.GetString("date")
  527. nurseID, _ := this.GetInt64("nurse")
  528. punctureNurseId, _ := this.GetInt64("puncture_nurse")
  529. startDateStr := this.GetString("start_time")
  530. blood_drawing, _ := this.GetInt64("blood_drawing")
  531. schedual_type, _ := this.GetInt64("schedual_type")
  532. bedID, _ := this.GetInt64("bed")
  533. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. return
  536. }
  537. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  538. if parseErr != nil {
  539. this.ErrorLog("时间解析失败:%v", parseErr)
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. startDate, parseErr := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  544. if parseErr != nil {
  545. this.ErrorLog("时间解析失败:%v", parseErr)
  546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. adminUserInfo := this.GetAdminUserInfo()
  550. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  551. if getPatientErr != nil {
  552. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  554. return
  555. } else if patient == nil {
  556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  557. return
  558. }
  559. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  560. if getNurseErr != nil {
  561. this.ErrorLog("获取护士失败:%v", getNurseErr)
  562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  563. return
  564. } else if nurse == nil {
  565. this.ErrorLog("护士不存在")
  566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. nurse, getNurseErr = service.GetAdminUserByUserID(punctureNurseId)
  570. if getNurseErr != nil {
  571. this.ErrorLog("获取护士失败:%v", getNurseErr)
  572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  573. return
  574. } else if nurse == nil {
  575. this.ErrorLog("护士不存在")
  576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  577. return
  578. }
  579. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  580. if getDeviceNumberErr != nil {
  581. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  583. return
  584. } else if deviceNumber == nil {
  585. this.ErrorLog("床位号不存在")
  586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  587. return
  588. }
  589. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  590. if getRecordErr != nil {
  591. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  593. return
  594. } else if dialysisRecord != nil {
  595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  596. return
  597. }
  598. template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  599. //是否启动自动扣减功能
  600. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  601. //启动的话
  602. if config.IsOpen == 1 {
  603. niprocart, _ := beego.AppConfig.Int64("niprocart")
  604. jms, _ := beego.AppConfig.Int64("jms")
  605. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  606. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  607. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  608. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  609. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  610. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  611. injector, _ := beego.AppConfig.Int64("injector")
  612. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  613. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  614. safe_package, _ := beego.AppConfig.Int64("package")
  615. aliquid, _ := beego.AppConfig.Int64("aliquid")
  616. //库存自动扣减功能
  617. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  618. if prescription.ID > 0 {
  619. out, err := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, recordDate.Unix())
  620. if err == gorm.ErrRecordNotFound {
  621. //没有记录,则创建出库单
  622. timeStr := time.Now().Format("2006-01-02")
  623. timeArr := strings.Split(timeStr, "-")
  624. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  625. total = total + 1
  626. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  627. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  628. number = number + total
  629. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  630. creater := adminUserInfo.AdminUser.Id
  631. warehouseOut := models.WarehouseOut{
  632. WarehouseOutOrderNumber: warehousing_out_order,
  633. OperationTime: time.Now().Unix(),
  634. OrgId: adminUserInfo.CurrentOrgId,
  635. Creater: creater,
  636. Ctime: time.Now().Unix(),
  637. Status: 1,
  638. WarehouseOutTime: recordDate.Unix(),
  639. Dealer: 0,
  640. Manufacturer: 0,
  641. Type: 1,
  642. IsSys: 1,
  643. }
  644. err := service.AddSigleWarehouseOut(&warehouseOut)
  645. if err != nil {
  646. utils.TraceLog("创建出库单失败 err = %v", err)
  647. } else {
  648. if prescription.Niprocart > 0 {
  649. warehouseOutInfo := &models.WarehouseOutInfo{
  650. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  651. WarehouseOutId: warehouseOut.ID,
  652. Count: 1,
  653. Status: 1,
  654. Ctime: time.Now().Unix(),
  655. Remark: "",
  656. OrgId: adminUserInfo.CurrentOrgId,
  657. Type: 1,
  658. Manufacturer: 0,
  659. Dealer: 0,
  660. IsSys: 1,
  661. SysRecordTime: startDate.Unix(),
  662. }
  663. //查出入库记录中最后一条记录
  664. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.CurrentOrgId)
  665. warehouseOutInfo.Price = stockInInfo.Price
  666. warehouseOutInfo.GoodId = prescription.Niprocart
  667. warehouseOutInfo.GoodTypeId = niprocart
  668. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  669. if err == nil {
  670. details := &models.AutomaticReduceDetail{
  671. WarehouseOutId: warehouseOutInfo.ID,
  672. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  673. PatientId: patientID,
  674. Ctime: time.Now().Unix(),
  675. Mtime: time.Now().Unix(),
  676. Status: 1,
  677. RecordTime: startDate.Unix(),
  678. OrgId: adminUserInfo.CurrentOrgId,
  679. GoodId: prescription.Niprocart,
  680. GoodTypeId: niprocart,
  681. }
  682. service.AddSigleAutoReduceRecordInfo(details)
  683. }
  684. }
  685. if prescription.Jms > 0 {
  686. warehouseOutInfo := &models.WarehouseOutInfo{
  687. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  688. WarehouseOutId: warehouseOut.ID,
  689. Count: 1,
  690. Status: 1,
  691. Ctime: time.Now().Unix(),
  692. Remark: "",
  693. OrgId: adminUserInfo.CurrentOrgId,
  694. Type: 1,
  695. Manufacturer: 0,
  696. Dealer: 0,
  697. IsSys: 1,
  698. SysRecordTime: startDate.Unix(),
  699. }
  700. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.CurrentOrgId)
  701. warehouseOutInfo.Price = stockInInfo.Price
  702. warehouseOutInfo.GoodId = prescription.Jms
  703. warehouseOutInfo.GoodTypeId = jms
  704. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  705. if err == nil {
  706. details := &models.AutomaticReduceDetail{
  707. WarehouseOutId: warehouseOutInfo.ID,
  708. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  709. PatientId: patientID,
  710. Ctime: time.Now().Unix(),
  711. Mtime: time.Now().Unix(),
  712. Status: 1,
  713. RecordTime: startDate.Unix(),
  714. OrgId: adminUserInfo.CurrentOrgId,
  715. GoodId: prescription.Jms,
  716. GoodTypeId: jms,
  717. }
  718. service.AddSigleAutoReduceRecordInfo(details)
  719. }
  720. }
  721. if prescription.FistulaNeedleSet > 0 {
  722. warehouseOutInfo := &models.WarehouseOutInfo{
  723. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  724. WarehouseOutId: warehouseOut.ID,
  725. Count: 1,
  726. Status: 1,
  727. Ctime: time.Now().Unix(),
  728. Remark: "",
  729. OrgId: adminUserInfo.CurrentOrgId,
  730. Type: 1,
  731. Manufacturer: 0,
  732. Dealer: 0,
  733. IsSys: 1,
  734. SysRecordTime: startDate.Unix(),
  735. }
  736. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.CurrentOrgId)
  737. warehouseOutInfo.Price = stockInInfo.Price
  738. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  739. warehouseOutInfo.GoodTypeId = fistula_needle_set
  740. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  741. if err == nil {
  742. details := &models.AutomaticReduceDetail{
  743. WarehouseOutId: warehouseOutInfo.ID,
  744. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  745. PatientId: patientID,
  746. Ctime: time.Now().Unix(),
  747. Mtime: time.Now().Unix(),
  748. Status: 1,
  749. RecordTime: startDate.Unix(),
  750. OrgId: adminUserInfo.CurrentOrgId,
  751. GoodId: prescription.FistulaNeedleSet,
  752. GoodTypeId: fistula_needle_set,
  753. }
  754. service.AddSigleAutoReduceRecordInfo(details)
  755. }
  756. }
  757. if prescription.FistulaNeedleSet16 > 0 {
  758. warehouseOutInfo := &models.WarehouseOutInfo{
  759. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  760. WarehouseOutId: warehouseOut.ID,
  761. Count: 1,
  762. Status: 1,
  763. Ctime: time.Now().Unix(),
  764. Remark: "",
  765. OrgId: adminUserInfo.CurrentOrgId,
  766. Type: 1,
  767. Manufacturer: 0,
  768. Dealer: 0,
  769. IsSys: 1,
  770. SysRecordTime: startDate.Unix(),
  771. }
  772. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.CurrentOrgId)
  773. warehouseOutInfo.Price = stockInInfo.Price
  774. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  775. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  776. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  777. if err == nil {
  778. details := &models.AutomaticReduceDetail{
  779. WarehouseOutId: warehouseOutInfo.ID,
  780. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  781. PatientId: patientID,
  782. Ctime: time.Now().Unix(),
  783. Mtime: time.Now().Unix(),
  784. Status: 1,
  785. RecordTime: startDate.Unix(),
  786. OrgId: adminUserInfo.CurrentOrgId,
  787. GoodId: prescription.FistulaNeedleSet16,
  788. GoodTypeId: fistula_needle_set_16,
  789. }
  790. service.AddSigleAutoReduceRecordInfo(details)
  791. }
  792. }
  793. if prescription.Hemoperfusion > 0 {
  794. warehouseOutInfo := &models.WarehouseOutInfo{
  795. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  796. WarehouseOutId: warehouseOut.ID,
  797. Count: 1,
  798. Status: 1,
  799. Ctime: time.Now().Unix(),
  800. Remark: "",
  801. OrgId: adminUserInfo.CurrentOrgId,
  802. Type: 1,
  803. Manufacturer: 0,
  804. Dealer: 0,
  805. IsSys: 1,
  806. SysRecordTime: startDate.Unix(),
  807. }
  808. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.CurrentOrgId)
  809. warehouseOutInfo.Price = stockInInfo.Price
  810. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  811. warehouseOutInfo.GoodTypeId = hemoperfusion
  812. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  813. if err == nil {
  814. details := &models.AutomaticReduceDetail{
  815. WarehouseOutId: warehouseOutInfo.ID,
  816. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  817. PatientId: patientID,
  818. Ctime: time.Now().Unix(),
  819. Mtime: time.Now().Unix(),
  820. Status: 1,
  821. RecordTime: startDate.Unix(),
  822. OrgId: adminUserInfo.CurrentOrgId,
  823. GoodId: prescription.Hemoperfusion,
  824. GoodTypeId: hemoperfusion,
  825. }
  826. service.AddSigleAutoReduceRecordInfo(details)
  827. }
  828. }
  829. if prescription.DialyserSterilised > 0 {
  830. warehouseOutInfo := &models.WarehouseOutInfo{
  831. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  832. WarehouseOutId: warehouseOut.ID,
  833. Count: 1,
  834. Status: 1,
  835. Ctime: time.Now().Unix(),
  836. Remark: "",
  837. OrgId: adminUserInfo.CurrentOrgId,
  838. Type: 1,
  839. Manufacturer: 0,
  840. Dealer: 0,
  841. IsSys: 1,
  842. SysRecordTime: startDate.Unix(),
  843. }
  844. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.CurrentOrgId)
  845. warehouseOutInfo.Price = stockInInfo.Price
  846. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  847. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  848. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  849. if err == nil {
  850. details := &models.AutomaticReduceDetail{
  851. WarehouseOutId: warehouseOutInfo.ID,
  852. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  853. PatientId: patientID,
  854. Ctime: time.Now().Unix(),
  855. Mtime: time.Now().Unix(),
  856. Status: 1,
  857. RecordTime: startDate.Unix(),
  858. OrgId: adminUserInfo.CurrentOrgId,
  859. GoodId: prescription.DialyserSterilised,
  860. GoodTypeId: dialyser_sterilised,
  861. }
  862. service.AddSigleAutoReduceRecordInfo(details)
  863. }
  864. }
  865. if prescription.Filtryzer > 0 {
  866. warehouseOutInfo := &models.WarehouseOutInfo{
  867. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  868. WarehouseOutId: warehouseOut.ID,
  869. Count: 1,
  870. Status: 1,
  871. Ctime: time.Now().Unix(),
  872. Remark: "",
  873. OrgId: adminUserInfo.CurrentOrgId,
  874. Type: 1,
  875. Manufacturer: 0,
  876. Dealer: 0,
  877. IsSys: 1,
  878. SysRecordTime: startDate.Unix(),
  879. }
  880. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.CurrentOrgId)
  881. warehouseOutInfo.Price = stockInInfo.Price
  882. warehouseOutInfo.GoodId = prescription.Filtryzer
  883. warehouseOutInfo.GoodTypeId = filtryzer
  884. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  885. if err == nil {
  886. details := &models.AutomaticReduceDetail{
  887. WarehouseOutId: warehouseOutInfo.ID,
  888. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  889. PatientId: patientID,
  890. Ctime: time.Now().Unix(),
  891. Mtime: time.Now().Unix(),
  892. Status: 1,
  893. RecordTime: startDate.Unix(),
  894. OrgId: adminUserInfo.CurrentOrgId,
  895. GoodId: prescription.Filtryzer,
  896. GoodTypeId: filtryzer,
  897. }
  898. service.AddSigleAutoReduceRecordInfo(details)
  899. }
  900. }
  901. if prescription.Dialyzers > 0 {
  902. warehouseOutInfo := &models.WarehouseOutInfo{
  903. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  904. WarehouseOutId: warehouseOut.ID,
  905. Count: 1,
  906. Status: 1,
  907. Ctime: time.Now().Unix(),
  908. Remark: "",
  909. OrgId: adminUserInfo.CurrentOrgId,
  910. Type: 1,
  911. Manufacturer: 0,
  912. Dealer: 0,
  913. IsSys: 1,
  914. SysRecordTime: startDate.Unix(),
  915. }
  916. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.CurrentOrgId)
  917. warehouseOutInfo.Price = stockInInfo.Price
  918. warehouseOutInfo.GoodId = prescription.Dialyzers
  919. warehouseOutInfo.GoodTypeId = dialyzers
  920. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  921. if err == nil {
  922. details := &models.AutomaticReduceDetail{
  923. WarehouseOutId: warehouseOutInfo.ID,
  924. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  925. PatientId: patientID,
  926. Ctime: time.Now().Unix(),
  927. Mtime: time.Now().Unix(),
  928. Status: 1,
  929. RecordTime: startDate.Unix(),
  930. OrgId: adminUserInfo.CurrentOrgId,
  931. GoodId: prescription.Dialyzers,
  932. GoodTypeId: dialyzers,
  933. }
  934. service.AddSigleAutoReduceRecordInfo(details)
  935. }
  936. }
  937. if prescription.Injector > 0 {
  938. warehouseOutInfo := &models.WarehouseOutInfo{
  939. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  940. WarehouseOutId: warehouseOut.ID,
  941. Count: 1,
  942. Status: 1,
  943. Ctime: time.Now().Unix(),
  944. Remark: "",
  945. OrgId: adminUserInfo.CurrentOrgId,
  946. Type: 1,
  947. Manufacturer: 0,
  948. Dealer: 0,
  949. IsSys: 1,
  950. SysRecordTime: startDate.Unix(),
  951. }
  952. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.CurrentOrgId)
  953. warehouseOutInfo.Price = stockInInfo.Price
  954. warehouseOutInfo.GoodId = prescription.Injector
  955. warehouseOutInfo.GoodTypeId = injector
  956. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  957. if err == nil {
  958. details := &models.AutomaticReduceDetail{
  959. WarehouseOutId: warehouseOutInfo.ID,
  960. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  961. PatientId: patientID,
  962. Ctime: time.Now().Unix(),
  963. Mtime: time.Now().Unix(),
  964. Status: 1,
  965. RecordTime: startDate.Unix(),
  966. OrgId: adminUserInfo.CurrentOrgId,
  967. GoodId: prescription.Injector,
  968. GoodTypeId: injector,
  969. }
  970. service.AddSigleAutoReduceRecordInfo(details)
  971. }
  972. }
  973. if prescription.Bloodlines > 0 {
  974. warehouseOutInfo := &models.WarehouseOutInfo{
  975. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  976. WarehouseOutId: warehouseOut.ID,
  977. Count: 1,
  978. Status: 1,
  979. Ctime: time.Now().Unix(),
  980. Remark: "",
  981. OrgId: adminUserInfo.CurrentOrgId,
  982. Type: 1,
  983. Manufacturer: 0,
  984. Dealer: 0,
  985. IsSys: 1,
  986. SysRecordTime: startDate.Unix(),
  987. }
  988. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.CurrentOrgId)
  989. warehouseOutInfo.Price = stockInInfo.Price
  990. warehouseOutInfo.GoodId = prescription.Bloodlines
  991. warehouseOutInfo.GoodTypeId = bloodlines
  992. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  993. if err == nil {
  994. details := &models.AutomaticReduceDetail{
  995. WarehouseOutId: warehouseOutInfo.ID,
  996. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  997. PatientId: patientID,
  998. Ctime: time.Now().Unix(),
  999. Mtime: time.Now().Unix(),
  1000. Status: 1,
  1001. RecordTime: startDate.Unix(),
  1002. OrgId: adminUserInfo.CurrentOrgId,
  1003. GoodId: prescription.Bloodlines,
  1004. GoodTypeId: bloodlines,
  1005. }
  1006. service.AddSigleAutoReduceRecordInfo(details)
  1007. }
  1008. }
  1009. if prescription.TubingHemodialysis > 0 {
  1010. warehouseOutInfo := &models.WarehouseOutInfo{
  1011. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1012. WarehouseOutId: warehouseOut.ID,
  1013. Count: 1,
  1014. Status: 1,
  1015. Ctime: time.Now().Unix(),
  1016. Remark: "",
  1017. OrgId: adminUserInfo.CurrentOrgId,
  1018. Type: 1,
  1019. Manufacturer: 0,
  1020. Dealer: 0,
  1021. IsSys: 1,
  1022. SysRecordTime: startDate.Unix(),
  1023. }
  1024. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.CurrentOrgId)
  1025. warehouseOutInfo.Price = stockInInfo.Price
  1026. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  1027. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  1028. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1029. if err == nil {
  1030. details := &models.AutomaticReduceDetail{
  1031. WarehouseOutId: warehouseOutInfo.ID,
  1032. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1033. PatientId: patientID,
  1034. Ctime: time.Now().Unix(),
  1035. Mtime: time.Now().Unix(),
  1036. Status: 1,
  1037. RecordTime: startDate.Unix(),
  1038. OrgId: adminUserInfo.CurrentOrgId,
  1039. GoodId: prescription.TubingHemodialysis,
  1040. GoodTypeId: tubingHemodialysis,
  1041. }
  1042. service.AddSigleAutoReduceRecordInfo(details)
  1043. }
  1044. }
  1045. if prescription.Package > 0 {
  1046. warehouseOutInfo := &models.WarehouseOutInfo{
  1047. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1048. WarehouseOutId: warehouseOut.ID,
  1049. Count: 1,
  1050. Status: 1,
  1051. Ctime: time.Now().Unix(),
  1052. Remark: "",
  1053. OrgId: adminUserInfo.CurrentOrgId,
  1054. Type: 1,
  1055. Manufacturer: 0,
  1056. Dealer: 0,
  1057. IsSys: 1,
  1058. SysRecordTime: startDate.Unix(),
  1059. }
  1060. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.CurrentOrgId)
  1061. warehouseOutInfo.Price = stockInInfo.Price
  1062. warehouseOutInfo.GoodId = prescription.Package
  1063. warehouseOutInfo.GoodTypeId = safe_package
  1064. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1065. if err == nil {
  1066. details := &models.AutomaticReduceDetail{
  1067. WarehouseOutId: warehouseOutInfo.ID,
  1068. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1069. PatientId: patientID,
  1070. Ctime: time.Now().Unix(),
  1071. Mtime: time.Now().Unix(),
  1072. Status: 1,
  1073. RecordTime: startDate.Unix(),
  1074. OrgId: adminUserInfo.CurrentOrgId,
  1075. GoodId: prescription.Package,
  1076. GoodTypeId: safe_package,
  1077. }
  1078. service.AddSigleAutoReduceRecordInfo(details)
  1079. }
  1080. }
  1081. if prescription.ALiquid > 0 {
  1082. warehouseOutInfo := &models.WarehouseOutInfo{
  1083. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1084. WarehouseOutId: warehouseOut.ID,
  1085. Count: 1,
  1086. Status: 1,
  1087. Ctime: time.Now().Unix(),
  1088. Remark: "",
  1089. OrgId: adminUserInfo.CurrentOrgId,
  1090. Type: 1,
  1091. Manufacturer: 0,
  1092. Dealer: 0,
  1093. IsSys: 1,
  1094. SysRecordTime: startDate.Unix(),
  1095. }
  1096. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.CurrentOrgId)
  1097. warehouseOutInfo.Price = stockInInfo.Price
  1098. warehouseOutInfo.GoodId = prescription.ALiquid
  1099. warehouseOutInfo.GoodTypeId = aliquid
  1100. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1101. if err == nil {
  1102. details := &models.AutomaticReduceDetail{
  1103. WarehouseOutId: warehouseOutInfo.ID,
  1104. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1105. PatientId: patientID,
  1106. Ctime: time.Now().Unix(),
  1107. Mtime: time.Now().Unix(),
  1108. Status: 1,
  1109. RecordTime: startDate.Unix(),
  1110. OrgId: adminUserInfo.CurrentOrgId,
  1111. GoodId: prescription.ALiquid,
  1112. GoodTypeId: aliquid,
  1113. }
  1114. service.AddSigleAutoReduceRecordInfo(details)
  1115. }
  1116. }
  1117. }
  1118. } else if err == nil {
  1119. if out.ID > 0 {
  1120. if prescription.Niprocart > 0 {
  1121. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, niprocart, prescription.Niprocart, out.WarehouseOutOrderNumber)
  1122. if err == gorm.ErrRecordNotFound {
  1123. warehouseOutInfo := &models.WarehouseOutInfo{
  1124. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1125. WarehouseOutId: out.ID,
  1126. Status: 1,
  1127. Ctime: time.Now().Unix(),
  1128. Remark: "",
  1129. OrgId: adminUserInfo.CurrentOrgId,
  1130. Type: 1,
  1131. Manufacturer: 0,
  1132. Dealer: 0,
  1133. IsSys: 1,
  1134. SysRecordTime: startDate.Unix(),
  1135. }
  1136. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.CurrentOrgId)
  1137. warehouseOutInfo.Price = stockInInfo.Price
  1138. warehouseOutInfo.GoodId = prescription.Niprocart
  1139. warehouseOutInfo.GoodTypeId = niprocart
  1140. warehouseOutInfo.Count = 1
  1141. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1142. if err == nil {
  1143. details := &models.AutomaticReduceDetail{
  1144. WarehouseOutId: warehouseOutInfo.ID,
  1145. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1146. PatientId: patientID,
  1147. Ctime: time.Now().Unix(),
  1148. Mtime: time.Now().Unix(),
  1149. Status: 1,
  1150. RecordTime: startDate.Unix(),
  1151. OrgId: adminUserInfo.CurrentOrgId,
  1152. GoodId: prescription.Niprocart,
  1153. GoodTypeId: niprocart,
  1154. }
  1155. service.AddSigleAutoReduceRecordInfo(details)
  1156. }
  1157. } else if err == nil { //记录存在,则将数量加1
  1158. if outInfo.ID > 0 {
  1159. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1160. }
  1161. details := &models.AutomaticReduceDetail{
  1162. WarehouseOutId: outInfo.ID,
  1163. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1164. PatientId: patientID,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: time.Now().Unix(),
  1167. Status: 1,
  1168. RecordTime: startDate.Unix(),
  1169. OrgId: adminUserInfo.CurrentOrgId,
  1170. GoodId: prescription.Niprocart,
  1171. GoodTypeId: niprocart,
  1172. }
  1173. service.AddSigleAutoReduceRecordInfo(details)
  1174. }
  1175. }
  1176. if prescription.Jms > 0 {
  1177. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, jms, prescription.Jms, out.WarehouseOutOrderNumber)
  1178. if err == gorm.ErrRecordNotFound {
  1179. warehouseOutInfo := &models.WarehouseOutInfo{
  1180. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1181. WarehouseOutId: out.ID,
  1182. Status: 1,
  1183. Ctime: time.Now().Unix(),
  1184. Remark: "",
  1185. OrgId: adminUserInfo.CurrentOrgId,
  1186. Type: 1,
  1187. Manufacturer: 0,
  1188. Dealer: 0,
  1189. IsSys: 1,
  1190. SysRecordTime: startDate.Unix(),
  1191. }
  1192. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.CurrentOrgId)
  1193. warehouseOutInfo.Price = stockInInfo.Price
  1194. warehouseOutInfo.GoodId = prescription.Jms
  1195. warehouseOutInfo.GoodTypeId = jms
  1196. warehouseOutInfo.Count = 1
  1197. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1198. if err == nil {
  1199. details := &models.AutomaticReduceDetail{
  1200. WarehouseOutId: warehouseOutInfo.ID,
  1201. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1202. PatientId: patientID,
  1203. Ctime: time.Now().Unix(),
  1204. Mtime: time.Now().Unix(),
  1205. Status: 1,
  1206. RecordTime: startDate.Unix(),
  1207. OrgId: adminUserInfo.CurrentOrgId,
  1208. GoodId: prescription.Jms,
  1209. GoodTypeId: jms,
  1210. }
  1211. service.AddSigleAutoReduceRecordInfo(details)
  1212. }
  1213. } else if err == nil { //记录存在,则将数量加1
  1214. if outInfo.ID > 0 {
  1215. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1216. }
  1217. details := &models.AutomaticReduceDetail{
  1218. WarehouseOutId: outInfo.ID,
  1219. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1220. PatientId: patientID,
  1221. Ctime: time.Now().Unix(),
  1222. Mtime: time.Now().Unix(),
  1223. Status: 1,
  1224. RecordTime: startDate.Unix(),
  1225. OrgId: adminUserInfo.CurrentOrgId,
  1226. GoodId: prescription.Jms,
  1227. GoodTypeId: jms,
  1228. }
  1229. service.AddSigleAutoReduceRecordInfo(details)
  1230. }
  1231. }
  1232. if prescription.FistulaNeedleSet > 0 {
  1233. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, fistula_needle_set, prescription.FistulaNeedleSet, out.WarehouseOutOrderNumber)
  1234. if err == gorm.ErrRecordNotFound {
  1235. warehouseOutInfo := &models.WarehouseOutInfo{
  1236. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1237. WarehouseOutId: out.ID,
  1238. Status: 1,
  1239. Ctime: time.Now().Unix(),
  1240. Remark: "",
  1241. OrgId: adminUserInfo.CurrentOrgId,
  1242. Type: 1,
  1243. Manufacturer: 0,
  1244. Dealer: 0,
  1245. IsSys: 1,
  1246. SysRecordTime: startDate.Unix(),
  1247. }
  1248. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.CurrentOrgId)
  1249. warehouseOutInfo.Price = stockInInfo.Price
  1250. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  1251. warehouseOutInfo.GoodTypeId = fistula_needle_set
  1252. warehouseOutInfo.Count = 1
  1253. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1254. if err == nil {
  1255. details := &models.AutomaticReduceDetail{
  1256. WarehouseOutId: warehouseOutInfo.ID,
  1257. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1258. PatientId: patientID,
  1259. Ctime: time.Now().Unix(),
  1260. Mtime: time.Now().Unix(),
  1261. Status: 1,
  1262. RecordTime: startDate.Unix(),
  1263. OrgId: adminUserInfo.CurrentOrgId,
  1264. GoodId: prescription.FistulaNeedleSet,
  1265. GoodTypeId: fistula_needle_set,
  1266. }
  1267. service.AddSigleAutoReduceRecordInfo(details)
  1268. }
  1269. } else if err == nil { //记录存在,则将数量加1
  1270. if outInfo.ID > 0 {
  1271. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1272. }
  1273. details := &models.AutomaticReduceDetail{
  1274. WarehouseOutId: outInfo.ID,
  1275. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1276. PatientId: patientID,
  1277. Ctime: time.Now().Unix(),
  1278. Mtime: time.Now().Unix(),
  1279. Status: 1,
  1280. RecordTime: startDate.Unix(),
  1281. OrgId: adminUserInfo.CurrentOrgId,
  1282. GoodId: prescription.FistulaNeedleSet,
  1283. GoodTypeId: fistula_needle_set,
  1284. }
  1285. service.AddSigleAutoReduceRecordInfo(details)
  1286. }
  1287. }
  1288. if prescription.FistulaNeedleSet16 > 0 {
  1289. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber)
  1290. if err == gorm.ErrRecordNotFound {
  1291. warehouseOutInfo := &models.WarehouseOutInfo{
  1292. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1293. WarehouseOutId: out.ID,
  1294. Status: 1,
  1295. Ctime: time.Now().Unix(),
  1296. Remark: "",
  1297. OrgId: adminUserInfo.CurrentOrgId,
  1298. Type: 1,
  1299. Manufacturer: 0,
  1300. Dealer: 0,
  1301. IsSys: 1,
  1302. SysRecordTime: startDate.Unix(),
  1303. }
  1304. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.CurrentOrgId)
  1305. warehouseOutInfo.Price = stockInInfo.Price
  1306. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  1307. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  1308. warehouseOutInfo.Count = 1
  1309. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1310. if err == nil {
  1311. details := &models.AutomaticReduceDetail{
  1312. WarehouseOutId: warehouseOutInfo.ID,
  1313. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1314. PatientId: patientID,
  1315. Ctime: time.Now().Unix(),
  1316. Mtime: time.Now().Unix(),
  1317. Status: 1,
  1318. RecordTime: startDate.Unix(),
  1319. OrgId: adminUserInfo.CurrentOrgId,
  1320. GoodId: prescription.FistulaNeedleSet16,
  1321. GoodTypeId: fistula_needle_set_16,
  1322. }
  1323. service.AddSigleAutoReduceRecordInfo(details)
  1324. }
  1325. } else if err == nil { //记录存在,则将数量加1
  1326. if outInfo.ID > 0 {
  1327. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1328. }
  1329. details := &models.AutomaticReduceDetail{
  1330. WarehouseOutId: outInfo.ID,
  1331. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1332. PatientId: patientID,
  1333. Ctime: time.Now().Unix(),
  1334. Mtime: time.Now().Unix(),
  1335. Status: 1,
  1336. RecordTime: startDate.Unix(),
  1337. OrgId: adminUserInfo.CurrentOrgId,
  1338. GoodId: prescription.FistulaNeedleSet16,
  1339. GoodTypeId: fistula_needle_set_16,
  1340. }
  1341. service.AddSigleAutoReduceRecordInfo(details)
  1342. }
  1343. }
  1344. if prescription.Hemoperfusion > 0 {
  1345. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, hemoperfusion, prescription.Hemoperfusion, out.WarehouseOutOrderNumber)
  1346. if err == gorm.ErrRecordNotFound {
  1347. warehouseOutInfo := &models.WarehouseOutInfo{
  1348. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1349. WarehouseOutId: out.ID,
  1350. Status: 1,
  1351. Ctime: time.Now().Unix(),
  1352. Remark: "",
  1353. OrgId: adminUserInfo.CurrentOrgId,
  1354. Type: 1,
  1355. Manufacturer: 0,
  1356. Dealer: 0,
  1357. IsSys: 1,
  1358. SysRecordTime: startDate.Unix(),
  1359. }
  1360. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.CurrentOrgId)
  1361. warehouseOutInfo.Price = stockInInfo.Price
  1362. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  1363. warehouseOutInfo.GoodTypeId = hemoperfusion
  1364. warehouseOutInfo.Count = 1
  1365. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1366. if err == nil {
  1367. details := &models.AutomaticReduceDetail{
  1368. WarehouseOutId: warehouseOutInfo.ID,
  1369. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1370. PatientId: patientID,
  1371. Ctime: time.Now().Unix(),
  1372. Mtime: time.Now().Unix(),
  1373. Status: 1,
  1374. RecordTime: startDate.Unix(),
  1375. OrgId: adminUserInfo.CurrentOrgId,
  1376. GoodId: prescription.Hemoperfusion,
  1377. GoodTypeId: hemoperfusion,
  1378. }
  1379. service.AddSigleAutoReduceRecordInfo(details)
  1380. }
  1381. } else if err == nil { //记录存在,则将数量加1
  1382. if outInfo.ID > 0 {
  1383. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1384. }
  1385. details := &models.AutomaticReduceDetail{
  1386. WarehouseOutId: outInfo.ID,
  1387. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1388. PatientId: patientID,
  1389. Ctime: time.Now().Unix(),
  1390. Mtime: time.Now().Unix(),
  1391. Status: 1,
  1392. RecordTime: startDate.Unix(),
  1393. OrgId: adminUserInfo.CurrentOrgId,
  1394. GoodId: prescription.Hemoperfusion,
  1395. GoodTypeId: hemoperfusion,
  1396. }
  1397. service.AddSigleAutoReduceRecordInfo(details)
  1398. }
  1399. }
  1400. if prescription.DialyserSterilised > 0 {
  1401. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, dialyser_sterilised, prescription.DialyserSterilised, out.WarehouseOutOrderNumber)
  1402. if err == gorm.ErrRecordNotFound {
  1403. warehouseOutInfo := &models.WarehouseOutInfo{
  1404. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1405. WarehouseOutId: out.ID,
  1406. Status: 1,
  1407. Ctime: time.Now().Unix(),
  1408. Remark: "",
  1409. OrgId: adminUserInfo.CurrentOrgId,
  1410. Type: 1,
  1411. Manufacturer: 0,
  1412. Dealer: 0,
  1413. IsSys: 1,
  1414. SysRecordTime: startDate.Unix(),
  1415. }
  1416. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.CurrentOrgId)
  1417. warehouseOutInfo.Price = stockInInfo.Price
  1418. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  1419. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  1420. warehouseOutInfo.Count = 1
  1421. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1422. if err == nil {
  1423. details := &models.AutomaticReduceDetail{
  1424. WarehouseOutId: warehouseOutInfo.ID,
  1425. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1426. PatientId: patientID,
  1427. Ctime: time.Now().Unix(),
  1428. Mtime: time.Now().Unix(),
  1429. Status: 1,
  1430. RecordTime: startDate.Unix(),
  1431. OrgId: adminUserInfo.CurrentOrgId,
  1432. GoodId: prescription.DialyserSterilised,
  1433. GoodTypeId: dialyser_sterilised,
  1434. }
  1435. service.AddSigleAutoReduceRecordInfo(details)
  1436. }
  1437. } else if err == nil { //记录存在,则将数量加1
  1438. if outInfo.ID > 0 {
  1439. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1440. }
  1441. details := &models.AutomaticReduceDetail{
  1442. WarehouseOutId: outInfo.ID,
  1443. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1444. PatientId: patientID,
  1445. Ctime: time.Now().Unix(),
  1446. Mtime: time.Now().Unix(),
  1447. Status: 1,
  1448. RecordTime: startDate.Unix(),
  1449. OrgId: adminUserInfo.CurrentOrgId,
  1450. GoodId: prescription.DialyserSterilised,
  1451. GoodTypeId: dialyser_sterilised,
  1452. }
  1453. service.AddSigleAutoReduceRecordInfo(details)
  1454. }
  1455. }
  1456. if prescription.Filtryzer > 0 {
  1457. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, filtryzer, prescription.Filtryzer, out.WarehouseOutOrderNumber)
  1458. if err == gorm.ErrRecordNotFound {
  1459. warehouseOutInfo := &models.WarehouseOutInfo{
  1460. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1461. WarehouseOutId: out.ID,
  1462. Status: 1,
  1463. Ctime: time.Now().Unix(),
  1464. Remark: "",
  1465. OrgId: adminUserInfo.CurrentOrgId,
  1466. Type: 1,
  1467. Manufacturer: 0,
  1468. Dealer: 0,
  1469. IsSys: 1,
  1470. SysRecordTime: startDate.Unix(),
  1471. }
  1472. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.CurrentOrgId)
  1473. warehouseOutInfo.Price = stockInInfo.Price
  1474. warehouseOutInfo.GoodId = prescription.Filtryzer
  1475. warehouseOutInfo.GoodTypeId = filtryzer
  1476. warehouseOutInfo.Count = 1
  1477. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1478. if err == nil {
  1479. details := &models.AutomaticReduceDetail{
  1480. WarehouseOutId: warehouseOutInfo.ID,
  1481. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1482. PatientId: patientID,
  1483. Ctime: time.Now().Unix(),
  1484. Mtime: time.Now().Unix(),
  1485. Status: 1,
  1486. RecordTime: startDate.Unix(),
  1487. OrgId: adminUserInfo.CurrentOrgId,
  1488. GoodId: prescription.Filtryzer,
  1489. GoodTypeId: filtryzer,
  1490. }
  1491. service.AddSigleAutoReduceRecordInfo(details)
  1492. }
  1493. } else if err == nil { //记录存在,则将耗材使用数量加1
  1494. if outInfo.ID > 0 {
  1495. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1496. }
  1497. //插入病人耗材使用记录
  1498. details := &models.AutomaticReduceDetail{
  1499. WarehouseOutId: outInfo.ID,
  1500. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1501. PatientId: patientID,
  1502. Ctime: time.Now().Unix(),
  1503. Mtime: time.Now().Unix(),
  1504. Status: 1,
  1505. RecordTime: startDate.Unix(),
  1506. OrgId: adminUserInfo.CurrentOrgId,
  1507. GoodId: prescription.Filtryzer,
  1508. GoodTypeId: filtryzer,
  1509. }
  1510. service.AddSigleAutoReduceRecordInfo(details)
  1511. }
  1512. }
  1513. if prescription.Dialyzers > 0 {
  1514. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, dialyzers, prescription.Dialyzers, out.WarehouseOutOrderNumber)
  1515. if err == gorm.ErrRecordNotFound {
  1516. warehouseOutInfo := &models.WarehouseOutInfo{
  1517. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1518. WarehouseOutId: out.ID,
  1519. Status: 1,
  1520. Ctime: time.Now().Unix(),
  1521. Remark: "",
  1522. OrgId: adminUserInfo.CurrentOrgId,
  1523. Type: 1,
  1524. Manufacturer: 0,
  1525. Dealer: 0,
  1526. IsSys: 1,
  1527. SysRecordTime: startDate.Unix(),
  1528. }
  1529. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.CurrentOrgId)
  1530. warehouseOutInfo.Price = stockInInfo.Price
  1531. warehouseOutInfo.GoodId = prescription.Dialyzers
  1532. warehouseOutInfo.GoodTypeId = dialyzers
  1533. warehouseOutInfo.Count = 1
  1534. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1535. if err == nil {
  1536. details := &models.AutomaticReduceDetail{
  1537. WarehouseOutId: warehouseOutInfo.ID,
  1538. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1539. PatientId: patientID,
  1540. Ctime: time.Now().Unix(),
  1541. Mtime: time.Now().Unix(),
  1542. Status: 1,
  1543. RecordTime: startDate.Unix(),
  1544. OrgId: adminUserInfo.CurrentOrgId,
  1545. GoodId: prescription.Dialyzers,
  1546. GoodTypeId: dialyzers,
  1547. }
  1548. service.AddSigleAutoReduceRecordInfo(details)
  1549. }
  1550. } else if err == nil { //记录存在,则将耗材使用数量加1
  1551. if outInfo.ID > 0 {
  1552. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1553. }
  1554. //插入病人耗材使用记录
  1555. details := &models.AutomaticReduceDetail{
  1556. WarehouseOutId: outInfo.ID,
  1557. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1558. PatientId: patientID,
  1559. Ctime: time.Now().Unix(),
  1560. Mtime: time.Now().Unix(),
  1561. Status: 1,
  1562. RecordTime: startDate.Unix(),
  1563. OrgId: adminUserInfo.CurrentOrgId,
  1564. GoodId: prescription.Dialyzer,
  1565. GoodTypeId: dialyzers,
  1566. }
  1567. service.AddSigleAutoReduceRecordInfo(details)
  1568. }
  1569. }
  1570. if prescription.Injector > 0 {
  1571. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, injector, prescription.Injector, out.WarehouseOutOrderNumber)
  1572. if err == gorm.ErrRecordNotFound {
  1573. warehouseOutInfo := &models.WarehouseOutInfo{
  1574. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1575. WarehouseOutId: out.ID,
  1576. Status: 1,
  1577. Ctime: time.Now().Unix(),
  1578. Remark: "",
  1579. OrgId: adminUserInfo.CurrentOrgId,
  1580. Type: 1,
  1581. Manufacturer: 0,
  1582. Dealer: 0,
  1583. IsSys: 1,
  1584. SysRecordTime: startDate.Unix(),
  1585. }
  1586. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.CurrentOrgId)
  1587. warehouseOutInfo.Price = stockInInfo.Price
  1588. warehouseOutInfo.GoodId = prescription.Injector
  1589. warehouseOutInfo.GoodTypeId = injector
  1590. warehouseOutInfo.Count = 1
  1591. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1592. if err == nil {
  1593. details := &models.AutomaticReduceDetail{
  1594. WarehouseOutId: warehouseOutInfo.ID,
  1595. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1596. PatientId: patientID,
  1597. Ctime: time.Now().Unix(),
  1598. Mtime: time.Now().Unix(),
  1599. Status: 1,
  1600. RecordTime: startDate.Unix(),
  1601. OrgId: adminUserInfo.CurrentOrgId,
  1602. GoodId: prescription.Injector,
  1603. GoodTypeId: injector,
  1604. }
  1605. service.AddSigleAutoReduceRecordInfo(details)
  1606. }
  1607. } else if err == nil { //记录存在,则将耗材使用数量加1
  1608. if outInfo.ID > 0 {
  1609. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1610. }
  1611. //插入病人耗材使用记录
  1612. details := &models.AutomaticReduceDetail{
  1613. WarehouseOutId: outInfo.ID,
  1614. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1615. PatientId: patientID,
  1616. Ctime: time.Now().Unix(),
  1617. Mtime: time.Now().Unix(),
  1618. Status: 1,
  1619. RecordTime: startDate.Unix(),
  1620. OrgId: adminUserInfo.CurrentOrgId,
  1621. GoodId: prescription.Injector,
  1622. GoodTypeId: injector,
  1623. }
  1624. service.AddSigleAutoReduceRecordInfo(details)
  1625. }
  1626. }
  1627. if prescription.Bloodlines > 0 {
  1628. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, bloodlines, prescription.Bloodlines, out.WarehouseOutOrderNumber)
  1629. if err == gorm.ErrRecordNotFound {
  1630. warehouseOutInfo := &models.WarehouseOutInfo{
  1631. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1632. WarehouseOutId: out.ID,
  1633. Status: 1,
  1634. Ctime: time.Now().Unix(),
  1635. Remark: "",
  1636. OrgId: adminUserInfo.CurrentOrgId,
  1637. Type: 1,
  1638. Manufacturer: 0,
  1639. Dealer: 0,
  1640. IsSys: 1,
  1641. SysRecordTime: startDate.Unix(),
  1642. }
  1643. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.CurrentOrgId)
  1644. warehouseOutInfo.Price = stockInInfo.Price
  1645. warehouseOutInfo.GoodId = prescription.Bloodlines
  1646. warehouseOutInfo.GoodTypeId = bloodlines
  1647. warehouseOutInfo.Count = 1
  1648. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1649. if err == nil {
  1650. details := &models.AutomaticReduceDetail{
  1651. WarehouseOutId: warehouseOutInfo.ID,
  1652. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1653. PatientId: patientID,
  1654. Ctime: time.Now().Unix(),
  1655. Mtime: time.Now().Unix(),
  1656. Status: 1,
  1657. RecordTime: startDate.Unix(),
  1658. OrgId: adminUserInfo.CurrentOrgId,
  1659. GoodId: prescription.Bloodlines,
  1660. GoodTypeId: bloodlines,
  1661. }
  1662. service.AddSigleAutoReduceRecordInfo(details)
  1663. }
  1664. } else if err == nil { //记录存在,则将耗材使用数量加1
  1665. if outInfo.ID > 0 {
  1666. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1667. }
  1668. //插入病人耗材使用记录
  1669. details := &models.AutomaticReduceDetail{
  1670. WarehouseOutId: outInfo.ID,
  1671. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1672. PatientId: patientID,
  1673. Ctime: time.Now().Unix(),
  1674. Mtime: time.Now().Unix(),
  1675. Status: 1,
  1676. RecordTime: startDate.Unix(),
  1677. OrgId: adminUserInfo.CurrentOrgId,
  1678. GoodId: prescription.Bloodlines,
  1679. GoodTypeId: bloodlines,
  1680. }
  1681. service.AddSigleAutoReduceRecordInfo(details)
  1682. }
  1683. }
  1684. if prescription.TubingHemodialysis > 0 {
  1685. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, tubingHemodialysis, prescription.TubingHemodialysis, out.WarehouseOutOrderNumber)
  1686. if err == gorm.ErrRecordNotFound {
  1687. warehouseOutInfo := &models.WarehouseOutInfo{
  1688. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1689. WarehouseOutId: out.ID,
  1690. Status: 1,
  1691. Ctime: time.Now().Unix(),
  1692. Remark: "",
  1693. OrgId: adminUserInfo.CurrentOrgId,
  1694. Type: 1,
  1695. Manufacturer: 0,
  1696. Dealer: 0,
  1697. IsSys: 1,
  1698. SysRecordTime: startDate.Unix(),
  1699. }
  1700. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.CurrentOrgId)
  1701. warehouseOutInfo.Price = stockInInfo.Price
  1702. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  1703. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  1704. warehouseOutInfo.Count = 1
  1705. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1706. if err == nil {
  1707. details := &models.AutomaticReduceDetail{
  1708. WarehouseOutId: warehouseOutInfo.ID,
  1709. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1710. PatientId: patientID,
  1711. Ctime: time.Now().Unix(),
  1712. Mtime: time.Now().Unix(),
  1713. Status: 1,
  1714. RecordTime: startDate.Unix(),
  1715. OrgId: adminUserInfo.CurrentOrgId,
  1716. GoodId: prescription.TubingHemodialysis,
  1717. GoodTypeId: tubingHemodialysis,
  1718. }
  1719. service.AddSigleAutoReduceRecordInfo(details)
  1720. }
  1721. } else if err == nil { //记录存在,则将耗材使用数量加1
  1722. if outInfo.ID > 0 {
  1723. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1724. }
  1725. //插入病人耗材使用记录
  1726. details := &models.AutomaticReduceDetail{
  1727. WarehouseOutId: outInfo.ID,
  1728. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1729. PatientId: patientID,
  1730. Ctime: time.Now().Unix(),
  1731. Mtime: time.Now().Unix(),
  1732. Status: 1,
  1733. RecordTime: startDate.Unix(),
  1734. OrgId: adminUserInfo.CurrentOrgId,
  1735. GoodId: prescription.TubingHemodialysis,
  1736. GoodTypeId: tubingHemodialysis,
  1737. }
  1738. service.AddSigleAutoReduceRecordInfo(details)
  1739. }
  1740. }
  1741. if prescription.Package > 0 {
  1742. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, safe_package, prescription.Package, out.WarehouseOutOrderNumber)
  1743. if err == gorm.ErrRecordNotFound {
  1744. warehouseOutInfo := &models.WarehouseOutInfo{
  1745. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1746. WarehouseOutId: out.ID,
  1747. Status: 1,
  1748. Ctime: time.Now().Unix(),
  1749. Remark: "",
  1750. OrgId: adminUserInfo.CurrentOrgId,
  1751. Type: 1,
  1752. Manufacturer: 0,
  1753. Dealer: 0,
  1754. IsSys: 1,
  1755. SysRecordTime: startDate.Unix(),
  1756. }
  1757. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.CurrentOrgId)
  1758. warehouseOutInfo.Price = stockInInfo.Price
  1759. warehouseOutInfo.GoodId = prescription.Package
  1760. warehouseOutInfo.GoodTypeId = safe_package
  1761. warehouseOutInfo.Count = 1
  1762. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1763. if err == nil {
  1764. details := &models.AutomaticReduceDetail{
  1765. WarehouseOutId: warehouseOutInfo.ID,
  1766. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1767. PatientId: patientID,
  1768. Ctime: time.Now().Unix(),
  1769. Mtime: time.Now().Unix(),
  1770. Status: 1,
  1771. RecordTime: startDate.Unix(),
  1772. OrgId: adminUserInfo.CurrentOrgId,
  1773. GoodId: prescription.Package,
  1774. GoodTypeId: safe_package,
  1775. }
  1776. service.AddSigleAutoReduceRecordInfo(details)
  1777. }
  1778. } else if err == nil { //记录存在,则将耗材使用数量加1
  1779. if outInfo.ID > 0 {
  1780. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1781. }
  1782. //插入病人耗材使用记录
  1783. details := &models.AutomaticReduceDetail{
  1784. WarehouseOutId: outInfo.ID,
  1785. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1786. PatientId: patientID,
  1787. Ctime: time.Now().Unix(),
  1788. Mtime: time.Now().Unix(),
  1789. Status: 1,
  1790. RecordTime: startDate.Unix(),
  1791. OrgId: adminUserInfo.CurrentOrgId,
  1792. GoodId: prescription.Package,
  1793. GoodTypeId: safe_package,
  1794. }
  1795. service.AddSigleAutoReduceRecordInfo(details)
  1796. }
  1797. }
  1798. if prescription.ALiquid > 0 {
  1799. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, aliquid, prescription.ALiquid, out.WarehouseOutOrderNumber)
  1800. if err == gorm.ErrRecordNotFound {
  1801. warehouseOutInfo := &models.WarehouseOutInfo{
  1802. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1803. WarehouseOutId: out.ID,
  1804. Status: 1,
  1805. Ctime: time.Now().Unix(),
  1806. Remark: "",
  1807. OrgId: adminUserInfo.CurrentOrgId,
  1808. Type: 1,
  1809. Manufacturer: 0,
  1810. Dealer: 0,
  1811. IsSys: 1,
  1812. SysRecordTime: startDate.Unix(),
  1813. }
  1814. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.CurrentOrgId)
  1815. warehouseOutInfo.Price = stockInInfo.Price
  1816. warehouseOutInfo.GoodId = prescription.ALiquid
  1817. warehouseOutInfo.GoodTypeId = aliquid
  1818. warehouseOutInfo.Count = 1
  1819. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1820. if err == nil {
  1821. details := &models.AutomaticReduceDetail{
  1822. WarehouseOutId: warehouseOutInfo.ID,
  1823. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1824. PatientId: patientID,
  1825. Ctime: time.Now().Unix(),
  1826. Mtime: time.Now().Unix(),
  1827. Status: 1,
  1828. RecordTime: startDate.Unix(),
  1829. OrgId: adminUserInfo.CurrentOrgId,
  1830. GoodId: prescription.ALiquid,
  1831. GoodTypeId: aliquid,
  1832. }
  1833. service.AddSigleAutoReduceRecordInfo(details)
  1834. }
  1835. } else if err == nil { //记录存在,则将耗材使用数量加1
  1836. if outInfo.ID > 0 {
  1837. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, outInfo.ID)
  1838. }
  1839. //插入病人耗材使用记录
  1840. details := &models.AutomaticReduceDetail{
  1841. WarehouseOutId: outInfo.ID,
  1842. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1843. PatientId: patientID,
  1844. Ctime: time.Now().Unix(),
  1845. Mtime: time.Now().Unix(),
  1846. Status: 1,
  1847. RecordTime: startDate.Unix(),
  1848. OrgId: adminUserInfo.CurrentOrgId,
  1849. GoodId: prescription.ALiquid,
  1850. GoodTypeId: aliquid,
  1851. }
  1852. service.AddSigleAutoReduceRecordInfo(details)
  1853. }
  1854. }
  1855. }
  1856. }
  1857. } else {
  1858. this.ErrorLog("上机失败,还没开处方")
  1859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  1860. return
  1861. }
  1862. }
  1863. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1864. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1865. timeLayout := "2006-01-02 15:04:05"
  1866. loc, _ := time.LoadLocation("Local")
  1867. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1868. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1869. schedulestartTime := theStartTime.Unix()
  1870. scheduleendTime := theEndTime.Unix()
  1871. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1872. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  1873. if err == gorm.ErrRecordNotFound { //空床位
  1874. // 修改了床位逻辑
  1875. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  1876. if daySchedule.ID > 0 {
  1877. daySchedule.PartitionId = deviceNumber.ZoneID
  1878. daySchedule.BedId = bedID
  1879. daySchedule.ScheduleType = schedual_type
  1880. daySchedule.UpdatedTime = time.Now().Unix()
  1881. err := service.UpdateSchedule(&daySchedule)
  1882. if err != nil {
  1883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1884. return
  1885. }
  1886. }
  1887. } else if err == nil {
  1888. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1889. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, patientID)
  1890. if daySchedule.ID > 0 {
  1891. daySchedule.PartitionId = deviceNumber.ZoneID
  1892. daySchedule.BedId = bedID
  1893. daySchedule.ScheduleType = schedual_type
  1894. daySchedule.UpdatedTime = time.Now().Unix()
  1895. err := service.UpdateSchedule(&daySchedule)
  1896. if err != nil {
  1897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1898. return
  1899. }
  1900. }
  1901. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1903. return
  1904. }
  1905. } else if err != nil {
  1906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. dialysisRecord = &models.DialysisOrder{
  1910. DialysisDate: recordDate.Unix(),
  1911. UserOrgId: adminUserInfo.CurrentOrgId,
  1912. PatientId: patientID,
  1913. Stage: 1,
  1914. BedID: bedID,
  1915. StartNurse: nurseID,
  1916. Status: 1,
  1917. StartTime: startDate.Unix(),
  1918. CreatedTime: time.Now().Unix(),
  1919. UpdatedTime: time.Now().Unix(),
  1920. PunctureNurse: punctureNurseId,
  1921. Creator: adminUserInfo.AdminUser.Id,
  1922. Modifier: adminUserInfo.AdminUser.Id,
  1923. SchedualType: schedual_type,
  1924. }
  1925. createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
  1926. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  1927. if createErr != nil {
  1928. this.ErrorLog("上机失败:%v", createErr)
  1929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1930. return
  1931. } else if createErr == nil {
  1932. var tempdispose string
  1933. // 只针对中能建
  1934. if blood_drawing > 0 && adminUserInfo.CurrentOrgId == 9538 { //adminUserInfo.CurrentOrgId == 9538
  1935. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1936. }
  1937. var ultrafiltration_rate float64
  1938. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.CurrentOrgId)
  1939. if prescription.ID > 0 {
  1940. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1941. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1942. if template.TemplateId == 6 {
  1943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1944. }
  1945. // 只针对方济医院
  1946. if template.TemplateId == 1 {
  1947. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1948. ultrafiltration_rate = value
  1949. }
  1950. }
  1951. }
  1952. record := models.MonitoringRecord{
  1953. UserOrgId: adminUserInfo.CurrentOrgId,
  1954. PatientId: patientID,
  1955. DialysisOrderId: dialysisRecord.ID,
  1956. MonitoringDate: schedulestartTime,
  1957. OperateTime: startDate.Unix(),
  1958. // MonitoringTime: recordTime,
  1959. MonitoringNurse: nurseID,
  1960. Dispose: tempdispose,
  1961. UltrafiltrationRate: ultrafiltration_rate,
  1962. UltrafiltrationVolume: 0,
  1963. Status: 1,
  1964. CreatedTime: time.Now().Unix(),
  1965. UpdatedTime: time.Now().Unix(),
  1966. }
  1967. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1968. if newdialysisRecord.ID > 0 {
  1969. err := service.CreateMonitor(&record)
  1970. if err != nil {
  1971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1972. return
  1973. }
  1974. }
  1975. this.ServeSuccessJSON(map[string]interface{}{
  1976. "dialysis_order": dialysisRecord,
  1977. "monitor": record,
  1978. })
  1979. }
  1980. }
  1981. // /api/dialysis/finish [post]
  1982. // @param patient_id:int
  1983. // @param date:string 排班时间 (yyyy-mm-dd)
  1984. // @param nurse:int 下机护士
  1985. func (this *DialysisRecordAPIController) FinishDialysis() {
  1986. patientID, _ := this.GetInt64("patient_id")
  1987. recordDateStr := this.GetString("date")
  1988. nurseID, _ := this.GetInt64("nurse")
  1989. end_time := this.GetString("end_time")
  1990. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 {
  1991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1992. return
  1993. }
  1994. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1995. if parseErr != nil {
  1996. this.ErrorLog("时间解析失败:%v", parseErr)
  1997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1998. return
  1999. }
  2000. //if parseEndDateErr != nil {
  2001. // this.ErrorLog("时间解析失败:%v", parseEndDateErr)
  2002. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2003. // return
  2004. //}
  2005. adminUserInfo := this.GetAdminUserInfo()
  2006. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.CurrentOrgId, patientID)
  2007. if getPatientErr != nil {
  2008. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2009. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2010. return
  2011. } else if patient == nil {
  2012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2013. return
  2014. }
  2015. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2016. if getNurseErr != nil {
  2017. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2019. return
  2020. } else if nurse == nil {
  2021. this.ErrorLog("护士不存在")
  2022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2023. return
  2024. }
  2025. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2026. if getRecordErr != nil {
  2027. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2029. return
  2030. }
  2031. if dialysisRecord.Stage == 2 {
  2032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2033. return
  2034. }
  2035. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  2036. if parseEndDateErr != nil {
  2037. this.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2039. return
  2040. }
  2041. // 获取当天的第一条透析纪录
  2042. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2043. if getMonitorRecordsErr != nil {
  2044. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2046. return
  2047. }
  2048. // 获取当前的最后一条透析纪录
  2049. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2050. if getMonitorRecordsErr != nil {
  2051. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2053. return
  2054. }
  2055. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
  2056. if getAADErr != nil {
  2057. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  2058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2059. return
  2060. }
  2061. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2062. if assessmentAfterDislysis != nil {
  2063. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2064. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2065. } else {
  2066. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2067. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2068. tempassessmentAfterDislysis.Status = 1
  2069. tempassessmentAfterDislysis.PatientId = patientID
  2070. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.CurrentOrgId
  2071. }
  2072. if dialysisRecord.Stage == 1 {
  2073. temp_time := (float64(endDate.Unix()) - float64(dialysisRecord.StartTime)) / 3600
  2074. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2075. fmt.Println(value)
  2076. a, b := math.Modf(value)
  2077. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2078. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2079. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2080. fmt.Println(hour)
  2081. fmt.Println(minute)
  2082. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2083. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2084. }
  2085. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2086. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2087. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2088. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2089. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2090. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2091. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2092. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2093. }
  2094. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2095. if err != nil {
  2096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2097. return
  2098. }
  2099. updateErr := service.ModifyDialysisRecord(dialysisRecord.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2100. if updateErr != nil {
  2101. this.ErrorLog("下机失败:%v", updateErr)
  2102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2103. return
  2104. } else {
  2105. dialysisRecord.Stage = 2
  2106. dialysisRecord.FinishNurse = nurseID
  2107. dialysisRecord.FinishCreator = adminUserInfo.AdminUser.Id
  2108. dialysisRecord.FinishModifier = adminUserInfo.AdminUser.Id
  2109. dialysisRecord.EndTime = endDate.Unix()
  2110. // 结束时候透析次数加1
  2111. service.UpdateSolutionByPatientId(patientID)
  2112. this.ServeSuccessJSON(map[string]interface{}{
  2113. "dialysis_order": dialysisRecord,
  2114. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2115. })
  2116. }
  2117. }
  2118. func (this *DialysisRecordAPIController) ModifyStartDialysis() {
  2119. record_id, _ := this.GetInt64("id")
  2120. nurseID, _ := this.GetInt64("nurse")
  2121. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2122. bedID, _ := this.GetInt64("bed")
  2123. start_time := this.GetString("start_time")
  2124. schedual_type, _ := this.GetInt64("schedual_type")
  2125. if record_id == 0 {
  2126. this.ErrorLog("id:%v", record_id)
  2127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", start_time)
  2131. if parseStartDateErr != nil {
  2132. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2134. return
  2135. }
  2136. adminUserInfo := this.GetAdminUserInfo()
  2137. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2138. if getNurseErr != nil {
  2139. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2141. return
  2142. } else if nurse == nil {
  2143. this.ErrorLog("护士不存在")
  2144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2145. return
  2146. }
  2147. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2148. if getNurseErr != nil {
  2149. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2151. return
  2152. } else if nurse == nil {
  2153. this.ErrorLog("护士不存在")
  2154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2155. return
  2156. }
  2157. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, bedID)
  2158. if getDeviceNumberErr != nil {
  2159. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2161. return
  2162. } else if deviceNumber == nil {
  2163. this.ErrorLog("床位号不存在")
  2164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2165. return
  2166. }
  2167. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2168. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2169. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2170. // if getPermissionErr != nil {
  2171. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2172. // return
  2173. // } else if headNursePermission == nil {
  2174. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2175. // return
  2176. // }
  2177. //}
  2178. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2179. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2180. timeLayout := "2006-01-02 15:04:05"
  2181. loc, _ := time.LoadLocation("Local")
  2182. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2183. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2184. schedulestartTime := theStartTime.Unix()
  2185. scheduleendTime := theEndTime.Unix()
  2186. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2187. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
  2188. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2189. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2190. if err == gorm.ErrRecordNotFound { //空床位
  2191. // 修改了床位逻辑
  2192. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2193. if daySchedule.ID > 0 {
  2194. daySchedule.BedId = bedID
  2195. daySchedule.PartitionId = deviceNumber.ZoneID
  2196. daySchedule.ScheduleType = schedual_type
  2197. daySchedule.UpdatedTime = time.Now().Unix()
  2198. err := service.UpdateSchedule(&daySchedule)
  2199. if err != nil {
  2200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2201. return
  2202. }
  2203. }
  2204. } else if err == nil {
  2205. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2206. daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2207. if daySchedule.ID > 0 {
  2208. daySchedule.BedId = bedID
  2209. daySchedule.PartitionId = deviceNumber.ZoneID
  2210. daySchedule.ScheduleType = schedual_type
  2211. daySchedule.UpdatedTime = time.Now().Unix()
  2212. err := service.UpdateSchedule(&daySchedule)
  2213. if err != nil {
  2214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2215. return
  2216. }
  2217. }
  2218. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2220. return
  2221. }
  2222. } else if err != nil {
  2223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2224. return
  2225. }
  2226. }
  2227. dialysisRecord := &models.DialysisOrder{
  2228. ID: record_id,
  2229. UserOrgId: adminUserInfo.CurrentOrgId,
  2230. BedID: bedID,
  2231. StartNurse: nurseID,
  2232. StartTime: startDate.Unix(),
  2233. PunctureNurse: puncture_nurse,
  2234. Creator: adminUserInfo.AdminUser.Id,
  2235. Modifier: adminUserInfo.AdminUser.Id,
  2236. SchedualType: schedual_type,
  2237. }
  2238. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2239. if updateErr != nil {
  2240. this.ErrorLog("修改上机失败:%v", updateErr)
  2241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2242. return
  2243. }
  2244. if updateErr == nil {
  2245. if tempDialysisRecord.Stage == 2 {
  2246. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2247. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2248. fmt.Println(value)
  2249. a, b := math.Modf(value)
  2250. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2251. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2252. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2253. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2254. if updateAssessmentErr != nil {
  2255. utils.ErrorLog("%v", updateAssessmentErr)
  2256. }
  2257. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecord.UserOrgId, tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  2258. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2259. this.ServeSuccessJSON(map[string]interface{}{
  2260. "dialysis_order": dialysisRecords,
  2261. "after": after,
  2262. })
  2263. } else {
  2264. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2265. this.ServeSuccessJSON(map[string]interface{}{
  2266. "dialysis_order": dialysisRecords,
  2267. })
  2268. }
  2269. }
  2270. }
  2271. func (c *DialysisRecordAPIController) ModifyFinishDialysis() {
  2272. record_id, _ := c.GetInt64("id")
  2273. nurseID, _ := c.GetInt64("nurse")
  2274. end_time := c.GetString("end_time")
  2275. if record_id <= 0 || nurseID <= 0 {
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2277. return
  2278. }
  2279. adminUserInfo := c.GetAdminUserInfo()
  2280. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2281. if getNurseErr != nil {
  2282. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. return
  2285. } else if nurse == nil {
  2286. c.ErrorLog("护士不存在")
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2288. return
  2289. }
  2290. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04", end_time)
  2291. if parseEndDateErr != nil {
  2292. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2294. return
  2295. }
  2296. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2297. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2298. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2299. // if getPermissionErr != nil {
  2300. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2301. // return
  2302. // } else if headNursePermission == nil {
  2303. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2304. // return
  2305. // }
  2306. //}
  2307. dialysisRecord := &models.DialysisOrder{
  2308. ID: record_id,
  2309. UserOrgId: adminUserInfo.CurrentOrgId,
  2310. EndTime: endDate.Unix(),
  2311. FinishNurse: nurseID,
  2312. FinishModifier: adminUserInfo.AdminUser.Id,
  2313. }
  2314. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2315. if updateErr != nil {
  2316. c.ErrorLog("修改下机失败:%v", updateErr)
  2317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2318. return
  2319. }
  2320. if updateErr == nil {
  2321. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2322. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2323. fmt.Println(value)
  2324. a, b := math.Modf(value)
  2325. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2326. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2327. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2328. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2329. if updateAssessmentErr != nil {
  2330. utils.ErrorLog("%v", updateAssessmentErr)
  2331. }
  2332. }
  2333. after, _ := service.FindAssessmentAfterDislysisById(tempDialysisRecords.UserOrgId, tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate)
  2334. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2335. c.ServeSuccessJSON(map[string]interface{}{
  2336. "dialysis_order": dialysisRecords,
  2337. "after": after,
  2338. })
  2339. }