dialysis_api_controller.go 159KB

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