dialysis_api_controller.go 158KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "math"
  15. )
  16. // type DialysisTestAPIController struct {
  17. // MobileBaseAPIController
  18. // }
  19. // [get]/m/api/test
  20. // func (this *DialysisTestAPIController) Test() {
  21. // orgID := int64(3907)
  22. // now := time.Now()
  23. // nextWeek := now.AddDate(0, 0, 7)
  24. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  25. // nextTwoWeek := now.AddDate(0, 0, 14)
  26. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  27. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  28. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  29. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  30. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  31. // return
  32. // }
  33. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  34. // if exchangeErr != nil {
  35. // this.ErrorLog("%v", exchangeErr)
  36. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  37. // return
  38. // }
  39. // this.ServeSuccessJSON(map[string]interface{}{
  40. // // "now": now,
  41. // // "next_week": nextWeek,f
  42. // // "next_week_mon": nextWeekMon,
  43. // // "next_week_sun": nextWeekSun,
  44. // // "next_two_week_mon": nextTwoWeekMon,
  45. // // "next_two_week_sun": nextTwoWeekSun,
  46. // "next_week_schs": nextWeekSchs,
  47. // "next_two_week_schs": nextTwoWeekSchs,
  48. // })
  49. // }
  50. type DialysisAPIController struct {
  51. MobileBaseAPIAuthController
  52. }
  53. // /m/api/scheduals [get]
  54. // @param type:int
  55. // @param date:string
  56. func (this *DialysisAPIController) Scheduals() {
  57. schedualType, _ := this.GetInt64("type")
  58. schedualDate := this.GetString("date")
  59. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  60. schedualType = 0
  61. }
  62. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  63. if parseDateErr != nil {
  64. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  65. return
  66. }
  67. adminInfo := this.GetMobileAdminUserInfo()
  68. orgID := adminInfo.Org.Id
  69. redis := service.RedisClient()
  70. defer redis.Close()
  71. // cur_date := time.Now().Format("2006-01-02")
  72. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  73. scheduals_json_str, _ := redis.Get(key).Result()
  74. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  75. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  76. if err != nil {
  77. this.ErrorLog("获取排班信息失败:%v", err)
  78. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  79. } else {
  80. if len(scheduals) > 0 {
  81. //缓存数据
  82. scheduals_json, err := json.Marshal(scheduals)
  83. if err == nil {
  84. redis.Set(key, scheduals_json, time.Second*30)
  85. }
  86. }
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "scheduals": scheduals,
  89. })
  90. }
  91. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  92. var dat []map[string]interface{}
  93. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  94. } else {
  95. }
  96. this.ServeSuccessJSON(map[string]interface{}{
  97. "scheduals": dat,
  98. "redis": "true",
  99. "date": schedualDate,
  100. })
  101. }
  102. }
  103. // /m/api/waiting_scheduals [get]
  104. // @param date:string
  105. func (this *DialysisAPIController) WaitingScheduals() {
  106. schedualDate := this.GetString("date")
  107. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  108. if parseDateErr != nil && len(schedualDate) != 0 {
  109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  110. return
  111. }
  112. adminInfo := this.GetMobileAdminUserInfo()
  113. orgID := adminInfo.Org.Id
  114. redis := service.RedisClient()
  115. defer redis.Close()
  116. // cur_date := time.Now().Format("2006-01-02")
  117. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  118. wait_scheduals, _ := redis.Get(key).Result()
  119. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  120. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  121. if err != nil {
  122. this.ErrorLog("获取排班信息失败:%v", err)
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  124. } else {
  125. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  126. for _, s := range scheduals {
  127. returnScheduals = append(returnScheduals, s)
  128. }
  129. if len(returnScheduals) > 0 {
  130. //缓存数据
  131. wait_scheduals_json, err := json.Marshal(scheduals)
  132. if err == nil {
  133. redis.Set(key, wait_scheduals_json, time.Second*30)
  134. }
  135. }
  136. this.ServeSuccessJSON(map[string]interface{}{
  137. "scheduals": scheduals,
  138. })
  139. }
  140. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  141. var dat []map[string]interface{}
  142. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  143. } else {
  144. }
  145. this.ServeSuccessJSON(map[string]interface{}{
  146. "scheduals": dat,
  147. "redis": "true",
  148. "date": schedualDate,
  149. })
  150. }
  151. }
  152. //else{
  153. // fmt.Println("33333333")
  154. //
  155. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  156. // if err != nil {
  157. // this.ErrorLog("获取排班信息失败:%v", err)
  158. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  159. // } else {
  160. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  161. // for _, s := range scheduals {
  162. //
  163. // returnScheduals = append(returnScheduals, s)
  164. // }
  165. //
  166. // this.ServeSuccessJSON(map[string]interface{}{
  167. // "scheduals": returnScheduals,
  168. // })
  169. // }
  170. //
  171. // }
  172. //if err == nil{
  173. //
  174. //
  175. //
  176. //
  177. //
  178. //}else{
  179. //}
  180. // /m/api/dialysis/record [get]
  181. // @param patient_id:int
  182. // @param date:string (yyyy-MM-dd)
  183. func (this *DialysisAPIController) DialysisRecord() {
  184. patientID, _ := this.GetInt64("patient_id")
  185. recordDateStr := this.GetString("date")
  186. if patientID <= 0 {
  187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. if len(recordDateStr) == 0 {
  191. recordDateStr = time.Now().Format("2006-01-02")
  192. }
  193. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  194. if parseDateErr != nil {
  195. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. return
  198. }
  199. adminInfo := this.GetMobileAdminUserInfo()
  200. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  201. if getPatientErr != nil {
  202. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  204. return
  205. } else if patient == nil {
  206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  207. return
  208. }
  209. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  210. // this.TraceLog("==================================%+v", schedual)
  211. if getSchedualErr != nil {
  212. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  214. return
  215. }
  216. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  217. if getRTARErr != nil {
  218. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  220. return
  221. }
  222. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  223. if getPEErr != nil {
  224. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  226. return
  227. }
  228. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  229. if getLPEErr != nil {
  230. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  232. return
  233. }
  234. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  235. if getDoctorAdvicesErr != nil {
  236. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  238. return
  239. }
  240. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  241. if getDialysisOrderErr != nil {
  242. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  244. return
  245. }
  246. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  247. if getDoubleCheckErr != nil {
  248. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  250. return
  251. }
  252. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  253. if getMonitorRecordsErr != nil {
  254. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  256. return
  257. }
  258. var lastMonitorRecord *models.MonitoringRecord
  259. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  260. if getLastErr != nil {
  261. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  263. return
  264. }
  265. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  266. if getAADErr != nil {
  267. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  269. return
  270. }
  271. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  272. if getLAADErr != nil {
  273. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  275. return
  276. }
  277. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  278. if getTreatmentSummaryErr != nil {
  279. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  281. return
  282. }
  283. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  284. //if getDialysisPrescribeErr != nil {
  285. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  286. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  287. // return
  288. //}
  289. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  290. //if getDialysisSolutionErr != nil {
  291. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  292. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  293. // return
  294. //}
  295. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  296. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  297. //if getDialysisPrescribeErr != nil {
  298. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  299. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  300. // return
  301. //}
  302. //获取系统透析处方模版
  303. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  304. //if getSystemDialysisPrescribeErr != nil {
  305. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  306. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  307. // return
  308. //}
  309. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  310. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  311. his_advices, _ := service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  312. if getLPEErr != nil {
  313. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  315. return
  316. }
  317. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  318. if getDryErr != nil {
  319. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. return
  322. }
  323. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  324. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  325. //goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  326. //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  327. operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
  328. //consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  329. //lastConsumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  330. returnData := map[string]interface{}{
  331. "patient": patient,
  332. "schedual": schedual,
  333. "prescription": dialysisPrescribe,
  334. "solution": dialysisSolution,
  335. "last_prescription": lastDialysisPrescribe,
  336. "receiver_treatment_access": receiverTreatmentAccess,
  337. "predialysis_evaluation": predialysisEvaluation,
  338. "doctor_advices": doctorAdvices,
  339. "double_check": doubleCheck,
  340. "assessment_after_dislysis": assessmentAfterDislysis,
  341. "treatment_summary": treatmentSummary,
  342. "monitor_records": monitorRecords,
  343. "dialysis_order": dialysisOrder,
  344. "operators": operators,
  345. "last_predialysis_evaluation": lastPredialysisEvaluation,
  346. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  347. "last_monitor_record": lastMonitorRecord,
  348. "config": gobalConfig,
  349. "dry_weight": lastDryWeightDislysis,
  350. "system_prescription": systemDialysisPrescribe,
  351. "his_advices": his_advices,
  352. }
  353. this.ServeSuccessJSON(returnData)
  354. }
  355. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  356. adminInfo := c.GetMobileAdminUserInfo()
  357. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  358. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  359. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  360. returnData := map[string]interface{}{
  361. "admin_users": adminUsers,
  362. "devices": devices,
  363. "device_numbers": device_numbers,
  364. }
  365. c.ServeSuccessJSON(returnData)
  366. }
  367. func (c *DialysisAPIController) PostAtreatmentInfo() {
  368. id, _ := c.GetInt64("patient", 0)
  369. recordDateStr := c.GetString("record_date")
  370. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  371. summaryContent := c.GetString("summaryContent")
  372. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  373. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  374. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  375. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  376. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  377. nursingRecord := c.GetString("nursing_record")
  378. fmt.Println("护理记录", nursingRecord)
  379. specialRecord := c.GetString("special_record")
  380. fmt.Println("特殊记录", specialRecord)
  381. adminUserInfo := c.GetMobileAdminUserInfo()
  382. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  383. checkStaffId = adminUserInfo.AdminUser.Id
  384. deboardNurseId = adminUserInfo.AdminUser.Id
  385. treatDoctor = adminUserInfo.AdminUser.Id
  386. if id <= 0 {
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  391. if patient.ID == 0 {
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  393. return
  394. }
  395. if len(recordDateStr) == 0 {
  396. recordDateStr = time.Now().Format("2006-01-02")
  397. }
  398. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  399. if parseDateErr != nil {
  400. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. //now := time.Now()
  405. //year, month, day := now.Date()
  406. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  407. //todayTimeStamp := today_time.Unix()
  408. summary := models.TreatmentSummary{
  409. UserOrgId: adminUserInfo.Org.Id,
  410. PatientId: id,
  411. AssessmentDate: recordDate.Unix(),
  412. Mission: propagandaAndEducationContent,
  413. DialysisSummary: summaryContent,
  414. SjNurse: changeMedicalNurseId,
  415. ZlNurse: treatNurseId,
  416. HdNurse: checkStaffId,
  417. XjNurse: deboardNurseId,
  418. ZlDoctor: treatDoctor,
  419. CreatedTime: time.Now().Unix(),
  420. Status: 1,
  421. NursingRecord: nursingRecord,
  422. SpecialRecord: specialRecord,
  423. }
  424. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  425. if treatmentSummary.ID == 0 { //新增
  426. summary.Creater = adminUserInfo.AdminUser.Id
  427. service.AddSigleSummaryRecord(&summary)
  428. c.ServeSuccessJSON(map[string]interface{}{
  429. "summary": summary,
  430. })
  431. } else { //修改
  432. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  433. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  434. // if getPermissionErr != nil {
  435. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  436. // return
  437. // } else if headNursePermission == nil {
  438. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  439. // return
  440. // }
  441. //}
  442. summary.Creater = treatmentSummary.Creater
  443. summary.CreatedTime = treatmentSummary.CreatedTime
  444. summary.Modifier = adminUserInfo.AdminUser.Id
  445. summary.ID = treatmentSummary.ID
  446. service.UpdateSummeRecord(&summary)
  447. c.ServeSuccessJSON(map[string]interface{}{
  448. "summary": summary,
  449. })
  450. }
  451. }
  452. func (c *DialysisAPIController) PostDoubleCheck() {
  453. id, _ := c.GetInt64("patient", 0)
  454. recordDateStr := c.GetString("record_date")
  455. checkTimeStr := c.GetString("check_time")
  456. firstCheckTimeStr := c.GetString("first_check_time")
  457. creater, _ := c.GetInt64("creater", 0)
  458. modifier, _ := c.GetInt64("modifier", 0)
  459. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  460. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  461. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  462. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  463. dialysis_item_desc := c.GetString("dialysis_item_desc")
  464. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  465. vascular_access_desc := c.GetString("vascular_access_desc")
  466. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  467. collator, _ := c.GetInt64("collator", 0)
  468. if id <= 0 {
  469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  470. return
  471. }
  472. adminUserInfo := c.GetMobileAdminUserInfo()
  473. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  474. if patient.ID == 0 {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  476. return
  477. }
  478. if len(recordDateStr) == 0 {
  479. recordDateStr = time.Now().Format("2006-01-02")
  480. }
  481. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  482. if parseDateErr != nil {
  483. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. var checkDate int64
  488. if len(checkTimeStr) == 0 {
  489. checkDate = 0
  490. } else {
  491. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  492. checkDate = checkDateUnix.Unix()
  493. }
  494. var firstCheckDate int64
  495. if len(firstCheckTimeStr) == 0 {
  496. firstCheckDate = 0
  497. } else {
  498. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  499. firstCheckDate = firstCheckDateUnix.Unix()
  500. }
  501. //now := time.Now()
  502. //year, month, day := now.Date()
  503. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  504. //todayTimeStamp := today_time.Unix()
  505. doubleCheck := models.DoubleCheck{
  506. UserOrgId: adminUserInfo.Org.Id,
  507. PatientId: id,
  508. DialysisItemCheck: dialysis_item_check,
  509. DialysisParameterCheck: dialysis_parameter_check,
  510. VascularAccessVerification: vascular_access_verification,
  511. PipelineConnectionCheck: pipeline_connection_check,
  512. DialysisItemDesc: dialysis_item_desc,
  513. DialysisParameterDesc: dialysis_parameter_desc,
  514. VascularAccessDesc: vascular_access_desc,
  515. PipelineConnectionDesc: pipeline_connection_desc,
  516. Collator: collator,
  517. Status: 1,
  518. CreatedTime: time.Now().Unix(),
  519. CheckDate: recordDate.Unix(),
  520. UpdatedTime: time.Now().Unix(),
  521. }
  522. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  523. if check.ID == 0 { //新增
  524. doubleCheck.FirstCheckTime = firstCheckDate
  525. doubleCheck.CheckTime = checkDate
  526. doubleCheck.Creater = creater
  527. doubleCheck.Modifier = modifier
  528. err := service.AddSigleDoubleCheck(&doubleCheck)
  529. if err == nil {
  530. c.ServeSuccessJSON(map[string]interface{}{
  531. "doubleCheck": &doubleCheck,
  532. })
  533. }
  534. } else { //修改
  535. doubleCheck.FirstCheckTime = firstCheckDate
  536. doubleCheck.CheckTime = checkDate
  537. doubleCheck.Creater = creater
  538. doubleCheck.Modifier = modifier
  539. doubleCheck.CreatedTime = check.CreatedTime
  540. doubleCheck.ID = check.ID
  541. err := service.UpdateDoubleCheck(&doubleCheck)
  542. if err == nil {
  543. c.ServeSuccessJSON(map[string]interface{}{
  544. "doubleCheck": &doubleCheck,
  545. })
  546. }
  547. }
  548. }
  549. func (c *DialysisAPIController) PostAcceptsAssessment() {
  550. id, _ := c.GetInt64("patient", 0)
  551. recordDateStr := c.GetString("record_date")
  552. way, _ := c.GetInt64("way", 0)
  553. consciousness, _ := c.GetInt64("consciousness", 0)
  554. appetite, _ := c.GetInt64("appetite", 0)
  555. condition, _ := c.GetInt64("condition", 0)
  556. posture, _ := c.GetInt64("posture")
  557. sick_condition, _ := c.GetInt64("sick_condition", 0)
  558. danger_level, _ := c.GetInt64("danger_level", 0)
  559. intake, _ := c.GetInt64("intake", 0)
  560. nutrition, _ := c.GetInt64("nutrition", 0)
  561. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  562. psychological_assessment_other := c.GetString("psychological_assessment_other")
  563. score := c.GetString("score")
  564. sick_condition_other := c.GetString("sick_condition_other")
  565. //precaution, _ := c.GetInt64("precaution", 0)
  566. precaution := c.GetString("precaution")
  567. precaution_other := c.GetString("precaution_other")
  568. psychological_other := c.GetString("psychological_other")
  569. admission_number := c.GetString("admission_number")
  570. if id <= 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  572. return
  573. }
  574. adminUserInfo := c.GetMobileAdminUserInfo()
  575. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  576. if patient.ID == 0 {
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  578. return
  579. }
  580. //now := time.Now()
  581. //year, month, day := now.Date()
  582. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  583. //todayTimeStamp := today_time.Unix()
  584. if len(recordDateStr) == 0 {
  585. recordDateStr = time.Now().Format("2006-01-02")
  586. }
  587. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  588. if parseDateErr != nil {
  589. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  591. return
  592. }
  593. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  594. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  595. UserOrgId: adminUserInfo.Org.Id,
  596. PatientId: id,
  597. RecordDate: recordDate.Unix(),
  598. Way: way,
  599. Consciousness: consciousness,
  600. Appetite: appetite,
  601. Condition: condition,
  602. SickCondition: sick_condition,
  603. DangerLevel: danger_level,
  604. Intake: intake,
  605. Nutrition: nutrition,
  606. PsychologicalAssessment: psychological_assessment,
  607. PsychologicalAssessmentOther: psychological_assessment_other,
  608. SickConditionOther: sick_condition_other,
  609. Posture: posture,
  610. CreatedTime: time.Now().Unix(),
  611. UpdateTime: time.Now().Unix(),
  612. Status: 1,
  613. Score: score,
  614. Precaution: precaution,
  615. PrecautionOther: precaution_other,
  616. PsychologicalOther: psychological_other,
  617. AdmissionNumber: admission_number,
  618. }
  619. if receiveTreatment.ID == 0 { //新增
  620. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  621. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  622. if err == nil {
  623. c.ServeSuccessJSON(map[string]interface{}{
  624. "receiveTreatmentAsses": receiveTreatmentAsses,
  625. })
  626. }
  627. } else { //修改
  628. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  629. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  630. // if getPermissionErr != nil {
  631. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  632. // return
  633. // } else if headNursePermission == nil {
  634. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  635. // return
  636. // }
  637. //}
  638. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  639. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  640. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  641. receiveTreatmentAsses.ID = receiveTreatment.ID
  642. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  643. if err == nil {
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "receiveTreatmentAsses": receiveTreatmentAsses,
  646. })
  647. }
  648. }
  649. }
  650. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  651. id, _ := c.GetInt64("patient", 0)
  652. recordDateStr := c.GetString("record_date")
  653. weightAfter, _ := c.GetFloat("weight_after", 0)
  654. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  655. weightReduce, _ := c.GetFloat("weight_loss", 0)
  656. temperature, _ := c.GetFloat("temperature", 0)
  657. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  658. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  659. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  660. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  661. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  662. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  663. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  664. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  665. cruor := c.GetString("cruor")
  666. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  667. internalFistula := c.GetString("internal_fistula")
  668. catheter := c.GetString("catheter")
  669. complications := c.GetString("complication")
  670. remark := c.GetString("remark")
  671. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  672. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  673. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  674. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  675. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  676. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  677. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  678. patientGose, _ := c.GetInt64("patient_gose", 0)
  679. inpatientDepartment := c.GetString("inpatient_department")
  680. observationContent := c.GetString("observation_content")
  681. observationContentOther := c.GetString("observation_content_other")
  682. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  683. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  684. in_advance_reason := c.GetString("in_advance_reason")
  685. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  686. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  687. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  688. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  689. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  690. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  691. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  692. dialyzer, _ := c.GetInt64("dialyzer", 0)
  693. in_advance_reason_other := c.GetString("in_advance_reason_other")
  694. is_eat, _ := c.GetInt64("is_eat", 0)
  695. cvc_a, _ := c.GetFloat("cvc_a", 0)
  696. cvc_v, _ := c.GetFloat("cvc_v", 0)
  697. channels, _ := c.GetInt64("channel", 0)
  698. return_blood, _ := c.GetInt64("return_blood", 0)
  699. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  700. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  701. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  702. blood_flow, _ := c.GetInt64("blood_flow", 0)
  703. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  704. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  705. sealing_fluid_special := c.GetString("sealing_fluid_special")
  706. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  707. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  708. setting_pressure := c.GetString("setting_pressure")
  709. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  710. diastolic_pressure := c.GetString("diastolic_pressure")
  711. other_complication := c.GetString("other_complication")
  712. if id <= 0 {
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. adminUserInfo := c.GetMobileAdminUserInfo()
  717. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  718. if patient.ID == 0 {
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  720. return
  721. }
  722. if len(recordDateStr) == 0 {
  723. recordDateStr = time.Now().Format("2006-01-02")
  724. }
  725. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  726. if parseDateErr != nil {
  727. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. //now := time.Now()
  732. //year, month, day := now.Date()
  733. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  734. //todayTimeStamp := today_time.Unix()
  735. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  736. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  737. UserOrgId: adminUserInfo.Org.Id,
  738. PatientId: id,
  739. AssessmentDate: recordDate.Unix(),
  740. Temperature: temperature,
  741. PulseFrequency: pulse_frequency,
  742. BreathingRate: breathing_rate,
  743. SystolicBloodPressure: systolic_blood_pressure,
  744. DiastolicBloodPressure: diastolic_blood_pressure,
  745. ActualUltrafiltration: actual_ultrafiltration,
  746. ActualDisplacement: actual_displacement,
  747. ActualTreatmentHour: actualtreatHour,
  748. ActualTreatmentMinute: actualtreatmin,
  749. WeightAfter: weightAfter,
  750. AdditionalWeight: additionalWeight,
  751. WeightLoss: weightReduce,
  752. Cruor: cruor,
  753. SymptomAfterDialysis: symptomsAfterDialysi,
  754. InternalFistula: internalFistula,
  755. Catheter: catheter,
  756. Complication: complications,
  757. DialysisIntakes: dialysateVolume,
  758. CreatedTime: time.Now().Unix(),
  759. Status: 1,
  760. Remark: remark,
  761. BloodAccessPartId: blood_access_part_id,
  762. BloodAccessPartOperaId: blood_access_part_opera_id,
  763. DialysisIntakesUnit: dialysis_intakes_unit,
  764. PuncturePointOozingBlood: puncturePointOozingBlood,
  765. PuncturePointHaematoma: puncturePointHaematoma,
  766. InternalFistulaTremorAc: internalFistulaTremorAc,
  767. PatientGose: patientGose,
  768. InpatientDepartment: inpatientDepartment,
  769. ObservationContent: observationContent,
  770. ObservationContentOther: observationContentOther,
  771. DialysisProcess: dialysis_process,
  772. InAdvanceMinute: in_advance_minute,
  773. InAdvanceReason: in_advance_reason,
  774. HemostasisMinute: hemostasis_minute,
  775. HemostasisOpera: hemostasis_opera,
  776. TremorNoise: tremor_noise,
  777. DisequilibriumSyndrome: disequilibrium_syndrome,
  778. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  779. ArterialTube: arterial_tube,
  780. IntravenousTube: intravenous_tube,
  781. Dialyzer: dialyzer,
  782. InAdvanceReasonOther: in_advance_reason_other,
  783. IsEat: is_eat,
  784. CvcA: cvc_a,
  785. CvcV: cvc_v,
  786. Channel: channels,
  787. ReturnBlood: return_blood,
  788. RehydrationVolume: rehydration_volume,
  789. DialysisDuring: dialysis_during,
  790. StrokeVolume: stroke_volume,
  791. BloodFlow: blood_flow,
  792. SealingFluidDispose: sealing_fluid_dispose,
  793. SealingFluidSpecial: sealing_fluid_special,
  794. DosageOfAnticoagulants: dosage_of_anticoagulants,
  795. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  796. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  797. SettingPressure: setting_pressure,
  798. DiastolicPressure: diastolic_pressure,
  799. OtherComplication: other_complication,
  800. }
  801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  802. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  803. if assessmentAfter.ID == 0 { //新增
  804. if appRole.UserType == 2 || appRole.UserType == 1 {
  805. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  806. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  807. } else {
  808. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  809. }
  810. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  811. if err == nil {
  812. c.ServeSuccessJSON(map[string]interface{}{
  813. "assessmentAfterDislysis": assessmentAfterDislysis,
  814. })
  815. }
  816. } else { //修改
  817. if appRole.UserType == 2 || appRole.UserType == 1 {
  818. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  819. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  820. } else {
  821. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  822. if assessmentAfterDislysis.Creater == 0 {
  823. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  824. }
  825. }
  826. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  827. assessmentAfterDislysis.ID = assessmentAfter.ID
  828. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  829. if err == nil {
  830. c.ServeSuccessJSON(map[string]interface{}{
  831. "assessmentAfterDislysis": assessmentAfterDislysis,
  832. })
  833. }
  834. }
  835. }
  836. func (c *DialysisAPIController) PostDialysisPrescription() {
  837. id, _ := c.GetInt64("patient", 0)
  838. recordDateStr := c.GetString("record_date")
  839. if id <= 0 {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  841. return
  842. }
  843. adminUserInfo := c.GetMobileAdminUserInfo()
  844. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  845. if patient.ID == 0 {
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  847. return
  848. }
  849. if len(recordDateStr) == 0 {
  850. recordDateStr = time.Now().Format("2006-01-02")
  851. }
  852. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  853. if parseDateErr != nil {
  854. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. mode_id, _ := c.GetInt64("mode_id", 0)
  859. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  860. dialyzer, _ := c.GetInt64("dialyzer", 0)
  861. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  862. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  863. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  864. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  865. replacement_total, _ := c.GetFloat("replacement_total", 0)
  866. replacement_way, _ := c.GetInt64("replacement_way", 0)
  867. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  868. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  869. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  870. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  871. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  872. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  873. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  874. kalium, _ := c.GetFloat("kalium", 0)
  875. sodium, _ := c.GetFloat("sodium", 0)
  876. calcium, _ := c.GetFloat("calcium", 0)
  877. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  878. glucose, _ := c.GetFloat("glucose", 0)
  879. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  880. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  881. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  882. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  883. conductivity, _ := c.GetFloat("conductivity", 0)
  884. remark := c.GetString("remark")
  885. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  886. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  887. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  888. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  889. body_fluid, _ := c.GetInt64("body_fluid", 0)
  890. special_medicine, _ := c.GetInt64("special_medicine", 0)
  891. special_medicine_other := c.GetString("special_medicine_other")
  892. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  893. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  894. blood_access, _ := c.GetInt64("blood_access", 0)
  895. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  896. body_fluid_other := c.GetString("body_fluid_other")
  897. niprocart, _ := c.GetInt64("niprocart", 0)
  898. jms, _ := c.GetInt64("jms", 0)
  899. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  900. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  901. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  902. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  903. filtryzer, _ := c.GetInt64("filtryzer", 0)
  904. target_ktv, _ := c.GetFloat("target_ktv", 0)
  905. dialyzers, _ := c.GetInt64("dialyzers", 0)
  906. injector, _ := c.GetInt64("injector", 0)
  907. bloodlines, _ := c.GetInt64("bloodlines", 0)
  908. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  909. safe_package, _ := c.GetInt64("package", 0)
  910. a_liquid, _ := c.GetInt64("a_liquid", 0)
  911. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  912. fmt.Println("预冲量====", pre_impulse)
  913. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  914. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  915. blood := c.GetString("blood")
  916. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  917. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  918. //
  919. //if template.TemplateId == 2 || template.TemplateId == 6 {
  920. // if appRole.UserType == 3 {
  921. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  922. // if getPermissionErr != nil {
  923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  924. // return
  925. // } else if headNursePermission == nil {
  926. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  927. // return
  928. // }
  929. // }
  930. //}
  931. //TODO 需要根据角色去判断
  932. prescription := models.DialysisPrescription{
  933. UserOrgId: adminUserInfo.Org.Id,
  934. PatientId: id,
  935. RecordDate: recordDate.Unix(),
  936. ModeId: mode_id,
  937. DialysisDuration: dialysis_duration,
  938. Dialyzer: dialyzer,
  939. PerfusionApparatus: perfusion_apparatus,
  940. BloodFlowVolume: blood_flow_volume,
  941. DewaterAmount: dewater_amount,
  942. DisplaceLiqui: displace_liqui,
  943. ReplacementWay: replacement_way,
  944. Anticoagulant: anticoagulant,
  945. AnticoagulantShouji: anticoagulant_shouji,
  946. AnticoagulantWeichi: anticoagulant_weichi,
  947. AnticoagulantZongliang: anticoagulant_zongliang,
  948. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  949. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  950. Kalium: kalium,
  951. Sodium: sodium,
  952. Calcium: calcium,
  953. Bicarbonate: bicarbonate,
  954. Glucose: glucose,
  955. // DryWeight: dry_weight,
  956. DialysateFlow: dialysate_flow,
  957. DialysateTemperature: dialysate_temperature,
  958. // PrescriptionDoctor: prescription_doctor,
  959. ReplacementTotal: replacement_total,
  960. Conductivity: conductivity,
  961. Remark: remark,
  962. Status: 1,
  963. CreatedTime: time.Now().Unix(),
  964. UpdatedTime: time.Now().Unix(),
  965. DialysisDurationMinute: dialysisDurationMinute,
  966. DialysisDurationHour: dialysisDurationHour,
  967. TargetUltrafiltration: targetUltrafiltration,
  968. DialysateFormulation: dialysateFormulation,
  969. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  970. BodyFluid: body_fluid,
  971. SpecialMedicine: special_medicine,
  972. SpecialMedicineOther: special_medicine_other,
  973. DisplaceLiquiPart: displace_liqui_part,
  974. DisplaceLiquiValue: displace_liqui_value,
  975. BloodAccess: blood_access,
  976. Ultrafiltration: ultrafiltration,
  977. BodyFluidOther: body_fluid_other,
  978. Niprocart: niprocart,
  979. Jms: jms,
  980. FistulaNeedleSet: fistula_needle_set,
  981. FistulaNeedleSet16: fistula_needle_set_16,
  982. Hemoperfusion: hemoperfusion,
  983. DialyserSterilised: dialyser_sterilised,
  984. Filtryzer: filtryzer,
  985. Dialyzers: dialyzers,
  986. Injector: injector,
  987. Bloodlines: bloodlines,
  988. TubingHemodialysis: tubing_hemodialysis,
  989. Package: safe_package,
  990. ALiquid: a_liquid,
  991. TargetKtv: target_ktv,
  992. PreImpulse: pre_impulse,
  993. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  994. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  995. Blood: blood,
  996. }
  997. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  998. if dialysisPrescription.ID == 0 { //新增
  999. //if mode_id > 0 {
  1000. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1001. //}
  1002. if appRole.UserType == 2 || appRole.UserType == 1 {
  1003. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1004. }
  1005. prescription.Creater = adminUserInfo.AdminUser.Id
  1006. err := service.AddSigleRecord(&prescription)
  1007. if err == nil {
  1008. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1009. if updateErr != nil {
  1010. utils.ErrorLog("%v", updateErr)
  1011. }
  1012. c.ServeSuccessJSON(map[string]interface{}{
  1013. "prescription": prescription,
  1014. })
  1015. }
  1016. } else { //修改
  1017. //if mode_id > 0 {
  1018. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. //}
  1020. //if template.TemplateId == 1 {
  1021. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1022. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1023. // if getPermissionErr != nil {
  1024. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1025. // return
  1026. // } else if headNursePermission == nil {
  1027. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1028. // return
  1029. // }
  1030. // }
  1031. //}
  1032. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1033. prescription.Modifier = adminUserInfo.AdminUser.Id
  1034. if appRole.UserType == 2 || appRole.UserType == 1 {
  1035. prescription_doctor := adminUserInfo.AdminUser.Id
  1036. prescription.PrescriptionDoctor = prescription_doctor
  1037. } else {
  1038. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1039. }
  1040. if dialysisPrescription.Creater == 0 { //体重称
  1041. prescription.Creater = adminUserInfo.AdminUser.Id
  1042. } else {
  1043. prescription.Creater = dialysisPrescription.Creater
  1044. }
  1045. prescription.ID = dialysisPrescription.ID
  1046. err := service.UpDateDialysisPrescription(&prescription)
  1047. if err == nil {
  1048. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1049. if updateErr != nil {
  1050. utils.ErrorLog("%v", updateErr)
  1051. }
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "prescription": prescription,
  1054. })
  1055. }
  1056. }
  1057. }
  1058. func (c *DialysisAPIController) Finish() {
  1059. id, _ := c.GetInt64("patient", 0)
  1060. recordDateStr := c.GetString("record_date")
  1061. nurseID, _ := c.GetInt64("nurse")
  1062. end_time := c.GetString("end_time")
  1063. if id <= 0 || nurseID <= 0 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1065. return
  1066. }
  1067. adminUserInfo := c.GetMobileAdminUserInfo()
  1068. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1069. if patient.ID == 0 {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1071. return
  1072. }
  1073. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1074. if getNurseErr != nil {
  1075. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1077. return
  1078. } else if nurse == nil {
  1079. c.ErrorLog("护士不存在")
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1081. return
  1082. }
  1083. if len(recordDateStr) == 0 {
  1084. recordDateStr = time.Now().Format("2006-01-02")
  1085. }
  1086. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1087. if parseDateErr != nil {
  1088. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1090. return
  1091. }
  1092. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1093. if parseEndDateErr != nil {
  1094. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1096. return
  1097. }
  1098. //now := time.Now()
  1099. //year, month, day := now.Date()
  1100. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1101. //todayTimeStamp := today_time.Unix()
  1102. // 获取当天的第一条透析纪录
  1103. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1104. if getMonitorRecordsErr != nil {
  1105. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1107. return
  1108. }
  1109. // 获取当前的最后一条透析纪录
  1110. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  1111. if getMonitorRecordsErr != nil {
  1112. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1114. return
  1115. }
  1116. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1117. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1118. if getAADErr != nil {
  1119. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1121. return
  1122. }
  1123. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1124. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1125. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1126. if assessmentAfterDislysis != nil {
  1127. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1128. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1129. } else {
  1130. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1131. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1132. tempassessmentAfterDislysis.Status = 1
  1133. tempassessmentAfterDislysis.PatientId = id
  1134. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1135. }
  1136. if dialysisOrder.Stage == 1 {
  1137. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1138. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1139. fmt.Println(value)
  1140. a, b := math.Modf(value)
  1141. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1142. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1143. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1144. fmt.Println(hour)
  1145. fmt.Println(minute)
  1146. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1147. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1148. }
  1149. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1150. //var num1 int64
  1151. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1152. //fmt.Println(num1)
  1153. //sub := float64(num1 / 3600)
  1154. //fmt.Println(sub)
  1155. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1156. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1157. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1158. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1159. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1160. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1161. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1162. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1163. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1164. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1165. }
  1166. if lastAssessmentAfterDislysis != nil {
  1167. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1168. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1169. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1170. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1171. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1172. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1173. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1174. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1175. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1176. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1177. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1178. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1179. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1180. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1181. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1182. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1183. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1184. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1185. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1186. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1187. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1188. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1189. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1190. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1191. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1192. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1193. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1194. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1195. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1196. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1197. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1198. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1199. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1200. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1201. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1202. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1203. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1204. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1205. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1206. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1207. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1208. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1209. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1210. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1211. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1212. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1213. }
  1214. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1217. return
  1218. }
  1219. if dialysisOrder == nil {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1221. return
  1222. }
  1223. if dialysisOrder.Stage == 2 {
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1225. return
  1226. }
  1227. if dialysisOrder.Stage == 1 {
  1228. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1229. //结束时候透析次数加1
  1230. service.UpdateSolutionByPatientId(id)
  1231. dialysisOrder.Stage = 2
  1232. dialysisOrder.FinishNurse = nurseID
  1233. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1234. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1235. dialysisOrder.EndTime = endDate.Unix()
  1236. if err == nil {
  1237. c.ServeSuccessJSON(map[string]interface{}{
  1238. "dialysisOrder": dialysisOrder,
  1239. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1240. })
  1241. } else {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1243. }
  1244. }
  1245. }
  1246. func (c *DialysisAPIController) GetAllZone() {
  1247. adminUserInfo := c.GetMobileAdminUserInfo()
  1248. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1249. if err == nil {
  1250. c.ServeSuccessJSON(map[string]interface{}{
  1251. "zone": zone,
  1252. })
  1253. }
  1254. }
  1255. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1256. adminUserInfo := c.GetMobileAdminUserInfo()
  1257. page, _ := c.GetInt64("page", 1)
  1258. limit, _ := c.GetInt64("limit", 10)
  1259. schedulType, _ := c.GetInt64("schedul_type", 0)
  1260. startTime, _ := c.GetInt64("schedul_time", 0)
  1261. partitionType, _ := c.GetInt64("partition_type", 0)
  1262. keywords := c.GetString("keywords")
  1263. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1264. if err == nil {
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "schedule": dialysisSchedule,
  1267. })
  1268. }
  1269. return
  1270. }
  1271. // /m/api/dialysis/start [post]
  1272. // @param patient_id:int
  1273. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1274. // @param nurse:int 上机护士
  1275. // @param bed:int 床位号
  1276. func (this *DialysisAPIController) StartDialysis() {
  1277. patientID, _ := this.GetInt64("patient_id")
  1278. recordDateStr := this.GetString("record_date")
  1279. nurseID, _ := this.GetInt64("nurse")
  1280. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1281. blood_drawing, _ := this.GetInt64("blood_drawing")
  1282. schedual_type, _ := this.GetInt64("schedual_type")
  1283. bedID, _ := this.GetInt64("bed")
  1284. start_time := this.GetString("start_time")
  1285. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1286. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1288. return
  1289. }
  1290. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1291. if parseStartDateErr != nil {
  1292. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1294. return
  1295. }
  1296. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1297. if parseErr != nil {
  1298. this.ErrorLog("时间解析失败:%v", parseErr)
  1299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1300. return
  1301. }
  1302. adminUserInfo := this.GetMobileAdminUserInfo()
  1303. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1304. if getPatientErr != nil {
  1305. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1307. return
  1308. } else if patient == nil {
  1309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1310. return
  1311. }
  1312. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1313. if getNurseErr != nil {
  1314. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1316. return
  1317. } else if nurse == nil {
  1318. this.ErrorLog("护士不存在")
  1319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1323. if getNurseErr != nil {
  1324. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. } else if nurse == nil {
  1328. this.ErrorLog("护士不存在")
  1329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1333. if getDeviceNumberErr != nil {
  1334. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1336. return
  1337. } else if deviceNumber == nil {
  1338. this.ErrorLog("床位号不存在")
  1339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1343. if getRecordErr != nil {
  1344. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1346. return
  1347. } else if dialysisRecord != nil {
  1348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1349. return
  1350. }
  1351. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1352. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1353. timeLayout := "2006-01-02 15:04:05"
  1354. loc, _ := time.LoadLocation("Local")
  1355. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1356. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1357. schedulestartTime := theStartTime.Unix()
  1358. scheduleendTime := theEndTime.Unix()
  1359. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1360. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1361. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1362. //查询该床位是否有人用了
  1363. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1364. if err == gorm.ErrRecordNotFound { //空床位
  1365. // 修改了床位逻辑
  1366. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1367. if daySchedule.ID > 0 {
  1368. daySchedule.PartitionId = deviceNumber.ZoneID
  1369. daySchedule.BedId = bedID
  1370. daySchedule.ScheduleType = schedual_type
  1371. daySchedule.UpdatedTime = time.Now().Unix()
  1372. err := service.UpdateSchedule(&daySchedule)
  1373. if err != nil {
  1374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1375. return
  1376. }
  1377. }
  1378. } else if err == nil {
  1379. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1380. if order_err == nil {
  1381. if order.ID > 0 { //该机位被其他人占用了
  1382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1383. return
  1384. } else {
  1385. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1386. if daySchedule.ID > 0 {
  1387. daySchedule.PartitionId = deviceNumber.ZoneID
  1388. daySchedule.BedId = bedID
  1389. daySchedule.ScheduleType = schedual_type
  1390. daySchedule.UpdatedTime = time.Now().Unix()
  1391. err := service.UpdateSchedule(&daySchedule)
  1392. if err != nil {
  1393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1394. return
  1395. }
  1396. }
  1397. }
  1398. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1399. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1400. if daySchedule.ID > 0 {
  1401. daySchedule.PartitionId = deviceNumber.ZoneID
  1402. daySchedule.BedId = bedID
  1403. daySchedule.ScheduleType = schedual_type
  1404. daySchedule.UpdatedTime = time.Now().Unix()
  1405. err := service.UpdateSchedule(&daySchedule)
  1406. if err != nil {
  1407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1408. return
  1409. }
  1410. }
  1411. }
  1412. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1414. return
  1415. }
  1416. } else if err != nil {
  1417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1418. return
  1419. }
  1420. dialysisRecord = &models.DialysisOrder{
  1421. DialysisDate: recordDate.Unix(),
  1422. UserOrgId: adminUserInfo.Org.Id,
  1423. PatientId: patientID,
  1424. Stage: 1,
  1425. BedID: bedID,
  1426. StartNurse: nurseID,
  1427. Status: 1,
  1428. StartTime: startDate.Unix(),
  1429. CreatedTime: time.Now().Unix(),
  1430. UpdatedTime: time.Now().Unix(),
  1431. PunctureNurse: puncture_nurse,
  1432. Creator: adminUserInfo.AdminUser.Id,
  1433. Modifier: adminUserInfo.AdminUser.Id,
  1434. SchedualType: schedual_type,
  1435. WashpipeNurse: washpipe_nurse,
  1436. }
  1437. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1438. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1439. var tempdispose string
  1440. // 只针对中能建
  1441. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1442. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1443. }
  1444. var ultrafiltration_rate float64
  1445. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1446. if prescription.ID > 0 {
  1447. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1448. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1449. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  1450. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1451. }
  1452. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1453. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1454. }
  1455. // 只针对方济医院
  1456. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1457. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1458. ultrafiltration_rate = value
  1459. }
  1460. }
  1461. }
  1462. record := models.MonitoringRecord{
  1463. UserOrgId: adminUserInfo.Org.Id,
  1464. PatientId: patientID,
  1465. DialysisOrderId: dialysisRecord.ID,
  1466. MonitoringDate: schedulestartTime,
  1467. OperateTime: startDate.Unix(),
  1468. // MonitoringTime: recordTime,
  1469. MonitoringNurse: nurseID,
  1470. Dispose: tempdispose,
  1471. UltrafiltrationRate: ultrafiltration_rate,
  1472. UltrafiltrationVolume: 0,
  1473. Status: 1,
  1474. CreatedTime: time.Now().Unix(),
  1475. UpdatedTime: time.Now().Unix(),
  1476. }
  1477. //只针对广慈医院
  1478. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 {
  1479. // 查询病人是否有透前评估数据
  1480. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1481. //如果有数据就插入
  1482. if errcode == nil {
  1483. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1484. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1485. record.BreathingRate = befor.BreathingRate
  1486. record.PulseFrequency = befor.PulseFrequency
  1487. record.Temperature = befor.Temperature
  1488. }
  1489. }
  1490. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1491. if newdialysisRecord.ID > 0 {
  1492. err := service.CreateMonitor(&record)
  1493. if err != nil {
  1494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1495. return
  1496. }
  1497. }
  1498. if createErr != nil {
  1499. this.ErrorLog("上机失败:%v", createErr)
  1500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1501. return
  1502. }
  1503. this.ServeSuccessJSON(map[string]interface{}{
  1504. "dialysis_order": newdialysisRecord,
  1505. "monitor": record,
  1506. })
  1507. }
  1508. func (c *DialysisAPIController) PostSolution() {
  1509. id, _ := c.GetInt64("patient", 0)
  1510. recordDateStr := c.GetString("record_date")
  1511. if id <= 0 {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1513. return
  1514. }
  1515. adminUserInfo := c.GetMobileAdminUserInfo()
  1516. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1517. if patient.ID == 0 {
  1518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1519. return
  1520. }
  1521. if len(recordDateStr) == 0 {
  1522. recordDateStr = time.Now().Format("2006-01-02")
  1523. }
  1524. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1525. if parseDateErr != nil {
  1526. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1528. return
  1529. }
  1530. mode_id, _ := c.GetInt64("mode_id", 0)
  1531. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1532. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1533. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1534. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1535. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1536. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1537. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1538. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1539. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1540. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1541. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1542. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1543. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1544. kalium, _ := c.GetFloat("kalium", 0)
  1545. sodium, _ := c.GetFloat("sodium", 0)
  1546. calcium, _ := c.GetFloat("calcium", 0)
  1547. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1548. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1549. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1550. glucose, _ := c.GetFloat("glucose", 0)
  1551. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1552. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1553. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1554. conductivity, _ := c.GetFloat("conductivity", 0)
  1555. remark := c.GetString("remark")
  1556. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1557. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1558. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1559. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1560. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1561. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1562. special_medicine_other := c.GetString("special_medicine_other")
  1563. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1564. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1565. blood_access, _ := c.GetInt64("blood_access", 0)
  1566. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1567. body_fluid_other := c.GetString("body_fluid_other")
  1568. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1569. niprocart, _ := c.GetInt64("niprocart", 0)
  1570. jms, _ := c.GetInt64("jms", 0)
  1571. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1572. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1573. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1574. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1575. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1576. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1577. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1578. injector, _ := c.GetInt64("injector", 0)
  1579. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1580. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1581. safe_package, _ := c.GetInt64("package", 0)
  1582. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1583. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1584. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1585. blood := c.GetString("blood")
  1586. if mode_id > 0 {
  1587. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1588. }
  1589. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1590. //
  1591. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1592. // if appRole.UserType == 3 {
  1593. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1594. // if getPermissionErr != nil {
  1595. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1596. // return
  1597. // } else if headNursePermission == nil {
  1598. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1599. // return
  1600. // }
  1601. // }
  1602. //}
  1603. prescription := models.DialysisPrescription{
  1604. UserOrgId: adminUserInfo.Org.Id,
  1605. PatientId: id,
  1606. RecordDate: recordDate.Unix(),
  1607. ModeId: mode_id,
  1608. DialysisDuration: dialysis_duration,
  1609. Dialyzer: dialyzer,
  1610. PerfusionApparatus: perfusion_apparatus,
  1611. BloodFlowVolume: blood_flow_volume,
  1612. DewaterAmount: dewater_amount,
  1613. DisplaceLiqui: displace_liqui,
  1614. ReplacementWay: replacement_way,
  1615. Anticoagulant: anticoagulant,
  1616. AnticoagulantShouji: anticoagulant_shouji,
  1617. AnticoagulantWeichi: anticoagulant_weichi,
  1618. AnticoagulantZongliang: anticoagulant_zongliang,
  1619. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1620. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1621. Kalium: kalium,
  1622. Sodium: sodium,
  1623. Calcium: calcium,
  1624. Bicarbonate: bicarbonate,
  1625. Glucose: glucose,
  1626. // DryWeight: dry_weight,
  1627. DialysateFlow: dialysate_flow,
  1628. DialysateTemperature: dialysate_temperature,
  1629. Conductivity: conductivity,
  1630. Remark: remark,
  1631. Status: 1,
  1632. CreatedTime: time.Now().Unix(),
  1633. UpdatedTime: time.Now().Unix(),
  1634. DialysisDurationMinute: dialysisDurationMinute,
  1635. DialysisDurationHour: dialysisDurationHour,
  1636. TargetUltrafiltration: targetUltrafiltration,
  1637. DialysateFormulation: dialysateFormulation,
  1638. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1639. BodyFluid: body_fluid,
  1640. SpecialMedicine: special_medicine,
  1641. SpecialMedicineOther: special_medicine_other,
  1642. DisplaceLiquiPart: displace_liqui_part,
  1643. DisplaceLiquiValue: displace_liqui_value,
  1644. BloodAccess: blood_access,
  1645. Ultrafiltration: ultrafiltration,
  1646. BodyFluidOther: body_fluid_other,
  1647. ReplacementTotal: replacement_total,
  1648. Niprocart: niprocart,
  1649. Jms: jms,
  1650. FistulaNeedleSet: fistula_needle_set,
  1651. FistulaNeedleSet16: fistula_needle_set_16,
  1652. Hemoperfusion: hemoperfusion,
  1653. DialyserSterilised: dialyser_sterilised,
  1654. Filtryzer: filtryzer,
  1655. TargetKtv: target_ktv,
  1656. Dialyzers: dialyzers,
  1657. Injector: injector,
  1658. Bloodlines: bloodlines,
  1659. TubingHemodialysis: tubing_hemodialysis,
  1660. Package: safe_package,
  1661. ALiquid: a_liquid,
  1662. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1663. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1664. Blood: blood,
  1665. }
  1666. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1667. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1668. //
  1669. if appRole.UserType == 2 || appRole.UserType == 1 {
  1670. prescription_doctor = adminUserInfo.AdminUser.Id
  1671. prescription.PrescriptionDoctor = prescription_doctor
  1672. }
  1673. if dialysisPrescription.ID == 0 { //新增
  1674. prescription.Creater = adminUserInfo.AdminUser.Id
  1675. } else { //修改
  1676. if dialysisPrescription.Creater == 0 {
  1677. prescription.Creater = adminUserInfo.AdminUser.Id
  1678. } else {
  1679. prescription.Creater = dialysisPrescription.Creater
  1680. }
  1681. //if/**/
  1682. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1683. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1684. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1685. // if getPermissionErr != nil {
  1686. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1687. // return
  1688. // } else if headNursePermission == nil {
  1689. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1690. // return
  1691. // }
  1692. //}
  1693. //prescription.Creater = dialysisPrescription.Creater
  1694. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1695. prescription.Modifier = adminUserInfo.AdminUser.Id
  1696. prescription.ID = dialysisPrescription.ID
  1697. }
  1698. solution := models.DialysisSolution{
  1699. RegistrarsId: adminUserInfo.AdminUser.Id,
  1700. UserOrgId: adminUserInfo.Org.Id,
  1701. Doctor: prescription_doctor,
  1702. PatientId: id,
  1703. ModeId: mode_id,
  1704. DialysisDuration: dialysis_duration,
  1705. PerfusionApparatus: perfusion_apparatus,
  1706. BloodFlowVolume: blood_flow_volume,
  1707. Dewater: dewater_amount,
  1708. DisplaceLiqui: displace_liqui,
  1709. ReplacementWay: replacement_way,
  1710. Anticoagulant: anticoagulant,
  1711. AnticoagulantShouji: anticoagulant_shouji,
  1712. AnticoagulantWeichi: anticoagulant_weichi,
  1713. AnticoagulantZongliang: anticoagulant_zongliang,
  1714. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1715. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1716. Kalium: kalium,
  1717. Sodium: sodium,
  1718. Calcium: calcium,
  1719. Bicarbonate: bicarbonate,
  1720. Glucose: glucose,
  1721. // DryWeight: dry_weight,
  1722. DialysateFlow: dialysate_flow,
  1723. DialysateTemperature: dialysate_temperature,
  1724. Conductivity: conductivity,
  1725. Remark: remark,
  1726. Status: 1,
  1727. CreatedTime: time.Now().Unix(),
  1728. UpdatedTime: time.Now().Unix(),
  1729. DialysisDurationMinute: dialysisDurationMinute,
  1730. DialysisDurationHour: dialysisDurationHour,
  1731. TargetUltrafiltration: targetUltrafiltration,
  1732. DialysateFormulation: dialysateFormulation,
  1733. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1734. BodyFluid: body_fluid,
  1735. SpecialMedicine: special_medicine,
  1736. SpecialMedicineOther: special_medicine_other,
  1737. DisplaceLiquiPart: displace_liqui_part,
  1738. DisplaceLiquiValue: displace_liqui_value,
  1739. BloodAccess: blood_access,
  1740. Ultrafiltration: ultrafiltration,
  1741. BodyFluidOther: body_fluid_other,
  1742. ReplacementTotal: replacement_total,
  1743. TargetKtv: target_ktv,
  1744. }
  1745. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1746. c.ServeSuccessJSON(map[string]interface{}{
  1747. "solution": &solution,
  1748. "prescription": &prescription,
  1749. })
  1750. }
  1751. func (c *DialysisAPIController) GetAcceptsAssessment() {
  1752. patient, _ := c.GetInt64("patient", 0)
  1753. adminUserInfo := c.GetMobileAdminUserInfo()
  1754. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  1755. c.ServeSuccessJSON(map[string]interface{}{
  1756. "receiveTreatmentAsses": receiveTreatmentAsses,
  1757. })
  1758. }
  1759. func (this *DialysisAPIController) PostSignInfo() {
  1760. patientID, _ := this.GetInt64("patient_id")
  1761. recordDateStr := this.GetString("date")
  1762. if patientID <= 0 {
  1763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. if len(recordDateStr) == 0 {
  1767. recordDateStr = time.Now().Format("2006-01-02")
  1768. }
  1769. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1770. if parseDateErr != nil {
  1771. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. adminInfo := this.GetMobileAdminUserInfo()
  1776. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  1777. if err != nil {
  1778. this.ErrorLog("签名失败:%v", err)
  1779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1780. return
  1781. }
  1782. this.ServeSuccessJSON(map[string]interface{}{
  1783. "doctor_id": adminInfo.AdminUser.Id,
  1784. })
  1785. }
  1786. func (this *DialysisAPIController) GetLastMonitorRecord() {
  1787. patientID, _ := this.GetInt64("patient_id")
  1788. adminInfo := this.GetMobileAdminUserInfo()
  1789. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  1790. this.ServeSuccessJSON(map[string]interface{}{
  1791. "monitor": record,
  1792. })
  1793. }
  1794. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  1795. thisTime := time.Now()
  1796. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1797. timeLayout := "2006-01-02 15:04:05"
  1798. loc, _ := time.LoadLocation("Local")
  1799. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1800. theAssessmentDateTime := theStartTime.Unix()
  1801. patientID, _ := this.GetInt64("patient_id")
  1802. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  1803. adminInfo := this.GetMobileAdminUserInfo()
  1804. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1805. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1806. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  1807. var ultrafiltration_rate float64
  1808. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  1809. if prescription.ID > 0 {
  1810. fmt.Println("444444444")
  1811. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1812. fmt.Println("4444444445555")
  1813. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1814. if template.TemplateId == 6 {
  1815. fmt.Println("12222222")
  1816. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1817. record.UltrafiltrationRate = ultrafiltration_rate
  1818. }
  1819. if template.TemplateId == 20 || template.TemplateId == 22 {
  1820. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1821. record.UltrafiltrationRate = ultrafiltration_rate
  1822. }
  1823. // 只针对方济医院
  1824. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  1825. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1826. ultrafiltration_rate = value
  1827. record.UltrafiltrationRate = ultrafiltration_rate
  1828. }
  1829. }
  1830. }
  1831. // record.UltrafiltrationRate = ultrafiltration_rate
  1832. record.UltrafiltrationVolume = 0
  1833. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  1834. if ultrafiltration_rate > 0 {
  1835. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  1836. record.UltrafiltrationVolume = value
  1837. }
  1838. }
  1839. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  1840. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  1841. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  1842. record.UltrafiltrationVolume = ultrafiltration_volume
  1843. }
  1844. }
  1845. this.ServeSuccessJSON(map[string]interface{}{
  1846. "monitor": record,
  1847. })
  1848. }
  1849. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  1850. record_id, _ := this.GetInt64("id")
  1851. nurseID, _ := this.GetInt64("nurse")
  1852. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1853. bedID, _ := this.GetInt64("bed")
  1854. start_time := this.GetString("start_time")
  1855. schedual_type, _ := this.GetInt64("schedual_type")
  1856. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1857. if record_id == 0 {
  1858. this.ErrorLog("id:%v", record_id)
  1859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1860. return
  1861. }
  1862. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1863. if parseStartDateErr != nil {
  1864. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1866. return
  1867. }
  1868. adminUserInfo := this.GetMobileAdminUserInfo()
  1869. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1870. if getNurseErr != nil {
  1871. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1873. return
  1874. } else if nurse == nil {
  1875. this.ErrorLog("护士不存在")
  1876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1877. return
  1878. }
  1879. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1880. if getNurseErr != nil {
  1881. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1883. return
  1884. } else if nurse == nil {
  1885. this.ErrorLog("护士不存在")
  1886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1887. return
  1888. }
  1889. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1890. if getDeviceNumberErr != nil {
  1891. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1893. return
  1894. } else if deviceNumber == nil {
  1895. this.ErrorLog("床位号不存在")
  1896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1897. return
  1898. }
  1899. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1900. //
  1901. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1902. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1903. // if getPermissionErr != nil {
  1904. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1905. // return
  1906. // } else if headNursePermission == nil {
  1907. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1908. // return
  1909. // }
  1910. //}
  1911. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1912. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1913. timeLayout := "2006-01-02 15:04:05"
  1914. loc, _ := time.LoadLocation("Local")
  1915. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1916. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1917. schedulestartTime := theStartTime.Unix()
  1918. scheduleendTime := theEndTime.Unix()
  1919. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1921. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1922. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1923. if err == gorm.ErrRecordNotFound { //空床位
  1924. // 修改了床位逻辑
  1925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1926. if daySchedule.ID > 0 {
  1927. daySchedule.BedId = bedID
  1928. daySchedule.PartitionId = deviceNumber.ZoneID
  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 err == nil {
  1938. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1939. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1940. if daySchedule.ID > 0 {
  1941. daySchedule.BedId = bedID
  1942. daySchedule.PartitionId = deviceNumber.ZoneID
  1943. daySchedule.ScheduleType = schedual_type
  1944. daySchedule.UpdatedTime = time.Now().Unix()
  1945. err := service.UpdateSchedule(&daySchedule)
  1946. if err != nil {
  1947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1948. return
  1949. }
  1950. }
  1951. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1953. return
  1954. }
  1955. } else if err != nil {
  1956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1957. return
  1958. }
  1959. }
  1960. dialysisRecord := &models.DialysisOrder{
  1961. ID: record_id,
  1962. UserOrgId: adminUserInfo.Org.Id,
  1963. BedID: bedID,
  1964. StartNurse: nurseID,
  1965. StartTime: startDate.Unix(),
  1966. PunctureNurse: puncture_nurse,
  1967. Creator: adminUserInfo.AdminUser.Id,
  1968. Modifier: adminUserInfo.AdminUser.Id,
  1969. WashpipeNurse: washpipe_nurse,
  1970. SchedualType: schedual_type,
  1971. }
  1972. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  1973. if updateErr != nil {
  1974. this.ErrorLog("修改上机失败:%v", updateErr)
  1975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1976. return
  1977. }
  1978. if updateErr == nil {
  1979. if tempDialysisRecord.Stage == 2 {
  1980. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  1981. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1982. fmt.Println(value)
  1983. a, b := math.Modf(value)
  1984. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1985. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1986. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  1987. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  1988. if updateAssessmentErr != nil {
  1989. utils.ErrorLog("%v", updateAssessmentErr)
  1990. }
  1991. }
  1992. }
  1993. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  1994. this.ServeSuccessJSON(map[string]interface{}{
  1995. "dialysis_order": dialysisRecords,
  1996. })
  1997. }
  1998. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  1999. record_id, _ := c.GetInt64("id")
  2000. nurseID, _ := c.GetInt64("nurse")
  2001. end_time := c.GetString("end_time")
  2002. if record_id <= 0 || nurseID <= 0 {
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2004. return
  2005. }
  2006. adminUserInfo := c.GetMobileAdminUserInfo()
  2007. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2008. if getNurseErr != nil {
  2009. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2011. return
  2012. } else if nurse == nil {
  2013. c.ErrorLog("护士不存在")
  2014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2015. return
  2016. }
  2017. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2018. if parseEndDateErr != nil {
  2019. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2021. return
  2022. }
  2023. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2024. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2025. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2026. // if getPermissionErr != nil {
  2027. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2028. // return
  2029. // } else if headNursePermission == nil {
  2030. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2031. // return
  2032. // }
  2033. //}
  2034. dialysisRecord := &models.DialysisOrder{
  2035. ID: record_id,
  2036. UserOrgId: adminUserInfo.Org.Id,
  2037. EndTime: endDate.Unix(),
  2038. FinishNurse: nurseID,
  2039. FinishModifier: adminUserInfo.AdminUser.Id,
  2040. }
  2041. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2042. if updateErr != nil {
  2043. c.ErrorLog("修改下机失败:%v", updateErr)
  2044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2045. return
  2046. }
  2047. if updateErr == nil {
  2048. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2049. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2050. a, b := math.Modf(value)
  2051. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2052. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2053. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2054. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2055. if updateAssessmentErr != nil {
  2056. utils.ErrorLog("%v", updateAssessmentErr)
  2057. }
  2058. }
  2059. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2060. c.ServeSuccessJSON(map[string]interface{}{
  2061. "dialysis_order": dialysisRecords,
  2062. })
  2063. }
  2064. func (c *DialysisAPIController) GetLongAdvice() {
  2065. patient_id, _ := c.GetInt64("id")
  2066. adminUserInfo := c.GetMobileAdminUserInfo()
  2067. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2068. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2069. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2070. c.ServeSuccessJSON(map[string]interface{}{
  2071. "status": "1",
  2072. })
  2073. return
  2074. } else { //开启推送提醒
  2075. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2076. var advice_three []*models.DoctorAdvice
  2077. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2078. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2079. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2080. for _, advice := range advices {
  2081. if advice.FrequencyType == 3 {
  2082. t := time.Now()
  2083. week := int(t.Weekday())
  2084. fmt.Println(t.Weekday())
  2085. fmt.Println(week)
  2086. switch week {
  2087. case 1:
  2088. if strings.Index(advice.WeekDay, "周一") == -1 {
  2089. advice_three = append(advice_three, advice)
  2090. }
  2091. break
  2092. case 2:
  2093. if strings.Index(advice.WeekDay, "周二") == -1 {
  2094. advice_three = append(advice_three, advice)
  2095. }
  2096. break
  2097. case 3:
  2098. if strings.Index(advice.WeekDay, "周三") == -1 {
  2099. advice_three = append(advice_three, advice)
  2100. }
  2101. break
  2102. case 4:
  2103. if strings.Index(advice.WeekDay, "周四") == -1 {
  2104. advice_three = append(advice_three, advice)
  2105. }
  2106. break
  2107. case 5:
  2108. if strings.Index(advice.WeekDay, "周五") == -1 {
  2109. advice_three = append(advice_three, advice)
  2110. }
  2111. break
  2112. case 6:
  2113. if strings.Index(advice.WeekDay, "周六") == -1 {
  2114. advice_three = append(advice_three, advice)
  2115. }
  2116. break
  2117. case 0:
  2118. if strings.Index(advice.WeekDay, "周日") == -1 {
  2119. advice_three = append(advice_three, advice)
  2120. }
  2121. break
  2122. }
  2123. }
  2124. }
  2125. for _, advice := range advices_two {
  2126. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2127. now := p.Unix()
  2128. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2129. dayStr2 := "-" + dayStr
  2130. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2131. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2132. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2133. for _, ad := range advices {
  2134. advice_three = append(advice_three, ad)
  2135. }
  2136. }
  2137. if err == nil {
  2138. c.ServeSuccessJSON(map[string]interface{}{
  2139. "status": "2",
  2140. "advices": advices,
  2141. "advices_two": RemoveRepeatedElement(advice_three),
  2142. "is_open_remind": config.IsOpenRemind,
  2143. })
  2144. }
  2145. }
  2146. }
  2147. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2148. newArr = make([]*models.DoctorAdvice, 0)
  2149. for i := 0; i < len(arr); i++ {
  2150. repeat := false
  2151. for j := i + 1; j < len(arr); j++ {
  2152. if arr[i].ID == arr[j].ID {
  2153. repeat = true
  2154. break
  2155. }
  2156. }
  2157. if !repeat {
  2158. newArr = append(newArr, arr[i])
  2159. }
  2160. }
  2161. return
  2162. }
  2163. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2164. patient, _ := c.GetInt64("id", 0)
  2165. groupNo, _ := c.GetInt64("groupno", 0)
  2166. if patient <= 0 {
  2167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2168. return
  2169. }
  2170. adminUserInfo := c.GetMobileAdminUserInfo()
  2171. dataBody := make(map[string]interface{}, 0)
  2172. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2173. if err != nil {
  2174. utils.ErrorLog(err.Error())
  2175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2176. return
  2177. }
  2178. utils.ErrorLog("%v", dataBody)
  2179. timeLayout := "2006-01-02 15:04"
  2180. loc, _ := time.LoadLocation("Local")
  2181. timeLayout2 := "2006-01-02"
  2182. loc2, _ := time.LoadLocation("Local")
  2183. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2184. utils.ErrorLog("advice_type")
  2185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2186. return
  2187. }
  2188. adviceType := int64(2)
  2189. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2190. utils.ErrorLog("advice_date")
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2192. return
  2193. }
  2194. adviceDate, _ := dataBody["advice_date"].(string)
  2195. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2196. AdviceDate := theTime.Unix()
  2197. RecordDate := theTime.Unix()
  2198. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2199. utils.ErrorLog("start_time")
  2200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2201. return
  2202. }
  2203. startTime, _ := dataBody["start_time"].(string)
  2204. if len(startTime) == 0 {
  2205. utils.ErrorLog("len(start_time) == 0")
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2207. return
  2208. }
  2209. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2210. if err != nil {
  2211. utils.ErrorLog(err.Error())
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2213. return
  2214. }
  2215. StartTime := theTime.Unix()
  2216. Remark := ""
  2217. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2218. remark, _ := dataBody["remark"].(string)
  2219. Remark = remark
  2220. }
  2221. var advices []*models.GroupAdvice
  2222. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2223. utils.ErrorLog("advices")
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adviceNames := dataBody["advices"].([]interface{})
  2228. for _, adviceNameMap := range adviceNames {
  2229. adviceNameM := adviceNameMap.(map[string]interface{})
  2230. var advice models.GroupAdvice
  2231. advice.Remark = Remark
  2232. advice.AdviceType = adviceType
  2233. advice.StartTime = StartTime
  2234. advice.AdviceDate = AdviceDate
  2235. advice.RecordDate = RecordDate
  2236. advice.Status = 1
  2237. advice.CreatedTime = time.Now().Unix()
  2238. advice.UpdatedTime = time.Now().Unix()
  2239. advice.StopState = 2
  2240. advice.ExecutionState = 2
  2241. advice.UserOrgId = adminUserInfo.Org.Id
  2242. advice.PatientId = patient
  2243. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2244. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2245. utils.ErrorLog("advice_name")
  2246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2247. return
  2248. }
  2249. adviceName, _ := adviceNameM["advice_name"].(string)
  2250. if len(adviceName) == 0 {
  2251. utils.ErrorLog("len(advice_name) == 0")
  2252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2253. return
  2254. }
  2255. advice.AdviceName = adviceName
  2256. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2257. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2258. advice.DrugSpec = drugSpec
  2259. }
  2260. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2261. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2262. advice.AdviceDesc = adviceDesc
  2263. }
  2264. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2265. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2266. advice.DrugSpecUnit = drugSpecUnit
  2267. }
  2268. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2269. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2270. // advice.SingleDose = singleDose
  2271. //}
  2272. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2273. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2274. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2275. }
  2276. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2277. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2278. advice.SingleDoseUnit = singleDoseUnit
  2279. }
  2280. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2281. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2282. // advice.PrescribingNumber = prescribingNumber
  2283. //}
  2284. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2285. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2286. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2287. }
  2288. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2289. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2290. advice.PrescribingNumberUnit = prescribingNumberUnit
  2291. }
  2292. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2293. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2294. advice.DeliveryWay = deliveryWay
  2295. }
  2296. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2297. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2298. advice.ExecutionFrequency = executionFrequency
  2299. }
  2300. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2301. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2302. advice.FrequencyType = frequency_type
  2303. }
  2304. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2305. day_count := int64(adviceNameM["day_count"].(float64))
  2306. advice.DayCount = day_count
  2307. }
  2308. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2309. week_day, _ := adviceNameM["week_day"].(string)
  2310. advice.WeekDay = week_day
  2311. }
  2312. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2313. way := int64(adviceNameM["way"].(float64))
  2314. advice.Way = way
  2315. }
  2316. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2317. drug_id := int64(adviceNameM["drug_id"].(float64))
  2318. advice.DrugId = drug_id
  2319. }
  2320. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2321. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2322. advice.DrugNameId = drug_name_id
  2323. }
  2324. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2325. template_id, _ := adviceNameM["template_id"].(string)
  2326. advice.TemplateId = template_id
  2327. }
  2328. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2329. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2330. advice.ExecutionFrequency = executionFrequency
  2331. }
  2332. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2333. children := adviceNameM["child"].([]interface{})
  2334. if len(children) > 0 {
  2335. for _, childrenMap := range children {
  2336. childMap := childrenMap.(map[string]interface{})
  2337. var child models.GroupAdvice
  2338. child.Remark = Remark
  2339. child.AdviceType = adviceType
  2340. child.StartTime = StartTime
  2341. child.AdviceDate = AdviceDate
  2342. child.RecordDate = RecordDate
  2343. child.Status = 1
  2344. child.CreatedTime = time.Now().Unix()
  2345. child.UpdatedTime = time.Now().Unix()
  2346. child.StopState = 2
  2347. child.ExecutionState = 2
  2348. child.UserOrgId = adminUserInfo.Org.Id
  2349. child.PatientId = patient
  2350. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2351. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2352. utils.ErrorLog("child advice_name")
  2353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2354. return
  2355. }
  2356. childAdviceName, _ := childMap["advice_name"].(string)
  2357. if len(childAdviceName) == 0 {
  2358. utils.ErrorLog("len(child advice_name) == 0")
  2359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2360. return
  2361. }
  2362. child.AdviceName = childAdviceName
  2363. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2364. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2365. child.AdviceDesc = childAdviceDesc
  2366. }
  2367. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2368. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2369. child.DrugSpec = childDrugSpec
  2370. }
  2371. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2372. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2373. child.DrugSpecUnit = childDrugSpecUnit
  2374. }
  2375. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2376. child.SingleDose = childMap["single_dose"].(float64)
  2377. }
  2378. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2379. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2380. child.SingleDoseUnit = childSingleDoseUnit
  2381. }
  2382. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2383. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2384. }
  2385. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2386. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2387. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2388. }
  2389. child.DeliveryWay = advice.DeliveryWay
  2390. child.ExecutionFrequency = advice.ExecutionFrequency
  2391. advice.Children = append(advice.Children, &child)
  2392. }
  2393. }
  2394. }
  2395. advices = append(advices, &advice)
  2396. }
  2397. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2398. if err != nil {
  2399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2400. return
  2401. }
  2402. c.ServeSuccessJSON(map[string]interface{}{
  2403. "msg": "ok",
  2404. "advices": list,
  2405. })
  2406. return
  2407. }
  2408. func (c *DialysisAPIController) UploadDryWeight() {
  2409. patient_id, _ := c.GetInt64("id")
  2410. dry_weight, _ := c.GetFloat("dry_weight")
  2411. doctor_id, _ := c.GetInt64("doctor_id")
  2412. remark := c.GetString("remark")
  2413. adminUserInfo := c.GetMobileAdminUserInfo()
  2414. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2415. if err == gorm.ErrRecordNotFound {
  2416. dryWeight := &models.SgjPatientDryweight{
  2417. PatientId: patient_id,
  2418. DryWeight: dry_weight,
  2419. Remakes: remark,
  2420. Ctime: time.Now().Unix(),
  2421. Mtime: time.Now().Unix(),
  2422. Creator: doctor_id,
  2423. Status: 1,
  2424. UserOrgId: adminUserInfo.Org.Id,
  2425. AdjustedValue: "/",
  2426. UserId: adminUserInfo.AdminUser.Id,
  2427. }
  2428. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2429. if createErr == nil {
  2430. c.ServeSuccessJSON(map[string]interface{}{
  2431. "msg": "提交成功",
  2432. "weight": dryWeight,
  2433. })
  2434. }
  2435. } else {
  2436. dryWeight := &models.SgjPatientDryweight{
  2437. PatientId: patient_id,
  2438. DryWeight: dry_weight,
  2439. Remakes: remark,
  2440. Ctime: time.Now().Unix(),
  2441. Mtime: time.Now().Unix(),
  2442. Creator: doctor_id,
  2443. Status: 1,
  2444. UserOrgId: adminUserInfo.Org.Id,
  2445. AdjustedValue: "/",
  2446. UserId: adminUserInfo.AdminUser.Id,
  2447. }
  2448. var value float64
  2449. value = dry_weight - weightAdjust.DryWeight
  2450. if value < 0 {
  2451. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2452. } else if value == 0 {
  2453. dryWeight.AdjustedValue = "/"
  2454. } else if value > 0 {
  2455. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2456. }
  2457. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2458. if createErr == nil {
  2459. c.ServeSuccessJSON(map[string]interface{}{
  2460. "msg": "提交成功",
  2461. "weight": dryWeight,
  2462. })
  2463. }
  2464. }
  2465. }
  2466. func (c *DialysisAPIController) GetSolution() {
  2467. patient_id, _ := c.GetInt64("patient_id")
  2468. mode_id, _ := c.GetInt64("mode_id")
  2469. adminUserInfo := c.GetMobileAdminUserInfo()
  2470. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2471. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2472. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2473. if err != nil {
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2475. return
  2476. }
  2477. c.ServeSuccessJSON(map[string]interface{}{
  2478. "solution": solution,
  2479. "prescription": prescription,
  2480. "system_prescription": system_prescription,
  2481. })
  2482. }
  2483. func (c *DialysisAPIController) GetSchedule() {
  2484. schedual_type, _ := c.GetInt64("schedual_type")
  2485. adminUserInfo := c.GetMobileAdminUserInfo()
  2486. timeLayout := "2006-01-02 15:04:05"
  2487. date := time.Now().Format("2006-01-02") + " 00:00:00"
  2488. loc, _ := time.LoadLocation("Local")
  2489. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2490. scheduleTime := theStartTime.Unix()
  2491. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2492. c.ServeSuccessJSON(map[string]interface{}{
  2493. "number": deviceNumber,
  2494. })
  2495. }
  2496. func (c *DialysisAPIController) GetPatientId() {
  2497. id, _ := c.GetInt64("id")
  2498. patientId, _ := service.GetPatientId(id)
  2499. c.ServeSuccessJSON(map[string]interface{}{
  2500. "patient": patientId,
  2501. })
  2502. }
  2503. func (this *DialysisAPIController) GetDialysisSchedule() {
  2504. schedualDate := this.GetString("date")
  2505. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2506. if parseDateErr != nil {
  2507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2508. return
  2509. }
  2510. adminInfo := this.GetMobileAdminUserInfo()
  2511. orgID := adminInfo.Org.Id
  2512. redis := service.RedisClient()
  2513. defer redis.Close()
  2514. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2515. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2516. if len(scheduals) > 0 {
  2517. //缓存数据
  2518. scheduals_json, err := json.Marshal(scheduals)
  2519. if err == nil {
  2520. redis.Set(key, scheduals_json, time.Second*30)
  2521. }
  2522. }
  2523. this.ServeSuccessJSON(map[string]interface{}{
  2524. "scheduals": scheduals,
  2525. })
  2526. }
  2527. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2528. change_type, _ := this.GetInt64("type", 0)
  2529. record_date := this.GetString("record_time")
  2530. patient_id, _ := this.GetInt64("patient_id", 0)
  2531. timeLayout := "2006-01-02"
  2532. loc, _ := time.LoadLocation("Local")
  2533. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2534. record_time := theAdviceRecordTime.Unix()
  2535. adminUserInfo := this.GetMobileAdminUserInfo()
  2536. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2537. if err == nil {
  2538. if len(advices) == 0 {
  2539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2540. return
  2541. } else {
  2542. this.ServeSuccessJSON(map[string]interface{}{
  2543. "advices": advices,
  2544. "schedule": sch,
  2545. })
  2546. return
  2547. }
  2548. } else {
  2549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2550. return
  2551. }
  2552. }
  2553. func (c *DialysisAPIController) CreateConsumables() {
  2554. record_date := c.GetString("record_time")
  2555. patient_id, _ := c.GetInt64("patient_id", 0)
  2556. adminUser := c.GetMobileAdminUserInfo()
  2557. timeLayout := "2006-01-02"
  2558. loc, _ := time.LoadLocation("Local")
  2559. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2560. record_time := theRecordTime.Unix()
  2561. dataBody := make(map[string]interface{}, 0)
  2562. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2563. if err != nil {
  2564. utils.ErrorLog(err.Error())
  2565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2566. return
  2567. }
  2568. var beforePrepares []*models.DialysisBeforePrepare
  2569. var updateBeforePrepares []*models.DialysisBeforePrepare
  2570. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2571. goods, _ := dataBody["goods"].([]interface{})
  2572. if len(goods) > 0 {
  2573. for _, item := range goods {
  2574. items := item.(map[string]interface{})
  2575. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2576. utils.ErrorLog("good_id")
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2578. return
  2579. }
  2580. good_id := int64(items["good_id"].(float64))
  2581. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2582. utils.ErrorLog("good_type_id")
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2584. return
  2585. }
  2586. good_type_id := int64(items["good_type_id"].(float64))
  2587. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2588. utils.ErrorLog("count")
  2589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2590. return
  2591. }
  2592. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2593. adminUser := c.GetMobileAdminUserInfo()
  2594. prepare := &models.DialysisBeforePrepare{
  2595. UserOrgId: adminUser.Org.Id,
  2596. PatientId: patient_id,
  2597. RecordDate: record_time,
  2598. GoodId: good_id,
  2599. GoodTypeId: good_type_id,
  2600. Count: count,
  2601. Ctime: time.Now().Unix(),
  2602. Mtime: time.Now().Unix(),
  2603. Creater: adminUser.AdminUser.Id,
  2604. Modifier: 0,
  2605. }
  2606. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2607. if record_count == 0 {
  2608. beforePrepares = append(beforePrepares, prepare)
  2609. }
  2610. }
  2611. }
  2612. }
  2613. if len(beforePrepares) > 0 {
  2614. service.CreateDialysisBeforePrepare(beforePrepares)
  2615. }
  2616. var errs error
  2617. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2618. goods, _ := dataBody["update_goods"].([]interface{})
  2619. if len(goods) > 0 {
  2620. for _, item := range goods {
  2621. items := item.(map[string]interface{})
  2622. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2623. utils.ErrorLog("record_time")
  2624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2625. return
  2626. }
  2627. record_time := int64(items["record_time"].(float64))
  2628. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2629. utils.ErrorLog("id")
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2631. return
  2632. }
  2633. id := int64(items["id"].(float64))
  2634. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2635. utils.ErrorLog("patient_id")
  2636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2637. return
  2638. }
  2639. patient_id := int64(items["patient_id"].(float64))
  2640. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2641. utils.ErrorLog("creater")
  2642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2643. return
  2644. }
  2645. creater := int64(items["creater"].(float64))
  2646. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2647. utils.ErrorLog("good_id")
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. good_id := int64(items["good_id"].(float64))
  2652. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2653. utils.ErrorLog("good_type_id")
  2654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2655. return
  2656. }
  2657. good_type_id := int64(items["good_type_id"].(float64))
  2658. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2659. utils.ErrorLog("count")
  2660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2661. return
  2662. }
  2663. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2664. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2665. utils.ErrorLog("ctime")
  2666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2667. return
  2668. }
  2669. ctime := int64(items["ctime"].(float64))
  2670. prepare := &models.DialysisBeforePrepare{
  2671. ID: id,
  2672. UserOrgId: adminUser.Org.Id,
  2673. PatientId: patient_id,
  2674. RecordDate: record_time,
  2675. GoodId: good_id,
  2676. GoodTypeId: good_type_id,
  2677. Count: count,
  2678. Ctime: ctime,
  2679. Mtime: time.Now().Unix(),
  2680. Creater: creater,
  2681. Modifier: adminUser.AdminUser.Id,
  2682. Status: 1,
  2683. }
  2684. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2685. }
  2686. }
  2687. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2688. if len(updateBeforePrepares) > 0 {
  2689. for _, item := range updateBeforePrepares {
  2690. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2691. }
  2692. }
  2693. }
  2694. if errs == nil {
  2695. c.ServeSuccessJSON(map[string]interface{}{
  2696. "msg": "提交成功",
  2697. })
  2698. return
  2699. } else {
  2700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2701. return
  2702. }
  2703. }
  2704. func (c *DialysisAPIController) CreateStockOutInfo() {
  2705. patient_id, _ := c.GetInt64("patient_id", 0)
  2706. record_date := c.GetString("record_time")
  2707. if patient_id <= 0 {
  2708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2709. return
  2710. }
  2711. adminInfo := c.GetMobileAdminUserInfo()
  2712. timeLayout := "2006-01-02"
  2713. loc, _ := time.LoadLocation("Local")
  2714. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2715. record_time := theRecordTime.Unix()
  2716. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2717. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2718. consumables = RemoveRepeatedGood(consumables)
  2719. if record.IsOpen == 1 {
  2720. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2721. if err == gorm.ErrRecordNotFound {
  2722. //没有记录,则创建出库单
  2723. timeStr := time.Now().Format("2006-01-02")
  2724. timeArr := strings.Split(timeStr, "-")
  2725. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2726. total = total + 1
  2727. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2728. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2729. number = number + total
  2730. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2731. creater := adminInfo.AdminUser.Id
  2732. warehouseOut := models.WarehouseOut{
  2733. WarehouseOutOrderNumber: warehousing_out_order,
  2734. OperationTime: time.Now().Unix(),
  2735. OrgId: adminInfo.Org.Id,
  2736. Creater: creater,
  2737. Ctime: time.Now().Unix(),
  2738. Status: 1,
  2739. WarehouseOutTime: record_time,
  2740. Dealer: 0,
  2741. Manufacturer: 0,
  2742. Type: 1,
  2743. IsSys: 1,
  2744. }
  2745. err := service.AddSigleWarehouseOut(&warehouseOut)
  2746. if err != nil {
  2747. utils.TraceLog("创建出库单失败 err = %v", err)
  2748. } else {
  2749. for _, item := range consumables {
  2750. if item.Count > 0 {
  2751. warehouseOutInfo := &models.WarehouseOutInfo{
  2752. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2753. WarehouseOutId: warehouseOut.ID,
  2754. Status: 1,
  2755. Ctime: time.Now().Unix(),
  2756. Remark: "",
  2757. OrgId: adminInfo.Org.Id,
  2758. Type: 1,
  2759. Manufacturer: 0,
  2760. Dealer: 0,
  2761. IsSys: 1,
  2762. SysRecordTime: record_time,
  2763. GoodTypeId: item.GoodTypeId,
  2764. GoodId: item.GoodId,
  2765. }
  2766. warehouseOutInfo.Count = item.Count
  2767. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2768. warehouseOutInfo.Price = stockInInfo.Price
  2769. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2770. if err == nil {
  2771. details := &models.AutomaticReduceDetail{
  2772. WarehouseOutId: warehouseOutInfo.ID,
  2773. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2774. PatientId: patient_id,
  2775. Ctime: time.Now().Unix(),
  2776. Mtime: time.Now().Unix(),
  2777. Status: 1,
  2778. RecordTime: record_time,
  2779. OrgId: adminInfo.Org.Id,
  2780. GoodId: item.GoodId,
  2781. GoodTypeId: item.GoodTypeId,
  2782. Count: item.Count,
  2783. }
  2784. service.AddSigleAutoReduceRecordInfo(details)
  2785. }
  2786. }
  2787. }
  2788. }
  2789. } else if err == nil {
  2790. for _, item := range consumables {
  2791. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  2792. if err == gorm.ErrRecordNotFound {
  2793. warehouseOutInfo := &models.WarehouseOutInfo{
  2794. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2795. WarehouseOutId: out.ID,
  2796. Status: 1,
  2797. Ctime: time.Now().Unix(),
  2798. Remark: "",
  2799. OrgId: adminInfo.Org.Id,
  2800. Type: 1,
  2801. Manufacturer: 0,
  2802. Dealer: 0,
  2803. IsSys: 1,
  2804. SysRecordTime: record_time,
  2805. }
  2806. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2807. warehouseOutInfo.Price = stockInInfo.Price
  2808. warehouseOutInfo.GoodId = item.GoodId
  2809. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  2810. warehouseOutInfo.Count = item.Count
  2811. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2812. if err == nil {
  2813. details := &models.AutomaticReduceDetail{
  2814. WarehouseOutId: warehouseOutInfo.ID,
  2815. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2816. PatientId: patient_id,
  2817. Ctime: time.Now().Unix(),
  2818. Mtime: time.Now().Unix(),
  2819. Status: 1,
  2820. RecordTime: record_time,
  2821. OrgId: adminInfo.Org.Id,
  2822. GoodId: item.GoodId,
  2823. GoodTypeId: item.GoodTypeId,
  2824. Count: item.Count,
  2825. }
  2826. service.AddSigleAutoReduceRecordInfo(details)
  2827. }
  2828. } else if err == nil { //记录存在,则将增加数量
  2829. if outInfo.ID > 0 {
  2830. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  2831. }
  2832. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  2833. if count == 0 {
  2834. details := &models.AutomaticReduceDetail{
  2835. WarehouseOutId: outInfo.ID,
  2836. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2837. PatientId: patient_id,
  2838. Ctime: time.Now().Unix(),
  2839. Mtime: time.Now().Unix(),
  2840. Status: 1,
  2841. RecordTime: record_time,
  2842. OrgId: adminInfo.Org.Id,
  2843. GoodId: item.GoodId,
  2844. GoodTypeId: item.GoodTypeId,
  2845. Count: item.Count,
  2846. }
  2847. service.AddSigleAutoReduceRecordInfo(details)
  2848. } else if count == 1 {
  2849. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  2850. }
  2851. }
  2852. }
  2853. }
  2854. c.ServeSuccessJSON(map[string]interface{}{
  2855. "msg": "提交成功",
  2856. })
  2857. return
  2858. } else {
  2859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  2860. return
  2861. }
  2862. }
  2863. func (c *DialysisAPIController) EditConsumables() {
  2864. patient_id, _ := c.GetInt64("patient_id", 0)
  2865. record_date := c.GetString("record_time")
  2866. if patient_id <= 0 {
  2867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2868. return
  2869. }
  2870. adminInfo := c.GetMobileAdminUserInfo()
  2871. timeLayout := "2006-01-02"
  2872. loc, _ := time.LoadLocation("Local")
  2873. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2874. record_time := theRecordTime.Unix()
  2875. dataBody := make(map[string]interface{}, 0)
  2876. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2877. if err != nil {
  2878. utils.ErrorLog(err.Error())
  2879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2880. return
  2881. }
  2882. var beforePrepares []*models.DialysisBeforePrepare
  2883. var newBeforePrepares []*models.DialysisBeforePrepare
  2884. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2885. if record.IsOpen == 1 {
  2886. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2887. goods, _ := dataBody["goods"].([]interface{})
  2888. if len(goods) > 0 {
  2889. for _, item := range goods {
  2890. items := item.(map[string]interface{})
  2891. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2892. utils.ErrorLog("record_time")
  2893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2894. return
  2895. }
  2896. record_time := int64(items["record_time"].(float64))
  2897. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2898. utils.ErrorLog("id")
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2900. return
  2901. }
  2902. id := int64(items["id"].(float64))
  2903. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2904. utils.ErrorLog("patient_id")
  2905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2906. return
  2907. }
  2908. patient_id := int64(items["patient_id"].(float64))
  2909. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2910. utils.ErrorLog("creater")
  2911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2912. return
  2913. }
  2914. creater := int64(items["creater"].(float64))
  2915. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2916. utils.ErrorLog("good_id")
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2918. return
  2919. }
  2920. good_id := int64(items["good_id"].(float64))
  2921. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2922. utils.ErrorLog("good_type_id")
  2923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2924. return
  2925. }
  2926. good_type_id := int64(items["good_type_id"].(float64))
  2927. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2928. utils.ErrorLog("count")
  2929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2930. return
  2931. }
  2932. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2933. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2934. utils.ErrorLog("ctime")
  2935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. return
  2937. }
  2938. ctime := int64(items["ctime"].(float64))
  2939. adminUser := c.GetMobileAdminUserInfo()
  2940. prepare := &models.DialysisBeforePrepare{
  2941. ID: id,
  2942. UserOrgId: adminUser.Org.Id,
  2943. PatientId: patient_id,
  2944. RecordDate: record_time,
  2945. GoodId: good_id,
  2946. GoodTypeId: good_type_id,
  2947. Count: count,
  2948. Ctime: ctime,
  2949. Mtime: time.Now().Unix(),
  2950. Creater: creater,
  2951. Modifier: adminUser.AdminUser.Id,
  2952. Status: 1,
  2953. }
  2954. beforePrepares = append(beforePrepares, prepare)
  2955. }
  2956. }
  2957. }
  2958. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2959. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  2960. goods, _ := dataBody["new_goods"].([]interface{})
  2961. if len(goods) > 0 {
  2962. for _, item := range goods {
  2963. items := item.(map[string]interface{})
  2964. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2965. utils.ErrorLog("good_id")
  2966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2967. return
  2968. }
  2969. good_id := int64(items["good_id"].(float64))
  2970. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2971. utils.ErrorLog("good_type_id")
  2972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2973. return
  2974. }
  2975. good_type_id := int64(items["good_type_id"].(float64))
  2976. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2977. utils.ErrorLog("count")
  2978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2979. return
  2980. }
  2981. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2982. adminUser := c.GetMobileAdminUserInfo()
  2983. prepare := &models.DialysisBeforePrepare{
  2984. UserOrgId: adminUser.Org.Id,
  2985. PatientId: patient_id,
  2986. RecordDate: record_time,
  2987. GoodId: good_id,
  2988. GoodTypeId: good_type_id,
  2989. Count: count,
  2990. Ctime: time.Now().Unix(),
  2991. Mtime: time.Now().Unix(),
  2992. Creater: adminUser.AdminUser.Id,
  2993. Modifier: 0,
  2994. }
  2995. newBeforePrepares = append(newBeforePrepares, prepare)
  2996. }
  2997. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  2998. }
  2999. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3000. }
  3001. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3002. if err == gorm.ErrRecordNotFound {
  3003. //没有记录,则创建出库单
  3004. timeStr := time.Now().Format("2006-01-02")
  3005. timeArr := strings.Split(timeStr, "-")
  3006. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3007. total = total + 1
  3008. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3009. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3010. number = number + total
  3011. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3012. creater := adminInfo.AdminUser.Id
  3013. warehouseOut := models.WarehouseOut{
  3014. WarehouseOutOrderNumber: warehousing_out_order,
  3015. OperationTime: time.Now().Unix(),
  3016. OrgId: adminInfo.Org.Id,
  3017. Creater: creater,
  3018. Ctime: time.Now().Unix(),
  3019. Status: 1,
  3020. WarehouseOutTime: record_time,
  3021. Dealer: 0,
  3022. Manufacturer: 0,
  3023. Type: 1,
  3024. IsSys: 1,
  3025. }
  3026. err := service.AddSigleWarehouseOut(&warehouseOut)
  3027. if err != nil {
  3028. utils.TraceLog("创建出库单失败 err = %v", err)
  3029. } else {
  3030. for _, item := range beforePrepares {
  3031. if item.Count > 0 {
  3032. warehouseOutInfo := &models.WarehouseOutInfo{
  3033. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3034. WarehouseOutId: warehouseOut.ID,
  3035. Count: 1,
  3036. Status: 1,
  3037. Ctime: time.Now().Unix(),
  3038. Remark: "",
  3039. OrgId: adminInfo.Org.Id,
  3040. Type: 1,
  3041. Manufacturer: 0,
  3042. Dealer: 0,
  3043. IsSys: 1,
  3044. SysRecordTime: record_time,
  3045. GoodTypeId: item.GoodTypeId,
  3046. GoodId: item.GoodId,
  3047. }
  3048. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3049. warehouseOutInfo.Price = stockInInfo.Price
  3050. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3051. if err == nil {
  3052. details := &models.AutomaticReduceDetail{
  3053. WarehouseOutId: warehouseOutInfo.ID,
  3054. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3055. PatientId: patient_id,
  3056. Ctime: time.Now().Unix(),
  3057. Mtime: time.Now().Unix(),
  3058. Status: 1,
  3059. RecordTime: record_time,
  3060. OrgId: adminInfo.Org.Id,
  3061. GoodId: item.GoodId,
  3062. GoodTypeId: item.GoodTypeId,
  3063. }
  3064. service.AddSigleAutoReduceRecordInfo(details)
  3065. }
  3066. }
  3067. }
  3068. }
  3069. } else if err == nil {
  3070. if len(newBeforePrepares) > 0 { //新增
  3071. for _, item := range newBeforePrepares {
  3072. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3073. if err == gorm.ErrRecordNotFound {
  3074. warehouseOutInfo := &models.WarehouseOutInfo{
  3075. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3076. WarehouseOutId: out.ID,
  3077. Status: 1,
  3078. Ctime: time.Now().Unix(),
  3079. Remark: "",
  3080. OrgId: adminInfo.Org.Id,
  3081. Type: 1,
  3082. Manufacturer: 0,
  3083. Dealer: 0,
  3084. IsSys: 1,
  3085. SysRecordTime: record_time,
  3086. }
  3087. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3088. warehouseOutInfo.Price = stockInInfo.Price
  3089. warehouseOutInfo.GoodId = item.GoodId
  3090. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3091. warehouseOutInfo.Count = item.Count
  3092. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3093. if err == nil {
  3094. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3095. if count == 0 {
  3096. details := &models.AutomaticReduceDetail{
  3097. WarehouseOutId: warehouseOutInfo.ID,
  3098. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3099. PatientId: patient_id,
  3100. Ctime: time.Now().Unix(),
  3101. Mtime: time.Now().Unix(),
  3102. Status: 1,
  3103. RecordTime: record_time,
  3104. OrgId: adminInfo.Org.Id,
  3105. GoodId: item.GoodId,
  3106. GoodTypeId: item.GoodTypeId,
  3107. Count: item.Count,
  3108. }
  3109. service.AddSigleAutoReduceRecordInfo(details)
  3110. } else if count == 1 {
  3111. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3112. }
  3113. }
  3114. } else if err == nil { //记录存在,则将加数量
  3115. if outInfo.ID > 0 {
  3116. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3117. }
  3118. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3119. if count == 0 {
  3120. details := &models.AutomaticReduceDetail{
  3121. WarehouseOutId: outInfo.ID,
  3122. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3123. PatientId: patient_id,
  3124. Ctime: time.Now().Unix(),
  3125. Mtime: time.Now().Unix(),
  3126. Status: 1,
  3127. RecordTime: record_time,
  3128. OrgId: adminInfo.Org.Id,
  3129. GoodId: item.GoodId,
  3130. GoodTypeId: item.GoodTypeId,
  3131. Count: item.Count,
  3132. }
  3133. service.AddSigleAutoReduceRecordInfo(details)
  3134. } else if count == 1 {
  3135. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3136. }
  3137. //details := &models.AutomaticReduceDetail{
  3138. // WarehouseOutId: outInfo.ID,
  3139. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3140. // PatientId: patient_id,
  3141. // Ctime: time.Now().Unix(),
  3142. // Mtime: time.Now().Unix(),
  3143. // Status: 1,
  3144. // RecordTime: record_time,
  3145. // OrgId: adminInfo.Org.Id,
  3146. // GoodId: item.GoodId,
  3147. // GoodTypeId: item.GoodTypeId,
  3148. // Count: item.Count,
  3149. //}
  3150. //service.AddSigleAutoReduceRecordInfo(details)
  3151. }
  3152. }
  3153. }
  3154. if len(beforePrepares) > 0 { //修改
  3155. for _, consumable := range consumables_source {
  3156. for _, before := range beforePrepares {
  3157. if consumable.GoodId == before.GoodId {
  3158. if consumable.Count != before.Count {
  3159. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3160. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3161. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3162. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3163. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3164. warehouseOutInfo := &models.WarehouseOutInfo{
  3165. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3166. WarehouseOutId: out.ID,
  3167. Count: before.Count,
  3168. Status: 1,
  3169. Ctime: time.Now().Unix(),
  3170. Remark: "",
  3171. OrgId: adminInfo.Org.Id,
  3172. Type: 1,
  3173. Manufacturer: 0,
  3174. Dealer: 0,
  3175. IsSys: 1,
  3176. SysRecordTime: record_time,
  3177. }
  3178. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3179. warehouseOutInfo.Price = stockInInfo.Price
  3180. warehouseOutInfo.GoodId = before.GoodId
  3181. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3182. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3183. if err == nil {
  3184. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3185. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3186. if err == gorm.ErrRecordNotFound {
  3187. details := &models.AutomaticReduceDetail{
  3188. WarehouseOutId: warehouseOutInfo.ID,
  3189. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3190. PatientId: patient_id,
  3191. Ctime: time.Now().Unix(),
  3192. Mtime: time.Now().Unix(),
  3193. Status: 1,
  3194. RecordTime: record_time,
  3195. OrgId: adminInfo.Org.Id,
  3196. GoodId: consumable.GoodId,
  3197. GoodTypeId: consumable.GoodTypeId,
  3198. Count: before.Count,
  3199. }
  3200. service.AddSigleAutoReduceRecordInfo(details)
  3201. } else if err == nil {
  3202. if user.ID > 0 {
  3203. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3204. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3205. }
  3206. }
  3207. }
  3208. } else if err == nil { //存在,则更改使用人商品信息
  3209. fmt.Println("333333333")
  3210. //处理原来的数据
  3211. if newOut.ID > 0 {
  3212. if consumable.Count > before.Count { // 减少
  3213. num := int64(0)
  3214. if consumable.Count-before.Count > 0 {
  3215. num = consumable.Count - before.Count
  3216. } else {
  3217. num = before.Count - consumable.Count
  3218. }
  3219. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3220. } else if consumable.Count < before.Count { //增加
  3221. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3222. }
  3223. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3224. if err == gorm.ErrRecordNotFound {
  3225. details := &models.AutomaticReduceDetail{
  3226. WarehouseOutId: newOut.ID,
  3227. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3228. PatientId: patient_id,
  3229. Ctime: time.Now().Unix(),
  3230. Mtime: time.Now().Unix(),
  3231. Status: 1,
  3232. RecordTime: record_time,
  3233. OrgId: adminInfo.Org.Id,
  3234. GoodId: consumable.GoodId,
  3235. GoodTypeId: consumable.GoodTypeId,
  3236. Count: before.Count,
  3237. }
  3238. service.AddSigleAutoReduceRecordInfo(details)
  3239. } else if err == nil {
  3240. if user.ID > 0 {
  3241. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3242. }
  3243. }
  3244. }
  3245. }
  3246. fmt.Println("444444444")
  3247. }
  3248. }
  3249. }
  3250. }
  3251. }
  3252. }
  3253. fmt.Println("655555555")
  3254. var errs error
  3255. if len(beforePrepares) > 0 {
  3256. for _, item := range beforePrepares {
  3257. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3258. }
  3259. }
  3260. if errs == nil {
  3261. c.ServeSuccessJSON(map[string]interface{}{
  3262. "msg": "修改成功",
  3263. })
  3264. return
  3265. } else {
  3266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3267. return
  3268. }
  3269. } else {
  3270. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3271. goods, _ := dataBody["goods"].([]interface{})
  3272. if len(goods) > 0 {
  3273. for _, item := range goods {
  3274. items := item.(map[string]interface{})
  3275. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3276. utils.ErrorLog("record_time")
  3277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3278. return
  3279. }
  3280. record_time := int64(items["record_time"].(float64))
  3281. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3282. utils.ErrorLog("id")
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3284. return
  3285. }
  3286. id := int64(items["id"].(float64))
  3287. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3288. utils.ErrorLog("patient_id")
  3289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3290. return
  3291. }
  3292. patient_id := int64(items["patient_id"].(float64))
  3293. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3294. utils.ErrorLog("creater")
  3295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3296. return
  3297. }
  3298. creater := int64(items["creater"].(float64))
  3299. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3300. utils.ErrorLog("good_id")
  3301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3302. return
  3303. }
  3304. good_id := int64(items["good_id"].(float64))
  3305. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3306. utils.ErrorLog("good_type_id")
  3307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3308. return
  3309. }
  3310. good_type_id := int64(items["good_type_id"].(float64))
  3311. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3312. utils.ErrorLog("count")
  3313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3314. return
  3315. }
  3316. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3317. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3318. utils.ErrorLog("ctime")
  3319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3320. return
  3321. }
  3322. ctime := int64(items["ctime"].(float64))
  3323. adminUser := c.GetMobileAdminUserInfo()
  3324. prepare := &models.DialysisBeforePrepare{
  3325. ID: id,
  3326. UserOrgId: adminUser.Org.Id,
  3327. PatientId: patient_id,
  3328. RecordDate: record_time,
  3329. GoodId: good_id,
  3330. GoodTypeId: good_type_id,
  3331. Count: count,
  3332. Ctime: ctime,
  3333. Mtime: time.Now().Unix(),
  3334. Creater: creater,
  3335. Modifier: adminUser.AdminUser.Id,
  3336. Status: 1,
  3337. }
  3338. beforePrepares = append(beforePrepares, prepare)
  3339. }
  3340. }
  3341. }
  3342. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3343. goods, _ := dataBody["new_goods"].([]interface{})
  3344. if len(goods) > 0 {
  3345. for _, item := range goods {
  3346. items := item.(map[string]interface{})
  3347. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3348. utils.ErrorLog("good_id")
  3349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3350. return
  3351. }
  3352. good_id := int64(items["good_id"].(float64))
  3353. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3354. utils.ErrorLog("good_type_id")
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3356. return
  3357. }
  3358. good_type_id := int64(items["good_type_id"].(float64))
  3359. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3360. utils.ErrorLog("count")
  3361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3362. return
  3363. }
  3364. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3365. adminUser := c.GetMobileAdminUserInfo()
  3366. prepare := &models.DialysisBeforePrepare{
  3367. UserOrgId: adminUser.Org.Id,
  3368. PatientId: patient_id,
  3369. RecordDate: record_time,
  3370. GoodId: good_id,
  3371. GoodTypeId: good_type_id,
  3372. Count: count,
  3373. Ctime: time.Now().Unix(),
  3374. Mtime: time.Now().Unix(),
  3375. Creater: adminUser.AdminUser.Id,
  3376. Modifier: 0,
  3377. }
  3378. newBeforePrepares = append(newBeforePrepares, prepare)
  3379. }
  3380. }
  3381. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3382. }
  3383. var errs error
  3384. if len(beforePrepares) > 0 {
  3385. for _, item := range beforePrepares {
  3386. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3387. }
  3388. }
  3389. if errs == nil {
  3390. c.ServeSuccessJSON(map[string]interface{}{
  3391. "msg": "修改成功",
  3392. })
  3393. return
  3394. } else {
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3396. return
  3397. }
  3398. }
  3399. }
  3400. func (c *DialysisAPIController) GetDialysisGoods() {
  3401. schedualDate := c.GetString("schedule_date")
  3402. schedule_type, _ := c.GetInt64("schedule_type")
  3403. partition_id, _ := c.GetInt64("partition_id")
  3404. page, _ := c.GetInt("page")
  3405. patient_id, _ := c.GetInt64("patient_id")
  3406. schedualEndDate := int64(0)
  3407. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3408. if parseDateErr != nil && len(schedualDate) != 0 {
  3409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3410. return
  3411. }
  3412. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3413. if parseDateErr != nil && len(schedualDate) != 0 {
  3414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3415. return
  3416. }
  3417. schedualEndDate = endDate.Unix()
  3418. adminUser := c.GetMobileAdminUserInfo()
  3419. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3420. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3421. if err == gorm.ErrRecordNotFound {
  3422. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3423. if patient_id != 0 {
  3424. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3425. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3426. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3427. item.LastAutomaticReduceDetail = goodUser
  3428. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3429. }
  3430. }
  3431. c.ServeSuccessJSON(map[string]interface{}{
  3432. "dialysis_goods": dialysisGoods,
  3433. "good_type": goodTypes,
  3434. "total": total,
  3435. })
  3436. return
  3437. } else if err == nil {
  3438. //获取当天排班的每个患者的库存使用情况
  3439. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3440. if patient_id != 0 {
  3441. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3442. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3443. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3444. fmt.Println(goodUser)
  3445. fmt.Println(lastGoodUserDetial)
  3446. item.LastAutomaticReduceDetail = goodUser
  3447. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3448. }
  3449. }
  3450. if err == nil {
  3451. c.ServeSuccessJSON(map[string]interface{}{
  3452. "dialysis_goods": dialysisGoods,
  3453. "good_type": goodTypes,
  3454. "total": total,
  3455. })
  3456. return
  3457. } else {
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3459. return
  3460. }
  3461. } else if err != nil {
  3462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3463. return
  3464. }
  3465. }
  3466. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3467. start_time := c.GetString("start_time")
  3468. end_time := c.GetString("end_time")
  3469. timeLayout := "2006-01-02"
  3470. loc, _ := time.LoadLocation("Local")
  3471. var theStartTime int64
  3472. if len(start_time) > 0 {
  3473. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3474. if err != nil {
  3475. utils.ErrorLog(err.Error())
  3476. }
  3477. theStartTime = theTime.Unix()
  3478. }
  3479. var theEndtTime int64
  3480. if len(end_time) > 0 {
  3481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3482. if err != nil {
  3483. utils.ErrorLog(err.Error())
  3484. }
  3485. theEndtTime = theTime.Unix()
  3486. }
  3487. adminUser := c.GetMobileAdminUserInfo()
  3488. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3489. if err == nil {
  3490. c.ServeSuccessJSON(map[string]interface{}{
  3491. "stock_out": outInfo,
  3492. })
  3493. return
  3494. } else {
  3495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3496. return
  3497. }
  3498. }
  3499. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3500. patient_id, _ := c.GetInt64("patient_id", 0)
  3501. record_time := c.GetString("record_time")
  3502. adminUser := c.GetMobileAdminUserInfo()
  3503. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3504. if parseDateErr != nil && len(record_time) != 0 {
  3505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3506. return
  3507. }
  3508. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3509. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3510. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3511. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3512. c.ServeSuccessJSON(map[string]interface{}{
  3513. "good_type": goodTypes,
  3514. "good_user": goodUser,
  3515. "good_info": good_info,
  3516. "last_good_user": lastGoodUserDetial,
  3517. })
  3518. return
  3519. }
  3520. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3521. patient_id, _ := c.GetInt64("patient_id", 0)
  3522. record_date := c.GetString("record_time")
  3523. if patient_id <= 0 {
  3524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3525. return
  3526. }
  3527. adminInfo := c.GetMobileAdminUserInfo()
  3528. timeLayout := "2006-01-02"
  3529. loc, _ := time.LoadLocation("Local")
  3530. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3531. record_time := theRecordTime.Unix()
  3532. dataBody := make(map[string]interface{}, 0)
  3533. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3534. if err != nil {
  3535. utils.ErrorLog(err.Error())
  3536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3537. return
  3538. }
  3539. var beforePrepares []*models.DialysisBeforePrepare
  3540. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3541. goods, _ := dataBody["goods"].([]interface{})
  3542. if len(goods) > 0 {
  3543. for _, item := range goods {
  3544. items := item.(map[string]interface{})
  3545. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3546. utils.ErrorLog("good_id")
  3547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3548. return
  3549. }
  3550. good_id := int64(items["good_id"].(float64))
  3551. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3552. utils.ErrorLog("good_type_id")
  3553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3554. return
  3555. }
  3556. good_type_id := int64(items["good_type_id"].(float64))
  3557. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3558. utils.ErrorLog("count")
  3559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3560. return
  3561. }
  3562. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3563. adminUser := c.GetMobileAdminUserInfo()
  3564. prepare := &models.DialysisBeforePrepare{
  3565. UserOrgId: adminUser.Org.Id,
  3566. PatientId: patient_id,
  3567. RecordDate: record_time,
  3568. GoodId: good_id,
  3569. GoodTypeId: good_type_id,
  3570. Count: count,
  3571. Ctime: time.Now().Unix(),
  3572. Mtime: time.Now().Unix(),
  3573. Creater: adminUser.AdminUser.Id,
  3574. Modifier: 0,
  3575. }
  3576. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3577. if record_count == 0 {
  3578. beforePrepares = append(beforePrepares, prepare)
  3579. } else if record_count == 1 {
  3580. service.UpdateDialysisBeforePrepareTwo(prepare)
  3581. }
  3582. }
  3583. }
  3584. }
  3585. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3586. if len(beforePrepares) > 0 {
  3587. service.CreateDialysisBeforePrepare(beforePrepares)
  3588. }
  3589. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3590. consumables = RemoveRepeatedGood(consumables)
  3591. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3592. if record.IsOpen == 1 {
  3593. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3594. if err == gorm.ErrRecordNotFound {
  3595. //没有记录,则创建出库单
  3596. timeStr := time.Now().Format("2006-01-02")
  3597. timeArr := strings.Split(timeStr, "-")
  3598. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3599. total = total + 1
  3600. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3601. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3602. number = number + total
  3603. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3604. creater := adminInfo.AdminUser.Id
  3605. warehouseOut := models.WarehouseOut{
  3606. WarehouseOutOrderNumber: warehousing_out_order,
  3607. OperationTime: time.Now().Unix(),
  3608. OrgId: adminInfo.Org.Id,
  3609. Creater: creater,
  3610. Ctime: time.Now().Unix(),
  3611. Status: 1,
  3612. WarehouseOutTime: record_time,
  3613. Dealer: 0,
  3614. Manufacturer: 0,
  3615. Type: 1,
  3616. IsSys: 1,
  3617. }
  3618. err := service.AddSigleWarehouseOut(&warehouseOut)
  3619. if err != nil {
  3620. utils.TraceLog("创建出库单失败 err = %v", err)
  3621. } else {
  3622. for _, item := range consumables {
  3623. if item.Count > 0 {
  3624. warehouseOutInfo := &models.WarehouseOutInfo{
  3625. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3626. WarehouseOutId: warehouseOut.ID,
  3627. Status: 1,
  3628. Ctime: time.Now().Unix(),
  3629. Remark: "",
  3630. OrgId: adminInfo.Org.Id,
  3631. Type: 1,
  3632. Manufacturer: 0,
  3633. Dealer: 0,
  3634. IsSys: 1,
  3635. SysRecordTime: record_time,
  3636. GoodTypeId: item.GoodTypeId,
  3637. GoodId: item.GoodId,
  3638. }
  3639. warehouseOutInfo.Count = item.Count
  3640. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3641. warehouseOutInfo.Price = stockInInfo.Price
  3642. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3643. if err == nil {
  3644. details := &models.AutomaticReduceDetail{
  3645. WarehouseOutId: warehouseOutInfo.ID,
  3646. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3647. PatientId: patient_id,
  3648. Ctime: time.Now().Unix(),
  3649. Mtime: time.Now().Unix(),
  3650. Status: 1,
  3651. RecordTime: record_time,
  3652. OrgId: adminInfo.Org.Id,
  3653. GoodId: item.GoodId,
  3654. GoodTypeId: item.GoodTypeId,
  3655. Count: item.Count,
  3656. }
  3657. service.AddSigleAutoReduceRecordInfo(details)
  3658. }
  3659. }
  3660. }
  3661. }
  3662. } else if err == nil {
  3663. for _, item := range consumables {
  3664. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3665. if err == gorm.ErrRecordNotFound {
  3666. warehouseOutInfo := &models.WarehouseOutInfo{
  3667. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3668. WarehouseOutId: out.ID,
  3669. Status: 1,
  3670. Ctime: time.Now().Unix(),
  3671. Remark: "",
  3672. OrgId: adminInfo.Org.Id,
  3673. Type: 1,
  3674. Manufacturer: 0,
  3675. Dealer: 0,
  3676. IsSys: 1,
  3677. SysRecordTime: record_time,
  3678. }
  3679. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3680. warehouseOutInfo.Price = stockInInfo.Price
  3681. warehouseOutInfo.GoodId = item.GoodId
  3682. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3683. warehouseOutInfo.Count = item.Count
  3684. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3685. if err == nil {
  3686. details := &models.AutomaticReduceDetail{
  3687. WarehouseOutId: warehouseOutInfo.ID,
  3688. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3689. PatientId: patient_id,
  3690. Ctime: time.Now().Unix(),
  3691. Mtime: time.Now().Unix(),
  3692. Status: 1,
  3693. RecordTime: record_time,
  3694. OrgId: adminInfo.Org.Id,
  3695. GoodId: item.GoodId,
  3696. GoodTypeId: item.GoodTypeId,
  3697. Count: item.Count,
  3698. }
  3699. service.AddSigleAutoReduceRecordInfo(details)
  3700. }
  3701. } else if err == nil { //记录存在,则将增加数量
  3702. if outInfo.ID > 0 {
  3703. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3704. }
  3705. details := &models.AutomaticReduceDetail{
  3706. WarehouseOutId: outInfo.ID,
  3707. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3708. PatientId: patient_id,
  3709. Ctime: time.Now().Unix(),
  3710. Mtime: time.Now().Unix(),
  3711. Status: 1,
  3712. RecordTime: record_time,
  3713. OrgId: adminInfo.Org.Id,
  3714. GoodId: item.GoodId,
  3715. GoodTypeId: item.GoodTypeId,
  3716. Count: item.Count,
  3717. }
  3718. service.AddSigleAutoReduceRecordInfo(details)
  3719. }
  3720. }
  3721. }
  3722. c.ServeSuccessJSON(map[string]interface{}{
  3723. "msg": "提交成功",
  3724. })
  3725. return
  3726. } else {
  3727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3728. return
  3729. }
  3730. }
  3731. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3732. newArr = make([]*models.DialysisBeforePrepare, 0)
  3733. for i := 0; i < len(arr); i++ {
  3734. repeat := false
  3735. for j := i + 1; j < len(arr); j++ {
  3736. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  3737. repeat = true
  3738. break
  3739. }
  3740. }
  3741. if !repeat {
  3742. newArr = append(newArr, arr[i])
  3743. }
  3744. }
  3745. return
  3746. }
  3747. func (c *DialysisAPIController) GetAllDrug() {
  3748. patient_id, _ := c.GetInt64("patient_id", 0)
  3749. adminInfo := c.GetMobileAdminUserInfo()
  3750. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3751. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  3752. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  3753. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  3754. c.ServeSuccessJSON(map[string]interface{}{
  3755. "base_drug_config": drugStockConfig,
  3756. "private_drug_config": privateDrugConfig,
  3757. "base_drug_list": drugList,
  3758. "private_drug_list": privateDrugList,
  3759. })
  3760. }
  3761. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3762. newArr = make([]*models.DialysisBeforePrepare, 0)
  3763. for i := 0; i < len(arr); i++ {
  3764. repeat := false
  3765. for j := i + 1; j < len(arr); j++ {
  3766. if arr[i].GoodId == arr[j].GoodId {
  3767. repeat = true
  3768. break
  3769. }
  3770. }
  3771. if !repeat {
  3772. newArr = append(newArr, arr[i])
  3773. }
  3774. }
  3775. return
  3776. }