dialysis_record_api_controller.go 112KB

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