dialysis_record_api_controller.go 106KB

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