patient_api_controller.go 186KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 && infor.WeekDay > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. record_date, _ := c.GetInt64("record_date")
  530. if origin != 2 {
  531. adminUserInfo := c.GetMobileAdminUserInfo()
  532. execution_staff := adminUserInfo.AdminUser.Id
  533. var ids []string
  534. advice_ids := c.GetString("advice_id")
  535. if groupno == 0 {
  536. ids = strings.Split(advice_ids, ",")
  537. }
  538. if groupno < 0 {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if len(execution_time) <= 0 {
  543. utils.ErrorLog("execution_time")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeLayout2 := "2006-01-02 15:04:05"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  550. if errs != nil {
  551. utils.ErrorLog(errs.Error())
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. var advice models.DoctorAdvice
  556. if groupno > 0 {
  557. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  558. for _, item := range advices {
  559. if item.ExecutionState == 2 {
  560. advice = item
  561. }
  562. }
  563. } else {
  564. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  565. for _, item := range advices {
  566. if item.ExecutionState == 2 {
  567. advice = item
  568. }
  569. }
  570. }
  571. if advice.ExecutionState == 1 {
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  573. return
  574. }
  575. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  577. return
  578. }
  579. if advice.StartTime > theTime.Unix() {
  580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  581. return
  582. }
  583. advices := models.DoctorAdvice{
  584. ExecutionStaff: execution_staff,
  585. ExecutionTime: theTime.Unix(),
  586. UpdatedTime: time.Now().Unix(),
  587. }
  588. var err error
  589. if groupno > 0 {
  590. // 查询信息规挡的设置天数
  591. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  592. if infor.ID > 0 && infor.WeekDay > 0 {
  593. var cha_time int64
  594. timeNowStr := time.Now().Format("2006-01-02")
  595. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  596. //今日的日期减去设置的日期
  597. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  598. if cha_time >= record_date {
  599. //查询审核是否允许
  600. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  601. //申请状态不允许的情况 拒绝修改
  602. if infor.ApplicationStatus != 1 {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  604. return
  605. }
  606. }
  607. }
  608. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  609. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  610. redis := service.RedisClient()
  611. //清空key 值
  612. redis.Set(key, "", time.Second)
  613. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  614. redis.Set(keyTwo, "", time.Second)
  615. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  616. redis.Set(keyThree, "", time.Second)
  617. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  618. theTime := toTime.Format("2006-01-02")
  619. fmt.Println("theTIME", theTime)
  620. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  621. redis.Set(keyFour, "", time.Second)
  622. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  623. redis.Set(keyFive, "", time.Second)
  624. defer redis.Close()
  625. } else {
  626. // 查询信息规挡的设置天数
  627. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  628. if infor.ID > 0 {
  629. var cha_time int64
  630. timeNowStr := time.Now().Format("2006-01-02")
  631. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  632. //今日的日期减去设置的日期
  633. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  634. if cha_time >= record_date {
  635. //查询审核是否允许
  636. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  637. //申请状态不允许的情况 拒绝修改
  638. if infor.ApplicationStatus != 1 {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  640. return
  641. }
  642. }
  643. }
  644. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  646. redis := service.RedisClient()
  647. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  648. redis.Set(keyTwo, "", time.Second)
  649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  650. redis.Set(keyThree, "", time.Second)
  651. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  652. theTime := toTime.Format("2006-01-02")
  653. fmt.Println("theTIME", theTime)
  654. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyFour, "", time.Second)
  656. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  657. redis.Set(keySix, "", time.Second)
  658. defer redis.Close()
  659. //清空key 值
  660. redis.Set(key, "", time.Second)
  661. }
  662. if err != nil {
  663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  664. return
  665. }
  666. advice.ExecutionStaff = execution_staff
  667. advice.ExecutionTime = theTime.Unix()
  668. advice.ExecutionState = 1
  669. advice.Modifier = adminUserInfo.AdminUser.Id
  670. //处理出库相关逻辑
  671. //1.判断是否启用药品管理和自备药出库功能
  672. //药品管理信息
  673. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  674. //自备药信息
  675. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  676. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  677. if drugStockConfig.IsOpen == 1 {
  678. if groupno > 0 {
  679. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  680. if len(advices) > 0 {
  681. var total int64
  682. var prescribing_number_total int64
  683. //出库
  684. for _, item := range advices {
  685. if item.Way == 1 {
  686. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  687. //查询该药品的剩余库存
  688. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  689. //查询改药品信息
  690. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  691. //判断单位是否相等
  692. if medical.MaxUnit == item.PrescribingNumberUnit {
  693. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  694. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  695. //转化为最小单位
  696. total = list.Count * medical.MinNumber
  697. prescribing_number_total = count * medical.MinNumber
  698. }
  699. if medical.MinUnit == item.PrescribingNumberUnit {
  700. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  701. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  702. total = list.Count*medical.MinNumber + list.StockMinNumber
  703. prescribing_number_total = count
  704. }
  705. if medical.IsUse == 1 {
  706. c.ServeSuccessJSON(map[string]interface{}{
  707. "msg": "1",
  708. "advice": advice,
  709. "ids": ids,
  710. })
  711. return
  712. }
  713. if medical.IsUse != 1 {
  714. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  715. if advice.UserOrgId != 10278 {
  716. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  717. advice.ExecutionTime = 0
  718. advice.ExecutionState = 2
  719. advice.ExecutionStaff = 0
  720. }
  721. c.ServeSuccessJSON(map[string]interface{}{
  722. "msg": "3",
  723. "advice": advice,
  724. "ids": ids,
  725. })
  726. return
  727. }
  728. if prescribing_number_total > total {
  729. if advice.UserOrgId != 10278 {
  730. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  731. advice.ExecutionTime = 0
  732. advice.ExecutionState = 2
  733. advice.ExecutionStaff = 0
  734. }
  735. c.ServeSuccessJSON(map[string]interface{}{
  736. "msg": "2",
  737. "advice": advice,
  738. "ids": ids,
  739. })
  740. return
  741. }
  742. }
  743. //查询是否出库按钮开启
  744. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  745. if adviceSetting.IsAdviceOpen == 1 {
  746. //查询是否出库按钮开启
  747. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  748. //患者发药
  749. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  750. if prescriptionConfig.IsOpen == 1 {
  751. if medical.IsUse == 2 {
  752. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  753. //查询今日是否出库
  754. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  755. if drugOutInfo.ID == 0 {
  756. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  757. }
  758. }
  759. if pharmacyConfig.IsOpen != 1 {
  760. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  761. if drugOutInfo.ID == 0 {
  762. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  763. }
  764. }
  765. //更新字典里面的库存
  766. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  767. var sum_count int64
  768. for _, its := range stockInfo {
  769. if its.MaxUnit == medical.MaxUnit {
  770. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  771. }
  772. sum_count += its.StockMaxNumber + its.StockMinNumber
  773. }
  774. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  775. //剩余库存
  776. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  777. }
  778. }
  779. } else {
  780. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  781. if medical.IsUse == 2 {
  782. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  783. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  784. if drugOutInfo.ID == 0 {
  785. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  786. }
  787. }
  788. if pharmacyConfig.IsOpen != 1 {
  789. drugError := models.XtDrugError{
  790. ID: 0,
  791. UserOrgId: item.UserOrgId,
  792. DrugId: item.DrugId,
  793. RecordDate: item.AdviceDate,
  794. PatientId: item.PatientId,
  795. Remark: "恒泰中医院出库开始",
  796. Status: 1,
  797. Ctime: time.Now().Unix(),
  798. Mtime: 0,
  799. Prescribingnumber: item.PrescribingNumber,
  800. PrescribingNumberUnit: item.PrescribingNumberUnit,
  801. SumCount: 0,
  802. }
  803. service.CreateDrugError(drugError)
  804. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  805. if drugOutInfo.ID == 0 {
  806. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  807. }
  808. }
  809. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  810. var sum_count int64
  811. for _, its := range stockInfo {
  812. if its.MaxUnit == medical.MaxUnit {
  813. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  814. }
  815. sum_count += its.StockMaxNumber + its.StockMinNumber
  816. }
  817. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  818. //剩余库存
  819. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  820. }
  821. }
  822. }
  823. }
  824. }
  825. c.ServeSuccessJSON(map[string]interface{}{
  826. "msg": "1",
  827. "advice": advice,
  828. "ids": ids,
  829. })
  830. return
  831. } else {
  832. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  833. if len(advices) > 0 {
  834. var total int64
  835. var prescribing_number_total int64
  836. for _, item := range advices {
  837. if item.Way == 1 {
  838. //查询改药品信息
  839. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  840. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  841. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  842. //查询该药品的剩余库存
  843. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  844. //判断单位是否相等
  845. if medical.MaxUnit == item.PrescribingNumberUnit {
  846. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  847. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  848. //转化为最小单位
  849. total = list.Count*medical.MinNumber + list.StockMinNumber
  850. prescribing_number_total = count * medical.MinNumber
  851. }
  852. if medical.MinUnit == item.PrescribingNumberUnit {
  853. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  854. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  855. total = list.Count*medical.MinNumber + list.StockMinNumber
  856. prescribing_number_total = count
  857. }
  858. if medical.IsUse == 1 {
  859. c.ServeSuccessJSON(map[string]interface{}{
  860. "msg": "1",
  861. "advice": advice,
  862. "ids": ids,
  863. })
  864. return
  865. }
  866. if medical.IsUse != 1 {
  867. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  868. if advice.UserOrgId != 10278 {
  869. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  870. advice.ExecutionTime = 0
  871. advice.ExecutionState = 2
  872. advice.ExecutionStaff = 0
  873. }
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "msg": "3",
  876. "advice": advice,
  877. "ids": ids,
  878. })
  879. return
  880. }
  881. if prescribing_number_total > total {
  882. if advice.UserOrgId != 10278 {
  883. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  884. advice.ExecutionTime = 0
  885. advice.ExecutionState = 2
  886. advice.ExecutionStaff = 0
  887. }
  888. c.ServeSuccessJSON(map[string]interface{}{
  889. "msg": "2",
  890. "advice": advice,
  891. "ids": ids,
  892. })
  893. return
  894. }
  895. }
  896. if medical.IsUse == 2 {
  897. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  898. //查询今日是否出库
  899. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  900. if drugOutInfo.ID == 0 {
  901. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  902. }
  903. }
  904. if pharmacyConfig.IsOpen != 1 {
  905. //查询今日是否出库
  906. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  907. if drugOutInfo.ID == 0 {
  908. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  909. }
  910. }
  911. //更新字典里面的库存
  912. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  913. var sum_count int64
  914. for _, its := range stockInfo {
  915. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  916. if its.MaxUnit == baseDrug.MaxUnit {
  917. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  918. }
  919. sum_count += its.StockMaxNumber + its.StockMinNumber
  920. }
  921. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  922. //剩余库存
  923. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  924. }
  925. if medical.IsUse == 1 {
  926. c.ServeSuccessJSON(map[string]interface{}{
  927. "msg": "1",
  928. "advice": advice,
  929. "ids": ids,
  930. })
  931. return
  932. }
  933. }
  934. }
  935. }
  936. c.ServeSuccessJSON(map[string]interface{}{
  937. "msg": "1",
  938. "advice": advice,
  939. "ids": ids,
  940. })
  941. return
  942. }
  943. }
  944. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  945. if groupno > 0 {
  946. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  947. for _, item := range advices {
  948. if item.ExecutionState == 1 && item.Way == 2 {
  949. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  950. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  951. timeStr := time.Now().Format("2006-01-02")
  952. timeArr := strings.Split(timeStr, "-")
  953. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  954. total = total + 1
  955. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  956. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  957. number = number + total
  958. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  959. //插入自备药出库单
  960. outStock := models.XtSelfOutStock{
  961. DrugName: item.AdviceName,
  962. DrugNameId: item.DrugNameId,
  963. DrugSpec: item.AdviceDesc,
  964. OutstoreNumber: count,
  965. AdminUserId: adminUserInfo.AdminUser.Id,
  966. StorckTime: item.AdviceDate,
  967. UserOrgId: adminUserInfo.Org.Id,
  968. CreatedTime: time.Now().Unix(),
  969. Status: 1,
  970. PatientId: item.PatientId,
  971. ExitMode: 2,
  972. MedicId: item.DrugId,
  973. StockOutNumber: warehousing_out_order,
  974. }
  975. //查询 该患者是否已出库
  976. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  977. if errcode == gorm.ErrRecordNotFound {
  978. service.CreateOutStock(&outStock)
  979. } else if errcode == nil {
  980. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  981. fmt.Println("err", err)
  982. }
  983. }
  984. }
  985. } else {
  986. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  987. for _, item := range advices {
  988. if item.ExecutionState == 1 && item.Way == 2 {
  989. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  990. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  991. timeStr := time.Now().Format("2006-01-02")
  992. timeArr := strings.Split(timeStr, "-")
  993. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  994. total = total + 1
  995. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  996. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  997. number = number + total
  998. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  999. //插入自备药出库单
  1000. outStock := models.XtSelfOutStock{
  1001. DrugName: item.AdviceName,
  1002. DrugNameId: item.DrugNameId,
  1003. DrugSpec: item.AdviceDesc,
  1004. OutstoreNumber: count,
  1005. AdminUserId: adminUserInfo.AdminUser.Id,
  1006. StorckTime: item.AdviceDate,
  1007. UserOrgId: adminUserInfo.Org.Id,
  1008. CreatedTime: time.Now().Unix(),
  1009. Status: 1,
  1010. PatientId: item.PatientId,
  1011. ExitMode: 2,
  1012. MedicId: item.DrugId,
  1013. StockOutNumber: warehousing_out_order,
  1014. }
  1015. //查询 该患者是否已出库
  1016. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1017. if errcode == gorm.ErrRecordNotFound {
  1018. service.CreateOutStock(&outStock)
  1019. } else if errcode == nil {
  1020. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1021. fmt.Println("err", err)
  1022. }
  1023. }
  1024. }
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "msg": "1",
  1027. "advice": advice,
  1028. "ids": ids,
  1029. })
  1030. return
  1031. }
  1032. }
  1033. c.ServeSuccessJSON(map[string]interface{}{
  1034. "msg": "1",
  1035. "advice": advice,
  1036. "ids": ids,
  1037. })
  1038. return
  1039. } else if origin == 2 {
  1040. adminInfo := c.GetMobileAdminUserInfo()
  1041. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1042. var ids []string
  1043. advice_ids := c.GetString("advice_id")
  1044. ids = strings.Split(advice_ids, ",")
  1045. if len(execution_time) <= 0 {
  1046. utils.ErrorLog("execution_time")
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1048. return
  1049. }
  1050. timeLayout2 := "2006-01-02 15:04:05"
  1051. loc, _ := time.LoadLocation("Local")
  1052. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1053. if errs != nil {
  1054. utils.ErrorLog(errs.Error())
  1055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1056. return
  1057. }
  1058. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1059. var err error
  1060. for _, item := range advices {
  1061. if item.ExecutionState == 1 {
  1062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1063. return
  1064. }
  1065. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1067. return
  1068. }
  1069. if item.StartTime > theTime.Unix() {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1071. return
  1072. }
  1073. item.ExecutionState = 1
  1074. item.ExecutionStaff = adminInfo.AdminUser.Id
  1075. item.ExecutionTime = theTime.Unix()
  1076. item.IsMobile = 1
  1077. // 查询信息规挡的设置天数
  1078. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1079. if infor.ID > 0 {
  1080. var cha_time int64
  1081. timeNowStr := time.Now().Format("2006-01-02")
  1082. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1083. //今日的日期减去设置的日期
  1084. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1085. if cha_time >= item.AdviceDate {
  1086. //查询审核是否允许
  1087. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId)
  1088. //申请状态不允许的情况 拒绝修改
  1089. if infor.ApplicationStatus != 1 {
  1090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1091. return
  1092. }
  1093. }
  1094. }
  1095. err = service.SaveHisDoctorAdvice(item)
  1096. if err == nil {
  1097. drugError := models.XtDrugError{
  1098. UserOrgId: adminInfo.Org.Id,
  1099. DrugId: item.DrugId,
  1100. RecordDate: item.AdviceDate,
  1101. PatientId: item.PatientId,
  1102. Remark: "执行成功",
  1103. Status: 1,
  1104. Ctime: time.Now().Unix(),
  1105. Mtime: 0,
  1106. SumCount: 0,
  1107. Prescribingnumber: item.PrescribingNumber,
  1108. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1109. }
  1110. service.CreateDrugError(drugError)
  1111. }
  1112. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1113. redis := service.RedisClient()
  1114. //清空key 值
  1115. redis.Set(key, "", time.Second)
  1116. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1117. redis.Set(keyTwo, "", time.Second)
  1118. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1119. redis.Set(keyThree, "", time.Second)
  1120. recordDate := theTime.Format("2006-01-02")
  1121. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1122. redis.Set(keyFour, "", time.Second)
  1123. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1124. redis.Set(keyFive, "", time.Second)
  1125. defer redis.Close()
  1126. }
  1127. if err == nil {
  1128. //药品管理信息
  1129. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1130. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1131. if drugStockConfig.IsOpen == 1 {
  1132. for _, item := range advices {
  1133. //查询改药品信息
  1134. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1135. //判断单位是否合格
  1136. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1137. //查询该药品是否有出库记录
  1138. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  1139. if len(flowMap) == 0 {
  1140. errs := service.UpdateHisAdviceById(item.ID)
  1141. if errs != nil {
  1142. drugError := models.XtDrugError{
  1143. UserOrgId: adminInfo.Org.Id,
  1144. DrugId: item.DrugId,
  1145. RecordDate: item.AdviceDate,
  1146. PatientId: item.PatientId,
  1147. Remark: "单位不统一,执行失败",
  1148. Status: 1,
  1149. Ctime: time.Now().Unix(),
  1150. Mtime: 0,
  1151. SumCount: 0,
  1152. Prescribingnumber: item.PrescribingNumber,
  1153. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1154. }
  1155. service.CreateDrugError(drugError)
  1156. }
  1157. }
  1158. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1159. c.ServeSuccessJSON(map[string]interface{}{
  1160. "msg": "7",
  1161. "advice": advice,
  1162. "ids": ids,
  1163. })
  1164. return
  1165. }
  1166. //查询这个患者这个患者这个药已经出库的所有数量
  1167. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1168. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1169. var total_count int64
  1170. var drug_count int64
  1171. for _, it := range advicelist {
  1172. if it.PrescribingNumberUnit == medical.MaxUnit {
  1173. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1174. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1175. total_count += prenumber * medical.MinNumber
  1176. }
  1177. if it.PrescribingNumberUnit == medical.MinUnit {
  1178. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1179. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1180. total_count += prenumber
  1181. }
  1182. }
  1183. for _, its := range drugoutlist {
  1184. if its.CountUnit == medical.MaxUnit {
  1185. drug_count += its.Count * medical.MinNumber
  1186. }
  1187. if its.CountUnit == medical.MinUnit {
  1188. drug_count += its.Count
  1189. }
  1190. }
  1191. if total_count == drug_count {
  1192. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1193. c.ServeSuccessJSON(map[string]interface{}{
  1194. "msg": "1",
  1195. "advice": advice,
  1196. "ids": ids,
  1197. })
  1198. return
  1199. }
  1200. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1201. var total int64
  1202. var prescribing_number_total int64
  1203. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1204. if config.IsOpen != 1 {
  1205. //查询该药品是否有库存
  1206. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1207. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1208. //判断单位是否相等
  1209. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1210. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1211. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1212. //转化为最小单位
  1213. total = list.Count*medical.MinNumber + list.StockMinNumber
  1214. prescribing_number_total = count * medical.MinNumber
  1215. }
  1216. //fmt.Println("医嘱开的数量", total)
  1217. if medical.MinUnit == advice.PrescribingNumberUnit {
  1218. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1219. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1220. total = list.Count*medical.MinNumber + list.StockMinNumber
  1221. prescribing_number_total = count
  1222. }
  1223. if medical.IsUse == 1 {
  1224. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1225. drugError := models.XtDrugError{
  1226. UserOrgId: adminInfo.Org.Id,
  1227. DrugId: item.DrugId,
  1228. RecordDate: item.AdviceDate,
  1229. PatientId: item.PatientId,
  1230. Remark: "零用药品库存不足",
  1231. Status: 1,
  1232. Ctime: time.Now().Unix(),
  1233. Mtime: 0,
  1234. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1235. Prescribingnumber: advice.PrescribingNumber,
  1236. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1237. }
  1238. service.CreateDrugError(drugError)
  1239. c.ServeSuccessJSON(map[string]interface{}{
  1240. "msg": "1",
  1241. "advice": advice,
  1242. "ids": ids,
  1243. })
  1244. return
  1245. }
  1246. }
  1247. if medical.IsUse != 1 {
  1248. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1249. drugError := models.XtDrugError{
  1250. UserOrgId: adminInfo.Org.Id,
  1251. DrugId: item.DrugId,
  1252. RecordDate: item.AdviceDate,
  1253. PatientId: item.PatientId,
  1254. Remark: "药品库存不足",
  1255. Status: 1,
  1256. Ctime: time.Now().Unix(),
  1257. Mtime: 0,
  1258. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1259. Prescribingnumber: advice.PrescribingNumber,
  1260. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1261. }
  1262. service.CreateDrugError(drugError)
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "3",
  1265. "advice": advice,
  1266. "ids": ids,
  1267. })
  1268. return
  1269. }
  1270. if prescribing_number_total > total {
  1271. drugError := models.XtDrugError{
  1272. UserOrgId: adminInfo.Org.Id,
  1273. DrugId: item.DrugId,
  1274. RecordDate: item.AdviceDate,
  1275. PatientId: item.PatientId,
  1276. Remark: "出库数量大于库存",
  1277. Status: 1,
  1278. Ctime: time.Now().Unix(),
  1279. Mtime: 0,
  1280. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1281. Prescribingnumber: advice.PrescribingNumber,
  1282. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1283. }
  1284. service.CreateDrugError(drugError)
  1285. c.ServeSuccessJSON(map[string]interface{}{
  1286. "msg": "2",
  1287. "advice": advice,
  1288. "ids": ids,
  1289. })
  1290. return
  1291. }
  1292. }
  1293. if prescribing_number_total <= total {
  1294. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1295. //判断药品是否零用
  1296. if medical.IsUse == 2 {
  1297. if config.IsOpen != 1 {
  1298. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1299. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1300. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1301. //查询该药品是否有出库记录
  1302. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1303. if len(flowMap) == 0 {
  1304. errs := service.UpdateHisAdviceById(advice.ID)
  1305. if errs != nil {
  1306. drugError := models.XtDrugError{
  1307. UserOrgId: adminInfo.Org.Id,
  1308. DrugId: item.DrugId,
  1309. RecordDate: item.AdviceDate,
  1310. PatientId: item.PatientId,
  1311. Remark: "出库记录为空,更新执行人失败",
  1312. Status: 1,
  1313. Ctime: time.Now().Unix(),
  1314. Mtime: 0,
  1315. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1316. Prescribingnumber: advice.PrescribingNumber,
  1317. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1318. }
  1319. service.CreateDrugError(drugError)
  1320. }
  1321. c.ServeSuccessJSON(map[string]interface{}{
  1322. "msg": "6",
  1323. "advice": advice,
  1324. "ids": ids,
  1325. })
  1326. return
  1327. }
  1328. }
  1329. }
  1330. if pharmacyConfig.IsOpen != 1 {
  1331. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1332. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1333. //查询该药品是否有出库记录
  1334. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1335. if len(flowMap) == 0 {
  1336. errs := service.UpdateHisAdviceById(advice.ID)
  1337. if errs != nil {
  1338. drugError := models.XtDrugError{
  1339. UserOrgId: adminInfo.Org.Id,
  1340. DrugId: item.DrugId,
  1341. RecordDate: item.AdviceDate,
  1342. PatientId: item.PatientId,
  1343. Remark: "出库记录为空,更新执行人失败",
  1344. Status: 1,
  1345. Ctime: time.Now().Unix(),
  1346. Mtime: 0,
  1347. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1348. Prescribingnumber: advice.PrescribingNumber,
  1349. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1350. }
  1351. service.CreateDrugError(drugError)
  1352. }
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "msg": "6",
  1355. "advice": advice,
  1356. "ids": ids,
  1357. })
  1358. return
  1359. }
  1360. }
  1361. }
  1362. //更新字典里面的库存
  1363. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1364. var sum_count int64
  1365. for _, its := range stockInfo {
  1366. if its.MaxUnit == medical.MaxUnit {
  1367. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1368. }
  1369. sum_count += its.StockMaxNumber + its.StockMinNumber
  1370. }
  1371. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1372. //剩余库存
  1373. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1374. }
  1375. }
  1376. }
  1377. }
  1378. //
  1379. //if config.IsOpen == 1 && item.UserOrgId == 10188 {
  1380. //
  1381. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1382. // //更新字典里面的库存
  1383. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1384. // var sum_count int64
  1385. // for _, its := range stockInfo {
  1386. // if its.MaxUnit == medical.MaxUnit {
  1387. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1388. // }
  1389. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1390. // }
  1391. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1392. // //剩余库存
  1393. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1394. //}
  1395. }
  1396. }
  1397. for _, item := range advices {
  1398. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1399. c.ServeSuccessJSON(map[string]interface{}{
  1400. "msg": "1",
  1401. "advice": advice,
  1402. "ids": ids,
  1403. })
  1404. }
  1405. } else {
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1407. }
  1408. }
  1409. }
  1410. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1411. execution_time := c.GetString("execution_time")
  1412. fmt.Println("execution_time", execution_time)
  1413. groupno, _ := c.GetInt64("groupno", -1)
  1414. //patient_id, _ := c.GetInt64("patient_id")
  1415. advice_date, _ := c.GetInt64("advice_date")
  1416. var ids []string
  1417. if groupno == 0 {
  1418. advice_ids := c.GetString("advice_id")
  1419. ids = strings.Split(advice_ids, ",")
  1420. }
  1421. if groupno < 0 {
  1422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1423. return
  1424. }
  1425. if len(execution_time) <= 0 {
  1426. utils.ErrorLog("execution_time")
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1428. return
  1429. }
  1430. timeLayout2 := "2006-01-02 15:04:05"
  1431. loc, _ := time.LoadLocation("Local")
  1432. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1433. if errs != nil {
  1434. utils.ErrorLog(errs.Error())
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. adminUserInfo := c.GetMobileAdminUserInfo()
  1439. var advice models.DoctorAdvice
  1440. if groupno > 0 {
  1441. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1442. for _, item := range advices {
  1443. if item.ExecutionState == 1 {
  1444. advice = item
  1445. }
  1446. }
  1447. } else {
  1448. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1449. for _, item := range advices {
  1450. if item.ExecutionState == 1 {
  1451. advice = item
  1452. }
  1453. }
  1454. }
  1455. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1456. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1457. // if getPermissionErr != nil {
  1458. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1459. // return
  1460. // } else if headNursePermission == nil {
  1461. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1462. // return
  1463. // }
  1464. //}
  1465. if advice.StartTime > theTime.Unix() {
  1466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1467. return
  1468. }
  1469. advices := models.DoctorAdvice{
  1470. ExecutionTime: theTime.Unix(),
  1471. UpdatedTime: time.Now().Unix(),
  1472. }
  1473. var err error
  1474. if groupno > 0 {
  1475. // 查询信息规挡的设置天数
  1476. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1477. if infor.ID > 0 {
  1478. var cha_time int64
  1479. timeNowStr := time.Now().Format("2006-01-02")
  1480. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1481. //今日的日期减去设置的日期
  1482. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1483. if cha_time >= advices.AdviceDate {
  1484. //查询审核是否允许
  1485. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1486. //申请状态不允许的情况 拒绝修改
  1487. if infor.ApplicationStatus != 1 {
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1489. return
  1490. }
  1491. }
  1492. }
  1493. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1494. redis := service.RedisClient()
  1495. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1496. redis.Set(key, "", time.Second)
  1497. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1498. redis.Set(keyOne, "", time.Second)
  1499. defer redis.Close()
  1500. } else {
  1501. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1502. if infor.ID > 0 {
  1503. var cha_time int64
  1504. timeNowStr := time.Now().Format("2006-01-02")
  1505. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1506. //今日的日期减去设置的日期
  1507. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1508. if cha_time >= advices.AdviceDate {
  1509. //查询审核是否允许
  1510. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1511. //申请状态不允许的情况 拒绝修改
  1512. if infor.ApplicationStatus != 1 {
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1514. return
  1515. }
  1516. }
  1517. }
  1518. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1519. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1520. redis := service.RedisClient()
  1521. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1522. redis.Set(key, "", time.Second)
  1523. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1524. redis.Set(keyOne, "", time.Second)
  1525. defer redis.Close()
  1526. }
  1527. //判断是否开启his
  1528. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1529. //如果开启去修改执行时间
  1530. if config.IsOpen == 1 {
  1531. advicesinfo := models.HisDoctorAdviceInfo{
  1532. ExecutionTime: theTime.Unix(),
  1533. UpdatedTime: time.Now().Unix(),
  1534. }
  1535. var advicehis models.HisDoctorAdviceInfo
  1536. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1537. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1538. for _, item := range his_advices {
  1539. if item.ExecutionState == 1 {
  1540. advicehis = item
  1541. }
  1542. }
  1543. redis := service.RedisClient()
  1544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1545. redis.Set(keyThree, "", time.Second)
  1546. recordDate := theTime.Format("2006-01-02")
  1547. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1548. redis.Set(keyFour, "", time.Second)
  1549. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1550. redis.Set(keyFive, "", time.Second)
  1551. defer redis.Close()
  1552. project := models.HisPrescriptionProject{
  1553. ExecutionTime: theTime.Unix(),
  1554. Mtime: time.Now().Unix(),
  1555. }
  1556. service.ModifyHisPrescriptionProject(&project, ids)
  1557. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1558. redis.Set(keyEnd, "", time.Second)
  1559. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1560. redis.Set(keyFours, "", time.Second)
  1561. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1562. redis.Set(keyFives, "", time.Second)
  1563. defer redis.Close()
  1564. }
  1565. if err != nil {
  1566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1567. return
  1568. }
  1569. advice.ExecutionTime = theTime.Unix()
  1570. c.ServeSuccessJSON(map[string]interface{}{
  1571. "msg": "ok",
  1572. "advice": advice,
  1573. "ids": ids,
  1574. })
  1575. return
  1576. }
  1577. func (c *PatientApiController) CheckDoctorAdvice() {
  1578. origin, _ := c.GetInt64("origin", 0)
  1579. record_date, _ := c.GetInt64("record_date")
  1580. patient_id, _ := c.GetInt64("patient_id")
  1581. if origin != 2 {
  1582. groupno, _ := c.GetInt64("groupno", -1)
  1583. var ids []string
  1584. if groupno == 0 {
  1585. advice_ids := c.GetString("advice_id")
  1586. if advice_ids == "" {
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. } else {
  1590. ids = strings.Split(advice_ids, ",")
  1591. if len(ids) <= 0 {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. }
  1596. }
  1597. if groupno < 0 {
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. adminUserInfo := c.GetMobileAdminUserInfo()
  1602. var advice models.DoctorAdvice
  1603. if groupno > 0 {
  1604. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1605. for _, item := range advices {
  1606. if item.CheckState == 0 {
  1607. advice = item
  1608. }
  1609. }
  1610. if advice.CheckState == 1 {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1612. return
  1613. }
  1614. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1616. return
  1617. }
  1618. } else {
  1619. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1620. for _, item := range advices {
  1621. if item.CheckState == 0 {
  1622. advice = item
  1623. }
  1624. }
  1625. if advice.CheckState == 1 {
  1626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1627. return
  1628. }
  1629. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1631. return
  1632. }
  1633. }
  1634. checker := adminUserInfo.AdminUser.Id
  1635. theTime := time.Now()
  1636. advices := models.DoctorAdvice{
  1637. CheckTime: theTime.Unix(),
  1638. Checker: checker,
  1639. UpdatedTime: time.Now().Unix(),
  1640. }
  1641. var err error
  1642. if groupno > 0 {
  1643. // 查询信息规挡的设置天数
  1644. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1645. if infor.ID > 0 && infor.WeekDay > 0 {
  1646. var cha_time int64
  1647. timeNowStr := time.Now().Format("2006-01-02")
  1648. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1649. //今日的日期减去设置的日期
  1650. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1651. if cha_time >= record_date {
  1652. //查询审核是否允许
  1653. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id)
  1654. //申请状态不允许的情况 拒绝修改
  1655. if infor.ApplicationStatus != 1 {
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1657. return
  1658. }
  1659. }
  1660. }
  1661. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1663. redis := service.RedisClient()
  1664. //清空key 值
  1665. redis.Set(key, "", time.Second)
  1666. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1667. redis.Set(keyTwo, "", time.Second)
  1668. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1669. redis.Set(keyThree, "", time.Second)
  1670. recordDate := theTime.Format("2006-01-02")
  1671. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1672. redis.Set(keyFour, "", time.Second)
  1673. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1674. redis.Set(keyFive, "", time.Second)
  1675. defer redis.Close()
  1676. } else {
  1677. if len(ids[0]) <= 0 {
  1678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1679. return
  1680. } else {
  1681. //t := time.Now().Format("2006-01-02")/**/
  1682. //timeLayout2 := "2006-01-02"
  1683. //loc, _ := time.LoadLocation("Local")
  1684. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1685. // 查询信息规挡的设置天数
  1686. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1687. if infor.ID > 0 {
  1688. var cha_time int64
  1689. timeNowStr := time.Now().Format("2006-01-02")
  1690. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1691. //今日的日期减去设置的日期
  1692. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1693. if cha_time >= advices.AdviceDate {
  1694. //查询审核是否允许
  1695. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1696. //申请状态不允许的情况 拒绝修改
  1697. if infor.ApplicationStatus != 1 {
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1699. return
  1700. }
  1701. }
  1702. }
  1703. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1704. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1705. redis := service.RedisClient()
  1706. //清空key 值
  1707. redis.Set(key, "", time.Second)
  1708. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1709. redis.Set(keyTwo, "", time.Second)
  1710. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1711. redis.Set(keyThree, "", time.Second)
  1712. recordDate := theTime.Format("2006-01-02")
  1713. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1714. redis.Set(keyFour, "", time.Second)
  1715. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1716. redis.Set(keyFive, "", time.Second)
  1717. defer redis.Close()
  1718. }
  1719. }
  1720. if err != nil {
  1721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1722. return
  1723. }
  1724. advice.Checker = checker
  1725. advice.CheckTime = theTime.Unix()
  1726. advice.CheckState = 1
  1727. c.ServeSuccessJSON(map[string]interface{}{
  1728. "msg": "ok",
  1729. "advice": advice,
  1730. })
  1731. } else if origin == 2 {
  1732. adminInfo := c.GetMobileAdminUserInfo()
  1733. var ids []string
  1734. advice_ids := c.GetString("advice_id")
  1735. ids = strings.Split(advice_ids, ",")
  1736. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1737. var err error
  1738. for _, item := range advices {
  1739. if item.CheckState == 1 {
  1740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1741. return
  1742. }
  1743. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1745. return
  1746. }
  1747. item.Checker = adminInfo.AdminUser.Id
  1748. item.CheckTime = time.Now().Unix()
  1749. item.CheckState = 1
  1750. // 查询信息规挡的设置天数
  1751. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  1752. if infor.ID > 0 {
  1753. var cha_time int64
  1754. timeNowStr := time.Now().Format("2006-01-02")
  1755. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1756. //今日的日期减去设置的日期
  1757. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1758. if cha_time >= record_date {
  1759. //查询审核是否允许
  1760. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id)
  1761. //申请状态不允许的情况 拒绝修改
  1762. if infor.ApplicationStatus != 1 {
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1764. return
  1765. }
  1766. }
  1767. }
  1768. err = service.SaveHisDoctorAdvice(item)
  1769. redis := service.RedisClient()
  1770. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1771. //清空key 值
  1772. redis.Set(key, "", time.Second)
  1773. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1774. redis.Set(keyTwo, "", time.Second)
  1775. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1776. redis.Set(keyThree, "", time.Second)
  1777. theTime := time.Now()
  1778. recordDate := theTime.Format("2006-01-02")
  1779. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1780. redis.Set(keyFour, "", time.Second)
  1781. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1782. redis.Set(keyFive, "", time.Second)
  1783. defer redis.Close()
  1784. }
  1785. if err == nil {
  1786. c.ServeSuccessJSON(map[string]interface{}{
  1787. "msg": "ok",
  1788. "advice": advices,
  1789. })
  1790. } else {
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1792. return
  1793. }
  1794. }
  1795. return
  1796. }
  1797. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1798. id, _ := c.GetInt64("patient", 0)
  1799. assessmentDate := c.GetString("assessment_date", "")
  1800. if id <= 0 || len(assessmentDate) != 10 {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. timeLayout := "2006-01-02"
  1805. loc, _ := time.LoadLocation("Local")
  1806. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1807. if err != nil {
  1808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1809. return
  1810. }
  1811. theAssessmentDateTime := theTime.Unix()
  1812. adminUserInfo := c.GetMobileAdminUserInfo()
  1813. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1814. if patient.ID == 0 {
  1815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1816. return
  1817. }
  1818. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1819. if getPEErr != nil {
  1820. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1822. return
  1823. }
  1824. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1825. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1826. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1827. var evaluation models.PredialysisEvaluation
  1828. if theEvaluation != nil {
  1829. evaluation = *theEvaluation
  1830. }
  1831. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1832. if code > 0 {
  1833. c.ServeFailJSONWithSGJErrorCode(code)
  1834. return
  1835. }
  1836. if theEvaluation == nil {
  1837. evaluation.CreatedTime = time.Now().Unix()
  1838. evaluation.Status = 1
  1839. evaluation.AssessmentDate = theAssessmentDateTime
  1840. evaluation.PatientId = id
  1841. evaluation.UserOrgId = adminUserInfo.Org.Id
  1842. if appRole.UserType == 2 || appRole.UserType == 1 {
  1843. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1844. evaluation.AssessmentTime = time.Now().Unix()
  1845. } else {
  1846. evaluation.Creater = adminUserInfo.AdminUser.Id
  1847. }
  1848. } else {
  1849. evaluation.UpdatedTime = time.Now().Unix()
  1850. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1851. if appRole.UserType == 2 || appRole.UserType == 1 {
  1852. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1853. evaluation.AssessmentTime = time.Now().Unix()
  1854. } else {
  1855. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1856. if evaluation.Creater == 0 {
  1857. evaluation.Creater = adminUserInfo.AdminUser.Id
  1858. }
  1859. }
  1860. }
  1861. //新增逻辑
  1862. var dewater_amount float64
  1863. dewater_amount = 0
  1864. if evaluation.DryWeight > 0 {
  1865. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1866. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 {
  1867. dewater_amount = dewater_amount * 1000
  1868. }
  1869. if dewater_amount <= 0 {
  1870. dewater_amount = 0
  1871. }
  1872. } else {
  1873. dewater_amount = 0
  1874. }
  1875. // 计算透析处方的相关超滤量
  1876. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1877. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  1878. var lastDialysisPrescribe *models.DialysisPrescription
  1879. var dialysisSolution *models.DialysisSolution
  1880. var dialysisPrescribe *models.DialysisPrescription
  1881. var system_dialysisPrescribe *models.SystemPrescription
  1882. var mode_id int64
  1883. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1884. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1885. if schedual != nil {
  1886. // 获取透析模版
  1887. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1888. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1889. mode_id = schedual.ModeId
  1890. } else {
  1891. // 获取透析模版
  1892. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1893. if dialysisPrescribe == nil && dialysisSolution != nil {
  1894. mode_id = dialysisSolution.ModeId
  1895. }
  1896. if dialysisPrescribe == nil && dialysisSolution == nil {
  1897. mode_id = 0
  1898. }
  1899. }
  1900. // 插入透析处方
  1901. if dialysisPrescribe == nil && dialysisSolution != nil {
  1902. var newprescribe models.DialysisPrescription
  1903. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1904. newprescribe.PatientId = dialysisSolution.PatientId
  1905. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1906. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1907. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1908. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1909. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1910. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1911. newprescribe.ModeId = dialysisSolution.ModeId
  1912. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1913. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1914. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1915. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1916. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1917. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1918. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1919. newprescribe.Glucose = dialysisSolution.Glucose
  1920. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1921. newprescribe.Kalium = dialysisSolution.Kalium
  1922. newprescribe.Sodium = dialysisSolution.Sodium
  1923. newprescribe.Calcium = dialysisSolution.Calcium
  1924. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1925. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1926. newprescribe.Conductivity = dialysisSolution.Conductivity
  1927. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1928. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1929. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1930. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1931. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1932. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1933. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1934. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1935. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1936. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1937. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1938. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1939. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1940. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1941. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1942. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1943. newprescribe.CreatedTime = time.Now().Unix()
  1944. newprescribe.UpdatedTime = time.Now().Unix()
  1945. newprescribe.RecordDate = theAssessmentDateTime
  1946. newprescribe.DewaterAmount = dewater_amount
  1947. newprescribe.TargetUltrafiltration = dewater_amount
  1948. newprescribe.Status = 1
  1949. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1950. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1951. newprescribe.Remark = lastDialysisPrescription.Remark
  1952. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1953. newprescribe.ID = dialysisPrescription.ID
  1954. if dialysisPrescription.ID == 0 {
  1955. if adminUserInfo.Org.Id == 10340 {
  1956. newprescribe.Sodium = 138
  1957. newprescribe.Bicarbonate = 31.1
  1958. newprescribe.DialysateFlow = 500
  1959. newprescribe.PrescribingNumber = 1
  1960. }
  1961. err := service.AddSigleRecord(&newprescribe)
  1962. //获取key,清空redis
  1963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1964. redis := service.RedisClient()
  1965. //清空key 值
  1966. redis.Set(key, "", time.Second)
  1967. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1968. //清空key 值
  1969. redis.Set(keyOne, "", time.Second)
  1970. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1971. //清空key 值
  1972. redis.Set(keyTwo, "", time.Second)
  1973. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1974. redis.Set(keySix, "", time.Second)
  1975. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1976. redis.Set(keySeven, "", time.Second)
  1977. if err != nil {
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1979. }
  1980. } else {
  1981. if adminUserInfo.Org.Id == 10340 {
  1982. newprescribe.Sodium = 138
  1983. newprescribe.Bicarbonate = 31.1
  1984. newprescribe.DialysateFlow = 500
  1985. }
  1986. err := service.UpDateDialysisPrescription(&newprescribe)
  1987. //获取key,清空redis
  1988. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1989. redis := service.RedisClient()
  1990. //清空key 值
  1991. redis.Set(key, "", time.Second)
  1992. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1993. //清空key 值
  1994. redis.Set(keyOne, "", time.Second)
  1995. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1996. //清空key 值
  1997. redis.Set(keyTwo, "", time.Second)
  1998. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1999. redis.Set(keySix, "", time.Second)
  2000. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2001. redis.Set(keySeven, "", time.Second)
  2002. if err != nil {
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2004. }
  2005. }
  2006. }
  2007. if dialysisPrescribe == nil && dialysisSolution == nil {
  2008. if lastDialysisPrescribe != nil {
  2009. var newprescribe models.DialysisPrescription
  2010. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2011. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2012. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2013. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2014. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2015. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2016. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2017. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2018. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2019. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2020. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2021. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2022. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2023. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2024. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2025. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2026. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2027. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2028. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2029. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2030. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2031. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2032. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2033. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2034. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2035. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2036. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2037. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2038. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2039. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2040. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2041. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2042. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2043. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2044. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2045. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2046. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2047. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2048. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2049. newprescribe.CreatedTime = time.Now().Unix()
  2050. newprescribe.UpdatedTime = time.Now().Unix()
  2051. newprescribe.RecordDate = theAssessmentDateTime
  2052. newprescribe.DewaterAmount = dewater_amount
  2053. newprescribe.TargetUltrafiltration = dewater_amount
  2054. newprescribe.Status = 1
  2055. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2056. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2057. newprescribe.Remark = lastDialysisPrescription.Remark
  2058. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2059. newprescribe.ID = dialysisPrescription.ID
  2060. if dialysisPrescription.ID == 0 {
  2061. if adminUserInfo.Org.Id == 10340 {
  2062. newprescribe.Sodium = 138
  2063. newprescribe.Bicarbonate = 31.1
  2064. newprescribe.DialysateFlow = 500
  2065. }
  2066. err := service.AddSigleRecord(&newprescribe)
  2067. //获取key,清空redis
  2068. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2069. redis := service.RedisClient()
  2070. //清空key 值
  2071. redis.Set(key, "", time.Second)
  2072. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2073. //清空key 值
  2074. redis.Set(keyOne, "", time.Second)
  2075. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2076. //清空key 值
  2077. redis.Set(keyTwo, "", time.Second)
  2078. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2079. redis.Set(keySix, "", time.Second)
  2080. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2081. redis.Set(keySeven, "", time.Second)
  2082. if err != nil {
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2084. }
  2085. } else {
  2086. err := service.UpDateDialysisPrescription(&newprescribe)
  2087. //获取key,清空redis
  2088. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2089. redis := service.RedisClient()
  2090. //清空key 值
  2091. redis.Set(key, "", time.Second)
  2092. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2093. //清空key 值
  2094. redis.Set(keyOne, "", time.Second)
  2095. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2096. //清空key 值
  2097. redis.Set(keyTwo, "", time.Second)
  2098. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2099. redis.Set(keySix, "", time.Second)
  2100. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2101. redis.Set(keySeven, "", time.Second)
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2104. }
  2105. }
  2106. if err != nil {
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2108. }
  2109. } else if system_dialysisPrescribe != nil {
  2110. var newprescribe models.DialysisPrescription
  2111. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  2112. newprescribe.PatientId = id
  2113. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2114. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2115. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2116. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2117. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2118. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2119. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2120. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2121. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2122. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2123. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2124. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2125. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2126. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2127. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2128. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2129. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2130. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2131. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2132. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2133. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2134. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2135. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2136. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2137. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2138. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2139. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2140. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2141. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2142. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2143. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2144. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2145. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2146. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2147. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2148. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2149. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2150. newprescribe.CreatedTime = time.Now().Unix()
  2151. newprescribe.UpdatedTime = time.Now().Unix()
  2152. newprescribe.RecordDate = theAssessmentDateTime
  2153. newprescribe.DewaterAmount = dewater_amount
  2154. newprescribe.TargetUltrafiltration = dewater_amount
  2155. newprescribe.Status = 1
  2156. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2157. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2158. newprescribe.Remark = lastDialysisPrescription.Remark
  2159. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2160. newprescribe.ID = dialysisPrescription.ID
  2161. if dialysisPrescription.ID == 0 {
  2162. if adminUserInfo.Org.Id == 10340 {
  2163. newprescribe.Sodium = 138
  2164. newprescribe.Bicarbonate = 31.1
  2165. newprescribe.DialysateFlow = 500
  2166. }
  2167. err := service.AddSigleRecord(&newprescribe)
  2168. //获取key,清空redis
  2169. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2170. redis := service.RedisClient()
  2171. //清空key 值
  2172. redis.Set(key, "", time.Second)
  2173. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2174. //清空key 值
  2175. redis.Set(keyOne, "", time.Second)
  2176. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2177. //清空key 值
  2178. redis.Set(keyTwo, "", time.Second)
  2179. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2180. redis.Set(keySix, "", time.Second)
  2181. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2182. redis.Set(keySeven, "", time.Second)
  2183. if err != nil {
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2185. }
  2186. } else {
  2187. if adminUserInfo.Org.Id == 10340 {
  2188. newprescribe.Sodium = 138
  2189. newprescribe.Bicarbonate = 31.1
  2190. newprescribe.DialysateFlow = 500
  2191. }
  2192. err := service.UpDateDialysisPrescription(&newprescribe)
  2193. //获取key,清空redis
  2194. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2195. redis := service.RedisClient()
  2196. //清空key 值
  2197. redis.Set(key, "", time.Second)
  2198. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2199. //清空key 值
  2200. redis.Set(keyOne, "", time.Second)
  2201. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2202. //清空key 值
  2203. redis.Set(keyTwo, "", time.Second)
  2204. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2205. redis.Set(keySix, "", time.Second)
  2206. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2207. redis.Set(keySeven, "", time.Second)
  2208. if err != nil {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2210. }
  2211. }
  2212. if err != nil {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2214. }
  2215. } else {
  2216. var newprescribe models.DialysisPrescription
  2217. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2218. newprescribe.PatientId = id
  2219. newprescribe.ModeId = mode_id
  2220. newprescribe.CreatedTime = time.Now().Unix()
  2221. newprescribe.UpdatedTime = time.Now().Unix()
  2222. newprescribe.RecordDate = theAssessmentDateTime
  2223. newprescribe.DewaterAmount = dewater_amount
  2224. newprescribe.TargetUltrafiltration = dewater_amount
  2225. newprescribe.Status = 1
  2226. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2227. newprescribe.ID = dialysisPrescription.ID
  2228. if dialysisPrescription.ID == 0 {
  2229. if adminUserInfo.Org.Id == 10340 {
  2230. newprescribe.Sodium = 138
  2231. newprescribe.Bicarbonate = 31.1
  2232. newprescribe.DialysateFlow = 500
  2233. }
  2234. err := service.AddSigleRecord(&newprescribe)
  2235. //获取key,清空redis
  2236. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2237. redis := service.RedisClient()
  2238. //清空key 值
  2239. redis.Set(key, "", time.Second)
  2240. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2241. //清空key 值
  2242. redis.Set(keyOne, "", time.Second)
  2243. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2244. //清空key 值
  2245. redis.Set(keyTwo, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. if err != nil {
  2251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2252. }
  2253. } else {
  2254. if adminUserInfo.Org.Id == 10340 {
  2255. newprescribe.Sodium = 138
  2256. newprescribe.Bicarbonate = 31.1
  2257. newprescribe.DialysateFlow = 500
  2258. }
  2259. err := service.UpDateDialysisPrescription(&newprescribe)
  2260. //获取key,清空redis
  2261. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2262. redis := service.RedisClient()
  2263. //清空key 值
  2264. redis.Set(key, "", time.Second)
  2265. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2266. //清空key 值
  2267. redis.Set(keyOne, "", time.Second)
  2268. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2269. //清空key 值
  2270. redis.Set(keyTwo, "", time.Second)
  2271. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2272. redis.Set(keySix, "", time.Second)
  2273. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2274. redis.Set(keySeven, "", time.Second)
  2275. if err != nil {
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2277. }
  2278. }
  2279. if err != nil {
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2281. }
  2282. }
  2283. }
  2284. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2285. // if dialysisPrescribe != nil {
  2286. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2287. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2288. // dialysisPrescribe.DewaterAmount = dewater_amount
  2289. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2290. // dialysisPrescribe.Status = 1
  2291. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2292. // if updateErr != nil {
  2293. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2294. // }
  2295. // }
  2296. // 查询信息规挡的设置天数
  2297. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2298. if infor.ID > 0 && infor.WeekDay > 0 {
  2299. var cha_time int64
  2300. timeNowStr := time.Now().Format("2006-01-02")
  2301. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2302. //今日的日期减去设置的日期
  2303. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2304. if cha_time >= evaluation.AssessmentDate {
  2305. //查询审核是否允许
  2306. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id)
  2307. //申请状态不允许的情况 拒绝修改
  2308. if infor.ApplicationStatus != 1 {
  2309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2310. return
  2311. }
  2312. }
  2313. }
  2314. err = service.UpadatePredialysisEvaluation(&evaluation)
  2315. finish := models.XtDialysisFinish{
  2316. IsFinish: 1,
  2317. UserOrgId: adminUserInfo.Org.Id,
  2318. Status: 1,
  2319. Ctime: time.Now().Unix(),
  2320. Mtime: 0,
  2321. Module: 3,
  2322. RecordDate: evaluation.AssessmentDate,
  2323. Sourse: 1,
  2324. PatientId: id,
  2325. }
  2326. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2327. if dialysisFinish.ID == 0 {
  2328. service.CreateDialysisFinish(finish)
  2329. }
  2330. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2331. redis := service.RedisClient()
  2332. defer redis.Close()
  2333. //清空key 值
  2334. redis.Set(key, "", time.Second)
  2335. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2336. redis.Set(keyOne, "", time.Second)
  2337. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2338. redis.Set(keyTwo, "", time.Second)
  2339. if err != nil {
  2340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2341. return
  2342. }
  2343. c.ServeSuccessJSON(map[string]interface{}{
  2344. "msg": "ok",
  2345. "evaluation": evaluation,
  2346. })
  2347. return
  2348. }
  2349. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2350. dataBody := make(map[string]interface{}, 0)
  2351. err := json.Unmarshal(data, &dataBody)
  2352. utils.InfoLog(string(data))
  2353. if err != nil {
  2354. utils.ErrorLog(err.Error())
  2355. code = enums.ErrorCodeParamWrong
  2356. return
  2357. }
  2358. // if method == "create" {
  2359. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2360. utils.ErrorLog("mode")
  2361. code = enums.ErrorCodeParamWrong
  2362. return
  2363. }
  2364. mode := int64(dataBody["mode"].(float64))
  2365. if mode <= 0 {
  2366. utils.ErrorLog("mode <= 0")
  2367. code = enums.ErrorCodeParamWrong
  2368. return
  2369. }
  2370. solution.ModeId = mode
  2371. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2372. utils.ErrorLog("mode_name")
  2373. code = enums.ErrorCodeParamWrong
  2374. return
  2375. }
  2376. modeName, _ := dataBody["mode_name"].(string)
  2377. if len(modeName) == 0 {
  2378. utils.ErrorLog("len(mode_name) == 0")
  2379. code = enums.ErrorCodeParamWrong
  2380. return
  2381. }
  2382. solution.ModeName = modeName
  2383. solution.Name = modeName
  2384. // }
  2385. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2386. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2387. solution.DialysisDuration = dialysisDuration
  2388. }
  2389. if dataBody["dialysis_duration"] != nil {
  2390. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2391. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2392. solution.DialysisDuration = dialysisDuration
  2393. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2394. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2395. solution.DialysisDuration = dialysisDuration
  2396. }
  2397. }
  2398. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2399. dialyzer := int64(dataBody["dialyzer"].(float64))
  2400. solution.Dialyzer = dialyzer
  2401. }
  2402. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2403. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2404. solution.PerfusionApparatus = perfusionApparatus
  2405. }
  2406. if dataBody["blood_flow_volume"] != nil {
  2407. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2408. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2409. solution.BloodFlowVolume = bloodFlowVolume
  2410. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2411. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2412. solution.BloodFlowVolume = bloodFlowVolume
  2413. }
  2414. }
  2415. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2416. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2417. solution.HemodialysisMachine = hemodialysisMachine
  2418. }
  2419. if dataBody["dewater"] != nil {
  2420. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2421. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2422. solution.Dewater = dewater
  2423. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  2424. dewater := dataBody["dewater"].(float64)
  2425. solution.Dewater = dewater
  2426. }
  2427. }
  2428. if dataBody["replacement_total"] != nil {
  2429. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2430. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2431. solution.ReplacementTotal = replacementTotal
  2432. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2433. replacementTotal := dataBody["replacement_total"].(float64)
  2434. solution.ReplacementTotal = replacementTotal
  2435. }
  2436. }
  2437. if dataBody["displace_liqui"] != nil {
  2438. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2439. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2440. solution.DisplaceLiqui = displaceLiqui
  2441. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2442. displaceLiqui := dataBody["displace_liqui"].(float64)
  2443. solution.DisplaceLiqui = displaceLiqui
  2444. }
  2445. }
  2446. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2447. replacementWay := int64(dataBody["replacement_way"].(float64))
  2448. solution.ReplacementWay = replacementWay
  2449. }
  2450. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2451. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2452. solution.Anticoagulant = anticoagulant
  2453. }
  2454. if dataBody["anticoagulant_shouji"] != nil {
  2455. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2456. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2457. solution.AnticoagulantShouji = anticoagulantShouji
  2458. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  2459. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  2460. solution.AnticoagulantShouji = anticoagulantShouji
  2461. }
  2462. }
  2463. if dataBody["anticoagulant_weichi"] != nil {
  2464. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2465. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2466. solution.AnticoagulantWeichi = anticoagulantWeichi
  2467. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  2468. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  2469. solution.AnticoagulantWeichi = anticoagulantWeichi
  2470. }
  2471. }
  2472. if dataBody["anticoagulant_zongliang"] != nil {
  2473. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2474. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2475. solution.AnticoagulantZongliang = anticoagulantZongliang
  2476. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  2477. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  2478. solution.AnticoagulantZongliang = anticoagulantZongliang
  2479. }
  2480. }
  2481. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2482. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2483. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2484. }
  2485. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2486. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2487. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2488. }
  2489. if dataBody["kalium"] != nil {
  2490. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2491. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2492. solution.Kalium = kalium
  2493. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  2494. kalium := dataBody["kalium"].(float64)
  2495. solution.Kalium = kalium
  2496. }
  2497. }
  2498. if dataBody["sodium"] != nil {
  2499. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2500. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2501. solution.Sodium = sodium
  2502. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  2503. sodium := dataBody["sodium"].(float64)
  2504. solution.Sodium = sodium
  2505. }
  2506. }
  2507. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2508. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2509. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2510. solution.Calcium = calcium
  2511. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  2512. calcium := dataBody["calcium"].(float64)
  2513. solution.Calcium = calcium
  2514. }
  2515. }
  2516. if dataBody["bicarbonate"] != nil {
  2517. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2518. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2519. solution.Bicarbonate = bicarbonate
  2520. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  2521. bicarbonate := dataBody["bicarbonate"].(float64)
  2522. solution.Bicarbonate = bicarbonate
  2523. }
  2524. }
  2525. if dataBody["glucose"] != nil {
  2526. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2527. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2528. solution.Glucose = glucose
  2529. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  2530. glucose := dataBody["glucose"].(float64)
  2531. solution.Glucose = glucose
  2532. }
  2533. }
  2534. // if dataBody["dry_weight"] != nil {
  2535. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2536. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2537. // solution.DryWeight = dryWeight
  2538. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  2539. // dryWeight := dataBody["dry_weight"].(float64)
  2540. // solution.DryWeight = dryWeight
  2541. // }
  2542. // }
  2543. if dataBody["dialysate_flow"] != nil {
  2544. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2545. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2546. solution.DialysateFlow = dialysateFlow
  2547. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  2548. dialysateFlow := dataBody["dialysate_flow"].(float64)
  2549. solution.DialysateFlow = dialysateFlow
  2550. }
  2551. }
  2552. if dataBody["dialysate_temperature"] != nil {
  2553. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2554. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2555. solution.DialysateTemperature = dialysateTemperature
  2556. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  2557. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  2558. solution.DialysateTemperature = dialysateTemperature
  2559. }
  2560. }
  2561. if dataBody["conductivity"] != nil {
  2562. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2563. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2564. solution.Conductivity = conductivity
  2565. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  2566. conductivity := dataBody["conductivity"].(float64)
  2567. solution.Conductivity = conductivity
  2568. }
  2569. }
  2570. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2571. remark := dataBody["remark"].(string)
  2572. solution.Remark = remark
  2573. }
  2574. if dataBody["dialysis_duration_hour"] != nil {
  2575. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2576. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  2577. solution.DialysisDurationHour = dialysisDurationHour
  2578. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  2579. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  2580. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2581. }
  2582. }
  2583. if dataBody["dialysis_duration_minute"] != nil {
  2584. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2585. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  2586. solution.DialysisDurationMinute = dialysisDurationMinute
  2587. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  2588. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  2589. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2590. }
  2591. }
  2592. if dataBody["target_ultrafiltration"] != nil {
  2593. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2594. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2595. solution.TargetUltrafiltration = targetUltrafiltration
  2596. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  2597. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  2598. solution.TargetUltrafiltration = targetUltrafiltration
  2599. }
  2600. }
  2601. if dataBody["dialysate_formulation"] != nil {
  2602. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  2603. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  2604. solution.DialysateFormulation = dialysateFormulation
  2605. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2606. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  2607. solution.DialysateFormulation = int64(dialysateFormulation)
  2608. }
  2609. }
  2610. return
  2611. }
  2612. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2613. dataBody := make(map[string]interface{}, 0)
  2614. err := json.Unmarshal(data, &dataBody)
  2615. utils.InfoLog(string(data))
  2616. if err != nil {
  2617. utils.ErrorLog(err.Error())
  2618. code = enums.ErrorCodeParamWrong
  2619. return
  2620. }
  2621. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2622. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2623. evaluation.WeightBefore = weightVefore
  2624. }
  2625. // fmt.Println(dataBody["dry_weight"])
  2626. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2627. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2628. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2629. fmt.Println(additionalWeight)
  2630. evaluation.DryWeight = additionalWeight
  2631. }
  2632. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2633. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2634. fmt.Println(additionalWeight)
  2635. evaluation.AdditionalWeight = additionalWeight
  2636. }
  2637. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2638. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2639. evaluation.Temperature = Temperature
  2640. }
  2641. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2642. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2643. evaluation.SystolicBloodPressure = systolicBloodPressure
  2644. }
  2645. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2646. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2647. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2648. }
  2649. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2650. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2651. evaluation.PulseFrequency = pulseFrequency
  2652. }
  2653. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2654. breathingRate := dataBody["breathing_rate"].(string)
  2655. evaluation.BreathingRate = breathingRate
  2656. }
  2657. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2658. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2659. evaluation.LastPostDialysis = lastPostDialysis
  2660. }
  2661. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2662. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2663. evaluation.DialysisInterphase = dialysisInterphase
  2664. }
  2665. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2666. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2667. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2668. }
  2669. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2670. catheter, _ := dataBody["catheter"].(string)
  2671. evaluation.Catheter = catheter
  2672. }
  2673. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2674. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2675. evaluation.CatheterBend = catheter_bend
  2676. }
  2677. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2678. Complication, _ := dataBody["complication"].(string)
  2679. evaluation.Complication = Complication
  2680. }
  2681. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2682. remark := dataBody["remark"].(string)
  2683. evaluation.Remark = remark
  2684. }
  2685. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2686. machine_type := dataBody["machine_type"].(string)
  2687. evaluation.MachineType = machine_type
  2688. }
  2689. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2690. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2691. evaluation.BloodAccessPartId = blood_access_part_id
  2692. }
  2693. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2694. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2695. // evaluation.BloodAccessPartId = blood_access_part_id
  2696. //}
  2697. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2698. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2699. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2700. }
  2701. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2702. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2703. evaluation.InternalFistula = internal_fistula
  2704. }
  2705. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2706. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2707. evaluation.InternalFistulaSkin = internal_fistula_skin
  2708. }
  2709. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2710. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2711. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2712. evaluation.IsHemorrhage = is_hemorrhage
  2713. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2714. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2715. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2716. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2717. is_hemorrhage = 0
  2718. }
  2719. evaluation.IsHemorrhage = is_hemorrhage
  2720. if is_hemorrhage == 1 {
  2721. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2722. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2723. evaluation.Hemorrhage = hemorrhage
  2724. }
  2725. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2726. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2727. evaluation.HemorrhageOther = hemorrhage_other
  2728. }
  2729. }
  2730. } else {
  2731. evaluation.IsHemorrhage = 0
  2732. }
  2733. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2734. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2735. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2736. }
  2737. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2738. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2739. evaluation.InternalFistulaOther = internal_fistula_other
  2740. }
  2741. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2742. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2743. evaluation.BloodAccessNoise = blood_access_noise
  2744. }
  2745. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2746. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2747. puncture_way := dataBody["puncture_way"].(string)
  2748. evaluation.PunctureWay = puncture_way
  2749. }
  2750. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2751. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2752. evaluation.VenousCatheterization = venous_catheterization
  2753. }
  2754. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2755. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2756. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2757. }
  2758. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2759. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2760. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2761. }
  2762. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2763. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2764. evaluation.DuctusArantii = ductus_arantii
  2765. }
  2766. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2767. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2768. evaluation.EmergencyTreatment = emergency_treatment
  2769. }
  2770. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2771. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2772. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2773. }
  2774. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2775. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2776. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2777. evaluation.DialysisCount = dialysis_count
  2778. }
  2779. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2780. is_infect, _ := dataBody["is_infect"].(string)
  2781. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2782. evaluation.IsInfect = infect
  2783. }
  2784. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2785. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2786. evaluation.Exposed = exposed
  2787. }
  2788. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2789. skin, _ := dataBody["skin"].(string)
  2790. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2791. evaluation.Skin = skin
  2792. }
  2793. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2794. skin_other, _ := dataBody["skin_other"].(string)
  2795. evaluation.SkinOther = skin_other
  2796. }
  2797. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2798. infect_other, _ := dataBody["infect_other"].(string)
  2799. evaluation.InfectOther = infect_other
  2800. }
  2801. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2802. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2803. evaluation.DuctusArantiiOther = ductus_arantii_other
  2804. }
  2805. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2806. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2807. evaluation.PunctureNeedle = punctureNeedle
  2808. }
  2809. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2810. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2811. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2812. }
  2813. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2814. pinholing := dataBody["pinholing"].(string)
  2815. evaluation.Phinholing = pinholing
  2816. }
  2817. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2818. catheter_suture := dataBody["catheter_suture"].(string)
  2819. evaluation.CatheterSuture = catheter_suture
  2820. }
  2821. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2822. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2823. evaluation.CatheterSutureOther = catheter_suture_other
  2824. }
  2825. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2826. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2827. evaluation.UrineVolume = urine_volume
  2828. }
  2829. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2830. edema := dataBody["edema"].(string)
  2831. evaluation.Edema = edema
  2832. }
  2833. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2834. specialTreatment := dataBody["special_treatment"].(string)
  2835. evaluation.SpecialTreatment = specialTreatment
  2836. }
  2837. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2838. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2839. evaluation.CatheterMaintenance = catheter_maintenance
  2840. }
  2841. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2842. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2843. evaluation.ThromubusType = thromubusType
  2844. }
  2845. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2846. thrombus_av := dataBody["thrombus_av"].(string)
  2847. evaluation.ThrombusAv = thrombus_av
  2848. }
  2849. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2850. thromubus_a := dataBody["thromubus_a"].(string)
  2851. evaluation.ThromubusA = thromubus_a
  2852. }
  2853. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2854. thromubus_v := dataBody["thromubus_v"].(string)
  2855. evaluation.ThromubusV = thromubus_v
  2856. }
  2857. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2858. dehydration := dataBody["dehydration"].(string)
  2859. evaluation.Dehydration = dehydration
  2860. }
  2861. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2862. period := int64(dataBody["period"].(float64))
  2863. evaluation.Period = period
  2864. }
  2865. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2866. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2867. evaluation.EstimatedFoodIntake = estimated_food_intake
  2868. }
  2869. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2870. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2871. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2872. }
  2873. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2874. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2875. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2876. }
  2877. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2878. urea_befor := dataBody["urea_befor"].(string)
  2879. evaluation.UreaBefor = urea_befor
  2880. }
  2881. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  2882. suction := dataBody["suction"].(string)
  2883. evaluation.Suction = suction
  2884. }
  2885. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  2886. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  2887. evaluation.WeightBeforRemake = weight_befor_remake
  2888. }
  2889. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  2890. height := dataBody["height"].(string)
  2891. evaluation.Height = height
  2892. }
  2893. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  2894. age := dataBody["age"].(string)
  2895. evaluation.Age = age
  2896. }
  2897. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  2898. his_department := dataBody["his_department"].(string)
  2899. evaluation.HisDepartment = his_department
  2900. }
  2901. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  2902. his_bed := dataBody["his_bed"].(string)
  2903. evaluation.HisBed = his_bed
  2904. }
  2905. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  2906. point_puncture := dataBody["point_puncture"].(string)
  2907. evaluation.PointPuncture = point_puncture
  2908. }
  2909. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  2910. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  2911. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  2912. }
  2913. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  2914. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  2915. evaluation.SkinSiteCatheterization = skin_site_catheterization
  2916. }
  2917. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  2918. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  2919. evaluation.WhetherUnobstructed = whether_unobstructed
  2920. }
  2921. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  2922. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  2923. evaluation.LienNecessary = lien_necessary
  2924. }
  2925. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  2926. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  2927. timeLayout := "2006-01-02"
  2928. loc, _ := time.LoadLocation("Local")
  2929. var startTime int64
  2930. if len(pathway_formation_time) > 0 {
  2931. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2932. startTime = theTime.Unix()
  2933. }
  2934. evaluation.PathwayFormationTime = startTime
  2935. }
  2936. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  2937. befor_symptoms := dataBody["befor_symptoms"].(string)
  2938. evaluation.BeforSymptoms = befor_symptoms
  2939. fmt.Println("befor_symptomsss23333333333333333333333333", befor_symptoms)
  2940. }
  2941. return
  2942. }
  2943. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2944. dataBody := make(map[string]interface{}, 0)
  2945. err := json.Unmarshal(data, &dataBody)
  2946. if err != nil {
  2947. utils.ErrorLog(err.Error())
  2948. code = enums.ErrorCodeParamWrong
  2949. return
  2950. }
  2951. timeLayout := "2006-01-02"
  2952. loc, _ := time.LoadLocation("Local")
  2953. isChild := false
  2954. if action == "create" {
  2955. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2956. utils.ErrorLog("advice_type")
  2957. code = enums.ErrorCodeParamWrong
  2958. return
  2959. }
  2960. adviceType := int64(dataBody["advice_type"].(float64))
  2961. if adviceType != 1 && adviceType != 2 {
  2962. utils.ErrorLog("advice_type != 1&&2")
  2963. code = enums.ErrorCodeParamWrong
  2964. return
  2965. }
  2966. advice.AdviceType = adviceType
  2967. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2968. utils.ErrorLog("advice_date")
  2969. code = enums.ErrorCodeParamWrong
  2970. return
  2971. }
  2972. adviceDate, _ := dataBody["advice_date"].(string)
  2973. if len(adviceDate) == 0 {
  2974. utils.ErrorLog("len(adviceDate) == 0")
  2975. code = enums.ErrorCodeParamWrong
  2976. return
  2977. }
  2978. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2979. if err != nil {
  2980. utils.ErrorLog(err.Error())
  2981. code = enums.ErrorCodeParamWrong
  2982. return
  2983. }
  2984. advice.AdviceDate = theTime.Unix()
  2985. advice.RecordDate = theTime.Unix()
  2986. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2987. parentId := int64(dataBody["parent_id"].(float64))
  2988. advice.ParentId = parentId
  2989. if parentId > 0 {
  2990. isChild = true
  2991. }
  2992. }
  2993. } else {
  2994. isChild = advice.ParentId > 0
  2995. }
  2996. if !isChild {
  2997. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2998. utils.ErrorLog("start_time")
  2999. code = enums.ErrorCodeParamWrong
  3000. return
  3001. }
  3002. startTime, _ := dataBody["start_time"].(string)
  3003. if len(startTime) == 0 {
  3004. utils.ErrorLog("len(start_time) == 0")
  3005. code = enums.ErrorCodeParamWrong
  3006. return
  3007. }
  3008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3009. if err != nil {
  3010. utils.ErrorLog(err.Error())
  3011. code = enums.ErrorCodeParamWrong
  3012. return
  3013. }
  3014. advice.StartTime = theTime.Unix()
  3015. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3016. deliveryWay, _ := dataBody["delivery_way"].(string)
  3017. advice.DeliveryWay = deliveryWay
  3018. }
  3019. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3020. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3021. advice.ExecutionFrequency = executionFrequency
  3022. }
  3023. }
  3024. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3025. deliveryWay, _ := dataBody["delivery_way"].(string)
  3026. advice.DeliveryWay = deliveryWay
  3027. }
  3028. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3029. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3030. advice.ExecutionFrequency = executionFrequency
  3031. }
  3032. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3033. utils.ErrorLog("advice_name")
  3034. code = enums.ErrorCodeParamWrong
  3035. return
  3036. }
  3037. adviceName, _ := dataBody["advice_name"].(string)
  3038. if len(adviceName) == 0 {
  3039. utils.ErrorLog("len(advice_name) == 0")
  3040. code = enums.ErrorCodeParamWrong
  3041. return
  3042. }
  3043. advice.AdviceName = adviceName
  3044. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3045. adviceDsc, _ := dataBody["advice_desc"].(string)
  3046. advice.AdviceDesc = adviceDsc
  3047. }
  3048. if dataBody["way"] == nil {
  3049. advice.Way = 0
  3050. } else {
  3051. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3052. way := int64(dataBody["way"].(float64))
  3053. advice.Way = way
  3054. }
  3055. }
  3056. if dataBody["drug_id"] == nil {
  3057. advice.DrugId = 0
  3058. } else {
  3059. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3060. drug_id := int64(dataBody["drug_id"].(float64))
  3061. advice.DrugId = drug_id
  3062. }
  3063. }
  3064. if dataBody["drug_name_id"] == nil {
  3065. advice.DrugNameId = 0
  3066. } else {
  3067. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3068. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3069. advice.DrugNameId = drug_name_id
  3070. }
  3071. }
  3072. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3073. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3074. advice.SingleDose = singleDose
  3075. }
  3076. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3077. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3078. advice.SingleDoseUnit = singleDoseUnit
  3079. }
  3080. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3081. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3082. advice.DrugSpec = drugSpec
  3083. }
  3084. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3085. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3086. advice.DrugSpecUnit = drugSpecUnit
  3087. }
  3088. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3089. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3090. advice.PrescribingNumber = prescribingNumber
  3091. }
  3092. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3093. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3094. advice.PrescribingNumberUnit = prescribingNumberUnit
  3095. }
  3096. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3097. remark, _ := dataBody["remark"].(string)
  3098. advice.Remark = remark
  3099. }
  3100. return
  3101. }
  3102. func (c *PatientApiController) GetPatientEducation() {
  3103. patientID, _ := c.GetInt64("patient_id", 0)
  3104. page, _ := c.GetInt64("page", 0)
  3105. limit, _ := c.GetInt64("limit", 0)
  3106. startTime := c.GetString("start_time", "")
  3107. endTime := c.GetString("end_time", "")
  3108. if page <= 0 {
  3109. page = 1
  3110. }
  3111. if limit <= 0 {
  3112. limit = 10
  3113. }
  3114. if patientID <= 0 {
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3116. return
  3117. }
  3118. timeLayout := "2006-01-02"
  3119. loc, _ := time.LoadLocation("Local")
  3120. var theStartTIme int64
  3121. if len(startTime) > 0 {
  3122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3123. if err != nil {
  3124. theStartTIme = 0
  3125. }
  3126. theStartTIme = theTime.Unix()
  3127. }
  3128. var theEndtTIme int64
  3129. if len(endTime) > 0 {
  3130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3131. if err != nil {
  3132. theEndtTIme = 0
  3133. }
  3134. theEndtTIme = theTime.Unix()
  3135. }
  3136. adminUserInfo := c.GetMobileAdminUserInfo()
  3137. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3138. c.ServeSuccessJSON(map[string]interface{}{
  3139. "total": total,
  3140. "edus": edus,
  3141. })
  3142. return
  3143. }
  3144. func (c *PatientApiController) GetPatientSchedulesList() {
  3145. patientID, _ := c.GetInt64("patient_id", 0)
  3146. page, _ := c.GetInt64("page", 0)
  3147. limit, _ := c.GetInt64("limit", 0)
  3148. if patientID <= 0 {
  3149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3150. return
  3151. }
  3152. adminUserInfo := c.GetMobileAdminUserInfo()
  3153. todayTime := time.Now().Format("2006-01-02")
  3154. timeLayout := "2006-01-02 15:04:05"
  3155. loc, _ := time.LoadLocation("Local")
  3156. var theStartTime int64
  3157. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3158. theStartTime = theTime.Unix()
  3159. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3160. if len(schedules) > 0 {
  3161. for index, item := range schedules {
  3162. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3163. schedules[index].Week = int64(week)
  3164. }
  3165. }
  3166. c.ServeSuccessJSON(map[string]interface{}{
  3167. "schedules": schedules,
  3168. })
  3169. return
  3170. }
  3171. func (c *PatientApiController) GetRecords() {
  3172. patientID, _ := c.GetInt64("patient_id", 0)
  3173. page, _ := c.GetInt64("page", 0)
  3174. limit, _ := c.GetInt64("limit", 0)
  3175. startTime := c.GetString("start_time", "")
  3176. endTime := c.GetString("end_time", "")
  3177. mode_id, _ := c.GetInt64("mode_id", 0)
  3178. if page <= 0 {
  3179. page = 1
  3180. }
  3181. if limit <= 0 {
  3182. limit = 10
  3183. }
  3184. if patientID <= 0 {
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3186. return
  3187. }
  3188. timeLayout := "2006-01-02"
  3189. loc, _ := time.LoadLocation("Local")
  3190. var theStartTIme int64
  3191. if len(startTime) > 0 {
  3192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3193. if err != nil {
  3194. theStartTIme = 0
  3195. }
  3196. theStartTIme = theTime.Unix()
  3197. }
  3198. var theEndtTIme int64
  3199. if len(endTime) > 0 {
  3200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3201. if err != nil {
  3202. theEndtTIme = 0
  3203. }
  3204. theEndtTIme = theTime.Unix()
  3205. }
  3206. adminUserInfo := c.GetMobileAdminUserInfo()
  3207. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3208. c.ServeSuccessJSON(map[string]interface{}{
  3209. "total": total,
  3210. "records": records,
  3211. })
  3212. return
  3213. }
  3214. func (c *PatientApiController) GetPatientMonitor() {
  3215. partition, _ := c.GetInt64("partition")
  3216. monitorDate := c.GetString("date")
  3217. patient_id, _ := c.GetInt64("patient_id")
  3218. timeLayout := "2006-01-02"
  3219. loc, _ := time.LoadLocation("Local")
  3220. var theStartTime int64
  3221. if len(monitorDate) > 0 {
  3222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3223. if err != nil {
  3224. theStartTime = 0
  3225. }
  3226. theStartTime = theTime.Unix()
  3227. }
  3228. adminInfo := c.GetMobileAdminUserInfo()
  3229. orgID := adminInfo.Org.Id
  3230. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3231. fmt.Println("monitor-------------------", monitor)
  3232. if err != nil {
  3233. c.ErrorLog("获取排班信息失败:%v", err)
  3234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3235. } else {
  3236. if len(monitor) > 0 {
  3237. //获取所有床位
  3238. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3239. //获取所有分区
  3240. zoneList, _ := service.GetAllZoneByList(orgID)
  3241. //获取透析处方
  3242. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3243. //获取透前评估
  3244. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3245. //获取上机
  3246. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3247. //获取透后
  3248. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3249. //获取透后监测
  3250. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3251. //获取所有的患者
  3252. patients, _ := service.GetAllPatientListByListOne(orgID)
  3253. //获取所有透析模式
  3254. treatments, _ := service.GetAllTreatModeByList(orgID)
  3255. for key, item := range monitor {
  3256. // 获取床位信息
  3257. for _, it := range numberList {
  3258. if item.BedId == it.ID {
  3259. monitor[key].DeviceNumber = it
  3260. break
  3261. }
  3262. }
  3263. //获取分区信息
  3264. for _, it := range zoneList {
  3265. if item.PartitionId == it.ID {
  3266. monitor[key].DeviceZone = it
  3267. }
  3268. }
  3269. for _, prescription := range prescriptions {
  3270. if item.PatientId == prescription.PatientId {
  3271. monitor[key].Prescription = prescription
  3272. break
  3273. }
  3274. }
  3275. // 透前评估
  3276. for _, assessmentBefore := range assessmentBefores {
  3277. if item.PatientId == assessmentBefore.PatientId {
  3278. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3279. break
  3280. }
  3281. }
  3282. // 透析上下机
  3283. for _, dialysisOrder := range dialysisOrders {
  3284. if item.PatientId == dialysisOrder.PatientId {
  3285. monitor[key].DialysisOrder = dialysisOrder
  3286. break
  3287. }
  3288. }
  3289. // 治疗小节
  3290. for _, afterDislysis := range AssessmentAfterDislysis {
  3291. if item.PatientId == afterDislysis.PatientId {
  3292. monitor[key].AssessmentAfterDislysis = afterDislysis
  3293. break
  3294. }
  3295. }
  3296. for _, it := range monitorlist {
  3297. if item.PatientId == it.PatientId {
  3298. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3299. }
  3300. }
  3301. for _, patient := range patients {
  3302. if item.PatientId == patient.ID {
  3303. monitor[key].MonitorPatients = patient
  3304. break
  3305. }
  3306. }
  3307. for _, treatment := range treatments {
  3308. if item.ModeId == treatment.ID {
  3309. monitor[key].TreatmentMode = treatment
  3310. break
  3311. }
  3312. }
  3313. }
  3314. }
  3315. }
  3316. //获取患者的透析次数
  3317. count, err := service.GetDialysisCount(orgID, partition)
  3318. patients, err := service.GetAllpatientThirty(orgID)
  3319. if err == nil {
  3320. c.ServeSuccessJSON(map[string]interface{}{
  3321. "monitor": monitor,
  3322. "patientCount": count,
  3323. "patients": patients,
  3324. })
  3325. } else {
  3326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3327. }
  3328. }
  3329. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3330. // @param keyword:string 病人姓名或透析号
  3331. // @param page:int
  3332. func (this *PatientApiController) SearchMonitorPatient() {
  3333. keyword := this.GetString("keyword")
  3334. page, _ := this.GetInt("page")
  3335. if page <= 0 {
  3336. page = 1
  3337. }
  3338. if len(keyword) == 0 {
  3339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3340. return
  3341. }
  3342. adminUserInfo := this.GetMobileAdminUserInfo()
  3343. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3344. if getMonitorErr != nil {
  3345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3346. return
  3347. } else {
  3348. this.ServeSuccessJSON(map[string]interface{}{
  3349. "monitor": monitors,
  3350. })
  3351. }
  3352. }
  3353. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3354. id, _ := c.GetInt64("id", 0)
  3355. page, _ := c.GetInt64("page", 0)
  3356. limit, _ := c.GetInt64("limit", 0)
  3357. if id <= 0 {
  3358. c.ServeSuccessJSON(map[string]interface{}{
  3359. "solutions": nil,
  3360. })
  3361. return
  3362. }
  3363. if page <= 0 {
  3364. page = 1
  3365. }
  3366. if limit <= 0 {
  3367. limit = 10
  3368. }
  3369. adminInfo := c.GetMobileAdminUserInfo()
  3370. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3371. c.ServeSuccessJSON(map[string]interface{}{
  3372. "solutions": solutions,
  3373. "total": total,
  3374. })
  3375. return
  3376. }
  3377. // GetDoctorAdvices 医嘱列表
  3378. func (c *PatientApiController) GetDoctorAdvices() {
  3379. id, _ := c.GetInt64("id", 0)
  3380. adviceType, _ := c.GetInt64("advice_type", 0)
  3381. stopType, _ := c.GetInt64("stop_state", 0)
  3382. startTime := c.GetString("start_time", "")
  3383. endTime := c.GetString("end_time", "")
  3384. keywords := c.GetString("keywords", "")
  3385. need, _ := c.GetInt64("need_doctor", 0)
  3386. adminUserInfo := c.GetMobileAdminUserInfo()
  3387. timeLayout := "2006-01-02"
  3388. loc, _ := time.LoadLocation("Local")
  3389. var theStartTIme int64
  3390. if len(startTime) > 0 {
  3391. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3392. if err != nil {
  3393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3394. return
  3395. }
  3396. theStartTIme = theTime.Unix()
  3397. }
  3398. var theEndtTIme int64
  3399. if len(endTime) > 0 {
  3400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3401. if err != nil {
  3402. utils.ErrorLog(err.Error())
  3403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3404. return
  3405. }
  3406. theEndtTIme = theTime.Unix()
  3407. }
  3408. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  3409. if need == 1 {
  3410. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3411. c.ServeSuccessJSON(map[string]interface{}{
  3412. "advices": advices,
  3413. "total": total,
  3414. "users": users,
  3415. })
  3416. } else {
  3417. c.ServeSuccessJSON(map[string]interface{}{
  3418. "advices": advices,
  3419. "total": total,
  3420. "users": []string{},
  3421. })
  3422. }
  3423. return
  3424. }
  3425. func (c *PatientApiController) GetPrintDialysisOrder() {
  3426. xtno := c.GetString("xtno")
  3427. xtdate := c.GetString("xtdate")
  3428. timeLayout := "2006-01-02"
  3429. loc, _ := time.LoadLocation("Local")
  3430. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3431. if err != nil {
  3432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3433. return
  3434. }
  3435. xttime := theTime.Unix()
  3436. //获取当前日期月份的第一天
  3437. firstmonth := service.GetFirstDateOfMonth(theTime)
  3438. firstMonthDate := firstmonth.Unix()
  3439. operatorIDs := make([]int64, 0)
  3440. adminUserInfo := c.GetMobileAdminUserInfo()
  3441. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3442. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  3443. //透析单
  3444. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3445. if dialysisOrder != nil {
  3446. if dialysisOrder.FinishNurse > 0 {
  3447. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3448. }
  3449. if dialysisOrder.StartNurse > 0 {
  3450. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3451. }
  3452. }
  3453. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3454. //透前评估
  3455. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3456. //透后评估
  3457. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3458. if AssessmentAfterDislysis.Modifier > 0 {
  3459. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3460. }
  3461. //透析处方
  3462. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3463. if dialysisPrescription.PrescriptionDoctor > 0 {
  3464. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3465. }
  3466. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3467. patientInfo.TotalDialysis = dialysis_count
  3468. //临时医嘱
  3469. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3470. fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
  3471. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3472. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  3473. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  3474. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3475. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3476. for _, item := range projects {
  3477. cnt, _ := strconv.ParseFloat(item.Count, 64)
  3478. var advice models.HisDoctorAdviceInfo
  3479. advice.ID = item.ID
  3480. advice.Checker = item.Checker
  3481. advice.CheckTime = item.CheckTime
  3482. advice.CheckState = item.CheckState
  3483. advice.ExecutionState = item.ExecutionState
  3484. advice.ExecutionStaff = item.ExecutionStaff
  3485. //advice.PrescribingNumber = float64(item.Count)
  3486. advice.PrescribingNumber = cnt
  3487. advice.PrescribingNumberUnit = item.Unit
  3488. advice.AdviceDoctor = item.Doctor
  3489. if item.Type == 3 {
  3490. advice.AdviceName = item.GoodInfo.GoodName
  3491. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  3492. } else if item.Type == 2 {
  3493. advice.AdviceName = item.HisProject.ProjectName
  3494. }
  3495. advice.StartTime = item.StartTime
  3496. hisAdvice = append(hisAdvice, &advice)
  3497. }
  3498. }
  3499. if len(DoctorAdvice) > 0 {
  3500. for _, item := range DoctorAdvice {
  3501. if item.AdviceDoctor > 0 {
  3502. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3503. }
  3504. if item.ExecutionStaff > 0 {
  3505. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3506. }
  3507. if item.Checker > 0 {
  3508. operatorIDs = append(operatorIDs, item.Checker)
  3509. }
  3510. }
  3511. }
  3512. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3513. //透析监测
  3514. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3515. //透析小结
  3516. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3517. //接诊评估
  3518. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3519. //相关操作对应的操作人
  3520. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  3521. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  3522. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3523. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3524. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  3525. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3526. if config.IsOpen == 1 {
  3527. c.ServeSuccessJSON(map[string]interface{}{
  3528. "users": adminUser,
  3529. "patientInfo": patientInfo,
  3530. "PredialysisEvaluation": PredialysisEvaluation,
  3531. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3532. "dialysisPrescription": dialysisPrescription,
  3533. "advices": hisAdvice,
  3534. "monitors": Record,
  3535. "summary": TreatmentSummary,
  3536. "receiverTreatmentAccess": receiverTreatmentAccess,
  3537. "dialysisOrder": dialysisOrder,
  3538. "operators": operators,
  3539. "org_template_info": templateInfo,
  3540. "check": check,
  3541. "dialysiscount": dialysiscount,
  3542. "last_order": last_order,
  3543. "projects": projects,
  3544. "project_config": project_config,
  3545. "lastWeight": lastWeight,
  3546. })
  3547. }
  3548. if config.IsOpen == 0 || config.IsOpen == 2 {
  3549. c.ServeSuccessJSON(map[string]interface{}{
  3550. "users": adminUser,
  3551. "patientInfo": patientInfo,
  3552. "PredialysisEvaluation": PredialysisEvaluation,
  3553. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3554. "dialysisPrescription": dialysisPrescription,
  3555. "advices": DoctorAdvice,
  3556. "monitors": Record,
  3557. "summary": TreatmentSummary,
  3558. "receiverTreatmentAccess": receiverTreatmentAccess,
  3559. "dialysisOrder": dialysisOrder,
  3560. "operators": operators,
  3561. "org_template_info": templateInfo,
  3562. "check": check,
  3563. "dialysiscount": dialysiscount,
  3564. "last_order": last_order,
  3565. "projects": projects,
  3566. "project_config": project_config,
  3567. "lastWeight": lastWeight,
  3568. })
  3569. }
  3570. }
  3571. func (c *PatientApiController) CreateGroupAdvice() {
  3572. is_child, _ := c.GetInt64("is_child", 0)
  3573. if is_child == 1 {
  3574. patient, _ := c.GetInt64("id", 0)
  3575. if patient <= 0 {
  3576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3577. return
  3578. }
  3579. adminUserInfo := c.GetMobileAdminUserInfo()
  3580. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3581. if patientInfo.ID == 0 {
  3582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3583. return
  3584. }
  3585. group_no, _ := c.GetInt64("group_no")
  3586. if group_no <= 0 {
  3587. group_no = 0
  3588. }
  3589. dataBody := make(map[string]interface{}, 0)
  3590. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3591. if err != nil {
  3592. utils.ErrorLog(err.Error())
  3593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3594. return
  3595. }
  3596. timeLayout := "2006-01-02"
  3597. loc, _ := time.LoadLocation("Local")
  3598. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3599. utils.ErrorLog("advice_type")
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3601. return
  3602. }
  3603. adviceType := int64(dataBody["advice_type"].(float64))
  3604. if adviceType != 1 && adviceType != 2 {
  3605. utils.ErrorLog("advice_type != 1&&2")
  3606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3607. return
  3608. }
  3609. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3610. utils.ErrorLog("start_time")
  3611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3612. return
  3613. }
  3614. startTime2, _ := dataBody["start_time"].(string)
  3615. time_arr := strings.Split(startTime2, " ")
  3616. if len(time_arr) > 0 {
  3617. startTime2 = time_arr[0]
  3618. }
  3619. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3620. utils.ErrorLog("advice_date")
  3621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3622. return
  3623. }
  3624. advice_date, _ := dataBody["advice_date"].(string)
  3625. var advicedateunix int64
  3626. if len(advice_date) > 0 {
  3627. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  3628. if err != nil {
  3629. fmt.Println(err)
  3630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3631. return
  3632. }
  3633. advicedateunix = theTime.Unix()
  3634. }
  3635. adviceDate := startTime2
  3636. if len(adviceDate) == 0 {
  3637. utils.ErrorLog("len(adviceDate) == 0")
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3639. return
  3640. }
  3641. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3642. if err != nil {
  3643. utils.ErrorLog(err.Error())
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3645. return
  3646. }
  3647. AdviceDate := advicedateunix
  3648. RecordDate := advicedateunix
  3649. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3650. utils.ErrorLog("start_time")
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3652. return
  3653. }
  3654. startTime, _ := dataBody["start_time"].(string)
  3655. if len(startTime) == 0 {
  3656. utils.ErrorLog("len(start_time) == 0")
  3657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3658. return
  3659. }
  3660. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3661. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  3662. if err != nil {
  3663. utils.ErrorLog(err.Error())
  3664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3665. return
  3666. }
  3667. StartTime := theTime.Unix()
  3668. Remark := ""
  3669. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3670. remark, _ := dataBody["remark"].(string)
  3671. Remark = remark
  3672. }
  3673. Startdate := int64(dataBody["record_date"].(float64))
  3674. var advices []*models.GroupAdvice
  3675. // utils.TraceLog("%+v", dataBody["adviceNames"])
  3676. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  3677. utils.ErrorLog("adviceNames")
  3678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3679. return
  3680. }
  3681. adviceNames := dataBody["adviceNames"].([]interface{})
  3682. for _, adviceNameMap := range adviceNames {
  3683. adviceNameM := adviceNameMap.(map[string]interface{})
  3684. var advice models.GroupAdvice
  3685. advice.Remark = Remark
  3686. advice.AdviceType = adviceType
  3687. advice.StartTime = StartTime
  3688. if adminUserInfo.Org.Id == 10340 {
  3689. advice.AdviceDate = AdviceDate
  3690. advice.RecordDate = RecordDate
  3691. }
  3692. if adminUserInfo.Org.Id != 10340 {
  3693. advice.AdviceDate = theTimeOne.Unix()
  3694. advice.RecordDate = theTimeOne.Unix()
  3695. }
  3696. advice.Status = 1
  3697. advice.CreatedTime = time.Now().Unix()
  3698. advice.UpdatedTime = time.Now().Unix()
  3699. advice.StopState = 2
  3700. advice.ExecutionState = 2
  3701. advice.UserOrgId = adminUserInfo.Org.Id
  3702. advice.PatientId = patientInfo.ID
  3703. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3704. advice.IsSettle = 2
  3705. //入口
  3706. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3707. if errcode > 0 {
  3708. c.ServeFailJSONWithSGJErrorCode(errcode)
  3709. return
  3710. }
  3711. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3712. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3713. if len(subdrugs) > 0 {
  3714. for _, subdrug := range subdrugs {
  3715. var s models.GroupAdvice
  3716. s.Remark = Remark
  3717. s.AdviceType = adviceType
  3718. s.StartTime = StartTime
  3719. s.AdviceDate = AdviceDate
  3720. s.RecordDate = RecordDate
  3721. s.Status = 1
  3722. s.CreatedTime = time.Now().Unix()
  3723. s.UpdatedTime = time.Now().Unix()
  3724. s.StopState = 2
  3725. s.ExecutionState = 2
  3726. s.UserOrgId = adminUserInfo.Org.Id
  3727. s.PatientId = patientInfo.ID
  3728. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3729. s.IsSettle = 2
  3730. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3731. if errcode > 0 {
  3732. c.ServeFailJSONWithSGJErrorCode(errcode)
  3733. return
  3734. }
  3735. advice.Children = append(advice.Children, &s)
  3736. }
  3737. }
  3738. }
  3739. //长沙南雅
  3740. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3741. //查询该患者今日有没有双人核对
  3742. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  3743. if check.ID > 0 {
  3744. advice.Checker = check.Modifier
  3745. advice.CheckState = 1
  3746. advice.CheckTime = time.Now().Unix()
  3747. }
  3748. }
  3749. advices = append(advices, &advice)
  3750. }
  3751. // 查询信息规挡的设置天数
  3752. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3753. if infor.ID > 0 && infor.WeekDay > 0 {
  3754. var cha_time int64
  3755. timeNowStr := time.Now().Format("2006-01-02")
  3756. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3757. //今日的日期减去设置的日期
  3758. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3759. if cha_time >= Startdate {
  3760. //查询审核是否允许
  3761. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id)
  3762. //申请状态不允许的情况 拒绝修改
  3763. if infor.ApplicationStatus != 1 {
  3764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3765. return
  3766. }
  3767. }
  3768. }
  3769. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3770. finish := models.XtDialysisFinish{
  3771. IsFinish: 1,
  3772. UserOrgId: adminUserInfo.Org.Id,
  3773. Status: 1,
  3774. Ctime: time.Now().Unix(),
  3775. Mtime: 0,
  3776. Module: 4,
  3777. RecordDate: advicedateunix,
  3778. Sourse: 1,
  3779. PatientId: patient,
  3780. }
  3781. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  3782. if dialysisFinish.ID == 0 {
  3783. service.CreateDialysisFinish(finish)
  3784. }
  3785. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3786. redis := service.RedisClient()
  3787. //清空key 值
  3788. redis.Set(key, "", time.Second)
  3789. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3790. redis.Set(keyOne, "", time.Second)
  3791. defer redis.Close()
  3792. if createErr != nil {
  3793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3794. return
  3795. }
  3796. c.ServeSuccessJSON(map[string]interface{}{
  3797. "msg": "ok",
  3798. "advices": newAdvices,
  3799. })
  3800. return
  3801. } else if is_child == 2 {
  3802. patient, _ := c.GetInt64("id", 0)
  3803. if patient <= 0 {
  3804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3805. return
  3806. }
  3807. adminUserInfo := c.GetMobileAdminUserInfo()
  3808. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3809. if patientInfo.ID == 0 {
  3810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3811. return
  3812. }
  3813. var advice models.DoctorAdvice
  3814. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3815. if code > 0 {
  3816. c.ServeFailJSONWithSGJErrorCode(code)
  3817. return
  3818. }
  3819. if advice.ParentId > 0 {
  3820. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3821. if old.ID == 0 || old.PatientId != patient {
  3822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3823. return
  3824. }
  3825. if old.StopState == 1 || old.ExecutionState == 1 {
  3826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3827. return
  3828. }
  3829. if old.ParentId > 0 {
  3830. advice.ParentId = old.ParentId
  3831. }
  3832. advice.StartTime = old.StartTime
  3833. advice.AdviceDoctor = old.AdviceDoctor
  3834. advice.DeliveryWay = old.DeliveryWay
  3835. advice.ExecutionFrequency = old.ExecutionFrequency
  3836. advice.GroupNo = old.GroupNo
  3837. }
  3838. advice.Status = 1
  3839. advice.CreatedTime = time.Now().Unix()
  3840. advice.UpdatedTime = time.Now().Unix()
  3841. advice.StopState = 2
  3842. advice.ExecutionState = 2
  3843. advice.UserOrgId = adminUserInfo.Org.Id
  3844. advice.PatientId = patient
  3845. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3846. advice.IsSettle = 2
  3847. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3848. if advice.PrescribingNumber == 0 {
  3849. advice.PrescribingNumber = 1
  3850. }
  3851. //查询该患者今日有没有双人核对
  3852. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  3853. if check.ID > 0 {
  3854. advice.Checker = check.Modifier
  3855. advice.CheckState = 1
  3856. advice.CheckTime = time.Now().Unix()
  3857. }
  3858. }
  3859. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3860. if infor.ID > 0 {
  3861. var cha_time int64
  3862. timeNowStr := time.Now().Format("2006-01-02")
  3863. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3864. //今日的日期减去设置的日期
  3865. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3866. if cha_time >= advice.RecordDate {
  3867. //查询审核是否允许
  3868. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id)
  3869. //申请状态不允许的情况 拒绝修改
  3870. if infor.ApplicationStatus != 1 {
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3872. return
  3873. }
  3874. }
  3875. }
  3876. err := service.CreateDoctorAdvice(&advice)
  3877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3878. redis := service.RedisClient()
  3879. //清空key 值
  3880. redis.Set(key, "", time.Second)
  3881. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3882. redis.Set(keyOne, "", time.Second)
  3883. defer redis.Close()
  3884. if err != nil {
  3885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3886. return
  3887. }
  3888. c.ServeSuccessJSON(map[string]interface{}{
  3889. "msg": "ok",
  3890. "advice": advice,
  3891. })
  3892. return
  3893. }
  3894. }
  3895. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3896. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3897. utils.ErrorLog("advice_name")
  3898. return enums.ErrorCodeParamWrong
  3899. }
  3900. adviceName, _ := json["advice_name"].(string)
  3901. if len(adviceName) == 0 {
  3902. utils.ErrorLog("len(advice_name) == 0")
  3903. return enums.ErrorCodeParamWrong
  3904. }
  3905. advice.AdviceName = adviceName
  3906. adviceDesc, _ := json["advice_desc"].(string)
  3907. advice.AdviceDesc = adviceDesc
  3908. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3909. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3910. advice.DrugSpec = drugSpec
  3911. }
  3912. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3913. remark, _ := json["remark"].(string)
  3914. advice.Remark = remark
  3915. }
  3916. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3917. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3918. // advice.Way = src_type
  3919. //}
  3920. if json["way"] == nil {
  3921. advice.Way = 0
  3922. } else {
  3923. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3924. way := int64(json["way"].(float64))
  3925. advice.Way = way
  3926. }
  3927. }
  3928. if json["drug_id"] == nil {
  3929. advice.DrugId = 0
  3930. } else {
  3931. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3932. drug_id := int64(json["drug_id"].(float64))
  3933. advice.DrugId = drug_id
  3934. }
  3935. }
  3936. if json["drug_name_id"] == nil {
  3937. advice.DrugNameId = 0
  3938. } else {
  3939. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3940. drug_name_id := int64(json["drug_name_id"].(float64))
  3941. advice.DrugNameId = drug_name_id
  3942. }
  3943. }
  3944. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3945. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3946. advice.DrugSpecUnit = drugSpecUnit
  3947. }
  3948. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3949. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3950. advice.SingleDose = singleDose
  3951. }
  3952. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3953. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3954. advice.SingleDoseUnit = singleDoseUnit
  3955. }
  3956. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3957. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3958. advice.PrescribingNumber = prescribingNumber
  3959. }
  3960. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3961. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3962. advice.PrescribingNumberUnit = prescribingNumberUnit
  3963. }
  3964. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3965. deliveryWay, _ := json["delivery_way"].(string)
  3966. advice.DeliveryWay = deliveryWay
  3967. }
  3968. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3969. executionFrequency, _ := json["execution_frequency"].(string)
  3970. advice.ExecutionFrequency = executionFrequency
  3971. }
  3972. return 0
  3973. }
  3974. func (c *PatientApiController) DelDoctorAdvice() {
  3975. groupno, _ := c.GetInt64("groupno", -1)
  3976. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3977. patient_id, _ := c.GetInt64("patient_id")
  3978. doc_advice_date, _ := c.GetInt64("advice_date")
  3979. redis := service.RedisClient()
  3980. if is_sub == 1 { //是
  3981. advice_id, _ := c.GetInt64("advice_id")
  3982. adminUserInfo := c.GetMobileAdminUserInfo()
  3983. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3984. if advice.ID == 0 {
  3985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3986. return
  3987. }
  3988. advice.Status = 0
  3989. advice.UpdatedTime = time.Now().Unix()
  3990. advice.Modifier = adminUserInfo.AdminUser.Id
  3991. // 查询信息规挡的设置天数
  3992. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3993. if infor.ID > 0 && infor.WeekDay > 0 {
  3994. var cha_time int64
  3995. timeNowStr := time.Now().Format("2006-01-02")
  3996. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3997. //今日的日期减去设置的日期
  3998. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3999. if cha_time >= advice.AdviceDate {
  4000. //查询审核是否允许
  4001. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4002. //申请状态不允许的情况 拒绝修改
  4003. if infor.ApplicationStatus != 1 {
  4004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4005. return
  4006. }
  4007. }
  4008. }
  4009. err := service.DeleteDoctorAdvice(&advice)
  4010. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4011. redis.Set(key, "", time.Second)
  4012. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4013. redis.Set(keyTwo, "", time.Second)
  4014. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4015. redis.Set(keyThree, "", time.Second)
  4016. redis.Close()
  4017. if err != nil {
  4018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4019. return
  4020. }
  4021. c.ServeSuccessJSON(map[string]interface{}{
  4022. "msg": "ok",
  4023. })
  4024. return
  4025. } else { //
  4026. var ids []string
  4027. if groupno == 0 {
  4028. advice_id := c.GetString("advice_id")
  4029. ids = strings.Split(advice_id, ",")
  4030. if len(ids) <= 0 {
  4031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4032. return
  4033. }
  4034. }
  4035. if groupno < 0 {
  4036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4037. return
  4038. }
  4039. adminUserInfo := c.GetMobileAdminUserInfo()
  4040. var advice models.DoctorAdvice
  4041. if groupno > 0 {
  4042. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4043. if advice.ID == 0 {
  4044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4045. return
  4046. }
  4047. } else {
  4048. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4049. for _, item := range advices {
  4050. if item.ID == 0 {
  4051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4052. return
  4053. }
  4054. }
  4055. }
  4056. advice.UpdatedTime = time.Now().Unix()
  4057. advice.Status = 0
  4058. advice.GroupNo = groupno
  4059. advice.Modifier = adminUserInfo.AdminUser.Id
  4060. var err error
  4061. if groupno > 0 {
  4062. // 查询信息规挡的设置天数
  4063. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4064. if infor.ID > 0 {
  4065. var cha_time int64
  4066. timeNowStr := time.Now().Format("2006-01-02")
  4067. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4068. //今日的日期减去设置的日期
  4069. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4070. if cha_time >= advice.AdviceDate {
  4071. //查询审核是否允许
  4072. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4073. //申请状态不允许的情况 拒绝修改
  4074. if infor.ApplicationStatus != 1 {
  4075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4076. return
  4077. }
  4078. }
  4079. }
  4080. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4081. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4082. redis.Set(key, "", time.Second)
  4083. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4084. redis.Set(keyTwo, "", time.Second)
  4085. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4086. redis.Set(keyThree, "", time.Second)
  4087. } else {
  4088. // 查询信息规挡的设置天数
  4089. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4090. if infor.ID > 0 {
  4091. var cha_time int64
  4092. timeNowStr := time.Now().Format("2006-01-02")
  4093. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4094. //今日的日期减去设置的日期
  4095. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4096. if cha_time >= advice.AdviceDate {
  4097. //查询审核是否允许
  4098. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4099. //申请状态不允许的情况 拒绝修改
  4100. if infor.ApplicationStatus != 1 {
  4101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4102. return
  4103. }
  4104. }
  4105. }
  4106. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4107. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4108. redis.Set(key, "", time.Second)
  4109. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4110. redis.Set(keyTwo, "", time.Second)
  4111. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4112. redis.Set(keyThree, "", time.Second)
  4113. redis.Close()
  4114. }
  4115. if err != nil {
  4116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4117. return
  4118. }
  4119. c.ServeSuccessJSON(map[string]interface{}{
  4120. "msg": "ok",
  4121. })
  4122. return
  4123. }
  4124. }
  4125. // /m/api/advice/group/modify_starttime [post]
  4126. // @param group_no:int
  4127. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4128. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4129. group_no, _ := this.GetInt64("group_no")
  4130. start_time_str := this.GetString("start_time")
  4131. if group_no <= 0 || len(start_time_str) == 0 {
  4132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4133. return
  4134. }
  4135. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4136. if parseTimeErr != nil {
  4137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4138. return
  4139. }
  4140. adminUserInfo := this.GetMobileAdminUserInfo()
  4141. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4142. if updateStartTimeErr != nil {
  4143. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4145. return
  4146. }
  4147. this.ServeSuccessJSON(map[string]interface{}{
  4148. "start_time": startTime.Unix(),
  4149. })
  4150. }
  4151. func (this *PatientApiController) DelSubDoctorAdvice() {
  4152. advice_id, _ := this.GetInt64("advice_id")
  4153. adminUserInfo := this.GetMobileAdminUserInfo()
  4154. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4155. if advice.ID == 0 {
  4156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4157. return
  4158. }
  4159. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4160. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4161. // return
  4162. //}
  4163. advice.Status = 0
  4164. advice.UpdatedTime = time.Now().Unix()
  4165. advice.Modifier = adminUserInfo.AdminUser.Id
  4166. err := service.DeleteDoctorAdvice(&advice)
  4167. if err != nil {
  4168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4169. return
  4170. }
  4171. this.ServeSuccessJSON(map[string]interface{}{
  4172. "msg": "ok",
  4173. })
  4174. return
  4175. }
  4176. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4177. //adminUserInfo := this.GetMobileAdminUserInfo()
  4178. //service.FindUnReadDoctorAdviceMessage()
  4179. }
  4180. func (this *PatientApiController) GetPatientsByKeyWord() {
  4181. keyWord := this.GetString("keyword")
  4182. adminUserInfo := this.GetMobileAdminUserInfo()
  4183. today := utils.ZeroHourTimeOfDay(time.Now())
  4184. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4185. if err != nil {
  4186. utils.ErrorLog(err.Error())
  4187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4188. return
  4189. }
  4190. this.ServeSuccessJSON(map[string]interface{}{
  4191. "patient": patient,
  4192. })
  4193. }
  4194. func (this *PatientApiController) GetSearchPatient() {
  4195. keyWord := this.GetString("keyword")
  4196. adminUserInfo := this.GetMobileAdminUserInfo()
  4197. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4198. if err != nil {
  4199. utils.ErrorLog(err.Error())
  4200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4201. return
  4202. }
  4203. this.ServeSuccessJSON(map[string]interface{}{
  4204. "patient": patient,
  4205. })
  4206. }
  4207. func (c *PatientApiController) ExecProject() {
  4208. execution_time := c.GetString("execution_time")
  4209. project_id, _ := c.GetInt64("project_id")
  4210. team_id, _ := c.GetInt64("team_id")
  4211. is_check_team, _ := c.GetInt64("is_check_team")
  4212. if len(execution_time) <= 0 {
  4213. utils.ErrorLog("execution_time")
  4214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4215. return
  4216. }
  4217. timeLayout2 := "2006-01-02 15:04:05"
  4218. loc, _ := time.LoadLocation("Local")
  4219. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4220. if errs != nil {
  4221. utils.ErrorLog(errs.Error())
  4222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4223. return
  4224. }
  4225. adminInfo := c.GetMobileAdminUserInfo()
  4226. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4227. if project.Type == 3 {
  4228. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4229. if good.IsUser != 1 {
  4230. //查询开关是否开启
  4231. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4232. //开关已经开启
  4233. if stockSetting.IsType == 1 {
  4234. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4235. scheduleDateStart := theTime.Format("2006-01-02")
  4236. timeLayout3 := "2006-01-02"
  4237. loc, _ := time.LoadLocation("Local")
  4238. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4239. //查询该耗材是否已经出库
  4240. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4241. if auto.ID == 0 {
  4242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4243. return
  4244. }
  4245. }
  4246. }
  4247. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4248. //查询开关是否开启
  4249. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4250. //开关已经开启
  4251. if stockSetting.IsType == 1 {
  4252. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4253. scheduleDateStart := theTime.Format("2006-01-02")
  4254. timeLayout3 := "2006-01-02"
  4255. loc, _ := time.LoadLocation("Local")
  4256. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4257. //查询该耗材是否已经出库
  4258. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4259. if auto.ID == 0 {
  4260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4261. return
  4262. }
  4263. }
  4264. }
  4265. }
  4266. if project.ExecutionState == 1 {
  4267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4268. return
  4269. }
  4270. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4272. return
  4273. }
  4274. project.ExecutionState = 1
  4275. project.ExecutionStaff = adminInfo.AdminUser.Id
  4276. project.ExecutionTime = theTime.Unix()
  4277. if team_id == 0 {
  4278. // 查询信息规挡的设置天数
  4279. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4280. if infor.ID > 0 {
  4281. var cha_time int64
  4282. timeNowStr := time.Now().Format("2006-01-02")
  4283. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4284. //今日的日期减去设置的日期
  4285. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4286. if cha_time >= project.RecordDate {
  4287. //查询审核是否允许
  4288. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4289. //申请状态不允许的情况 拒绝修改
  4290. if infor.ApplicationStatus != 1 {
  4291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4292. return
  4293. }
  4294. }
  4295. }
  4296. err := service.SaveHisProject(&project)
  4297. if err == nil {
  4298. c.ServeSuccessJSON(map[string]interface{}{
  4299. "project": project,
  4300. })
  4301. } else {
  4302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4303. return
  4304. }
  4305. } else {
  4306. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4307. // 查询信息规挡的设置天数
  4308. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4309. if infor.ID > 0 {
  4310. var cha_time int64
  4311. timeNowStr := time.Now().Format("2006-01-02")
  4312. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4313. //今日的日期减去设置的日期
  4314. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4315. if cha_time >= project.RecordDate {
  4316. //查询审核是否允许
  4317. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4318. //申请状态不允许的情况 拒绝修改
  4319. if infor.ApplicationStatus != 1 {
  4320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4321. return
  4322. }
  4323. }
  4324. }
  4325. err := service.SaveHisProject(&project)
  4326. if err == nil {
  4327. c.ServeSuccessJSON(map[string]interface{}{
  4328. "project": project,
  4329. })
  4330. } else {
  4331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4332. return
  4333. }
  4334. } else {
  4335. // 查询信息规挡的设置天数
  4336. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4337. if infor.ID > 0 {
  4338. var cha_time int64
  4339. timeNowStr := time.Now().Format("2006-01-02")
  4340. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4341. //今日的日期减去设置的日期
  4342. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4343. if cha_time >= project.RecordDate {
  4344. //查询审核是否允许
  4345. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4346. //申请状态不允许的情况 拒绝修改
  4347. if infor.ApplicationStatus != 1 {
  4348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4349. return
  4350. }
  4351. }
  4352. }
  4353. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4354. var ids []int64
  4355. for _, items := range ps {
  4356. ids = append(ids, items.ID)
  4357. }
  4358. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  4359. if err == nil {
  4360. c.ServeSuccessJSON(map[string]interface{}{
  4361. "project": project,
  4362. })
  4363. } else {
  4364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4365. return
  4366. }
  4367. }
  4368. }
  4369. }
  4370. func (c *PatientApiController) CheckProject() {
  4371. adminInfo := c.GetMobileAdminUserInfo()
  4372. project_id, _ := c.GetInt64("project_id")
  4373. team_id, _ := c.GetInt64("team_id")
  4374. is_check_team, _ := c.GetInt64("is_check_team")
  4375. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4376. if project.CheckState == 1 {
  4377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  4378. return
  4379. }
  4380. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  4381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4382. return
  4383. }
  4384. project.Checker = adminInfo.AdminUser.Id
  4385. project.CheckTime = time.Now().Unix()
  4386. project.CheckState = 1
  4387. if team_id == 0 {
  4388. // 查询信息规挡的设置天数
  4389. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4390. if infor.ID > 0 {
  4391. var cha_time int64
  4392. timeNowStr := time.Now().Format("2006-01-02")
  4393. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4394. //今日的日期减去设置的日期
  4395. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4396. if cha_time >= project.RecordDate {
  4397. //查询审核是否允许
  4398. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4399. //申请状态不允许的情况 拒绝修改
  4400. if infor.ApplicationStatus != 1 {
  4401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4402. return
  4403. }
  4404. }
  4405. }
  4406. err := service.SaveHisProject(&project)
  4407. if err == nil {
  4408. c.ServeSuccessJSON(map[string]interface{}{
  4409. "msg": "ok",
  4410. "project": project,
  4411. })
  4412. } else {
  4413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4414. return
  4415. }
  4416. } else {
  4417. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4418. // 查询信息规挡的设置天数
  4419. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4420. if infor.ID > 0 {
  4421. var cha_time int64
  4422. timeNowStr := time.Now().Format("2006-01-02")
  4423. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4424. //今日的日期减去设置的日期
  4425. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4426. if cha_time >= project.RecordDate {
  4427. //查询审核是否允许
  4428. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4429. //申请状态不允许的情况 拒绝修改
  4430. if infor.ApplicationStatus != 1 {
  4431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4432. return
  4433. }
  4434. }
  4435. }
  4436. err := service.SaveHisProject(&project)
  4437. if err == nil {
  4438. c.ServeSuccessJSON(map[string]interface{}{
  4439. "msg": "ok",
  4440. "project": project,
  4441. })
  4442. } else {
  4443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4444. return
  4445. }
  4446. } else {
  4447. // 查询信息规挡的设置天数
  4448. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4449. if infor.ID > 0 {
  4450. var cha_time int64
  4451. timeNowStr := time.Now().Format("2006-01-02")
  4452. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4453. //今日的日期减去设置的日期
  4454. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4455. if cha_time >= project.RecordDate {
  4456. //查询审核是否允许
  4457. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4458. //申请状态不允许的情况 拒绝修改
  4459. if infor.ApplicationStatus != 1 {
  4460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4461. return
  4462. }
  4463. }
  4464. }
  4465. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4466. var ids []int64
  4467. for _, items := range ps {
  4468. ids = append(ids, items.ID)
  4469. }
  4470. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  4471. if err == nil {
  4472. c.ServeSuccessJSON(map[string]interface{}{
  4473. "project": project,
  4474. })
  4475. } else {
  4476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4477. return
  4478. }
  4479. }
  4480. }
  4481. }