dialysis_api_controller.go 161KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "math"
  15. "net/http"
  16. "net/url"
  17. "github.com/astaxie/beego"
  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. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  930. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  931. //
  932. //if template.TemplateId == 2 || template.TemplateId == 6 {
  933. // if appRole.UserType == 3 {
  934. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  935. // if getPermissionErr != nil {
  936. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  937. // return
  938. // } else if headNursePermission == nil {
  939. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  940. // return
  941. // }
  942. // }
  943. //}
  944. //TODO 需要根据角色去判断
  945. prescription := models.DialysisPrescription{
  946. UserOrgId: adminUserInfo.Org.Id,
  947. PatientId: id,
  948. RecordDate: recordDate.Unix(),
  949. ModeId: mode_id,
  950. DialysisDuration: dialysis_duration,
  951. Dialyzer: dialyzer,
  952. PerfusionApparatus: perfusion_apparatus,
  953. BloodFlowVolume: blood_flow_volume,
  954. DewaterAmount: dewater_amount,
  955. DisplaceLiqui: displace_liqui,
  956. ReplacementWay: replacement_way,
  957. Anticoagulant: anticoagulant,
  958. AnticoagulantShouji: anticoagulant_shouji,
  959. AnticoagulantWeichi: anticoagulant_weichi,
  960. AnticoagulantZongliang: anticoagulant_zongliang,
  961. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  962. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  963. Kalium: kalium,
  964. Sodium: sodium,
  965. Calcium: calcium,
  966. Bicarbonate: bicarbonate,
  967. Glucose: glucose,
  968. // DryWeight: dry_weight,
  969. DialysateFlow: dialysate_flow,
  970. DialysateTemperature: dialysate_temperature,
  971. // PrescriptionDoctor: prescription_doctor,
  972. ReplacementTotal: replacement_total,
  973. Conductivity: conductivity,
  974. Remark: remark,
  975. Status: 1,
  976. CreatedTime: time.Now().Unix(),
  977. UpdatedTime: time.Now().Unix(),
  978. DialysisDurationMinute: dialysisDurationMinute,
  979. DialysisDurationHour: dialysisDurationHour,
  980. TargetUltrafiltration: targetUltrafiltration,
  981. DialysateFormulation: dialysateFormulation,
  982. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  983. BodyFluid: body_fluid,
  984. SpecialMedicine: special_medicine,
  985. SpecialMedicineOther: special_medicine_other,
  986. DisplaceLiquiPart: displace_liqui_part,
  987. DisplaceLiquiValue: displace_liqui_value,
  988. BloodAccess: blood_access,
  989. Ultrafiltration: ultrafiltration,
  990. BodyFluidOther: body_fluid_other,
  991. Niprocart: niprocart,
  992. Jms: jms,
  993. FistulaNeedleSet: fistula_needle_set,
  994. FistulaNeedleSet16: fistula_needle_set_16,
  995. Hemoperfusion: hemoperfusion,
  996. DialyserSterilised: dialyser_sterilised,
  997. Filtryzer: filtryzer,
  998. Dialyzers: dialyzers,
  999. Injector: injector,
  1000. Bloodlines: bloodlines,
  1001. TubingHemodialysis: tubing_hemodialysis,
  1002. Package: safe_package,
  1003. ALiquid: a_liquid,
  1004. TargetKtv: target_ktv,
  1005. PreImpulse: pre_impulse,
  1006. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1007. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1008. Blood: blood,
  1009. DialysisDialyszers: dialysis_dialyszers,
  1010. DialysisIrrigation: dialysis_irrigation,
  1011. }
  1012. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1013. if dialysisPrescription.ID == 0 { //新增
  1014. //if mode_id > 0 {
  1015. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1016. //}
  1017. if appRole.UserType == 2 || appRole.UserType == 1 {
  1018. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1019. }
  1020. prescription.Creater = adminUserInfo.AdminUser.Id
  1021. err := service.AddSigleRecord(&prescription)
  1022. if err == nil {
  1023. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1024. if updateErr != nil {
  1025. utils.ErrorLog("%v", updateErr)
  1026. }
  1027. c.ServeSuccessJSON(map[string]interface{}{
  1028. "prescription": prescription,
  1029. })
  1030. }
  1031. } else { //修改
  1032. //if mode_id > 0 {
  1033. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1034. //}
  1035. //if template.TemplateId == 1 {
  1036. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1037. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1038. // if getPermissionErr != nil {
  1039. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1040. // return
  1041. // } else if headNursePermission == nil {
  1042. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1043. // return
  1044. // }
  1045. // }
  1046. //}
  1047. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1048. prescription.Modifier = adminUserInfo.AdminUser.Id
  1049. if appRole.UserType == 2 || appRole.UserType == 1 {
  1050. prescription_doctor := adminUserInfo.AdminUser.Id
  1051. prescription.PrescriptionDoctor = prescription_doctor
  1052. } else {
  1053. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1054. }
  1055. if dialysisPrescription.Creater == 0 { //体重称
  1056. prescription.Creater = adminUserInfo.AdminUser.Id
  1057. } else {
  1058. prescription.Creater = dialysisPrescription.Creater
  1059. }
  1060. prescription.ID = dialysisPrescription.ID
  1061. err := service.UpDateDialysisPrescription(&prescription)
  1062. if err == nil {
  1063. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1064. if updateErr != nil {
  1065. utils.ErrorLog("%v", updateErr)
  1066. }
  1067. c.ServeSuccessJSON(map[string]interface{}{
  1068. "prescription": prescription,
  1069. })
  1070. }
  1071. }
  1072. }
  1073. func (c *DialysisAPIController) Finish() {
  1074. id, _ := c.GetInt64("patient", 0)
  1075. recordDateStr := c.GetString("record_date")
  1076. nurseID, _ := c.GetInt64("nurse")
  1077. end_time := c.GetString("end_time")
  1078. if id <= 0 || nurseID <= 0 {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. adminUserInfo := c.GetMobileAdminUserInfo()
  1083. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1084. if patient.ID == 0 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1086. return
  1087. }
  1088. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1089. if getNurseErr != nil {
  1090. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1092. return
  1093. } else if nurse == nil {
  1094. c.ErrorLog("护士不存在")
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1096. return
  1097. }
  1098. if len(recordDateStr) == 0 {
  1099. recordDateStr = time.Now().Format("2006-01-02")
  1100. }
  1101. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1102. if parseDateErr != nil {
  1103. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1108. if parseEndDateErr != nil {
  1109. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. //now := time.Now()
  1114. //year, month, day := now.Date()
  1115. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1116. //todayTimeStamp := today_time.Unix()
  1117. // 获取当天的第一条透析纪录
  1118. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1119. if getMonitorRecordsErr != nil {
  1120. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1122. return
  1123. }
  1124. // 获取当前的最后一条透析纪录
  1125. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  1126. if getMonitorRecordsErr != nil {
  1127. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1129. return
  1130. }
  1131. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1132. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1133. if getAADErr != nil {
  1134. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1136. return
  1137. }
  1138. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1139. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1140. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1141. if assessmentAfterDislysis != nil {
  1142. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1143. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1144. } else {
  1145. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1146. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1147. tempassessmentAfterDislysis.Status = 1
  1148. tempassessmentAfterDislysis.PatientId = id
  1149. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1150. }
  1151. if dialysisOrder.Stage == 1 {
  1152. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1153. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1154. fmt.Println(value)
  1155. a, b := math.Modf(value)
  1156. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1157. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1158. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1159. fmt.Println(hour)
  1160. fmt.Println(minute)
  1161. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1162. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1163. }
  1164. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1165. //var num1 int64
  1166. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1167. //fmt.Println(num1)
  1168. //sub := float64(num1 / 3600)
  1169. //fmt.Println(sub)
  1170. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1171. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1172. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1173. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1174. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1175. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1176. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1177. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1178. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1179. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1180. }
  1181. if adminUserInfo.Org.Id == 9583 {
  1182. //获取透析处方的最后一条数据
  1183. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1184. if diaerr != nil {
  1185. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1187. return
  1188. }
  1189. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1190. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1191. }
  1192. }
  1193. if lastAssessmentAfterDislysis != nil {
  1194. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1195. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1196. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1197. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1198. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1199. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1200. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1201. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1202. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1203. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1204. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1205. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1206. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1207. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1208. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1209. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1210. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1211. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1212. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1213. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1214. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1215. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1216. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1217. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1218. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1219. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1220. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1221. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1222. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1223. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1224. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1225. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1226. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1227. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1228. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1229. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1230. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1231. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1232. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1233. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1234. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1235. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1236. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1237. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1238. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1239. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1240. }
  1241. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1242. if err != nil {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1244. return
  1245. }
  1246. if dialysisOrder == nil {
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1248. return
  1249. }
  1250. if dialysisOrder.Stage == 2 {
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1252. return
  1253. }
  1254. if dialysisOrder.Stage == 1 {
  1255. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1256. //结束时候透析次数加1
  1257. service.UpdateSolutionByPatientId(id)
  1258. dialysisOrder.Stage = 2
  1259. dialysisOrder.FinishNurse = nurseID
  1260. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1261. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1262. dialysisOrder.EndTime = endDate.Unix()
  1263. go func (){
  1264. ssoDomain := beego.AppConfig.String("call_domain")
  1265. api := ssoDomain + "/index/downpatient"
  1266. values := make(url.Values)
  1267. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id,10))
  1268. values.Set("admin_user_id", strconv.FormatInt(nurseID,10))
  1269. values.Set("patient_id", strconv.FormatInt(id,10))
  1270. http.PostForm(api, values)
  1271. } ()
  1272. if err == nil {
  1273. c.ServeSuccessJSON(map[string]interface{}{
  1274. "dialysisOrder": dialysisOrder,
  1275. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1276. })
  1277. } else {
  1278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1279. }
  1280. }
  1281. }
  1282. func (c *DialysisAPIController) GetAllZone() {
  1283. adminUserInfo := c.GetMobileAdminUserInfo()
  1284. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1285. if err == nil {
  1286. c.ServeSuccessJSON(map[string]interface{}{
  1287. "zone": zone,
  1288. })
  1289. }
  1290. }
  1291. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1292. adminUserInfo := c.GetMobileAdminUserInfo()
  1293. page, _ := c.GetInt64("page", 1)
  1294. limit, _ := c.GetInt64("limit", 10)
  1295. schedulType, _ := c.GetInt64("schedul_type", 0)
  1296. startTime, _ := c.GetInt64("schedul_time", 0)
  1297. partitionType, _ := c.GetInt64("partition_type", 0)
  1298. keywords := c.GetString("keywords")
  1299. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1300. if err == nil {
  1301. c.ServeSuccessJSON(map[string]interface{}{
  1302. "schedule": dialysisSchedule,
  1303. })
  1304. }
  1305. return
  1306. }
  1307. // /m/api/dialysis/start [post]
  1308. // @param patient_id:int
  1309. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1310. // @param nurse:int 上机护士
  1311. // @param bed:int 床位号
  1312. func (this *DialysisAPIController) StartDialysis() {
  1313. patientID, _ := this.GetInt64("patient_id")
  1314. recordDateStr := this.GetString("record_date")
  1315. nurseID, _ := this.GetInt64("nurse")
  1316. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1317. blood_drawing, _ := this.GetInt64("blood_drawing")
  1318. schedual_type, _ := this.GetInt64("schedual_type")
  1319. bedID, _ := this.GetInt64("bed")
  1320. start_time := this.GetString("start_time")
  1321. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1322. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1327. if parseStartDateErr != nil {
  1328. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1333. if parseErr != nil {
  1334. this.ErrorLog("时间解析失败:%v", parseErr)
  1335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1336. return
  1337. }
  1338. adminUserInfo := this.GetMobileAdminUserInfo()
  1339. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1340. if getPatientErr != nil {
  1341. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1343. return
  1344. } else if patient == nil {
  1345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1346. return
  1347. }
  1348. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1349. if getNurseErr != nil {
  1350. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1352. return
  1353. } else if nurse == nil {
  1354. this.ErrorLog("护士不存在")
  1355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1356. return
  1357. }
  1358. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1359. if getNurseErr != nil {
  1360. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1362. return
  1363. } else if nurse == nil {
  1364. this.ErrorLog("护士不存在")
  1365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1366. return
  1367. }
  1368. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1369. if getDeviceNumberErr != nil {
  1370. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1372. return
  1373. } else if deviceNumber == nil {
  1374. this.ErrorLog("床位号不存在")
  1375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1376. return
  1377. }
  1378. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1379. if getRecordErr != nil {
  1380. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1382. return
  1383. } else if dialysisRecord != nil {
  1384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1385. return
  1386. }
  1387. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1388. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1389. timeLayout := "2006-01-02 15:04:05"
  1390. loc, _ := time.LoadLocation("Local")
  1391. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1392. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1393. schedulestartTime := theStartTime.Unix()
  1394. scheduleendTime := theEndTime.Unix()
  1395. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1396. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1397. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1398. //查询该床位是否有人用了
  1399. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1400. if err == gorm.ErrRecordNotFound { //空床位
  1401. // 修改了床位逻辑
  1402. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1403. if daySchedule.ID > 0 {
  1404. daySchedule.PartitionId = deviceNumber.ZoneID
  1405. daySchedule.BedId = bedID
  1406. daySchedule.ScheduleType = schedual_type
  1407. daySchedule.UpdatedTime = time.Now().Unix()
  1408. err := service.UpdateSchedule(&daySchedule)
  1409. if err != nil {
  1410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. return
  1412. }
  1413. }
  1414. } else if err == nil {
  1415. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1416. if order_err == nil {
  1417. if order.ID > 0 { //该机位被其他人占用了
  1418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1419. return
  1420. } else {
  1421. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1422. if daySchedule.ID > 0 {
  1423. daySchedule.PartitionId = deviceNumber.ZoneID
  1424. daySchedule.BedId = bedID
  1425. daySchedule.ScheduleType = schedual_type
  1426. daySchedule.UpdatedTime = time.Now().Unix()
  1427. err := service.UpdateSchedule(&daySchedule)
  1428. if err != nil {
  1429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1430. return
  1431. }
  1432. }
  1433. }
  1434. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1435. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1436. if daySchedule.ID > 0 {
  1437. daySchedule.PartitionId = deviceNumber.ZoneID
  1438. daySchedule.BedId = bedID
  1439. daySchedule.ScheduleType = schedual_type
  1440. daySchedule.UpdatedTime = time.Now().Unix()
  1441. err := service.UpdateSchedule(&daySchedule)
  1442. if err != nil {
  1443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1450. return
  1451. }
  1452. } else if err != nil {
  1453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1454. return
  1455. }
  1456. dialysisRecord = &models.DialysisOrder{
  1457. DialysisDate: recordDate.Unix(),
  1458. UserOrgId: adminUserInfo.Org.Id,
  1459. PatientId: patientID,
  1460. Stage: 1,
  1461. BedID: bedID,
  1462. StartNurse: nurseID,
  1463. Status: 1,
  1464. StartTime: startDate.Unix(),
  1465. CreatedTime: time.Now().Unix(),
  1466. UpdatedTime: time.Now().Unix(),
  1467. PunctureNurse: puncture_nurse,
  1468. Creator: adminUserInfo.AdminUser.Id,
  1469. Modifier: adminUserInfo.AdminUser.Id,
  1470. SchedualType: schedual_type,
  1471. WashpipeNurse: washpipe_nurse,
  1472. }
  1473. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1474. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1475. var tempdispose string
  1476. // 只针对中能建
  1477. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1478. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1479. }
  1480. var ultrafiltration_rate float64
  1481. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1482. if prescription.ID > 0 {
  1483. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1484. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1485. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  1486. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1487. }
  1488. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1489. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1490. }
  1491. // 只针对方济医院
  1492. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1493. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1494. ultrafiltration_rate = value
  1495. }
  1496. }
  1497. }
  1498. record := models.MonitoringRecord{
  1499. UserOrgId: adminUserInfo.Org.Id,
  1500. PatientId: patientID,
  1501. DialysisOrderId: dialysisRecord.ID,
  1502. MonitoringDate: schedulestartTime,
  1503. OperateTime: startDate.Unix(),
  1504. // MonitoringTime: recordTime,
  1505. MonitoringNurse: nurseID,
  1506. Dispose: tempdispose,
  1507. UltrafiltrationRate: ultrafiltration_rate,
  1508. UltrafiltrationVolume: 0,
  1509. Status: 1,
  1510. CreatedTime: time.Now().Unix(),
  1511. UpdatedTime: time.Now().Unix(),
  1512. }
  1513. //只针对广慈医院
  1514. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 {
  1515. // 查询病人是否有透前评估数据
  1516. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1517. //如果有数据就插入
  1518. if errcode == nil {
  1519. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1520. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1521. record.BreathingRate = befor.BreathingRate
  1522. record.PulseFrequency = befor.PulseFrequency
  1523. record.Temperature = befor.Temperature
  1524. }
  1525. }
  1526. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1527. if newdialysisRecord.ID > 0 {
  1528. err := service.CreateMonitor(&record)
  1529. if err != nil {
  1530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1531. return
  1532. }
  1533. }
  1534. go func (){
  1535. ssoDomain := beego.AppConfig.String("call_domain")
  1536. api := ssoDomain + "/index/uppatient"
  1537. values := make(url.Values)
  1538. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id,10))
  1539. values.Set("admin_user_id", strconv.FormatInt(nurseID,10))
  1540. values.Set("patient_id", strconv.FormatInt(patientID,10))
  1541. values.Set("up_time", strconv.FormatInt(startDate.Unix(),10))
  1542. http.PostForm(api, values)
  1543. } ()
  1544. if createErr != nil {
  1545. this.ErrorLog("上机失败:%v", createErr)
  1546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1547. return
  1548. }
  1549. this.ServeSuccessJSON(map[string]interface{}{
  1550. "dialysis_order": newdialysisRecord,
  1551. "monitor": record,
  1552. })
  1553. }
  1554. func (c *DialysisAPIController) PostSolution() {
  1555. id, _ := c.GetInt64("patient", 0)
  1556. recordDateStr := c.GetString("record_date")
  1557. if id <= 0 {
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1559. return
  1560. }
  1561. adminUserInfo := c.GetMobileAdminUserInfo()
  1562. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1563. if patient.ID == 0 {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1565. return
  1566. }
  1567. if len(recordDateStr) == 0 {
  1568. recordDateStr = time.Now().Format("2006-01-02")
  1569. }
  1570. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1571. if parseDateErr != nil {
  1572. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. mode_id, _ := c.GetInt64("mode_id", 0)
  1577. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1578. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1579. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1580. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1581. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1582. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1583. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1584. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1585. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1586. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1587. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1588. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1589. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1590. kalium, _ := c.GetFloat("kalium", 0)
  1591. sodium, _ := c.GetFloat("sodium", 0)
  1592. calcium, _ := c.GetFloat("calcium", 0)
  1593. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1594. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1595. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1596. glucose, _ := c.GetFloat("glucose", 0)
  1597. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1598. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1599. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1600. conductivity, _ := c.GetFloat("conductivity", 0)
  1601. remark := c.GetString("remark")
  1602. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1603. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1604. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1605. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1606. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1607. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1608. special_medicine_other := c.GetString("special_medicine_other")
  1609. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1610. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1611. blood_access, _ := c.GetInt64("blood_access", 0)
  1612. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1613. body_fluid_other := c.GetString("body_fluid_other")
  1614. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1615. niprocart, _ := c.GetInt64("niprocart", 0)
  1616. jms, _ := c.GetInt64("jms", 0)
  1617. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1618. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1619. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1620. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1621. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1622. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1623. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1624. injector, _ := c.GetInt64("injector", 0)
  1625. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1626. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1627. safe_package, _ := c.GetInt64("package", 0)
  1628. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1629. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1630. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1631. blood := c.GetString("blood")
  1632. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1633. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1634. if mode_id > 0 {
  1635. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1636. }
  1637. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1638. //
  1639. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1640. // if appRole.UserType == 3 {
  1641. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1642. // if getPermissionErr != nil {
  1643. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1644. // return
  1645. // } else if headNursePermission == nil {
  1646. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1647. // return
  1648. // }
  1649. // }
  1650. //}
  1651. prescription := models.DialysisPrescription{
  1652. UserOrgId: adminUserInfo.Org.Id,
  1653. PatientId: id,
  1654. RecordDate: recordDate.Unix(),
  1655. ModeId: mode_id,
  1656. DialysisDuration: dialysis_duration,
  1657. Dialyzer: dialyzer,
  1658. PerfusionApparatus: perfusion_apparatus,
  1659. BloodFlowVolume: blood_flow_volume,
  1660. DewaterAmount: dewater_amount,
  1661. DisplaceLiqui: displace_liqui,
  1662. ReplacementWay: replacement_way,
  1663. Anticoagulant: anticoagulant,
  1664. AnticoagulantShouji: anticoagulant_shouji,
  1665. AnticoagulantWeichi: anticoagulant_weichi,
  1666. AnticoagulantZongliang: anticoagulant_zongliang,
  1667. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1668. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1669. Kalium: kalium,
  1670. Sodium: sodium,
  1671. Calcium: calcium,
  1672. Bicarbonate: bicarbonate,
  1673. Glucose: glucose,
  1674. // DryWeight: dry_weight,
  1675. DialysateFlow: dialysate_flow,
  1676. DialysateTemperature: dialysate_temperature,
  1677. Conductivity: conductivity,
  1678. Remark: remark,
  1679. Status: 1,
  1680. CreatedTime: time.Now().Unix(),
  1681. UpdatedTime: time.Now().Unix(),
  1682. DialysisDurationMinute: dialysisDurationMinute,
  1683. DialysisDurationHour: dialysisDurationHour,
  1684. TargetUltrafiltration: targetUltrafiltration,
  1685. DialysateFormulation: dialysateFormulation,
  1686. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1687. BodyFluid: body_fluid,
  1688. SpecialMedicine: special_medicine,
  1689. SpecialMedicineOther: special_medicine_other,
  1690. DisplaceLiquiPart: displace_liqui_part,
  1691. DisplaceLiquiValue: displace_liqui_value,
  1692. BloodAccess: blood_access,
  1693. Ultrafiltration: ultrafiltration,
  1694. BodyFluidOther: body_fluid_other,
  1695. ReplacementTotal: replacement_total,
  1696. Niprocart: niprocart,
  1697. Jms: jms,
  1698. FistulaNeedleSet: fistula_needle_set,
  1699. FistulaNeedleSet16: fistula_needle_set_16,
  1700. Hemoperfusion: hemoperfusion,
  1701. DialyserSterilised: dialyser_sterilised,
  1702. Filtryzer: filtryzer,
  1703. TargetKtv: target_ktv,
  1704. Dialyzers: dialyzers,
  1705. Injector: injector,
  1706. Bloodlines: bloodlines,
  1707. TubingHemodialysis: tubing_hemodialysis,
  1708. Package: safe_package,
  1709. ALiquid: a_liquid,
  1710. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1711. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1712. Blood: blood,
  1713. DialysisDialyszers: dialysis_dialyszers,
  1714. DialysisIrrigation: dialysis_irrigation,
  1715. }
  1716. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1717. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1718. //
  1719. if appRole.UserType == 2 || appRole.UserType == 1 {
  1720. prescription_doctor = adminUserInfo.AdminUser.Id
  1721. prescription.PrescriptionDoctor = prescription_doctor
  1722. }
  1723. if dialysisPrescription.ID == 0 { //新增
  1724. prescription.Creater = adminUserInfo.AdminUser.Id
  1725. } else { //修改
  1726. if dialysisPrescription.Creater == 0 {
  1727. prescription.Creater = adminUserInfo.AdminUser.Id
  1728. } else {
  1729. prescription.Creater = dialysisPrescription.Creater
  1730. }
  1731. //if/**/
  1732. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1733. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1734. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1735. // if getPermissionErr != nil {
  1736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1737. // return
  1738. // } else if headNursePermission == nil {
  1739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1740. // return
  1741. // }
  1742. //}
  1743. //prescription.Creater = dialysisPrescription.Creater
  1744. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1745. prescription.Modifier = adminUserInfo.AdminUser.Id
  1746. prescription.ID = dialysisPrescription.ID
  1747. }
  1748. solution := models.DialysisSolution{
  1749. RegistrarsId: adminUserInfo.AdminUser.Id,
  1750. UserOrgId: adminUserInfo.Org.Id,
  1751. Doctor: prescription_doctor,
  1752. PatientId: id,
  1753. ModeId: mode_id,
  1754. DialysisDuration: dialysis_duration,
  1755. PerfusionApparatus: perfusion_apparatus,
  1756. BloodFlowVolume: blood_flow_volume,
  1757. Dewater: dewater_amount,
  1758. DisplaceLiqui: displace_liqui,
  1759. ReplacementWay: replacement_way,
  1760. Anticoagulant: anticoagulant,
  1761. AnticoagulantShouji: anticoagulant_shouji,
  1762. AnticoagulantWeichi: anticoagulant_weichi,
  1763. AnticoagulantZongliang: anticoagulant_zongliang,
  1764. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1765. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1766. Kalium: kalium,
  1767. Sodium: sodium,
  1768. Calcium: calcium,
  1769. Bicarbonate: bicarbonate,
  1770. Glucose: glucose,
  1771. // DryWeight: dry_weight,
  1772. DialysateFlow: dialysate_flow,
  1773. DialysateTemperature: dialysate_temperature,
  1774. Conductivity: conductivity,
  1775. Remark: remark,
  1776. Status: 1,
  1777. CreatedTime: time.Now().Unix(),
  1778. UpdatedTime: time.Now().Unix(),
  1779. DialysisDurationMinute: dialysisDurationMinute,
  1780. DialysisDurationHour: dialysisDurationHour,
  1781. TargetUltrafiltration: targetUltrafiltration,
  1782. DialysateFormulation: dialysateFormulation,
  1783. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1784. BodyFluid: body_fluid,
  1785. SpecialMedicine: special_medicine,
  1786. SpecialMedicineOther: special_medicine_other,
  1787. DisplaceLiquiPart: displace_liqui_part,
  1788. DisplaceLiquiValue: displace_liqui_value,
  1789. BloodAccess: blood_access,
  1790. Ultrafiltration: ultrafiltration,
  1791. BodyFluidOther: body_fluid_other,
  1792. ReplacementTotal: replacement_total,
  1793. TargetKtv: target_ktv,
  1794. }
  1795. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1796. c.ServeSuccessJSON(map[string]interface{}{
  1797. "solution": &solution,
  1798. "prescription": &prescription,
  1799. })
  1800. }
  1801. func (c *DialysisAPIController) GetAcceptsAssessment() {
  1802. patient, _ := c.GetInt64("patient", 0)
  1803. adminUserInfo := c.GetMobileAdminUserInfo()
  1804. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "receiveTreatmentAsses": receiveTreatmentAsses,
  1807. })
  1808. }
  1809. func (this *DialysisAPIController) PostSignInfo() {
  1810. patientID, _ := this.GetInt64("patient_id")
  1811. recordDateStr := this.GetString("date")
  1812. if patientID <= 0 {
  1813. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1814. return
  1815. }
  1816. if len(recordDateStr) == 0 {
  1817. recordDateStr = time.Now().Format("2006-01-02")
  1818. }
  1819. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1820. if parseDateErr != nil {
  1821. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1823. return
  1824. }
  1825. adminInfo := this.GetMobileAdminUserInfo()
  1826. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  1827. if err != nil {
  1828. this.ErrorLog("签名失败:%v", err)
  1829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1830. return
  1831. }
  1832. this.ServeSuccessJSON(map[string]interface{}{
  1833. "doctor_id": adminInfo.AdminUser.Id,
  1834. })
  1835. }
  1836. func (this *DialysisAPIController) GetLastMonitorRecord() {
  1837. patientID, _ := this.GetInt64("patient_id")
  1838. adminInfo := this.GetMobileAdminUserInfo()
  1839. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  1840. this.ServeSuccessJSON(map[string]interface{}{
  1841. "monitor": record,
  1842. })
  1843. }
  1844. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  1845. thisTime := time.Now()
  1846. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1847. timeLayout := "2006-01-02 15:04:05"
  1848. loc, _ := time.LoadLocation("Local")
  1849. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1850. theAssessmentDateTime := theStartTime.Unix()
  1851. patientID, _ := this.GetInt64("patient_id")
  1852. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  1853. adminInfo := this.GetMobileAdminUserInfo()
  1854. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1855. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  1856. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  1857. var ultrafiltration_rate float64
  1858. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  1859. if prescription.ID > 0 {
  1860. fmt.Println("444444444")
  1861. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1862. fmt.Println("4444444445555")
  1863. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1864. if template.TemplateId == 6 {
  1865. fmt.Println("12222222")
  1866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1867. record.UltrafiltrationRate = ultrafiltration_rate
  1868. }
  1869. if template.TemplateId == 20 || template.TemplateId == 22 {
  1870. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1871. record.UltrafiltrationRate = ultrafiltration_rate
  1872. }
  1873. // 只针对方济医院
  1874. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  1875. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1876. ultrafiltration_rate = value
  1877. record.UltrafiltrationRate = ultrafiltration_rate
  1878. }
  1879. }
  1880. }
  1881. // record.UltrafiltrationRate = ultrafiltration_rate
  1882. record.UltrafiltrationVolume = 0
  1883. 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
  1884. if ultrafiltration_rate > 0 {
  1885. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  1886. record.UltrafiltrationVolume = value
  1887. }
  1888. }
  1889. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  1890. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  1891. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  1892. record.UltrafiltrationVolume = ultrafiltration_volume
  1893. }
  1894. }
  1895. this.ServeSuccessJSON(map[string]interface{}{
  1896. "monitor": record,
  1897. })
  1898. }
  1899. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  1900. record_id, _ := this.GetInt64("id")
  1901. nurseID, _ := this.GetInt64("nurse")
  1902. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1903. bedID, _ := this.GetInt64("bed")
  1904. start_time := this.GetString("start_time")
  1905. schedual_type, _ := this.GetInt64("schedual_type")
  1906. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1907. if record_id == 0 {
  1908. this.ErrorLog("id:%v", record_id)
  1909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1913. if parseStartDateErr != nil {
  1914. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1916. return
  1917. }
  1918. adminUserInfo := this.GetMobileAdminUserInfo()
  1919. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1920. if getNurseErr != nil {
  1921. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1923. return
  1924. } else if nurse == nil {
  1925. this.ErrorLog("护士不存在")
  1926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1927. return
  1928. }
  1929. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1930. if getNurseErr != nil {
  1931. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1933. return
  1934. } else if nurse == nil {
  1935. this.ErrorLog("护士不存在")
  1936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1937. return
  1938. }
  1939. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1940. if getDeviceNumberErr != nil {
  1941. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1943. return
  1944. } else if deviceNumber == nil {
  1945. this.ErrorLog("床位号不存在")
  1946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1947. return
  1948. }
  1949. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  1950. //
  1951. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  1952. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1953. // if getPermissionErr != nil {
  1954. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1955. // return
  1956. // } else if headNursePermission == nil {
  1957. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1958. // return
  1959. // }
  1960. //}
  1961. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1962. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1963. timeLayout := "2006-01-02 15:04:05"
  1964. loc, _ := time.LoadLocation("Local")
  1965. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1966. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1967. schedulestartTime := theStartTime.Unix()
  1968. scheduleendTime := theEndTime.Unix()
  1969. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1970. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1971. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1972. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  1973. if err == gorm.ErrRecordNotFound { //空床位
  1974. // 修改了床位逻辑
  1975. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1976. if daySchedule.ID > 0 {
  1977. daySchedule.BedId = bedID
  1978. daySchedule.PartitionId = deviceNumber.ZoneID
  1979. daySchedule.ScheduleType = schedual_type
  1980. daySchedule.UpdatedTime = time.Now().Unix()
  1981. err := service.UpdateSchedule(&daySchedule)
  1982. if err != nil {
  1983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1984. return
  1985. }
  1986. }
  1987. } else if err == nil {
  1988. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1989. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  1990. if daySchedule.ID > 0 {
  1991. daySchedule.BedId = bedID
  1992. daySchedule.PartitionId = deviceNumber.ZoneID
  1993. daySchedule.ScheduleType = schedual_type
  1994. daySchedule.UpdatedTime = time.Now().Unix()
  1995. err := service.UpdateSchedule(&daySchedule)
  1996. if err != nil {
  1997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1998. return
  1999. }
  2000. }
  2001. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2003. return
  2004. }
  2005. } else if err != nil {
  2006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2007. return
  2008. }
  2009. }
  2010. dialysisRecord := &models.DialysisOrder{
  2011. ID: record_id,
  2012. UserOrgId: adminUserInfo.Org.Id,
  2013. BedID: bedID,
  2014. StartNurse: nurseID,
  2015. StartTime: startDate.Unix(),
  2016. PunctureNurse: puncture_nurse,
  2017. Creator: adminUserInfo.AdminUser.Id,
  2018. Modifier: adminUserInfo.AdminUser.Id,
  2019. WashpipeNurse: washpipe_nurse,
  2020. SchedualType: schedual_type,
  2021. }
  2022. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2023. if updateErr != nil {
  2024. this.ErrorLog("修改上机失败:%v", updateErr)
  2025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2026. return
  2027. }
  2028. if updateErr == nil {
  2029. if tempDialysisRecord.Stage == 2 {
  2030. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2031. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2032. fmt.Println(value)
  2033. a, b := math.Modf(value)
  2034. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2035. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2036. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2037. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2038. if updateAssessmentErr != nil {
  2039. utils.ErrorLog("%v", updateAssessmentErr)
  2040. }
  2041. }
  2042. }
  2043. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2044. this.ServeSuccessJSON(map[string]interface{}{
  2045. "dialysis_order": dialysisRecords,
  2046. })
  2047. }
  2048. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2049. record_id, _ := c.GetInt64("id")
  2050. nurseID, _ := c.GetInt64("nurse")
  2051. end_time := c.GetString("end_time")
  2052. if record_id <= 0 || nurseID <= 0 {
  2053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2054. return
  2055. }
  2056. adminUserInfo := c.GetMobileAdminUserInfo()
  2057. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2058. if getNurseErr != nil {
  2059. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2061. return
  2062. } else if nurse == nil {
  2063. c.ErrorLog("护士不存在")
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2065. return
  2066. }
  2067. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2068. if parseEndDateErr != nil {
  2069. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2071. return
  2072. }
  2073. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2074. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2075. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2076. // if getPermissionErr != nil {
  2077. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2078. // return
  2079. // } else if headNursePermission == nil {
  2080. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2081. // return
  2082. // }
  2083. //}
  2084. dialysisRecord := &models.DialysisOrder{
  2085. ID: record_id,
  2086. UserOrgId: adminUserInfo.Org.Id,
  2087. EndTime: endDate.Unix(),
  2088. FinishNurse: nurseID,
  2089. FinishModifier: adminUserInfo.AdminUser.Id,
  2090. }
  2091. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2092. if updateErr != nil {
  2093. c.ErrorLog("修改下机失败:%v", updateErr)
  2094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2095. return
  2096. }
  2097. if updateErr == nil {
  2098. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2099. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2100. a, b := math.Modf(value)
  2101. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2102. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2103. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2104. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2105. if updateAssessmentErr != nil {
  2106. utils.ErrorLog("%v", updateAssessmentErr)
  2107. }
  2108. }
  2109. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2110. c.ServeSuccessJSON(map[string]interface{}{
  2111. "dialysis_order": dialysisRecords,
  2112. })
  2113. }
  2114. func (c *DialysisAPIController) GetLongAdvice() {
  2115. patient_id, _ := c.GetInt64("id")
  2116. adminUserInfo := c.GetMobileAdminUserInfo()
  2117. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2118. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2119. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2120. c.ServeSuccessJSON(map[string]interface{}{
  2121. "status": "1",
  2122. })
  2123. return
  2124. } else { //开启推送提醒
  2125. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2126. var advice_three []*models.DoctorAdvice
  2127. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2128. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2129. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2130. for _, advice := range advices {
  2131. if advice.FrequencyType == 3 {
  2132. t := time.Now()
  2133. week := int(t.Weekday())
  2134. fmt.Println(t.Weekday())
  2135. fmt.Println(week)
  2136. switch week {
  2137. case 1:
  2138. if strings.Index(advice.WeekDay, "周一") == -1 {
  2139. advice_three = append(advice_three, advice)
  2140. }
  2141. break
  2142. case 2:
  2143. if strings.Index(advice.WeekDay, "周二") == -1 {
  2144. advice_three = append(advice_three, advice)
  2145. }
  2146. break
  2147. case 3:
  2148. if strings.Index(advice.WeekDay, "周三") == -1 {
  2149. advice_three = append(advice_three, advice)
  2150. }
  2151. break
  2152. case 4:
  2153. if strings.Index(advice.WeekDay, "周四") == -1 {
  2154. advice_three = append(advice_three, advice)
  2155. }
  2156. break
  2157. case 5:
  2158. if strings.Index(advice.WeekDay, "周五") == -1 {
  2159. advice_three = append(advice_three, advice)
  2160. }
  2161. break
  2162. case 6:
  2163. if strings.Index(advice.WeekDay, "周六") == -1 {
  2164. advice_three = append(advice_three, advice)
  2165. }
  2166. break
  2167. case 0:
  2168. if strings.Index(advice.WeekDay, "周日") == -1 {
  2169. advice_three = append(advice_three, advice)
  2170. }
  2171. break
  2172. }
  2173. }
  2174. }
  2175. for _, advice := range advices_two {
  2176. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2177. now := p.Unix()
  2178. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2179. dayStr2 := "-" + dayStr
  2180. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2181. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2182. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2183. for _, ad := range advices {
  2184. advice_three = append(advice_three, ad)
  2185. }
  2186. }
  2187. if err == nil {
  2188. c.ServeSuccessJSON(map[string]interface{}{
  2189. "status": "2",
  2190. "advices": advices,
  2191. "advices_two": RemoveRepeatedElement(advice_three),
  2192. "is_open_remind": config.IsOpenRemind,
  2193. })
  2194. }
  2195. }
  2196. }
  2197. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2198. newArr = make([]*models.DoctorAdvice, 0)
  2199. for i := 0; i < len(arr); i++ {
  2200. repeat := false
  2201. for j := i + 1; j < len(arr); j++ {
  2202. if arr[i].ID == arr[j].ID {
  2203. repeat = true
  2204. break
  2205. }
  2206. }
  2207. if !repeat {
  2208. newArr = append(newArr, arr[i])
  2209. }
  2210. }
  2211. return
  2212. }
  2213. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2214. patient, _ := c.GetInt64("id", 0)
  2215. groupNo, _ := c.GetInt64("groupno", 0)
  2216. if patient <= 0 {
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2218. return
  2219. }
  2220. adminUserInfo := c.GetMobileAdminUserInfo()
  2221. dataBody := make(map[string]interface{}, 0)
  2222. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2223. if err != nil {
  2224. utils.ErrorLog(err.Error())
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2226. return
  2227. }
  2228. utils.ErrorLog("%v", dataBody)
  2229. timeLayout := "2006-01-02 15:04"
  2230. loc, _ := time.LoadLocation("Local")
  2231. timeLayout2 := "2006-01-02"
  2232. loc2, _ := time.LoadLocation("Local")
  2233. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2234. utils.ErrorLog("advice_type")
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2236. return
  2237. }
  2238. adviceType := int64(2)
  2239. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2240. utils.ErrorLog("advice_date")
  2241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2242. return
  2243. }
  2244. adviceDate, _ := dataBody["advice_date"].(string)
  2245. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2246. AdviceDate := theTime.Unix()
  2247. RecordDate := theTime.Unix()
  2248. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2249. utils.ErrorLog("start_time")
  2250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2251. return
  2252. }
  2253. startTime, _ := dataBody["start_time"].(string)
  2254. if len(startTime) == 0 {
  2255. utils.ErrorLog("len(start_time) == 0")
  2256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2257. return
  2258. }
  2259. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2260. if err != nil {
  2261. utils.ErrorLog(err.Error())
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. StartTime := theTime.Unix()
  2266. Remark := ""
  2267. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2268. remark, _ := dataBody["remark"].(string)
  2269. Remark = remark
  2270. }
  2271. var advices []*models.GroupAdvice
  2272. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2273. utils.ErrorLog("advices")
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2275. return
  2276. }
  2277. adviceNames := dataBody["advices"].([]interface{})
  2278. for _, adviceNameMap := range adviceNames {
  2279. adviceNameM := adviceNameMap.(map[string]interface{})
  2280. var advice models.GroupAdvice
  2281. advice.Remark = Remark
  2282. advice.AdviceType = adviceType
  2283. advice.StartTime = StartTime
  2284. advice.AdviceDate = AdviceDate
  2285. advice.RecordDate = RecordDate
  2286. advice.Status = 1
  2287. advice.CreatedTime = time.Now().Unix()
  2288. advice.UpdatedTime = time.Now().Unix()
  2289. advice.StopState = 2
  2290. advice.ExecutionState = 2
  2291. advice.UserOrgId = adminUserInfo.Org.Id
  2292. advice.PatientId = patient
  2293. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2294. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2295. utils.ErrorLog("advice_name")
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2297. return
  2298. }
  2299. adviceName, _ := adviceNameM["advice_name"].(string)
  2300. if len(adviceName) == 0 {
  2301. utils.ErrorLog("len(advice_name) == 0")
  2302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2303. return
  2304. }
  2305. advice.AdviceName = adviceName
  2306. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2307. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2308. advice.DrugSpec = drugSpec
  2309. }
  2310. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2311. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2312. advice.AdviceDesc = adviceDesc
  2313. }
  2314. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2315. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2316. advice.DrugSpecUnit = drugSpecUnit
  2317. }
  2318. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2319. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2320. // advice.SingleDose = singleDose
  2321. //}
  2322. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2323. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2324. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2325. }
  2326. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2327. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2328. advice.SingleDoseUnit = singleDoseUnit
  2329. }
  2330. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2331. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2332. // advice.PrescribingNumber = prescribingNumber
  2333. //}
  2334. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2335. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2336. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2337. }
  2338. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2339. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2340. advice.PrescribingNumberUnit = prescribingNumberUnit
  2341. }
  2342. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2343. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2344. advice.DeliveryWay = deliveryWay
  2345. }
  2346. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2347. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2348. advice.ExecutionFrequency = executionFrequency
  2349. }
  2350. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2351. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2352. advice.FrequencyType = frequency_type
  2353. }
  2354. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2355. day_count := int64(adviceNameM["day_count"].(float64))
  2356. advice.DayCount = day_count
  2357. }
  2358. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2359. week_day, _ := adviceNameM["week_day"].(string)
  2360. advice.WeekDay = week_day
  2361. }
  2362. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2363. way := int64(adviceNameM["way"].(float64))
  2364. advice.Way = way
  2365. }
  2366. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2367. drug_id := int64(adviceNameM["drug_id"].(float64))
  2368. advice.DrugId = drug_id
  2369. }
  2370. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2371. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2372. advice.DrugNameId = drug_name_id
  2373. }
  2374. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2375. template_id, _ := adviceNameM["template_id"].(string)
  2376. advice.TemplateId = template_id
  2377. }
  2378. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2379. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2380. advice.ExecutionFrequency = executionFrequency
  2381. }
  2382. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2383. children := adviceNameM["child"].([]interface{})
  2384. if len(children) > 0 {
  2385. for _, childrenMap := range children {
  2386. childMap := childrenMap.(map[string]interface{})
  2387. var child models.GroupAdvice
  2388. child.Remark = Remark
  2389. child.AdviceType = adviceType
  2390. child.StartTime = StartTime
  2391. child.AdviceDate = AdviceDate
  2392. child.RecordDate = RecordDate
  2393. child.Status = 1
  2394. child.CreatedTime = time.Now().Unix()
  2395. child.UpdatedTime = time.Now().Unix()
  2396. child.StopState = 2
  2397. child.ExecutionState = 2
  2398. child.UserOrgId = adminUserInfo.Org.Id
  2399. child.PatientId = patient
  2400. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2401. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2402. utils.ErrorLog("child advice_name")
  2403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2404. return
  2405. }
  2406. childAdviceName, _ := childMap["advice_name"].(string)
  2407. if len(childAdviceName) == 0 {
  2408. utils.ErrorLog("len(child advice_name) == 0")
  2409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. return
  2411. }
  2412. child.AdviceName = childAdviceName
  2413. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2414. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2415. child.AdviceDesc = childAdviceDesc
  2416. }
  2417. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2418. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2419. child.DrugSpec = childDrugSpec
  2420. }
  2421. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2422. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2423. child.DrugSpecUnit = childDrugSpecUnit
  2424. }
  2425. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2426. child.SingleDose = childMap["single_dose"].(float64)
  2427. }
  2428. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2429. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2430. child.SingleDoseUnit = childSingleDoseUnit
  2431. }
  2432. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2433. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2434. }
  2435. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2436. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2437. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2438. }
  2439. child.DeliveryWay = advice.DeliveryWay
  2440. child.ExecutionFrequency = advice.ExecutionFrequency
  2441. advice.Children = append(advice.Children, &child)
  2442. }
  2443. }
  2444. }
  2445. advices = append(advices, &advice)
  2446. }
  2447. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2448. if err != nil {
  2449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2450. return
  2451. }
  2452. c.ServeSuccessJSON(map[string]interface{}{
  2453. "msg": "ok",
  2454. "advices": list,
  2455. })
  2456. return
  2457. }
  2458. func (c *DialysisAPIController) UploadDryWeight() {
  2459. patient_id, _ := c.GetInt64("id")
  2460. dry_weight, _ := c.GetFloat("dry_weight")
  2461. doctor_id, _ := c.GetInt64("doctor_id")
  2462. remark := c.GetString("remark")
  2463. adminUserInfo := c.GetMobileAdminUserInfo()
  2464. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2465. if err == gorm.ErrRecordNotFound {
  2466. dryWeight := &models.SgjPatientDryweight{
  2467. PatientId: patient_id,
  2468. DryWeight: dry_weight,
  2469. Remakes: remark,
  2470. Ctime: time.Now().Unix(),
  2471. Mtime: time.Now().Unix(),
  2472. Creator: doctor_id,
  2473. Status: 1,
  2474. UserOrgId: adminUserInfo.Org.Id,
  2475. AdjustedValue: "/",
  2476. UserId: adminUserInfo.AdminUser.Id,
  2477. }
  2478. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2479. if createErr == nil {
  2480. c.ServeSuccessJSON(map[string]interface{}{
  2481. "msg": "提交成功",
  2482. "weight": dryWeight,
  2483. })
  2484. }
  2485. } else {
  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. var value float64
  2499. value = dry_weight - weightAdjust.DryWeight
  2500. if value < 0 {
  2501. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2502. } else if value == 0 {
  2503. dryWeight.AdjustedValue = "/"
  2504. } else if value > 0 {
  2505. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2506. }
  2507. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2508. if createErr == nil {
  2509. c.ServeSuccessJSON(map[string]interface{}{
  2510. "msg": "提交成功",
  2511. "weight": dryWeight,
  2512. })
  2513. }
  2514. }
  2515. }
  2516. func (c *DialysisAPIController) GetSolution() {
  2517. patient_id, _ := c.GetInt64("patient_id")
  2518. mode_id, _ := c.GetInt64("mode_id")
  2519. adminUserInfo := c.GetMobileAdminUserInfo()
  2520. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2521. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2522. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2523. if err != nil {
  2524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2525. return
  2526. }
  2527. c.ServeSuccessJSON(map[string]interface{}{
  2528. "solution": solution,
  2529. "prescription": prescription,
  2530. "system_prescription": system_prescription,
  2531. })
  2532. }
  2533. func (c *DialysisAPIController) GetSchedule() {
  2534. schedual_type, _ := c.GetInt64("schedual_type")
  2535. adminUserInfo := c.GetMobileAdminUserInfo()
  2536. timeLayout := "2006-01-02 15:04:05"
  2537. date := time.Now().Format("2006-01-02") + " 00:00:00"
  2538. loc, _ := time.LoadLocation("Local")
  2539. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2540. scheduleTime := theStartTime.Unix()
  2541. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2542. c.ServeSuccessJSON(map[string]interface{}{
  2543. "number": deviceNumber,
  2544. })
  2545. }
  2546. func (c *DialysisAPIController) GetPatientId() {
  2547. id, _ := c.GetInt64("id")
  2548. patientId, _ := service.GetPatientId(id)
  2549. c.ServeSuccessJSON(map[string]interface{}{
  2550. "patient": patientId,
  2551. })
  2552. }
  2553. func (this *DialysisAPIController) GetDialysisSchedule() {
  2554. schedualDate := this.GetString("date")
  2555. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2556. if parseDateErr != nil {
  2557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2558. return
  2559. }
  2560. adminInfo := this.GetMobileAdminUserInfo()
  2561. orgID := adminInfo.Org.Id
  2562. redis := service.RedisClient()
  2563. defer redis.Close()
  2564. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2565. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2566. if len(scheduals) > 0 {
  2567. //缓存数据
  2568. scheduals_json, err := json.Marshal(scheduals)
  2569. if err == nil {
  2570. redis.Set(key, scheduals_json, time.Second*30)
  2571. }
  2572. }
  2573. this.ServeSuccessJSON(map[string]interface{}{
  2574. "scheduals": scheduals,
  2575. })
  2576. }
  2577. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2578. change_type, _ := this.GetInt64("type", 0)
  2579. record_date := this.GetString("record_time")
  2580. patient_id, _ := this.GetInt64("patient_id", 0)
  2581. timeLayout := "2006-01-02"
  2582. loc, _ := time.LoadLocation("Local")
  2583. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2584. record_time := theAdviceRecordTime.Unix()
  2585. adminUserInfo := this.GetMobileAdminUserInfo()
  2586. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2587. if err == nil {
  2588. if len(advices) == 0 {
  2589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2590. return
  2591. } else {
  2592. this.ServeSuccessJSON(map[string]interface{}{
  2593. "advices": advices,
  2594. "schedule": sch,
  2595. })
  2596. return
  2597. }
  2598. } else {
  2599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2600. return
  2601. }
  2602. }
  2603. func (c *DialysisAPIController) CreateConsumables() {
  2604. record_date := c.GetString("record_time")
  2605. patient_id, _ := c.GetInt64("patient_id", 0)
  2606. adminUser := c.GetMobileAdminUserInfo()
  2607. timeLayout := "2006-01-02"
  2608. loc, _ := time.LoadLocation("Local")
  2609. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2610. record_time := theRecordTime.Unix()
  2611. dataBody := make(map[string]interface{}, 0)
  2612. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2613. if err != nil {
  2614. utils.ErrorLog(err.Error())
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2616. return
  2617. }
  2618. var beforePrepares []*models.DialysisBeforePrepare
  2619. var updateBeforePrepares []*models.DialysisBeforePrepare
  2620. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2621. goods, _ := dataBody["goods"].([]interface{})
  2622. if len(goods) > 0 {
  2623. for _, item := range goods {
  2624. items := item.(map[string]interface{})
  2625. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2626. utils.ErrorLog("good_id")
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2628. return
  2629. }
  2630. good_id := int64(items["good_id"].(float64))
  2631. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2632. utils.ErrorLog("good_type_id")
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2634. return
  2635. }
  2636. good_type_id := int64(items["good_type_id"].(float64))
  2637. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2638. utils.ErrorLog("count")
  2639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2640. return
  2641. }
  2642. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2643. //commdity_code := items["commdity_code"].(string)
  2644. //fmt.Println("新建22222222222222",commdity_code)
  2645. adminUser := c.GetMobileAdminUserInfo()
  2646. prepare := &models.DialysisBeforePrepare{
  2647. UserOrgId: adminUser.Org.Id,
  2648. PatientId: patient_id,
  2649. RecordDate: record_time,
  2650. GoodId: good_id,
  2651. GoodTypeId: good_type_id,
  2652. Count: count,
  2653. Ctime: time.Now().Unix(),
  2654. Mtime: time.Now().Unix(),
  2655. Creater: adminUser.AdminUser.Id,
  2656. Modifier: 0,
  2657. //CommdityCode:commdity_code,
  2658. }
  2659. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2660. if record_count == 0 {
  2661. beforePrepares = append(beforePrepares, prepare)
  2662. }
  2663. }
  2664. }
  2665. }
  2666. if len(beforePrepares) > 0 {
  2667. service.CreateDialysisBeforePrepare(beforePrepares)
  2668. }
  2669. var errs error
  2670. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2671. goods, _ := dataBody["update_goods"].([]interface{})
  2672. if len(goods) > 0 {
  2673. for _, item := range goods {
  2674. items := item.(map[string]interface{})
  2675. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2676. utils.ErrorLog("record_time")
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2678. return
  2679. }
  2680. record_time := int64(items["record_time"].(float64))
  2681. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2682. utils.ErrorLog("id")
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. id := int64(items["id"].(float64))
  2687. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2688. utils.ErrorLog("patient_id")
  2689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2690. return
  2691. }
  2692. patient_id := int64(items["patient_id"].(float64))
  2693. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2694. utils.ErrorLog("creater")
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2696. return
  2697. }
  2698. creater := int64(items["creater"].(float64))
  2699. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2700. utils.ErrorLog("good_id")
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. good_id := int64(items["good_id"].(float64))
  2705. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2706. utils.ErrorLog("good_type_id")
  2707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2708. return
  2709. }
  2710. good_type_id := int64(items["good_type_id"].(float64))
  2711. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2712. utils.ErrorLog("count")
  2713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2714. return
  2715. }
  2716. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2717. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2718. utils.ErrorLog("ctime")
  2719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2720. return
  2721. }
  2722. ctime := int64(items["ctime"].(float64))
  2723. //commdity_code := items["commdity_code"].(string)
  2724. //fmt.Println("commdityecode22222222222222222222",commdity_code)
  2725. prepare := &models.DialysisBeforePrepare{
  2726. ID: id,
  2727. UserOrgId: adminUser.Org.Id,
  2728. PatientId: patient_id,
  2729. RecordDate: record_time,
  2730. GoodId: good_id,
  2731. GoodTypeId: good_type_id,
  2732. Count: count,
  2733. Ctime: ctime,
  2734. Mtime: time.Now().Unix(),
  2735. Creater: creater,
  2736. Modifier: adminUser.AdminUser.Id,
  2737. Status: 1,
  2738. //CommdityCode: commdity_code,
  2739. }
  2740. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2741. }
  2742. }
  2743. //去重
  2744. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2745. if len(updateBeforePrepares) > 0 {
  2746. for _, item := range updateBeforePrepares {
  2747. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2748. }
  2749. }
  2750. }
  2751. if errs == nil {
  2752. c.ServeSuccessJSON(map[string]interface{}{
  2753. "msg": "提交成功",
  2754. })
  2755. return
  2756. } else {
  2757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2758. return
  2759. }
  2760. }
  2761. func (c *DialysisAPIController) CreateStockOutInfo() {
  2762. patient_id, _ := c.GetInt64("patient_id", 0)
  2763. record_date := c.GetString("record_time")
  2764. if patient_id <= 0 {
  2765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2766. return
  2767. }
  2768. adminInfo := c.GetMobileAdminUserInfo()
  2769. timeLayout := "2006-01-02"
  2770. loc, _ := time.LoadLocation("Local")
  2771. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2772. record_time := theRecordTime.Unix()
  2773. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2774. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2775. consumables = RemoveRepeatedGood(consumables)
  2776. if record.IsOpen == 1 {
  2777. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2778. if err == gorm.ErrRecordNotFound {
  2779. //没有记录,则创建出库单
  2780. timeStr := time.Now().Format("2006-01-02")
  2781. timeArr := strings.Split(timeStr, "-")
  2782. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2783. total = total + 1
  2784. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2785. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2786. number = number + total
  2787. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2788. creater := adminInfo.AdminUser.Id
  2789. warehouseOut := models.WarehouseOut{
  2790. WarehouseOutOrderNumber: warehousing_out_order,
  2791. OperationTime: time.Now().Unix(),
  2792. OrgId: adminInfo.Org.Id,
  2793. Creater: creater,
  2794. Ctime: time.Now().Unix(),
  2795. Status: 1,
  2796. WarehouseOutTime: record_time,
  2797. Dealer: 0,
  2798. Manufacturer: 0,
  2799. Type: 1,
  2800. IsSys: 1,
  2801. }
  2802. err := service.AddSigleWarehouseOut(&warehouseOut)
  2803. if err != nil {
  2804. utils.TraceLog("创建出库单失败 err = %v", err)
  2805. } else {
  2806. for _, item := range consumables {
  2807. if item.Count > 0 {
  2808. warehouseOutInfo := &models.WarehouseOutInfo{
  2809. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2810. WarehouseOutId: warehouseOut.ID,
  2811. Status: 1,
  2812. Ctime: time.Now().Unix(),
  2813. Remark: "",
  2814. OrgId: adminInfo.Org.Id,
  2815. Type: 1,
  2816. Manufacturer: 0,
  2817. Dealer: 0,
  2818. IsSys: 1,
  2819. SysRecordTime: record_time,
  2820. GoodTypeId: item.GoodTypeId,
  2821. GoodId: item.GoodId,
  2822. }
  2823. warehouseOutInfo.Count = item.Count
  2824. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2825. warehouseOutInfo.Price = stockInInfo.Price
  2826. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2827. if err == nil {
  2828. details := &models.AutomaticReduceDetail{
  2829. WarehouseOutId: warehouseOutInfo.ID,
  2830. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2831. PatientId: patient_id,
  2832. Ctime: time.Now().Unix(),
  2833. Mtime: time.Now().Unix(),
  2834. Status: 1,
  2835. RecordTime: record_time,
  2836. OrgId: adminInfo.Org.Id,
  2837. GoodId: item.GoodId,
  2838. GoodTypeId: item.GoodTypeId,
  2839. Count: item.Count,
  2840. }
  2841. service.AddSigleAutoReduceRecordInfo(details)
  2842. }
  2843. }
  2844. }
  2845. }
  2846. } else if err == nil {
  2847. for _, item := range consumables {
  2848. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  2849. if err == gorm.ErrRecordNotFound {
  2850. warehouseOutInfo := &models.WarehouseOutInfo{
  2851. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2852. WarehouseOutId: out.ID,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Remark: "",
  2856. OrgId: adminInfo.Org.Id,
  2857. Type: 1,
  2858. Manufacturer: 0,
  2859. Dealer: 0,
  2860. IsSys: 1,
  2861. SysRecordTime: record_time,
  2862. }
  2863. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  2864. warehouseOutInfo.Price = stockInInfo.Price
  2865. warehouseOutInfo.GoodId = item.GoodId
  2866. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  2867. warehouseOutInfo.Count = item.Count
  2868. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2869. if err == nil {
  2870. details := &models.AutomaticReduceDetail{
  2871. WarehouseOutId: warehouseOutInfo.ID,
  2872. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2873. PatientId: patient_id,
  2874. Ctime: time.Now().Unix(),
  2875. Mtime: time.Now().Unix(),
  2876. Status: 1,
  2877. RecordTime: record_time,
  2878. OrgId: adminInfo.Org.Id,
  2879. GoodId: item.GoodId,
  2880. GoodTypeId: item.GoodTypeId,
  2881. Count: item.Count,
  2882. }
  2883. service.AddSigleAutoReduceRecordInfo(details)
  2884. }
  2885. } else if err == nil { //记录存在,则将增加数量
  2886. if outInfo.ID > 0 {
  2887. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  2888. }
  2889. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  2890. if count == 0 {
  2891. details := &models.AutomaticReduceDetail{
  2892. WarehouseOutId: outInfo.ID,
  2893. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2894. PatientId: patient_id,
  2895. Ctime: time.Now().Unix(),
  2896. Mtime: time.Now().Unix(),
  2897. Status: 1,
  2898. RecordTime: record_time,
  2899. OrgId: adminInfo.Org.Id,
  2900. GoodId: item.GoodId,
  2901. GoodTypeId: item.GoodTypeId,
  2902. Count: item.Count,
  2903. }
  2904. service.AddSigleAutoReduceRecordInfo(details)
  2905. } else if count == 1 {
  2906. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  2907. }
  2908. }
  2909. }
  2910. }
  2911. c.ServeSuccessJSON(map[string]interface{}{
  2912. "msg": "提交成功",
  2913. })
  2914. return
  2915. } else {
  2916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  2917. return
  2918. }
  2919. }
  2920. func (c *DialysisAPIController) EditConsumables() {
  2921. patient_id, _ := c.GetInt64("patient_id", 0)
  2922. record_date := c.GetString("record_time")
  2923. if patient_id <= 0 {
  2924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2925. return
  2926. }
  2927. adminInfo := c.GetMobileAdminUserInfo()
  2928. timeLayout := "2006-01-02"
  2929. loc, _ := time.LoadLocation("Local")
  2930. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2931. record_time := theRecordTime.Unix()
  2932. dataBody := make(map[string]interface{}, 0)
  2933. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2934. if err != nil {
  2935. utils.ErrorLog(err.Error())
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2937. return
  2938. }
  2939. var beforePrepares []*models.DialysisBeforePrepare
  2940. var newBeforePrepares []*models.DialysisBeforePrepare
  2941. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2942. if record.IsOpen == 1 {
  2943. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2944. goods, _ := dataBody["goods"].([]interface{})
  2945. if len(goods) > 0 {
  2946. for _, item := range goods {
  2947. items := item.(map[string]interface{})
  2948. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2949. utils.ErrorLog("record_time")
  2950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2951. return
  2952. }
  2953. record_time := int64(items["record_time"].(float64))
  2954. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2955. utils.ErrorLog("id")
  2956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2957. return
  2958. }
  2959. id := int64(items["id"].(float64))
  2960. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2961. utils.ErrorLog("patient_id")
  2962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2963. return
  2964. }
  2965. patient_id := int64(items["patient_id"].(float64))
  2966. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2967. utils.ErrorLog("creater")
  2968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2969. return
  2970. }
  2971. creater := int64(items["creater"].(float64))
  2972. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2973. utils.ErrorLog("good_id")
  2974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2975. return
  2976. }
  2977. good_id := int64(items["good_id"].(float64))
  2978. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2979. utils.ErrorLog("good_type_id")
  2980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2981. return
  2982. }
  2983. good_type_id := int64(items["good_type_id"].(float64))
  2984. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2985. utils.ErrorLog("count")
  2986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2987. return
  2988. }
  2989. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2990. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2991. utils.ErrorLog("ctime")
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2993. return
  2994. }
  2995. ctime := int64(items["ctime"].(float64))
  2996. //commdity_code := items["commdity_code"].(string)
  2997. //fmt.Println("commdityecode22222222222222222222",commdity_code)
  2998. adminUser := c.GetMobileAdminUserInfo()
  2999. prepare := &models.DialysisBeforePrepare{
  3000. ID: id,
  3001. UserOrgId: adminUser.Org.Id,
  3002. PatientId: patient_id,
  3003. RecordDate: record_time,
  3004. GoodId: good_id,
  3005. GoodTypeId: good_type_id,
  3006. Count: count,
  3007. Ctime: ctime,
  3008. Mtime: time.Now().Unix(),
  3009. Creater: creater,
  3010. Modifier: adminUser.AdminUser.Id,
  3011. Status: 1,
  3012. //CommdityCode: commdity_code,
  3013. }
  3014. beforePrepares = append(beforePrepares, prepare)
  3015. }
  3016. }
  3017. }
  3018. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3019. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3020. goods, _ := dataBody["new_goods"].([]interface{})
  3021. if len(goods) > 0 {
  3022. for _, item := range goods {
  3023. items := item.(map[string]interface{})
  3024. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3025. utils.ErrorLog("good_id")
  3026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3027. return
  3028. }
  3029. good_id := int64(items["good_id"].(float64))
  3030. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3031. utils.ErrorLog("good_type_id")
  3032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3033. return
  3034. }
  3035. good_type_id := int64(items["good_type_id"].(float64))
  3036. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3037. utils.ErrorLog("count")
  3038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3039. return
  3040. }
  3041. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3042. //commdity_code := items["commdity_code"].(string)
  3043. //fmt.Println("commdityecode22222222222222222222",commdity_code)
  3044. adminUser := c.GetMobileAdminUserInfo()
  3045. prepare := &models.DialysisBeforePrepare{
  3046. UserOrgId: adminUser.Org.Id,
  3047. PatientId: patient_id,
  3048. RecordDate: record_time,
  3049. GoodId: good_id,
  3050. GoodTypeId: good_type_id,
  3051. Count: count,
  3052. Ctime: time.Now().Unix(),
  3053. Mtime: time.Now().Unix(),
  3054. Creater: adminUser.AdminUser.Id,
  3055. Modifier: 0,
  3056. //CommdityCode:commdity_code,
  3057. }
  3058. newBeforePrepares = append(newBeforePrepares, prepare)
  3059. }
  3060. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  3061. }
  3062. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3063. }
  3064. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3065. if err == gorm.ErrRecordNotFound {
  3066. //没有记录,则创建出库单
  3067. timeStr := time.Now().Format("2006-01-02")
  3068. timeArr := strings.Split(timeStr, "-")
  3069. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3070. total = total + 1
  3071. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3072. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3073. number = number + total
  3074. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3075. creater := adminInfo.AdminUser.Id
  3076. warehouseOut := models.WarehouseOut{
  3077. WarehouseOutOrderNumber: warehousing_out_order,
  3078. OperationTime: time.Now().Unix(),
  3079. OrgId: adminInfo.Org.Id,
  3080. Creater: creater,
  3081. Ctime: time.Now().Unix(),
  3082. Status: 1,
  3083. WarehouseOutTime: record_time,
  3084. Dealer: 0,
  3085. Manufacturer: 0,
  3086. Type: 1,
  3087. IsSys: 1,
  3088. }
  3089. err := service.AddSigleWarehouseOut(&warehouseOut)
  3090. if err != nil {
  3091. utils.TraceLog("创建出库单失败 err = %v", err)
  3092. } else {
  3093. for _, item := range beforePrepares {
  3094. if item.Count > 0 {
  3095. warehouseOutInfo := &models.WarehouseOutInfo{
  3096. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3097. WarehouseOutId: warehouseOut.ID,
  3098. Count: 1,
  3099. Status: 1,
  3100. Ctime: time.Now().Unix(),
  3101. Remark: "",
  3102. OrgId: adminInfo.Org.Id,
  3103. Type: 1,
  3104. Manufacturer: 0,
  3105. Dealer: 0,
  3106. IsSys: 1,
  3107. SysRecordTime: record_time,
  3108. GoodTypeId: item.GoodTypeId,
  3109. GoodId: item.GoodId,
  3110. }
  3111. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3112. warehouseOutInfo.Price = stockInInfo.Price
  3113. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3114. if err == nil {
  3115. details := &models.AutomaticReduceDetail{
  3116. WarehouseOutId: warehouseOutInfo.ID,
  3117. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3118. PatientId: patient_id,
  3119. Ctime: time.Now().Unix(),
  3120. Mtime: time.Now().Unix(),
  3121. Status: 1,
  3122. RecordTime: record_time,
  3123. OrgId: adminInfo.Org.Id,
  3124. GoodId: item.GoodId,
  3125. GoodTypeId: item.GoodTypeId,
  3126. }
  3127. service.AddSigleAutoReduceRecordInfo(details)
  3128. }
  3129. }
  3130. }
  3131. }
  3132. } else if err == nil {
  3133. if len(newBeforePrepares) > 0 { //新增
  3134. for _, item := range newBeforePrepares {
  3135. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3136. if err == gorm.ErrRecordNotFound {
  3137. warehouseOutInfo := &models.WarehouseOutInfo{
  3138. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3139. WarehouseOutId: out.ID,
  3140. Status: 1,
  3141. Ctime: time.Now().Unix(),
  3142. Remark: "",
  3143. OrgId: adminInfo.Org.Id,
  3144. Type: 1,
  3145. Manufacturer: 0,
  3146. Dealer: 0,
  3147. IsSys: 1,
  3148. SysRecordTime: record_time,
  3149. }
  3150. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3151. warehouseOutInfo.Price = stockInInfo.Price
  3152. warehouseOutInfo.GoodId = item.GoodId
  3153. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3154. warehouseOutInfo.Count = item.Count
  3155. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3156. if err == nil {
  3157. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3158. if count == 0 {
  3159. details := &models.AutomaticReduceDetail{
  3160. WarehouseOutId: warehouseOutInfo.ID,
  3161. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3162. PatientId: patient_id,
  3163. Ctime: time.Now().Unix(),
  3164. Mtime: time.Now().Unix(),
  3165. Status: 1,
  3166. RecordTime: record_time,
  3167. OrgId: adminInfo.Org.Id,
  3168. GoodId: item.GoodId,
  3169. GoodTypeId: item.GoodTypeId,
  3170. Count: item.Count,
  3171. }
  3172. service.AddSigleAutoReduceRecordInfo(details)
  3173. } else if count == 1 {
  3174. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3175. }
  3176. }
  3177. } else if err == nil { //记录存在,则将加数量
  3178. if outInfo.ID > 0 {
  3179. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3180. }
  3181. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3182. if count == 0 {
  3183. details := &models.AutomaticReduceDetail{
  3184. WarehouseOutId: outInfo.ID,
  3185. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3186. PatientId: patient_id,
  3187. Ctime: time.Now().Unix(),
  3188. Mtime: time.Now().Unix(),
  3189. Status: 1,
  3190. RecordTime: record_time,
  3191. OrgId: adminInfo.Org.Id,
  3192. GoodId: item.GoodId,
  3193. GoodTypeId: item.GoodTypeId,
  3194. Count: item.Count,
  3195. }
  3196. service.AddSigleAutoReduceRecordInfo(details)
  3197. } else if count == 1 {
  3198. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3199. }
  3200. //details := &models.AutomaticReduceDetail{
  3201. // WarehouseOutId: outInfo.ID,
  3202. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3203. // PatientId: patient_id,
  3204. // Ctime: time.Now().Unix(),
  3205. // Mtime: time.Now().Unix(),
  3206. // Status: 1,
  3207. // RecordTime: record_time,
  3208. // OrgId: adminInfo.Org.Id,
  3209. // GoodId: item.GoodId,
  3210. // GoodTypeId: item.GoodTypeId,
  3211. // Count: item.Count,
  3212. //}
  3213. //service.AddSigleAutoReduceRecordInfo(details)
  3214. }
  3215. }
  3216. }
  3217. if len(beforePrepares) > 0 { //修改
  3218. for _, consumable := range consumables_source {
  3219. for _, before := range beforePrepares {
  3220. if consumable.GoodId == before.GoodId {
  3221. if consumable.Count != before.Count {
  3222. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3223. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3224. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3225. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3226. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3227. warehouseOutInfo := &models.WarehouseOutInfo{
  3228. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3229. WarehouseOutId: out.ID,
  3230. Count: before.Count,
  3231. Status: 1,
  3232. Ctime: time.Now().Unix(),
  3233. Remark: "",
  3234. OrgId: adminInfo.Org.Id,
  3235. Type: 1,
  3236. Manufacturer: 0,
  3237. Dealer: 0,
  3238. IsSys: 1,
  3239. SysRecordTime: record_time,
  3240. }
  3241. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3242. warehouseOutInfo.Price = stockInInfo.Price
  3243. warehouseOutInfo.GoodId = before.GoodId
  3244. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3245. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3246. if err == nil {
  3247. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3248. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3249. if err == gorm.ErrRecordNotFound {
  3250. details := &models.AutomaticReduceDetail{
  3251. WarehouseOutId: warehouseOutInfo.ID,
  3252. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3253. PatientId: patient_id,
  3254. Ctime: time.Now().Unix(),
  3255. Mtime: time.Now().Unix(),
  3256. Status: 1,
  3257. RecordTime: record_time,
  3258. OrgId: adminInfo.Org.Id,
  3259. GoodId: consumable.GoodId,
  3260. GoodTypeId: consumable.GoodTypeId,
  3261. Count: before.Count,
  3262. }
  3263. service.AddSigleAutoReduceRecordInfo(details)
  3264. } else if err == nil {
  3265. if user.ID > 0 {
  3266. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3267. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3268. }
  3269. }
  3270. }
  3271. } else if err == nil { //存在,则更改使用人商品信息
  3272. fmt.Println("333333333")
  3273. //处理原来的数据
  3274. if newOut.ID > 0 {
  3275. if consumable.Count > before.Count { // 减少
  3276. num := int64(0)
  3277. if consumable.Count-before.Count > 0 {
  3278. num = consumable.Count - before.Count
  3279. } else {
  3280. num = before.Count - consumable.Count
  3281. }
  3282. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3283. } else if consumable.Count < before.Count { //增加
  3284. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3285. }
  3286. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3287. if err == gorm.ErrRecordNotFound {
  3288. details := &models.AutomaticReduceDetail{
  3289. WarehouseOutId: newOut.ID,
  3290. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3291. PatientId: patient_id,
  3292. Ctime: time.Now().Unix(),
  3293. Mtime: time.Now().Unix(),
  3294. Status: 1,
  3295. RecordTime: record_time,
  3296. OrgId: adminInfo.Org.Id,
  3297. GoodId: consumable.GoodId,
  3298. GoodTypeId: consumable.GoodTypeId,
  3299. Count: before.Count,
  3300. }
  3301. service.AddSigleAutoReduceRecordInfo(details)
  3302. } else if err == nil {
  3303. if user.ID > 0 {
  3304. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3305. }
  3306. }
  3307. }
  3308. }
  3309. fmt.Println("444444444")
  3310. }
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. fmt.Println("655555555")
  3317. var errs error
  3318. if len(beforePrepares) > 0 {
  3319. for _, item := range beforePrepares {
  3320. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3321. }
  3322. }
  3323. if errs == nil {
  3324. c.ServeSuccessJSON(map[string]interface{}{
  3325. "msg": "修改成功",
  3326. })
  3327. return
  3328. } else {
  3329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3330. return
  3331. }
  3332. } else {
  3333. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3334. goods, _ := dataBody["goods"].([]interface{})
  3335. if len(goods) > 0 {
  3336. for _, item := range goods {
  3337. items := item.(map[string]interface{})
  3338. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3339. utils.ErrorLog("record_time")
  3340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3341. return
  3342. }
  3343. record_time := int64(items["record_time"].(float64))
  3344. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3345. utils.ErrorLog("id")
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3347. return
  3348. }
  3349. id := int64(items["id"].(float64))
  3350. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3351. utils.ErrorLog("patient_id")
  3352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3353. return
  3354. }
  3355. patient_id := int64(items["patient_id"].(float64))
  3356. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3357. utils.ErrorLog("creater")
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3359. return
  3360. }
  3361. creater := int64(items["creater"].(float64))
  3362. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3363. utils.ErrorLog("good_id")
  3364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3365. return
  3366. }
  3367. good_id := int64(items["good_id"].(float64))
  3368. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3369. utils.ErrorLog("good_type_id")
  3370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3371. return
  3372. }
  3373. good_type_id := int64(items["good_type_id"].(float64))
  3374. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3375. utils.ErrorLog("count")
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3377. return
  3378. }
  3379. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3380. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3381. utils.ErrorLog("ctime")
  3382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3383. return
  3384. }
  3385. ctime := int64(items["ctime"].(float64))
  3386. adminUser := c.GetMobileAdminUserInfo()
  3387. prepare := &models.DialysisBeforePrepare{
  3388. ID: id,
  3389. UserOrgId: adminUser.Org.Id,
  3390. PatientId: patient_id,
  3391. RecordDate: record_time,
  3392. GoodId: good_id,
  3393. GoodTypeId: good_type_id,
  3394. Count: count,
  3395. Ctime: ctime,
  3396. Mtime: time.Now().Unix(),
  3397. Creater: creater,
  3398. Modifier: adminUser.AdminUser.Id,
  3399. Status: 1,
  3400. }
  3401. beforePrepares = append(beforePrepares, prepare)
  3402. }
  3403. }
  3404. }
  3405. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3406. goods, _ := dataBody["new_goods"].([]interface{})
  3407. if len(goods) > 0 {
  3408. for _, item := range goods {
  3409. items := item.(map[string]interface{})
  3410. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3411. utils.ErrorLog("good_id")
  3412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3413. return
  3414. }
  3415. good_id := int64(items["good_id"].(float64))
  3416. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3417. utils.ErrorLog("good_type_id")
  3418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3419. return
  3420. }
  3421. good_type_id := int64(items["good_type_id"].(float64))
  3422. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3423. utils.ErrorLog("count")
  3424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3425. return
  3426. }
  3427. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3428. adminUser := c.GetMobileAdminUserInfo()
  3429. prepare := &models.DialysisBeforePrepare{
  3430. UserOrgId: adminUser.Org.Id,
  3431. PatientId: patient_id,
  3432. RecordDate: record_time,
  3433. GoodId: good_id,
  3434. GoodTypeId: good_type_id,
  3435. Count: count,
  3436. Ctime: time.Now().Unix(),
  3437. Mtime: time.Now().Unix(),
  3438. Creater: adminUser.AdminUser.Id,
  3439. Modifier: 0,
  3440. }
  3441. newBeforePrepares = append(newBeforePrepares, prepare)
  3442. }
  3443. }
  3444. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3445. }
  3446. var errs error
  3447. if len(beforePrepares) > 0 {
  3448. for _, item := range beforePrepares {
  3449. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3450. }
  3451. }
  3452. if errs == nil {
  3453. c.ServeSuccessJSON(map[string]interface{}{
  3454. "msg": "修改成功",
  3455. })
  3456. return
  3457. } else {
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3459. return
  3460. }
  3461. }
  3462. }
  3463. func (c *DialysisAPIController) GetDialysisGoods() {
  3464. schedualDate := c.GetString("schedule_date")
  3465. schedule_type, _ := c.GetInt64("schedule_type")
  3466. partition_id, _ := c.GetInt64("partition_id")
  3467. page, _ := c.GetInt("page")
  3468. patient_id, _ := c.GetInt64("patient_id")
  3469. schedualEndDate := int64(0)
  3470. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3471. if parseDateErr != nil && len(schedualDate) != 0 {
  3472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3473. return
  3474. }
  3475. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3476. if parseDateErr != nil && len(schedualDate) != 0 {
  3477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3478. return
  3479. }
  3480. schedualEndDate = endDate.Unix()
  3481. adminUser := c.GetMobileAdminUserInfo()
  3482. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3483. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3484. if err == gorm.ErrRecordNotFound {
  3485. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3486. if patient_id != 0 {
  3487. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3488. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3489. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3490. item.LastAutomaticReduceDetail = goodUser
  3491. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3492. }
  3493. }
  3494. c.ServeSuccessJSON(map[string]interface{}{
  3495. "dialysis_goods": dialysisGoods,
  3496. "good_type": goodTypes,
  3497. "total": total,
  3498. })
  3499. return
  3500. } else if err == nil {
  3501. //获取当天排班的每个患者的库存使用情况
  3502. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3503. if patient_id != 0 {
  3504. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3505. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3506. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3507. fmt.Println(goodUser)
  3508. fmt.Println(lastGoodUserDetial)
  3509. item.LastAutomaticReduceDetail = goodUser
  3510. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3511. }
  3512. }
  3513. if err == nil {
  3514. c.ServeSuccessJSON(map[string]interface{}{
  3515. "dialysis_goods": dialysisGoods,
  3516. "good_type": goodTypes,
  3517. "total": total,
  3518. })
  3519. return
  3520. } else {
  3521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3522. return
  3523. }
  3524. } else if err != nil {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3526. return
  3527. }
  3528. }
  3529. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3530. start_time := c.GetString("start_time")
  3531. end_time := c.GetString("end_time")
  3532. timeLayout := "2006-01-02"
  3533. loc, _ := time.LoadLocation("Local")
  3534. var theStartTime int64
  3535. if len(start_time) > 0 {
  3536. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3537. if err != nil {
  3538. utils.ErrorLog(err.Error())
  3539. }
  3540. theStartTime = theTime.Unix()
  3541. }
  3542. var theEndtTime int64
  3543. if len(end_time) > 0 {
  3544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3545. if err != nil {
  3546. utils.ErrorLog(err.Error())
  3547. }
  3548. theEndtTime = theTime.Unix()
  3549. }
  3550. adminUser := c.GetMobileAdminUserInfo()
  3551. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3552. if err == nil {
  3553. c.ServeSuccessJSON(map[string]interface{}{
  3554. "stock_out": outInfo,
  3555. })
  3556. return
  3557. } else {
  3558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3559. return
  3560. }
  3561. }
  3562. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3563. patient_id, _ := c.GetInt64("patient_id", 0)
  3564. record_time := c.GetString("record_time")
  3565. adminUser := c.GetMobileAdminUserInfo()
  3566. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3567. if parseDateErr != nil && len(record_time) != 0 {
  3568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3569. return
  3570. }
  3571. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  3572. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3573. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3574. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3575. c.ServeSuccessJSON(map[string]interface{}{
  3576. "good_type": goodTypes,
  3577. "good_user": goodUser,
  3578. "good_info": good_info,
  3579. "last_good_user": lastGoodUserDetial,
  3580. })
  3581. return
  3582. }
  3583. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3584. patient_id, _ := c.GetInt64("patient_id", 0)
  3585. record_date := c.GetString("record_time")
  3586. if patient_id <= 0 {
  3587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3588. return
  3589. }
  3590. adminInfo := c.GetMobileAdminUserInfo()
  3591. timeLayout := "2006-01-02"
  3592. loc, _ := time.LoadLocation("Local")
  3593. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3594. record_time := theRecordTime.Unix()
  3595. dataBody := make(map[string]interface{}, 0)
  3596. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3597. if err != nil {
  3598. utils.ErrorLog(err.Error())
  3599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3600. return
  3601. }
  3602. var beforePrepares []*models.DialysisBeforePrepare
  3603. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3604. goods, _ := dataBody["goods"].([]interface{})
  3605. if len(goods) > 0 {
  3606. for _, item := range goods {
  3607. items := item.(map[string]interface{})
  3608. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3609. utils.ErrorLog("good_id")
  3610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3611. return
  3612. }
  3613. good_id := int64(items["good_id"].(float64))
  3614. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3615. utils.ErrorLog("good_type_id")
  3616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3617. return
  3618. }
  3619. good_type_id := int64(items["good_type_id"].(float64))
  3620. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3621. utils.ErrorLog("count")
  3622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3623. return
  3624. }
  3625. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3626. adminUser := c.GetMobileAdminUserInfo()
  3627. prepare := &models.DialysisBeforePrepare{
  3628. UserOrgId: adminUser.Org.Id,
  3629. PatientId: patient_id,
  3630. RecordDate: record_time,
  3631. GoodId: good_id,
  3632. GoodTypeId: good_type_id,
  3633. Count: count,
  3634. Ctime: time.Now().Unix(),
  3635. Mtime: time.Now().Unix(),
  3636. Creater: adminUser.AdminUser.Id,
  3637. Modifier: 0,
  3638. }
  3639. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3640. if record_count == 0 {
  3641. beforePrepares = append(beforePrepares, prepare)
  3642. } else if record_count == 1 {
  3643. service.UpdateDialysisBeforePrepareTwo(prepare)
  3644. }
  3645. }
  3646. }
  3647. }
  3648. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3649. if len(beforePrepares) > 0 {
  3650. service.CreateDialysisBeforePrepare(beforePrepares)
  3651. }
  3652. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3653. //去重
  3654. consumables = RemoveRepeatedGood(consumables)
  3655. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3656. if record.IsOpen == 1 {
  3657. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3658. if err == gorm.ErrRecordNotFound {
  3659. //没有记录,则创建出库单
  3660. timeStr := time.Now().Format("2006-01-02")
  3661. timeArr := strings.Split(timeStr, "-")
  3662. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3663. total = total + 1
  3664. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3665. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3666. number = number + total
  3667. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3668. creater := adminInfo.AdminUser.Id
  3669. warehouseOut := models.WarehouseOut{
  3670. WarehouseOutOrderNumber: warehousing_out_order,
  3671. OperationTime: time.Now().Unix(),
  3672. OrgId: adminInfo.Org.Id,
  3673. Creater: creater,
  3674. Ctime: time.Now().Unix(),
  3675. Status: 1,
  3676. WarehouseOutTime: record_time,
  3677. Dealer: 0,
  3678. Manufacturer: 0,
  3679. Type: 1,
  3680. IsSys: 1,
  3681. }
  3682. err := service.AddSigleWarehouseOut(&warehouseOut)
  3683. if err != nil {
  3684. utils.TraceLog("创建出库单失败 err = %v", err)
  3685. } else {
  3686. for _, item := range consumables {
  3687. if item.Count > 0 {
  3688. warehouseOutInfo := &models.WarehouseOutInfo{
  3689. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3690. WarehouseOutId: warehouseOut.ID,
  3691. Status: 1,
  3692. Ctime: time.Now().Unix(),
  3693. Remark: "",
  3694. OrgId: adminInfo.Org.Id,
  3695. Type: 1,
  3696. Manufacturer: 0,
  3697. Dealer: 0,
  3698. IsSys: 1,
  3699. SysRecordTime: record_time,
  3700. GoodTypeId: item.GoodTypeId,
  3701. GoodId: item.GoodId,
  3702. }
  3703. warehouseOutInfo.Count = item.Count
  3704. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3705. warehouseOutInfo.Price = stockInInfo.Price
  3706. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3707. if err == nil {
  3708. details := &models.AutomaticReduceDetail{
  3709. WarehouseOutId: warehouseOutInfo.ID,
  3710. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3711. PatientId: patient_id,
  3712. Ctime: time.Now().Unix(),
  3713. Mtime: time.Now().Unix(),
  3714. Status: 1,
  3715. RecordTime: record_time,
  3716. OrgId: adminInfo.Org.Id,
  3717. GoodId: item.GoodId,
  3718. GoodTypeId: item.GoodTypeId,
  3719. Count: item.Count,
  3720. }
  3721. service.AddSigleAutoReduceRecordInfo(details)
  3722. }
  3723. }
  3724. }
  3725. }
  3726. } else if err == nil {
  3727. for _, item := range consumables {
  3728. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3729. if err == gorm.ErrRecordNotFound {
  3730. warehouseOutInfo := &models.WarehouseOutInfo{
  3731. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3732. WarehouseOutId: out.ID,
  3733. Status: 1,
  3734. Ctime: time.Now().Unix(),
  3735. Remark: "",
  3736. OrgId: adminInfo.Org.Id,
  3737. Type: 1,
  3738. Manufacturer: 0,
  3739. Dealer: 0,
  3740. IsSys: 1,
  3741. SysRecordTime: record_time,
  3742. }
  3743. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3744. warehouseOutInfo.Price = stockInInfo.Price
  3745. warehouseOutInfo.GoodId = item.GoodId
  3746. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3747. warehouseOutInfo.Count = item.Count
  3748. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3749. if err == nil {
  3750. details := &models.AutomaticReduceDetail{
  3751. WarehouseOutId: warehouseOutInfo.ID,
  3752. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3753. PatientId: patient_id,
  3754. Ctime: time.Now().Unix(),
  3755. Mtime: time.Now().Unix(),
  3756. Status: 1,
  3757. RecordTime: record_time,
  3758. OrgId: adminInfo.Org.Id,
  3759. GoodId: item.GoodId,
  3760. GoodTypeId: item.GoodTypeId,
  3761. Count: item.Count,
  3762. }
  3763. service.AddSigleAutoReduceRecordInfo(details)
  3764. }
  3765. } else if err == nil { //记录存在,则将增加数量
  3766. if outInfo.ID > 0 {
  3767. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3768. }
  3769. details := &models.AutomaticReduceDetail{
  3770. WarehouseOutId: outInfo.ID,
  3771. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3772. PatientId: patient_id,
  3773. Ctime: time.Now().Unix(),
  3774. Mtime: time.Now().Unix(),
  3775. Status: 1,
  3776. RecordTime: record_time,
  3777. OrgId: adminInfo.Org.Id,
  3778. GoodId: item.GoodId,
  3779. GoodTypeId: item.GoodTypeId,
  3780. Count: item.Count,
  3781. }
  3782. service.AddSigleAutoReduceRecordInfo(details)
  3783. }
  3784. }
  3785. }
  3786. c.ServeSuccessJSON(map[string]interface{}{
  3787. "msg": "提交成功",
  3788. })
  3789. return
  3790. } else {
  3791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3792. return
  3793. }
  3794. }
  3795. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3796. newArr = make([]*models.DialysisBeforePrepare, 0)
  3797. for i := 0; i < len(arr); i++ {
  3798. repeat := false
  3799. for j := i + 1; j < len(arr); j++ {
  3800. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  3801. repeat = true
  3802. break
  3803. }
  3804. }
  3805. if !repeat {
  3806. newArr = append(newArr, arr[i])
  3807. }
  3808. }
  3809. return
  3810. }
  3811. func (c *DialysisAPIController) GetAllDrug() {
  3812. patient_id, _ := c.GetInt64("patient_id", 0)
  3813. adminInfo := c.GetMobileAdminUserInfo()
  3814. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3815. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  3816. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  3817. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  3818. c.ServeSuccessJSON(map[string]interface{}{
  3819. "base_drug_config": drugStockConfig,
  3820. "private_drug_config": privateDrugConfig,
  3821. "base_drug_list": drugList,
  3822. "private_drug_list": privateDrugList,
  3823. })
  3824. }
  3825. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  3826. newArr = make([]*models.DialysisBeforePrepare, 0)
  3827. for i := 0; i < len(arr); i++ {
  3828. repeat := false
  3829. for j := i + 1; j < len(arr); j++ {
  3830. if arr[i].GoodId == arr[j].GoodId {
  3831. repeat = true
  3832. break
  3833. }
  3834. }
  3835. if !repeat {
  3836. newArr = append(newArr, arr[i])
  3837. }
  3838. }
  3839. return
  3840. }
  3841. func (c *DialysisAPIController) GetDepartment() {
  3842. adminInfo := c.GetMobileAdminUserInfo()
  3843. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  3844. if err == nil {
  3845. c.ServeSuccessJSON(map[string]interface{}{
  3846. "departments": departments,
  3847. })
  3848. } else {
  3849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3850. return
  3851. }
  3852. }