dialysis_record_api_controller.go 112KB

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