dialysis_api_controller.go 163KB

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