dialysis_api_controller.go 160KB

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