patient_api_controller.go 209KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. "github.com/jinzhu/gorm"
  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, 4)
  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, 4)
  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, 4)
  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. //恒泰中医院
  560. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  561. if item.DrugId == 0 || item.DrugNameId == 0 {
  562. //从字典里面查找
  563. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  564. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  565. }
  566. }
  567. if item.ExecutionState == 2 {
  568. advice = item
  569. }
  570. //记录日志
  571. byterequest, _ := json.Marshal(item)
  572. adviceLog := models.XtDoctorAdviceLog{
  573. UserOrgId: item.UserOrgId,
  574. PatientId: item.PatientId,
  575. AdminUserId: adminUserInfo.AdminUser.Id,
  576. Module: 2,
  577. ErrLog: string(byterequest),
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. Source: "手机端执行医嘱",
  582. RecordDate: item.AdviceDate,
  583. }
  584. service.CreateDoctorAdviceLog(adviceLog)
  585. }
  586. } else {
  587. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  588. for _, item := range advices {
  589. //恒泰中医院
  590. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  591. if item.DrugId == 0 || item.DrugNameId == 0 {
  592. //从字典里面查找
  593. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  594. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  595. }
  596. }
  597. if item.ExecutionState == 2 {
  598. advice = item
  599. }
  600. }
  601. }
  602. if advice.ExecutionState == 1 {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  604. return
  605. }
  606. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  608. return
  609. }
  610. //针对普宁
  611. if adminUserInfo.Org.Id != 10599 {
  612. if advice.StartTime > theTime.Unix() {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  614. return
  615. }
  616. }
  617. advices := models.DoctorAdvice{
  618. ExecutionStaff: execution_staff,
  619. ExecutionTime: theTime.Unix(),
  620. UpdatedTime: time.Now().Unix(),
  621. }
  622. var err error
  623. if groupno > 0 {
  624. // 查询信息规挡的设置天数
  625. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  626. if infor.ID > 0 && infor.WeekDay > 0 {
  627. var cha_time int64
  628. timeNowStr := time.Now().Format("2006-01-02")
  629. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  630. //今日的日期减去设置的日期
  631. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  632. if cha_time >= record_date {
  633. //查询审核是否允许
  634. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  635. //申请状态不允许的情况 拒绝修改
  636. if infor.ApplicationStatus != 1 {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  638. return
  639. }
  640. }
  641. }
  642. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  643. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  644. redis := service.RedisClient()
  645. //清空key 值
  646. redis.Set(key, "", time.Second)
  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. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  657. redis.Set(keyFive, "", time.Second)
  658. defer redis.Close()
  659. } else {
  660. // 查询信息规挡的设置天数
  661. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  662. if infor.ID > 0 {
  663. var cha_time int64
  664. timeNowStr := time.Now().Format("2006-01-02")
  665. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  666. //今日的日期减去设置的日期
  667. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  668. if cha_time >= record_date {
  669. //查询审核是否允许
  670. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  671. //申请状态不允许的情况 拒绝修改
  672. if infor.ApplicationStatus != 1 {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  674. return
  675. }
  676. }
  677. }
  678. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  679. //记录日志
  680. byterequest, _ := json.Marshal(advice)
  681. adviceLog := models.XtDoctorAdviceLog{
  682. UserOrgId: advice.UserOrgId,
  683. PatientId: advice.PatientId,
  684. AdminUserId: adminUserInfo.AdminUser.Id,
  685. Module: 2,
  686. ErrLog: string(byterequest),
  687. Status: 1,
  688. Ctime: time.Now().Unix(),
  689. Mtime: 0,
  690. Source: "手机端执行医嘱",
  691. RecordDate: advices.RecordDate,
  692. }
  693. service.CreateDoctorAdviceLog(adviceLog)
  694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  695. redis := service.RedisClient()
  696. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  697. redis.Set(keyTwo, "", time.Second)
  698. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  699. redis.Set(keyThree, "", time.Second)
  700. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  701. theTime := toTime.Format("2006-01-02")
  702. fmt.Println("theTIME", theTime)
  703. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  704. redis.Set(keyFour, "", time.Second)
  705. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  706. redis.Set(keySix, "", time.Second)
  707. defer redis.Close()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. }
  711. if err != nil {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  713. return
  714. }
  715. advice.ExecutionStaff = execution_staff
  716. advice.ExecutionTime = theTime.Unix()
  717. advice.ExecutionState = 1
  718. advice.Modifier = adminUserInfo.AdminUser.Id
  719. //处理出库相关逻辑
  720. //1.判断是否启用药品管理和自备药出库功能
  721. //药品管理信息
  722. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  723. //自备药信息
  724. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  725. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  726. if drugStockConfig.IsOpen == 1 {
  727. if groupno > 0 {
  728. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  729. if len(advices) > 0 {
  730. var total int64
  731. var prescribing_number_total int64
  732. //出库
  733. for _, item := range advices {
  734. if item.Way == 1 {
  735. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  736. //查询该药品的剩余库存
  737. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  738. //查询改药品信息
  739. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  740. //判断单位是否相等
  741. if medical.MaxUnit == item.PrescribingNumberUnit {
  742. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  743. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  744. //转化为最小单位
  745. total = list.Count * medical.MinNumber
  746. prescribing_number_total = count * medical.MinNumber
  747. }
  748. if medical.MinUnit == item.PrescribingNumberUnit {
  749. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  750. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  751. total = list.Count*medical.MinNumber + list.StockMinNumber
  752. prescribing_number_total = count
  753. }
  754. if medical.IsUse == 1 {
  755. c.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "1",
  757. "advice": advice,
  758. "ids": ids,
  759. })
  760. return
  761. }
  762. if medical.IsUse != 1 {
  763. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  764. if advice.UserOrgId != 10278 {
  765. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  766. advice.ExecutionTime = 0
  767. advice.ExecutionState = 2
  768. advice.ExecutionStaff = 0
  769. }
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "msg": "3",
  772. "advice": advice,
  773. "ids": ids,
  774. })
  775. return
  776. }
  777. if prescribing_number_total > total {
  778. if advice.UserOrgId != 10278 {
  779. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  780. advice.ExecutionTime = 0
  781. advice.ExecutionState = 2
  782. advice.ExecutionStaff = 0
  783. }
  784. c.ServeSuccessJSON(map[string]interface{}{
  785. "msg": "2",
  786. "advice": advice,
  787. "ids": ids,
  788. })
  789. return
  790. }
  791. }
  792. //查询是否出库按钮开启
  793. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  794. if adviceSetting.IsAdviceOpen == 1 {
  795. //查询是否出库按钮开启
  796. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  797. //患者发药
  798. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  799. if prescriptionConfig.IsOpen == 1 {
  800. if medical.IsUse == 2 {
  801. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  802. //查询今日是否出库
  803. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  804. if drugOutInfo.ID == 0 {
  805. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  806. }
  807. }
  808. if pharmacyConfig.IsOpen != 1 {
  809. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  810. if drugOutInfo.ID == 0 {
  811. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  812. }
  813. }
  814. //更新字典里面的库存
  815. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  816. var sum_count int64
  817. for _, its := range stockInfo {
  818. if its.MaxUnit == medical.MaxUnit {
  819. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  820. }
  821. sum_count += its.StockMaxNumber + its.StockMinNumber
  822. }
  823. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  824. //剩余库存
  825. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  826. }
  827. }
  828. } else {
  829. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  830. if medical.IsUse == 2 {
  831. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  832. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  833. if drugOutInfo.ID == 0 {
  834. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  835. }
  836. }
  837. if pharmacyConfig.IsOpen != 1 {
  838. drugError := models.XtDrugError{
  839. ID: 0,
  840. UserOrgId: item.UserOrgId,
  841. DrugId: item.DrugId,
  842. RecordDate: item.AdviceDate,
  843. PatientId: item.PatientId,
  844. Remark: "恒泰中医院出库开始",
  845. Status: 1,
  846. Ctime: time.Now().Unix(),
  847. Mtime: 0,
  848. Prescribingnumber: item.PrescribingNumber,
  849. PrescribingNumberUnit: item.PrescribingNumberUnit,
  850. SumCount: 0,
  851. }
  852. service.CreateDrugError(drugError)
  853. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  854. if drugOutInfo.ID == 0 {
  855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  856. }
  857. }
  858. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  859. var sum_count int64
  860. for _, its := range stockInfo {
  861. if its.MaxUnit == medical.MaxUnit {
  862. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  863. }
  864. sum_count += its.StockMaxNumber + its.StockMinNumber
  865. }
  866. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  867. //剩余库存
  868. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  869. }
  870. }
  871. }
  872. }
  873. }
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "msg": "1",
  876. "advice": advice,
  877. "ids": ids,
  878. })
  879. return
  880. } else {
  881. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  882. if len(advices) > 0 {
  883. var total int64
  884. var prescribing_number_total int64
  885. for _, item := range advices {
  886. if item.Way == 1 {
  887. //查询改药品信息
  888. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  889. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  890. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  891. //查询该药品的剩余库存
  892. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  893. //判断单位是否相等
  894. if medical.MaxUnit == item.PrescribingNumberUnit {
  895. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  896. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  897. //转化为最小单位
  898. total = list.Count*medical.MinNumber + list.StockMinNumber
  899. prescribing_number_total = count * medical.MinNumber
  900. }
  901. if medical.MinUnit == item.PrescribingNumberUnit {
  902. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  903. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  904. total = list.Count*medical.MinNumber + list.StockMinNumber
  905. prescribing_number_total = count
  906. }
  907. if medical.IsUse == 1 {
  908. c.ServeSuccessJSON(map[string]interface{}{
  909. "msg": "1",
  910. "advice": advice,
  911. "ids": ids,
  912. })
  913. return
  914. }
  915. if medical.IsUse != 1 {
  916. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  917. if advice.UserOrgId != 10278 {
  918. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  919. advice.ExecutionTime = 0
  920. advice.ExecutionState = 2
  921. advice.ExecutionStaff = 0
  922. }
  923. c.ServeSuccessJSON(map[string]interface{}{
  924. "msg": "3",
  925. "advice": advice,
  926. "ids": ids,
  927. })
  928. return
  929. }
  930. if prescribing_number_total > total {
  931. if advice.UserOrgId != 10278 {
  932. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  933. advice.ExecutionTime = 0
  934. advice.ExecutionState = 2
  935. advice.ExecutionStaff = 0
  936. }
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "msg": "2",
  939. "advice": advice,
  940. "ids": ids,
  941. })
  942. return
  943. }
  944. }
  945. if medical.IsUse == 2 {
  946. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  947. //查询今日是否出库
  948. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  949. if drugOutInfo.ID == 0 {
  950. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  951. }
  952. }
  953. if pharmacyConfig.IsOpen != 1 {
  954. //查询今日是否出库
  955. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  956. if drugOutInfo.ID == 0 {
  957. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  958. }
  959. }
  960. //更新字典里面的库存
  961. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  962. var sum_count int64
  963. for _, its := range stockInfo {
  964. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  965. if its.MaxUnit == baseDrug.MaxUnit {
  966. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  967. }
  968. sum_count += its.StockMaxNumber + its.StockMinNumber
  969. }
  970. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  971. //剩余库存
  972. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  973. }
  974. if medical.IsUse == 1 {
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "msg": "1",
  977. "advice": advice,
  978. "ids": ids,
  979. })
  980. return
  981. }
  982. }
  983. }
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "msg": "1",
  987. "advice": advice,
  988. "ids": ids,
  989. })
  990. return
  991. }
  992. }
  993. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  994. if groupno > 0 {
  995. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  996. for _, item := range advices {
  997. if item.ExecutionState == 1 && item.Way == 2 {
  998. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  999. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1000. timeStr := time.Now().Format("2006-01-02")
  1001. timeArr := strings.Split(timeStr, "-")
  1002. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1003. total = total + 1
  1004. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1005. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1006. number = number + total
  1007. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1008. //插入自备药出库单
  1009. outStock := models.XtSelfOutStock{
  1010. DrugName: item.AdviceName,
  1011. DrugNameId: item.DrugNameId,
  1012. DrugSpec: item.AdviceDesc,
  1013. OutstoreNumber: count,
  1014. AdminUserId: adminUserInfo.AdminUser.Id,
  1015. StorckTime: item.AdviceDate,
  1016. UserOrgId: adminUserInfo.Org.Id,
  1017. CreatedTime: time.Now().Unix(),
  1018. Status: 1,
  1019. PatientId: item.PatientId,
  1020. ExitMode: 2,
  1021. MedicId: item.DrugId,
  1022. StockOutNumber: warehousing_out_order,
  1023. }
  1024. //查询 该患者是否已出库
  1025. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1026. if errcode == gorm.ErrRecordNotFound {
  1027. service.CreateOutStock(&outStock)
  1028. } else if errcode == nil {
  1029. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1030. fmt.Println("err", err)
  1031. }
  1032. }
  1033. }
  1034. } else {
  1035. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1036. for _, item := range advices {
  1037. if item.ExecutionState == 1 && item.Way == 2 {
  1038. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1039. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1040. timeStr := time.Now().Format("2006-01-02")
  1041. timeArr := strings.Split(timeStr, "-")
  1042. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1043. total = total + 1
  1044. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1045. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1046. number = number + total
  1047. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1048. //插入自备药出库单
  1049. outStock := models.XtSelfOutStock{
  1050. DrugName: item.AdviceName,
  1051. DrugNameId: item.DrugNameId,
  1052. DrugSpec: item.AdviceDesc,
  1053. OutstoreNumber: count,
  1054. AdminUserId: adminUserInfo.AdminUser.Id,
  1055. StorckTime: item.AdviceDate,
  1056. UserOrgId: adminUserInfo.Org.Id,
  1057. CreatedTime: time.Now().Unix(),
  1058. Status: 1,
  1059. PatientId: item.PatientId,
  1060. ExitMode: 2,
  1061. MedicId: item.DrugId,
  1062. StockOutNumber: warehousing_out_order,
  1063. }
  1064. //查询 该患者是否已出库
  1065. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1066. if errcode == gorm.ErrRecordNotFound {
  1067. service.CreateOutStock(&outStock)
  1068. } else if errcode == nil {
  1069. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1070. fmt.Println("err", err)
  1071. }
  1072. }
  1073. }
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "msg": "1",
  1076. "advice": advice,
  1077. "ids": ids,
  1078. })
  1079. return
  1080. }
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "1",
  1084. "advice": advice,
  1085. "ids": ids,
  1086. })
  1087. return
  1088. } else if origin == 2 {
  1089. adminInfo := c.GetMobileAdminUserInfo()
  1090. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1091. var ids []string
  1092. advice_ids := c.GetString("advice_id")
  1093. ids = strings.Split(advice_ids, ",")
  1094. if len(execution_time) <= 0 {
  1095. utils.ErrorLog("execution_time")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. timeLayout2 := "2006-01-02 15:04:05"
  1100. loc, _ := time.LoadLocation("Local")
  1101. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1102. if errs != nil {
  1103. utils.ErrorLog(errs.Error())
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1108. var err error
  1109. for _, item := range advices {
  1110. if item.ExecutionState == 1 {
  1111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1112. return
  1113. }
  1114. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1116. return
  1117. }
  1118. if item.StartTime > theTime.Unix() {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1120. return
  1121. }
  1122. item.ExecutionState = 1
  1123. item.ExecutionStaff = adminInfo.AdminUser.Id
  1124. item.ExecutionTime = theTime.Unix()
  1125. item.IsMobile = 1
  1126. // 查询信息规挡的设置天数
  1127. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1128. if infor.ID > 0 {
  1129. var cha_time int64
  1130. timeNowStr := time.Now().Format("2006-01-02")
  1131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1132. //今日的日期减去设置的日期
  1133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1134. if cha_time >= item.AdviceDate {
  1135. //查询审核是否允许
  1136. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1137. //申请状态不允许的情况 拒绝修改
  1138. if infor.ApplicationStatus != 1 {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1140. return
  1141. }
  1142. }
  1143. }
  1144. err = service.SaveHisDoctorAdvice(item)
  1145. //记录日志
  1146. byterequest, _ := json.Marshal(item)
  1147. adviceLog := models.XtDoctorAdviceLog{
  1148. UserOrgId: item.UserOrgId,
  1149. PatientId: item.PatientId,
  1150. AdminUserId: item.ExecutionStaff,
  1151. Module: 2,
  1152. ErrLog: string(byterequest),
  1153. Status: 1,
  1154. Ctime: time.Now().Unix(),
  1155. Mtime: 0,
  1156. Source: "手机端执行his医嘱",
  1157. RecordDate: item.AdviceDate,
  1158. }
  1159. service.CreateDoctorAdviceLog(adviceLog)
  1160. if err == nil {
  1161. drugError := models.XtDrugError{
  1162. UserOrgId: adminInfo.Org.Id,
  1163. DrugId: item.DrugId,
  1164. RecordDate: item.AdviceDate,
  1165. PatientId: item.PatientId,
  1166. Remark: "执行成功",
  1167. Status: 1,
  1168. Ctime: time.Now().Unix(),
  1169. Mtime: 0,
  1170. SumCount: 0,
  1171. Prescribingnumber: item.PrescribingNumber,
  1172. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1173. }
  1174. service.CreateDrugError(drugError)
  1175. }
  1176. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1177. redis := service.RedisClient()
  1178. //清空key 值
  1179. redis.Set(key, "", time.Second)
  1180. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1181. redis.Set(keyTwo, "", time.Second)
  1182. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1183. redis.Set(keyThree, "", time.Second)
  1184. recordDate := theTime.Format("2006-01-02")
  1185. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1186. redis.Set(keyFour, "", time.Second)
  1187. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1188. redis.Set(keyFive, "", time.Second)
  1189. defer redis.Close()
  1190. }
  1191. //药品管理信息
  1192. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1193. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1194. if drugStockConfig.IsOpen == 1 {
  1195. for _, item := range advices {
  1196. //查询改药品信息
  1197. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1198. //判断单位是否合格
  1199. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1200. //查询该药品是否有出库记录
  1201. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  1202. if len(flowMap) == 0 {
  1203. errs := service.UpdateHisAdviceById(item.ID)
  1204. if errs != nil {
  1205. drugError := models.XtDrugError{
  1206. UserOrgId: adminInfo.Org.Id,
  1207. DrugId: item.DrugId,
  1208. RecordDate: item.AdviceDate,
  1209. PatientId: item.PatientId,
  1210. Remark: "单位不统一,执行失败",
  1211. Status: 1,
  1212. Ctime: time.Now().Unix(),
  1213. Mtime: 0,
  1214. SumCount: 0,
  1215. Prescribingnumber: item.PrescribingNumber,
  1216. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1217. }
  1218. service.CreateDrugError(drugError)
  1219. }
  1220. }
  1221. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "msg": "7",
  1224. "advice": advice,
  1225. "ids": ids,
  1226. })
  1227. return
  1228. }
  1229. //查询这个患者这个患者这个药已经出库的所有数量
  1230. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1231. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1232. var total_count int64
  1233. var drug_count int64
  1234. for _, it := range advicelist {
  1235. if it.PrescribingNumberUnit == medical.MaxUnit {
  1236. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1237. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1238. total_count += prenumber * medical.MinNumber
  1239. }
  1240. if it.PrescribingNumberUnit == medical.MinUnit {
  1241. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1242. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1243. total_count += prenumber
  1244. }
  1245. }
  1246. for _, its := range drugoutlist {
  1247. if its.CountUnit == medical.MaxUnit {
  1248. drug_count += its.Count * medical.MinNumber
  1249. }
  1250. if its.CountUnit == medical.MinUnit {
  1251. drug_count += its.Count
  1252. }
  1253. }
  1254. if total_count == drug_count {
  1255. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "msg": "1",
  1258. "advice": advice,
  1259. "ids": ids,
  1260. })
  1261. return
  1262. }
  1263. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1264. var total int64
  1265. var prescribing_number_total int64
  1266. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1267. if config.IsOpen != 1 {
  1268. //查询该药品是否有库存
  1269. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1270. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1271. //判断单位是否相等
  1272. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1273. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1274. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1275. //转化为最小单位
  1276. total = list.Count*medical.MinNumber + list.StockMinNumber
  1277. prescribing_number_total = count * medical.MinNumber
  1278. }
  1279. //fmt.Println("医嘱开的数量", total)
  1280. if medical.MinUnit == advice.PrescribingNumberUnit {
  1281. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1282. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1283. total = list.Count*medical.MinNumber + list.StockMinNumber
  1284. prescribing_number_total = count
  1285. }
  1286. if medical.IsUse == 1 {
  1287. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1288. drugError := models.XtDrugError{
  1289. UserOrgId: adminInfo.Org.Id,
  1290. DrugId: item.DrugId,
  1291. RecordDate: item.AdviceDate,
  1292. PatientId: item.PatientId,
  1293. Remark: "零用药品库存不足",
  1294. Status: 1,
  1295. Ctime: time.Now().Unix(),
  1296. Mtime: 0,
  1297. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1298. Prescribingnumber: advice.PrescribingNumber,
  1299. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1300. }
  1301. service.CreateDrugError(drugError)
  1302. c.ServeSuccessJSON(map[string]interface{}{
  1303. "msg": "1",
  1304. "advice": advice,
  1305. "ids": ids,
  1306. })
  1307. return
  1308. }
  1309. }
  1310. if medical.IsUse != 1 {
  1311. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1312. drugError := models.XtDrugError{
  1313. UserOrgId: adminInfo.Org.Id,
  1314. DrugId: item.DrugId,
  1315. RecordDate: item.AdviceDate,
  1316. PatientId: item.PatientId,
  1317. Remark: "药品库存不足",
  1318. Status: 1,
  1319. Ctime: time.Now().Unix(),
  1320. Mtime: 0,
  1321. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1322. Prescribingnumber: advice.PrescribingNumber,
  1323. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1324. }
  1325. service.CreateDrugError(drugError)
  1326. c.ServeSuccessJSON(map[string]interface{}{
  1327. "msg": "3",
  1328. "advice": advice,
  1329. "ids": ids,
  1330. })
  1331. return
  1332. }
  1333. if prescribing_number_total > total {
  1334. drugError := models.XtDrugError{
  1335. UserOrgId: adminInfo.Org.Id,
  1336. DrugId: item.DrugId,
  1337. RecordDate: item.AdviceDate,
  1338. PatientId: item.PatientId,
  1339. Remark: "出库数量大于库存",
  1340. Status: 1,
  1341. Ctime: time.Now().Unix(),
  1342. Mtime: 0,
  1343. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1344. Prescribingnumber: advice.PrescribingNumber,
  1345. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1346. }
  1347. service.CreateDrugError(drugError)
  1348. c.ServeSuccessJSON(map[string]interface{}{
  1349. "msg": "2",
  1350. "advice": advice,
  1351. "ids": ids,
  1352. })
  1353. return
  1354. }
  1355. }
  1356. if prescribing_number_total <= total {
  1357. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1358. //判断药品是否零用
  1359. if medical.IsUse == 2 {
  1360. if config.IsOpen != 1 {
  1361. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1362. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1363. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1364. //查询该药品是否有出库记录
  1365. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1366. if len(flowMap) == 0 {
  1367. errs := service.UpdateHisAdviceById(advice.ID)
  1368. if errs != nil {
  1369. drugError := models.XtDrugError{
  1370. UserOrgId: adminInfo.Org.Id,
  1371. DrugId: item.DrugId,
  1372. RecordDate: item.AdviceDate,
  1373. PatientId: item.PatientId,
  1374. Remark: "出库记录为空,更新执行人失败",
  1375. Status: 1,
  1376. Ctime: time.Now().Unix(),
  1377. Mtime: 0,
  1378. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1379. Prescribingnumber: advice.PrescribingNumber,
  1380. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1381. }
  1382. service.CreateDrugError(drugError)
  1383. }
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "msg": "6",
  1386. "advice": advice,
  1387. "ids": ids,
  1388. })
  1389. return
  1390. }
  1391. }
  1392. }
  1393. if pharmacyConfig.IsOpen != 1 {
  1394. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1395. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1396. //查询该药品是否有出库记录
  1397. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1398. if len(flowMap) == 0 {
  1399. errs := service.UpdateHisAdviceById(advice.ID)
  1400. if errs != nil {
  1401. drugError := models.XtDrugError{
  1402. UserOrgId: adminInfo.Org.Id,
  1403. DrugId: item.DrugId,
  1404. RecordDate: item.AdviceDate,
  1405. PatientId: item.PatientId,
  1406. Remark: "出库记录为空,更新执行人失败",
  1407. Status: 1,
  1408. Ctime: time.Now().Unix(),
  1409. Mtime: 0,
  1410. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1411. Prescribingnumber: advice.PrescribingNumber,
  1412. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1413. }
  1414. service.CreateDrugError(drugError)
  1415. }
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "msg": "6",
  1418. "advice": advice,
  1419. "ids": ids,
  1420. })
  1421. return
  1422. }
  1423. }
  1424. }
  1425. //更新字典里面的库存
  1426. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1427. var sum_count int64
  1428. for _, its := range stockInfo {
  1429. if its.MaxUnit == medical.MaxUnit {
  1430. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1431. }
  1432. sum_count += its.StockMaxNumber + its.StockMinNumber
  1433. }
  1434. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1435. //剩余库存
  1436. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1437. }
  1438. }
  1439. }
  1440. }
  1441. //
  1442. if config.IsOpen == 1 && item.UserOrgId == 10188 {
  1443. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1444. //更新字典里面的库存
  1445. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1446. var sum_count int64
  1447. for _, its := range stockInfo {
  1448. if its.MaxUnit == medical.MaxUnit {
  1449. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1450. }
  1451. sum_count += its.StockMaxNumber + its.StockMinNumber
  1452. }
  1453. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1454. //剩余库存
  1455. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1456. }
  1457. }
  1458. }
  1459. for _, item := range advices {
  1460. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1461. c.ServeSuccessJSON(map[string]interface{}{
  1462. "msg": "1",
  1463. "advice": advice,
  1464. "ids": ids,
  1465. })
  1466. }
  1467. }
  1468. }
  1469. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1470. execution_time := c.GetString("execution_time")
  1471. fmt.Println("execution_time", execution_time)
  1472. groupno, _ := c.GetInt64("groupno", -1)
  1473. //patient_id, _ := c.GetInt64("patient_id")
  1474. advice_date, _ := c.GetInt64("advice_date")
  1475. var ids []string
  1476. if groupno == 0 {
  1477. advice_ids := c.GetString("advice_id")
  1478. ids = strings.Split(advice_ids, ",")
  1479. }
  1480. if groupno < 0 {
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1482. return
  1483. }
  1484. if len(execution_time) <= 0 {
  1485. utils.ErrorLog("execution_time")
  1486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1487. return
  1488. }
  1489. timeLayout2 := "2006-01-02 15:04:05"
  1490. loc, _ := time.LoadLocation("Local")
  1491. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1492. if errs != nil {
  1493. utils.ErrorLog(errs.Error())
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. adminUserInfo := c.GetMobileAdminUserInfo()
  1498. var advice models.DoctorAdvice
  1499. if groupno > 0 {
  1500. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1501. for _, item := range advices {
  1502. if item.ExecutionState == 1 {
  1503. advice = item
  1504. }
  1505. }
  1506. } else {
  1507. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1508. for _, item := range advices {
  1509. if item.ExecutionState == 1 {
  1510. advice = item
  1511. }
  1512. }
  1513. }
  1514. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1515. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1516. // if getPermissionErr != nil {
  1517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1518. // return
  1519. // } else if headNursePermission == nil {
  1520. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1521. // return
  1522. // }
  1523. //}
  1524. if advice.StartTime > theTime.Unix() {
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1526. return
  1527. }
  1528. advices := models.DoctorAdvice{
  1529. ExecutionTime: theTime.Unix(),
  1530. UpdatedTime: time.Now().Unix(),
  1531. }
  1532. var err error
  1533. if groupno > 0 {
  1534. // 查询信息规挡的设置天数
  1535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1536. if infor.ID > 0 {
  1537. var cha_time int64
  1538. timeNowStr := time.Now().Format("2006-01-02")
  1539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1540. //今日的日期减去设置的日期
  1541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1542. if cha_time >= advices.AdviceDate {
  1543. //查询审核是否允许
  1544. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1545. //申请状态不允许的情况 拒绝修改
  1546. if infor.ApplicationStatus != 1 {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1553. //记录日志
  1554. byterequest, _ := json.Marshal(advices)
  1555. adviceLog := models.XtDoctorAdviceLog{
  1556. UserOrgId: adminUserInfo.Org.Id,
  1557. PatientId: advices.PatientId,
  1558. AdminUserId: adminUserInfo.AdminUser.Id,
  1559. Module: 1,
  1560. ErrLog: string(byterequest),
  1561. Status: 1,
  1562. Ctime: time.Now().Unix(),
  1563. Mtime: 0,
  1564. Source: "手机端编辑医嘱",
  1565. RecordDate: advices.AdviceDate,
  1566. }
  1567. service.CreateDoctorAdviceLog(adviceLog)
  1568. redis := service.RedisClient()
  1569. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1570. redis.Set(key, "", time.Second)
  1571. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1572. redis.Set(keyOne, "", time.Second)
  1573. defer redis.Close()
  1574. } else {
  1575. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1576. if infor.ID > 0 {
  1577. var cha_time int64
  1578. timeNowStr := time.Now().Format("2006-01-02")
  1579. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1580. //今日的日期减去设置的日期
  1581. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1582. if cha_time >= advices.AdviceDate {
  1583. //查询审核是否允许
  1584. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1585. //申请状态不允许的情况 拒绝修改
  1586. if infor.ApplicationStatus != 1 {
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1588. return
  1589. }
  1590. }
  1591. }
  1592. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1593. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1594. //记录日志
  1595. byterequest, _ := json.Marshal(advices)
  1596. adviceLog := models.XtDoctorAdviceLog{
  1597. UserOrgId: adminUserInfo.Org.Id,
  1598. PatientId: advices.PatientId,
  1599. AdminUserId: adminUserInfo.AdminUser.Id,
  1600. Module: 1,
  1601. ErrLog: string(byterequest),
  1602. Status: 1,
  1603. Ctime: time.Now().Unix(),
  1604. Mtime: 0,
  1605. Source: "手机端编辑执行医嘱",
  1606. RecordDate: advices.AdviceDate,
  1607. }
  1608. service.CreateDoctorAdviceLog(adviceLog)
  1609. redis := service.RedisClient()
  1610. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1611. redis.Set(key, "", time.Second)
  1612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1613. redis.Set(keyOne, "", time.Second)
  1614. defer redis.Close()
  1615. }
  1616. //判断是否开启his
  1617. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1618. //如果开启去修改执行时间
  1619. if config.IsOpen == 1 {
  1620. advicesinfo := models.HisDoctorAdviceInfo{
  1621. ExecutionTime: theTime.Unix(),
  1622. UpdatedTime: time.Now().Unix(),
  1623. }
  1624. var advicehis models.HisDoctorAdviceInfo
  1625. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1626. //记录日志
  1627. byterequest, _ := json.Marshal(advicesinfo)
  1628. adviceLog := models.XtDoctorAdviceLog{
  1629. UserOrgId: adminUserInfo.Org.Id,
  1630. PatientId: advices.PatientId,
  1631. AdminUserId: adminUserInfo.AdminUser.Id,
  1632. Module: 1,
  1633. ErrLog: string(byterequest),
  1634. Status: 1,
  1635. Ctime: time.Now().Unix(),
  1636. Mtime: 0,
  1637. Source: "手机端his编辑医嘱",
  1638. RecordDate: advices.AdviceDate,
  1639. }
  1640. service.CreateDoctorAdviceLog(adviceLog)
  1641. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1642. for _, item := range his_advices {
  1643. if item.ExecutionState == 1 {
  1644. advicehis = item
  1645. }
  1646. }
  1647. redis := service.RedisClient()
  1648. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1649. redis.Set(keyThree, "", time.Second)
  1650. recordDate := theTime.Format("2006-01-02")
  1651. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1652. redis.Set(keyFour, "", time.Second)
  1653. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1654. redis.Set(keyFive, "", time.Second)
  1655. defer redis.Close()
  1656. project := models.HisPrescriptionProject{
  1657. ExecutionTime: theTime.Unix(),
  1658. Mtime: time.Now().Unix(),
  1659. }
  1660. service.ModifyHisPrescriptionProject(&project, ids)
  1661. //记录日志
  1662. projectquerst, _ := json.Marshal(project)
  1663. projectLog := models.XtDoctorAdviceLog{
  1664. UserOrgId: adminUserInfo.Org.Id,
  1665. PatientId: advices.PatientId,
  1666. AdminUserId: adminUserInfo.AdminUser.Id,
  1667. Module: 1,
  1668. ErrLog: string(projectquerst),
  1669. Status: 1,
  1670. Ctime: time.Now().Unix(),
  1671. Mtime: 0,
  1672. Source: "手机端his编辑项目医嘱",
  1673. RecordDate: advices.AdviceDate,
  1674. }
  1675. service.CreateDoctorAdviceLog(projectLog)
  1676. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1677. redis.Set(keyEnd, "", time.Second)
  1678. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1679. redis.Set(keyFours, "", time.Second)
  1680. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1681. redis.Set(keyFives, "", time.Second)
  1682. defer redis.Close()
  1683. }
  1684. if err != nil {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1686. return
  1687. }
  1688. advice.ExecutionTime = theTime.Unix()
  1689. c.ServeSuccessJSON(map[string]interface{}{
  1690. "msg": "ok",
  1691. "advice": advice,
  1692. "ids": ids,
  1693. })
  1694. return
  1695. }
  1696. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  1697. origin, _ := c.GetInt64("origin", 0)
  1698. record_date, _ := c.GetInt64("record_date")
  1699. patient_id, _ := c.GetInt64("patient_id")
  1700. check_time := c.GetString("check_time")
  1701. if len(check_time) <= 0 {
  1702. utils.ErrorLog("check_time")
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1704. return
  1705. }
  1706. timeLayout2 := "2006-01-02 15:04:05"
  1707. loc, _ := time.LoadLocation("Local")
  1708. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  1709. fmt.Println("theTimewowowow", theTime)
  1710. if errs != nil {
  1711. utils.ErrorLog(errs.Error())
  1712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1713. return
  1714. }
  1715. if origin != 2 {
  1716. groupno, _ := c.GetInt64("groupno", -1)
  1717. var ids []string
  1718. if groupno == 0 {
  1719. advice_ids := c.GetString("advice_id")
  1720. if advice_ids == "" {
  1721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1722. return
  1723. } else {
  1724. ids = strings.Split(advice_ids, ",")
  1725. if len(ids) <= 0 {
  1726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1727. return
  1728. }
  1729. }
  1730. }
  1731. if groupno < 0 {
  1732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1733. return
  1734. }
  1735. adminUserInfo := c.GetMobileAdminUserInfo()
  1736. var advice models.DoctorAdvice
  1737. if groupno > 0 {
  1738. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1739. for _, item := range advices {
  1740. if item.CheckState == 0 {
  1741. advice = item
  1742. }
  1743. //记录日志
  1744. byterequest, _ := json.Marshal(advices)
  1745. adviceLog := models.XtDoctorAdviceLog{
  1746. UserOrgId: adminUserInfo.Org.Id,
  1747. PatientId: item.PatientId,
  1748. AdminUserId: adminUserInfo.AdminUser.Id,
  1749. Module: 3,
  1750. ErrLog: string(byterequest),
  1751. Status: 1,
  1752. Ctime: time.Now().Unix(),
  1753. Mtime: 0,
  1754. Source: "手机端核对医嘱",
  1755. RecordDate: item.AdviceDate,
  1756. }
  1757. service.CreateDoctorAdviceLog(adviceLog)
  1758. }
  1759. if advice.CheckState == 1 {
  1760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1761. return
  1762. }
  1763. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1765. return
  1766. }
  1767. } else {
  1768. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1769. for _, item := range advices {
  1770. if item.CheckState == 0 {
  1771. advice = item
  1772. }
  1773. //记录日志
  1774. byterequest, _ := json.Marshal(advices)
  1775. adviceLog := models.XtDoctorAdviceLog{
  1776. UserOrgId: adminUserInfo.Org.Id,
  1777. PatientId: item.PatientId,
  1778. AdminUserId: adminUserInfo.AdminUser.Id,
  1779. Module: 3,
  1780. ErrLog: string(byterequest),
  1781. Status: 1,
  1782. Ctime: time.Now().Unix(),
  1783. Mtime: 0,
  1784. Source: "手机端核对医嘱",
  1785. RecordDate: item.AdviceDate,
  1786. }
  1787. service.CreateDoctorAdviceLog(adviceLog)
  1788. }
  1789. if advice.CheckState == 1 {
  1790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1791. return
  1792. }
  1793. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1795. return
  1796. }
  1797. }
  1798. checker := adminUserInfo.AdminUser.Id
  1799. advices := models.DoctorAdvice{
  1800. CheckTime: theTime.Unix(),
  1801. Checker: checker,
  1802. UpdatedTime: time.Now().Unix(),
  1803. }
  1804. fmt.Println("groupnowowowowoowowow", groupno)
  1805. var err error
  1806. if groupno > 0 {
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= record_date {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  1826. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1827. redis := service.RedisClient()
  1828. //清空key 值
  1829. redis.Set(key, "", time.Second)
  1830. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1831. redis.Set(keyTwo, "", time.Second)
  1832. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1833. redis.Set(keyThree, "", time.Second)
  1834. recordDate := theTime.Format("2006-01-02")
  1835. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1836. redis.Set(keyFour, "", time.Second)
  1837. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1838. redis.Set(keyFive, "", time.Second)
  1839. defer redis.Close()
  1840. } else {
  1841. if len(ids[0]) <= 0 {
  1842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1843. return
  1844. } else {
  1845. //t := time.Now().Format("2006-01-02")/**/
  1846. //timeLayout2 := "2006-01-02"
  1847. //loc, _ := time.LoadLocation("Local")
  1848. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1849. // 查询信息规挡的设置天数
  1850. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1851. if infor.ID > 0 {
  1852. var cha_time int64
  1853. timeNowStr := time.Now().Format("2006-01-02")
  1854. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1855. //今日的日期减去设置的日期
  1856. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1857. if cha_time >= advices.AdviceDate {
  1858. //查询审核是否允许
  1859. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1860. //申请状态不允许的情况 拒绝修改
  1861. if infor.ApplicationStatus != 1 {
  1862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1863. return
  1864. }
  1865. }
  1866. }
  1867. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1868. //记录日志
  1869. byterequest, _ := json.Marshal(advices)
  1870. adviceLog := models.XtDoctorAdviceLog{
  1871. UserOrgId: adminUserInfo.Org.Id,
  1872. PatientId: advices.PatientId,
  1873. AdminUserId: advices.Checker,
  1874. Module: 3,
  1875. ErrLog: string(byterequest),
  1876. Status: 1,
  1877. Ctime: time.Now().Unix(),
  1878. Mtime: 0,
  1879. Source: "手机端核对医嘱",
  1880. RecordDate: advices.AdviceDate,
  1881. }
  1882. service.CreateDoctorAdviceLog(adviceLog)
  1883. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1884. redis := service.RedisClient()
  1885. //清空key 值
  1886. redis.Set(key, "", time.Second)
  1887. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1888. redis.Set(keyTwo, "", time.Second)
  1889. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1890. redis.Set(keyThree, "", time.Second)
  1891. recordDate := theTime.Format("2006-01-02")
  1892. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1893. redis.Set(keyFour, "", time.Second)
  1894. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1895. redis.Set(keyFive, "", time.Second)
  1896. defer redis.Close()
  1897. }
  1898. }
  1899. if err != nil {
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1901. return
  1902. }
  1903. advice.Checker = checker
  1904. advice.CheckTime = theTime.Unix()
  1905. advice.CheckState = 1
  1906. c.ServeSuccessJSON(map[string]interface{}{
  1907. "msg": "ok",
  1908. "advice": advice,
  1909. })
  1910. }
  1911. return
  1912. }
  1913. func (c *PatientApiController) CheckDoctorAdvice() {
  1914. origin, _ := c.GetInt64("origin", 0)
  1915. record_date, _ := c.GetInt64("record_date")
  1916. patient_id, _ := c.GetInt64("patient_id")
  1917. if origin != 2 {
  1918. groupno, _ := c.GetInt64("groupno", -1)
  1919. var ids []string
  1920. if groupno == 0 {
  1921. advice_ids := c.GetString("advice_id")
  1922. if advice_ids == "" {
  1923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1924. return
  1925. } else {
  1926. ids = strings.Split(advice_ids, ",")
  1927. if len(ids) <= 0 {
  1928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1929. return
  1930. }
  1931. }
  1932. }
  1933. if groupno < 0 {
  1934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1935. return
  1936. }
  1937. adminUserInfo := c.GetMobileAdminUserInfo()
  1938. var advice models.DoctorAdvice
  1939. if groupno > 0 {
  1940. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1941. for _, item := range advices {
  1942. if item.CheckState == 0 {
  1943. advice = item
  1944. }
  1945. //记录日志
  1946. byterequest, _ := json.Marshal(advices)
  1947. adviceLog := models.XtDoctorAdviceLog{
  1948. UserOrgId: adminUserInfo.Org.Id,
  1949. PatientId: item.PatientId,
  1950. AdminUserId: adminUserInfo.AdminUser.Id,
  1951. Module: 3,
  1952. ErrLog: string(byterequest),
  1953. Status: 1,
  1954. Ctime: time.Now().Unix(),
  1955. Mtime: 0,
  1956. Source: "手机端核对医嘱",
  1957. RecordDate: item.AdviceDate,
  1958. }
  1959. service.CreateDoctorAdviceLog(adviceLog)
  1960. }
  1961. if advice.CheckState == 1 {
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1963. return
  1964. }
  1965. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1967. return
  1968. }
  1969. } else {
  1970. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1971. for _, item := range advices {
  1972. if item.CheckState == 0 {
  1973. advice = item
  1974. }
  1975. //记录日志
  1976. byterequest, _ := json.Marshal(advices)
  1977. adviceLog := models.XtDoctorAdviceLog{
  1978. UserOrgId: adminUserInfo.Org.Id,
  1979. PatientId: item.PatientId,
  1980. AdminUserId: adminUserInfo.AdminUser.Id,
  1981. Module: 3,
  1982. ErrLog: string(byterequest),
  1983. Status: 1,
  1984. Ctime: time.Now().Unix(),
  1985. Mtime: 0,
  1986. Source: "手机端核对医嘱",
  1987. RecordDate: item.AdviceDate,
  1988. }
  1989. service.CreateDoctorAdviceLog(adviceLog)
  1990. }
  1991. if advice.CheckState == 1 {
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1993. return
  1994. }
  1995. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1997. return
  1998. }
  1999. }
  2000. checker := adminUserInfo.AdminUser.Id
  2001. theTime := time.Now()
  2002. advices := models.DoctorAdvice{
  2003. CheckTime: theTime.Unix(),
  2004. Checker: checker,
  2005. UpdatedTime: time.Now().Unix(),
  2006. }
  2007. var err error
  2008. if groupno > 0 {
  2009. // 查询信息规挡的设置天数
  2010. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2011. if infor.ID > 0 && infor.WeekDay > 0 {
  2012. var cha_time int64
  2013. timeNowStr := time.Now().Format("2006-01-02")
  2014. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2015. //今日的日期减去设置的日期
  2016. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2017. if cha_time >= record_date {
  2018. //查询审核是否允许
  2019. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2020. //申请状态不允许的情况 拒绝修改
  2021. if infor.ApplicationStatus != 1 {
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2023. return
  2024. }
  2025. }
  2026. }
  2027. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2028. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2029. redis := service.RedisClient()
  2030. //清空key 值
  2031. redis.Set(key, "", time.Second)
  2032. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2033. redis.Set(keyTwo, "", time.Second)
  2034. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2035. redis.Set(keyThree, "", time.Second)
  2036. recordDate := theTime.Format("2006-01-02")
  2037. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2038. redis.Set(keyFour, "", time.Second)
  2039. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2040. redis.Set(keyFive, "", time.Second)
  2041. defer redis.Close()
  2042. } else {
  2043. if len(ids[0]) <= 0 {
  2044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2045. return
  2046. } else {
  2047. //t := time.Now().Format("2006-01-02")/**/
  2048. //timeLayout2 := "2006-01-02"
  2049. //loc, _ := time.LoadLocation("Local")
  2050. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2051. // 查询信息规挡的设置天数
  2052. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2053. if infor.ID > 0 {
  2054. var cha_time int64
  2055. timeNowStr := time.Now().Format("2006-01-02")
  2056. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2057. //今日的日期减去设置的日期
  2058. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2059. if cha_time >= advices.AdviceDate {
  2060. //查询审核是否允许
  2061. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2062. //申请状态不允许的情况 拒绝修改
  2063. if infor.ApplicationStatus != 1 {
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2065. return
  2066. }
  2067. }
  2068. }
  2069. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2070. //记录日志
  2071. byterequest, _ := json.Marshal(advices)
  2072. adviceLog := models.XtDoctorAdviceLog{
  2073. UserOrgId: adminUserInfo.Org.Id,
  2074. PatientId: advices.PatientId,
  2075. AdminUserId: advices.Checker,
  2076. Module: 3,
  2077. ErrLog: string(byterequest),
  2078. Status: 1,
  2079. Ctime: time.Now().Unix(),
  2080. Mtime: 0,
  2081. Source: "手机端核对医嘱",
  2082. RecordDate: advices.AdviceDate,
  2083. }
  2084. service.CreateDoctorAdviceLog(adviceLog)
  2085. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2086. redis := service.RedisClient()
  2087. //清空key 值
  2088. redis.Set(key, "", time.Second)
  2089. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2090. redis.Set(keyTwo, "", time.Second)
  2091. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2092. redis.Set(keyThree, "", time.Second)
  2093. recordDate := theTime.Format("2006-01-02")
  2094. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. redis.Set(keyFour, "", time.Second)
  2096. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2097. redis.Set(keyFive, "", time.Second)
  2098. defer redis.Close()
  2099. }
  2100. }
  2101. if err != nil {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2103. return
  2104. }
  2105. advice.Checker = checker
  2106. advice.CheckTime = theTime.Unix()
  2107. advice.CheckState = 1
  2108. c.ServeSuccessJSON(map[string]interface{}{
  2109. "msg": "ok",
  2110. "advice": advice,
  2111. })
  2112. } else if origin == 2 {
  2113. adminInfo := c.GetMobileAdminUserInfo()
  2114. var ids []string
  2115. advice_ids := c.GetString("advice_id")
  2116. ids = strings.Split(advice_ids, ",")
  2117. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2118. var err error
  2119. for _, item := range advices {
  2120. if item.CheckState == 1 {
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2122. return
  2123. }
  2124. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2126. return
  2127. }
  2128. item.Checker = adminInfo.AdminUser.Id
  2129. item.CheckTime = time.Now().Unix()
  2130. item.CheckState = 1
  2131. // 查询信息规挡的设置天数
  2132. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2133. if infor.ID > 0 {
  2134. var cha_time int64
  2135. timeNowStr := time.Now().Format("2006-01-02")
  2136. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2137. //今日的日期减去设置的日期
  2138. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2139. if cha_time >= record_date {
  2140. //查询审核是否允许
  2141. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2142. //申请状态不允许的情况 拒绝修改
  2143. if infor.ApplicationStatus != 1 {
  2144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2145. return
  2146. }
  2147. }
  2148. }
  2149. err = service.SaveHisDoctorAdvice(item)
  2150. //记录日志
  2151. byterequest, _ := json.Marshal(advices)
  2152. adviceLog := models.XtDoctorAdviceLog{
  2153. UserOrgId: adminInfo.Org.Id,
  2154. PatientId: item.PatientId,
  2155. AdminUserId: item.Checker,
  2156. Module: 3,
  2157. ErrLog: string(byterequest),
  2158. Status: 1,
  2159. Ctime: time.Now().Unix(),
  2160. Mtime: 0,
  2161. Source: "手机端核对His医嘱",
  2162. RecordDate: item.AdviceDate,
  2163. }
  2164. service.CreateDoctorAdviceLog(adviceLog)
  2165. redis := service.RedisClient()
  2166. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2167. //清空key 值
  2168. redis.Set(key, "", time.Second)
  2169. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2170. redis.Set(keyTwo, "", time.Second)
  2171. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2172. redis.Set(keyThree, "", time.Second)
  2173. theTime := time.Now()
  2174. recordDate := theTime.Format("2006-01-02")
  2175. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2176. redis.Set(keyFour, "", time.Second)
  2177. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2178. redis.Set(keyFive, "", time.Second)
  2179. defer redis.Close()
  2180. }
  2181. if err == nil {
  2182. c.ServeSuccessJSON(map[string]interface{}{
  2183. "msg": "ok",
  2184. "advice": advices,
  2185. })
  2186. } else {
  2187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2188. return
  2189. }
  2190. }
  2191. return
  2192. }
  2193. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2194. id, _ := c.GetInt64("patient", 0)
  2195. assessmentDate := c.GetString("assessment_date", "")
  2196. if id <= 0 || len(assessmentDate) != 10 {
  2197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2198. return
  2199. }
  2200. timeLayout := "2006-01-02"
  2201. loc, _ := time.LoadLocation("Local")
  2202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2203. if err != nil {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2205. return
  2206. }
  2207. theAssessmentDateTime := theTime.Unix()
  2208. adminUserInfo := c.GetMobileAdminUserInfo()
  2209. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2210. if patient.ID == 0 {
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2212. return
  2213. }
  2214. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2215. if getPEErr != nil {
  2216. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2218. return
  2219. }
  2220. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2221. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2222. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2223. var evaluation models.PredialysisEvaluation
  2224. if theEvaluation != nil {
  2225. evaluation = *theEvaluation
  2226. }
  2227. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2228. if code > 0 {
  2229. c.ServeFailJSONWithSGJErrorCode(code)
  2230. return
  2231. }
  2232. if theEvaluation == nil {
  2233. evaluation.CreatedTime = time.Now().Unix()
  2234. evaluation.Status = 1
  2235. evaluation.AssessmentDate = theAssessmentDateTime
  2236. evaluation.PatientId = id
  2237. evaluation.UserOrgId = adminUserInfo.Org.Id
  2238. if appRole.UserType == 2 || appRole.UserType == 1 {
  2239. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2240. evaluation.AssessmentTime = time.Now().Unix()
  2241. } else {
  2242. evaluation.Creater = adminUserInfo.AdminUser.Id
  2243. }
  2244. } else {
  2245. evaluation.UpdatedTime = time.Now().Unix()
  2246. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2247. if appRole.UserType == 2 || appRole.UserType == 1 {
  2248. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2249. evaluation.AssessmentTime = time.Now().Unix()
  2250. } else {
  2251. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2252. if evaluation.Creater == 0 {
  2253. evaluation.Creater = adminUserInfo.AdminUser.Id
  2254. }
  2255. }
  2256. }
  2257. //新增逻辑
  2258. var dewater_amount float64
  2259. dewater_amount = 0
  2260. if evaluation.DryWeight > 0 {
  2261. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2262. 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 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  2263. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2264. dewater_amount = dewater_amount * 1000
  2265. }
  2266. }
  2267. if dewater_amount <= 0 {
  2268. dewater_amount = 0
  2269. }
  2270. } else {
  2271. dewater_amount = 0
  2272. }
  2273. // 计算透析处方的相关超滤量
  2274. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2275. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2276. var lastDialysisPrescribe *models.DialysisPrescription
  2277. var dialysisSolution *models.DialysisSolution
  2278. var dialysisPrescribe *models.DialysisPrescription
  2279. var system_dialysisPrescribe *models.SystemPrescription
  2280. var mode_id int64
  2281. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2282. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2283. if schedual != nil {
  2284. // 获取透析模版
  2285. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2286. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2287. mode_id = schedual.ModeId
  2288. } else {
  2289. // 获取透析模版
  2290. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2291. if dialysisPrescribe == nil && dialysisSolution != nil {
  2292. mode_id = dialysisSolution.ModeId
  2293. }
  2294. if dialysisPrescribe == nil && dialysisSolution == nil {
  2295. mode_id = 0
  2296. }
  2297. }
  2298. // 插入透析处方
  2299. if dialysisPrescribe == nil && dialysisSolution != nil {
  2300. var newprescribe models.DialysisPrescription
  2301. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2302. newprescribe.PatientId = id
  2303. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2304. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2305. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2306. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2307. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2308. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2309. newprescribe.ModeId = dialysisSolution.ModeId
  2310. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2311. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2312. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2313. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2314. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2315. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2316. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2317. newprescribe.Glucose = dialysisSolution.Glucose
  2318. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2319. newprescribe.Kalium = dialysisSolution.Kalium
  2320. newprescribe.Sodium = dialysisSolution.Sodium
  2321. newprescribe.Calcium = dialysisSolution.Calcium
  2322. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2323. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2324. newprescribe.Conductivity = dialysisSolution.Conductivity
  2325. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2326. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2327. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2328. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2329. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2330. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2331. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2332. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2333. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2334. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2335. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2336. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2337. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2338. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2339. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2340. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2341. newprescribe.CreatedTime = time.Now().Unix()
  2342. newprescribe.UpdatedTime = time.Now().Unix()
  2343. newprescribe.RecordDate = theAssessmentDateTime
  2344. newprescribe.DewaterAmount = dewater_amount
  2345. newprescribe.TargetUltrafiltration = dewater_amount
  2346. newprescribe.Status = 1
  2347. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2348. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2349. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2350. newprescribe.Remark = lastDialysisPrescription.Remark
  2351. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2352. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2353. newprescribe.ID = dialysisPrescription.ID
  2354. if dialysisPrescription.ID == 0 {
  2355. if adminUserInfo.Org.Id == 10340 {
  2356. newprescribe.Sodium = 138
  2357. newprescribe.Bicarbonate = 31.1
  2358. newprescribe.DialysateFlow = 500
  2359. newprescribe.PrescribingNumber = 1
  2360. }
  2361. err := service.AddSigleRecord(&newprescribe)
  2362. //记录日志
  2363. byterequest, _ := json.Marshal(newprescribe)
  2364. prescriptionLog := models.XtDialysisPrescriptionLog{
  2365. UserOrgId: adminUserInfo.Org.Id,
  2366. Ctime: time.Now().Unix(),
  2367. Mtime: 0,
  2368. ErrLog: string(byterequest),
  2369. AdminUserId: adminUserInfo.AdminUser.Id,
  2370. RecordDate: newprescribe.RecordDate,
  2371. PatientId: id,
  2372. Source: "手机端新增透前评估插入处方",
  2373. Status: 1,
  2374. }
  2375. service.CreatePrescriptionLog(prescriptionLog)
  2376. //获取key,清空redis
  2377. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2378. redis := service.RedisClient()
  2379. //清空key 值
  2380. redis.Set(key, "", time.Second)
  2381. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2382. //清空key 值
  2383. redis.Set(keyOne, "", time.Second)
  2384. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2385. //清空key 值
  2386. redis.Set(keyTwo, "", time.Second)
  2387. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2388. redis.Set(keySix, "", time.Second)
  2389. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2390. redis.Set(keySeven, "", time.Second)
  2391. if err != nil {
  2392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2393. }
  2394. } else {
  2395. if adminUserInfo.Org.Id == 10340 {
  2396. newprescribe.Sodium = 138
  2397. newprescribe.Bicarbonate = 31.1
  2398. newprescribe.DialysateFlow = 500
  2399. }
  2400. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2401. //
  2402. if appRole.UserType == 2 || appRole.UserType == 1 {
  2403. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2404. if adminUserInfo.Org.Id == 9882 {
  2405. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2406. }
  2407. }
  2408. err := service.UpDateDialysisPrescription(&newprescribe)
  2409. //记录日志
  2410. byterequest, _ := json.Marshal(newprescribe)
  2411. prescriptionLog := models.XtDialysisPrescriptionLog{
  2412. UserOrgId: adminUserInfo.Org.Id,
  2413. Ctime: time.Now().Unix(),
  2414. Mtime: 0,
  2415. ErrLog: string(byterequest),
  2416. AdminUserId: adminUserInfo.AdminUser.Id,
  2417. RecordDate: newprescribe.RecordDate,
  2418. PatientId: id,
  2419. Source: "手机端新增透前评估插入处方",
  2420. Status: 1,
  2421. }
  2422. service.CreatePrescriptionLog(prescriptionLog)
  2423. //获取key,清空redis
  2424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2425. redis := service.RedisClient()
  2426. //清空key 值
  2427. redis.Set(key, "", time.Second)
  2428. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2429. //清空key 值
  2430. redis.Set(keyOne, "", time.Second)
  2431. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2432. //清空key 值
  2433. redis.Set(keyTwo, "", time.Second)
  2434. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2435. redis.Set(keySix, "", time.Second)
  2436. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2437. redis.Set(keySeven, "", time.Second)
  2438. if err != nil {
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2440. }
  2441. }
  2442. }
  2443. if dialysisPrescribe == nil && dialysisSolution == nil {
  2444. if lastDialysisPrescribe != nil {
  2445. var newprescribe models.DialysisPrescription
  2446. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2447. newprescribe.PatientId = id
  2448. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2449. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2450. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2451. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2452. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2453. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2454. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2455. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2456. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2457. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2458. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2459. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2460. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2461. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2462. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2463. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2464. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2465. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2466. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2467. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2468. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2469. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2470. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2471. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2472. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2473. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2474. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2475. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2476. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2477. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2478. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2479. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2480. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2481. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2482. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2483. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2484. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2485. newprescribe.CreatedTime = time.Now().Unix()
  2486. newprescribe.UpdatedTime = time.Now().Unix()
  2487. newprescribe.RecordDate = theAssessmentDateTime
  2488. newprescribe.DewaterAmount = dewater_amount
  2489. newprescribe.TargetUltrafiltration = dewater_amount
  2490. newprescribe.Status = 1
  2491. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2492. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2493. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  2494. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2495. }
  2496. newprescribe.Remark = lastDialysisPrescription.Remark
  2497. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2498. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2499. newprescribe.ID = dialysisPrescription.ID
  2500. if dialysisPrescription.ID == 0 {
  2501. if adminUserInfo.Org.Id == 10340 {
  2502. newprescribe.Sodium = 138
  2503. newprescribe.Bicarbonate = 31.1
  2504. newprescribe.DialysateFlow = 500
  2505. }
  2506. err := service.AddSigleRecord(&newprescribe)
  2507. //记录日志
  2508. byterequest, _ := json.Marshal(newprescribe)
  2509. prescriptionLog := models.XtDialysisPrescriptionLog{
  2510. UserOrgId: adminUserInfo.Org.Id,
  2511. Ctime: time.Now().Unix(),
  2512. Mtime: 0,
  2513. ErrLog: string(byterequest),
  2514. AdminUserId: adminUserInfo.AdminUser.Id,
  2515. RecordDate: newprescribe.RecordDate,
  2516. PatientId: id,
  2517. Source: "手机端新增透前评估插入处方",
  2518. Status: 1,
  2519. }
  2520. service.CreatePrescriptionLog(prescriptionLog)
  2521. //获取key,清空redis
  2522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2523. redis := service.RedisClient()
  2524. //清空key 值
  2525. redis.Set(key, "", time.Second)
  2526. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2527. //清空key 值
  2528. redis.Set(keyOne, "", time.Second)
  2529. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2530. //清空key 值
  2531. redis.Set(keyTwo, "", time.Second)
  2532. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2533. redis.Set(keySix, "", time.Second)
  2534. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2535. redis.Set(keySeven, "", time.Second)
  2536. if err != nil {
  2537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2538. }
  2539. } else {
  2540. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2541. //
  2542. if appRole.UserType == 2 || appRole.UserType == 1 {
  2543. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2544. if adminUserInfo.Org.Id == 9882 {
  2545. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2546. }
  2547. }
  2548. err := service.UpDateDialysisPrescription(&newprescribe)
  2549. //记录日志
  2550. byterequest, _ := json.Marshal(newprescribe)
  2551. prescriptionLog := models.XtDialysisPrescriptionLog{
  2552. UserOrgId: adminUserInfo.Org.Id,
  2553. Ctime: time.Now().Unix(),
  2554. Mtime: 0,
  2555. ErrLog: string(byterequest),
  2556. AdminUserId: adminUserInfo.AdminUser.Id,
  2557. RecordDate: newprescribe.RecordDate,
  2558. PatientId: id,
  2559. Source: "手机端新增透前评估插入处方",
  2560. Status: 1,
  2561. }
  2562. service.CreatePrescriptionLog(prescriptionLog)
  2563. //获取key,清空redis
  2564. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2565. redis := service.RedisClient()
  2566. //清空key 值
  2567. redis.Set(key, "", time.Second)
  2568. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2569. //清空key 值
  2570. redis.Set(keyOne, "", time.Second)
  2571. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2572. //清空key 值
  2573. redis.Set(keyTwo, "", time.Second)
  2574. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2575. redis.Set(keySix, "", time.Second)
  2576. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2577. redis.Set(keySeven, "", time.Second)
  2578. if err != nil {
  2579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2580. }
  2581. }
  2582. if err != nil {
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2584. }
  2585. } else if system_dialysisPrescribe != nil {
  2586. var newprescribe models.DialysisPrescription
  2587. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2588. newprescribe.PatientId = id
  2589. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2590. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2591. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2592. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2593. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2594. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2595. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2596. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2597. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2598. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2599. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2600. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2601. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2602. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2603. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2604. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2605. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2606. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2607. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2608. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2609. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2610. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2611. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2612. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2613. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2614. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2615. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2616. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2617. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2618. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2619. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2620. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2621. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2622. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2623. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2624. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2625. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2626. newprescribe.CreatedTime = time.Now().Unix()
  2627. newprescribe.UpdatedTime = time.Now().Unix()
  2628. newprescribe.RecordDate = theAssessmentDateTime
  2629. newprescribe.DewaterAmount = dewater_amount
  2630. newprescribe.TargetUltrafiltration = dewater_amount
  2631. newprescribe.Status = 1
  2632. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2633. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2634. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2635. newprescribe.Remark = lastDialysisPrescription.Remark
  2636. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2637. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2638. newprescribe.ID = dialysisPrescription.ID
  2639. if dialysisPrescription.ID == 0 {
  2640. if adminUserInfo.Org.Id == 10340 {
  2641. newprescribe.Sodium = 138
  2642. newprescribe.Bicarbonate = 31.1
  2643. newprescribe.DialysateFlow = 500
  2644. }
  2645. err := service.AddSigleRecord(&newprescribe)
  2646. //记录日志
  2647. byterequest, _ := json.Marshal(newprescribe)
  2648. prescriptionLog := models.XtDialysisPrescriptionLog{
  2649. UserOrgId: adminUserInfo.Org.Id,
  2650. Ctime: time.Now().Unix(),
  2651. Mtime: 0,
  2652. ErrLog: string(byterequest),
  2653. AdminUserId: adminUserInfo.AdminUser.Id,
  2654. RecordDate: newprescribe.RecordDate,
  2655. PatientId: id,
  2656. Source: "手机端新增透前评估插入处方",
  2657. Status: 1,
  2658. }
  2659. service.CreatePrescriptionLog(prescriptionLog)
  2660. //获取key,清空redis
  2661. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2662. redis := service.RedisClient()
  2663. //清空key 值
  2664. redis.Set(key, "", time.Second)
  2665. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2666. //清空key 值
  2667. redis.Set(keyOne, "", time.Second)
  2668. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2669. //清空key 值
  2670. redis.Set(keyTwo, "", time.Second)
  2671. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2672. redis.Set(keySix, "", time.Second)
  2673. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2674. redis.Set(keySeven, "", time.Second)
  2675. if err != nil {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2677. }
  2678. } else {
  2679. if adminUserInfo.Org.Id == 10340 {
  2680. newprescribe.Sodium = 138
  2681. newprescribe.Bicarbonate = 31.1
  2682. newprescribe.DialysateFlow = 500
  2683. }
  2684. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2685. //
  2686. if appRole.UserType == 2 || appRole.UserType == 1 {
  2687. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2688. if adminUserInfo.Org.Id == 9882 {
  2689. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2690. }
  2691. }
  2692. err := service.UpDateDialysisPrescription(&newprescribe)
  2693. //记录日志
  2694. byterequest, _ := json.Marshal(newprescribe)
  2695. prescriptionLog := models.XtDialysisPrescriptionLog{
  2696. UserOrgId: adminUserInfo.Org.Id,
  2697. Ctime: time.Now().Unix(),
  2698. Mtime: 0,
  2699. ErrLog: string(byterequest),
  2700. AdminUserId: adminUserInfo.AdminUser.Id,
  2701. RecordDate: newprescribe.RecordDate,
  2702. PatientId: id,
  2703. Source: "手机端新增透前评估插入处方",
  2704. Status: 1,
  2705. }
  2706. service.CreatePrescriptionLog(prescriptionLog)
  2707. //获取key,清空redis
  2708. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2709. redis := service.RedisClient()
  2710. //清空key 值
  2711. redis.Set(key, "", time.Second)
  2712. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2713. //清空key 值
  2714. redis.Set(keyOne, "", time.Second)
  2715. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2716. //清空key 值
  2717. redis.Set(keyTwo, "", time.Second)
  2718. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2719. redis.Set(keySix, "", time.Second)
  2720. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2721. redis.Set(keySeven, "", time.Second)
  2722. if err != nil {
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2724. }
  2725. }
  2726. if err != nil {
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2728. }
  2729. } else {
  2730. var newprescribe models.DialysisPrescription
  2731. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2732. newprescribe.PatientId = id
  2733. newprescribe.ModeId = mode_id
  2734. newprescribe.CreatedTime = time.Now().Unix()
  2735. newprescribe.UpdatedTime = time.Now().Unix()
  2736. newprescribe.RecordDate = theAssessmentDateTime
  2737. newprescribe.DewaterAmount = dewater_amount
  2738. newprescribe.TargetUltrafiltration = dewater_amount
  2739. newprescribe.Status = 1
  2740. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2741. if dialysisPrescription.ID > 0 {
  2742. newprescribe.ID = dialysisPrescription.ID
  2743. }
  2744. if dialysisPrescription.ID == 0 {
  2745. if adminUserInfo.Org.Id == 10340 {
  2746. newprescribe.Sodium = 138
  2747. newprescribe.Bicarbonate = 31.1
  2748. newprescribe.DialysateFlow = 500
  2749. }
  2750. err := service.AddSigleRecord(&newprescribe)
  2751. //获取key,清空redis
  2752. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2753. redis := service.RedisClient()
  2754. //清空key 值
  2755. redis.Set(key, "", time.Second)
  2756. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2757. //清空key 值
  2758. redis.Set(keyOne, "", time.Second)
  2759. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2760. //清空key 值
  2761. redis.Set(keyTwo, "", time.Second)
  2762. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2763. redis.Set(keySix, "", time.Second)
  2764. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2765. redis.Set(keySeven, "", time.Second)
  2766. if err != nil {
  2767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2768. }
  2769. } else {
  2770. if adminUserInfo.Org.Id == 10340 {
  2771. newprescribe.Sodium = 138
  2772. newprescribe.Bicarbonate = 31.1
  2773. newprescribe.DialysateFlow = 500
  2774. }
  2775. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2776. //
  2777. if appRole.UserType == 2 || appRole.UserType == 1 {
  2778. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2779. if adminUserInfo.Org.Id == 9882 {
  2780. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2781. }
  2782. }
  2783. err := service.UpDateDialysisPrescription(&newprescribe)
  2784. //记录日志
  2785. byterequest, _ := json.Marshal(newprescribe)
  2786. prescriptionLog := models.XtDialysisPrescriptionLog{
  2787. UserOrgId: adminUserInfo.Org.Id,
  2788. Ctime: time.Now().Unix(),
  2789. Mtime: 0,
  2790. ErrLog: string(byterequest),
  2791. AdminUserId: adminUserInfo.AdminUser.Id,
  2792. RecordDate: newprescribe.RecordDate,
  2793. PatientId: id,
  2794. Source: "手机端新增透前评估插入处方",
  2795. Status: 1,
  2796. }
  2797. service.CreatePrescriptionLog(prescriptionLog)
  2798. //获取key,清空redis
  2799. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2800. redis := service.RedisClient()
  2801. //清空key 值
  2802. redis.Set(key, "", time.Second)
  2803. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2804. //清空key 值
  2805. redis.Set(keyOne, "", time.Second)
  2806. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2807. //清空key 值
  2808. redis.Set(keyTwo, "", time.Second)
  2809. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2810. redis.Set(keySix, "", time.Second)
  2811. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2812. redis.Set(keySeven, "", time.Second)
  2813. if err != nil {
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2815. }
  2816. }
  2817. if err != nil {
  2818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2819. }
  2820. }
  2821. }
  2822. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2823. // if dialysisPrescribe != nil {
  2824. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2825. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2826. // dialysisPrescribe.DewaterAmount = dewater_amount
  2827. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2828. // dialysisPrescribe.Status = 1
  2829. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2830. // if updateErr != nil {
  2831. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2832. // }
  2833. // }
  2834. // 查询信息规挡的设置天数
  2835. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2836. if infor.ID > 0 && infor.WeekDay > 0 {
  2837. var cha_time int64
  2838. timeNowStr := time.Now().Format("2006-01-02")
  2839. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2840. //今日的日期减去设置的日期
  2841. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2842. if cha_time >= evaluation.AssessmentDate {
  2843. //查询审核是否允许
  2844. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  2845. //申请状态不允许的情况 拒绝修改
  2846. if infor.ApplicationStatus != 1 {
  2847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2848. return
  2849. }
  2850. }
  2851. }
  2852. err = service.UpadatePredialysisEvaluation(&evaluation)
  2853. //记录日志
  2854. byterequest, _ := json.Marshal(evaluation)
  2855. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2856. UserOrgId: evaluation.UserOrgId,
  2857. AdminUserId: adminUserInfo.AdminUser.Id,
  2858. ErrLog: string(byterequest),
  2859. PatientId: evaluation.PatientId,
  2860. RecordDate: evaluation.AssessmentDate,
  2861. Ctime: time.Now().Unix(),
  2862. Mtime: 0,
  2863. Status: 1,
  2864. Source: "手机端保存透前评估",
  2865. }
  2866. service.CreateBeforLog(beforeDislysisLog)
  2867. finish := models.XtDialysisFinish{
  2868. IsFinish: 1,
  2869. UserOrgId: adminUserInfo.Org.Id,
  2870. Status: 1,
  2871. Ctime: time.Now().Unix(),
  2872. Mtime: 0,
  2873. Module: 3,
  2874. RecordDate: evaluation.AssessmentDate,
  2875. Sourse: 1,
  2876. PatientId: id,
  2877. }
  2878. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2879. if dialysisFinish.ID == 0 {
  2880. service.CreateDialysisFinish(finish)
  2881. }
  2882. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2883. redis := service.RedisClient()
  2884. defer redis.Close()
  2885. //清空key 值
  2886. redis.Set(key, "", time.Second)
  2887. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2888. redis.Set(keyOne, "", time.Second)
  2889. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2890. redis.Set(keyTwo, "", time.Second)
  2891. if err != nil {
  2892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2893. return
  2894. }
  2895. c.ServeSuccessJSON(map[string]interface{}{
  2896. "msg": "ok",
  2897. "evaluation": evaluation,
  2898. })
  2899. return
  2900. }
  2901. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2902. dataBody := make(map[string]interface{}, 0)
  2903. err := json.Unmarshal(data, &dataBody)
  2904. utils.InfoLog(string(data))
  2905. if err != nil {
  2906. utils.ErrorLog(err.Error())
  2907. code = enums.ErrorCodeParamWrong
  2908. return
  2909. }
  2910. // if method == "create" {
  2911. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2912. utils.ErrorLog("mode")
  2913. code = enums.ErrorCodeParamWrong
  2914. return
  2915. }
  2916. mode := int64(dataBody["mode"].(float64))
  2917. if mode <= 0 {
  2918. utils.ErrorLog("mode <= 0")
  2919. code = enums.ErrorCodeParamWrong
  2920. return
  2921. }
  2922. solution.ModeId = mode
  2923. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2924. utils.ErrorLog("mode_name")
  2925. code = enums.ErrorCodeParamWrong
  2926. return
  2927. }
  2928. modeName, _ := dataBody["mode_name"].(string)
  2929. if len(modeName) == 0 {
  2930. utils.ErrorLog("len(mode_name) == 0")
  2931. code = enums.ErrorCodeParamWrong
  2932. return
  2933. }
  2934. solution.ModeName = modeName
  2935. solution.Name = modeName
  2936. // }
  2937. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2938. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2939. solution.DialysisDuration = dialysisDuration
  2940. }
  2941. if dataBody["dialysis_duration"] != nil {
  2942. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2943. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2944. solution.DialysisDuration = dialysisDuration
  2945. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2946. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2947. solution.DialysisDuration = dialysisDuration
  2948. }
  2949. }
  2950. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2951. dialyzer := int64(dataBody["dialyzer"].(float64))
  2952. solution.Dialyzer = dialyzer
  2953. }
  2954. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2955. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2956. solution.PerfusionApparatus = perfusionApparatus
  2957. }
  2958. if dataBody["blood_flow_volume"] != nil {
  2959. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2960. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2961. solution.BloodFlowVolume = bloodFlowVolume
  2962. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2963. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2964. solution.BloodFlowVolume = bloodFlowVolume
  2965. }
  2966. }
  2967. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2968. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2969. solution.HemodialysisMachine = hemodialysisMachine
  2970. }
  2971. if dataBody["dewater"] != nil {
  2972. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2973. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2974. solution.Dewater = dewater
  2975. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  2976. dewater := dataBody["dewater"].(float64)
  2977. solution.Dewater = dewater
  2978. }
  2979. }
  2980. if dataBody["replacement_total"] != nil {
  2981. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2982. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2983. solution.ReplacementTotal = replacementTotal
  2984. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2985. replacementTotal := dataBody["replacement_total"].(float64)
  2986. solution.ReplacementTotal = replacementTotal
  2987. }
  2988. }
  2989. if dataBody["displace_liqui"] != nil {
  2990. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2991. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2992. solution.DisplaceLiqui = displaceLiqui
  2993. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2994. displaceLiqui := dataBody["displace_liqui"].(float64)
  2995. solution.DisplaceLiqui = displaceLiqui
  2996. }
  2997. }
  2998. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2999. replacementWay := int64(dataBody["replacement_way"].(float64))
  3000. solution.ReplacementWay = replacementWay
  3001. }
  3002. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3003. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3004. solution.Anticoagulant = anticoagulant
  3005. }
  3006. if dataBody["anticoagulant_shouji"] != nil {
  3007. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3008. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3009. solution.AnticoagulantShouji = anticoagulantShouji
  3010. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3011. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3012. solution.AnticoagulantShouji = anticoagulantShouji
  3013. }
  3014. }
  3015. if dataBody["anticoagulant_weichi"] != nil {
  3016. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3017. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3018. solution.AnticoagulantWeichi = anticoagulantWeichi
  3019. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3020. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3021. solution.AnticoagulantWeichi = anticoagulantWeichi
  3022. }
  3023. }
  3024. if dataBody["anticoagulant_zongliang"] != nil {
  3025. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3026. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3027. solution.AnticoagulantZongliang = anticoagulantZongliang
  3028. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3029. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3030. solution.AnticoagulantZongliang = anticoagulantZongliang
  3031. }
  3032. }
  3033. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3034. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3035. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3036. }
  3037. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3038. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3039. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3040. }
  3041. if dataBody["kalium"] != nil {
  3042. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3043. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3044. solution.Kalium = kalium
  3045. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3046. kalium := dataBody["kalium"].(float64)
  3047. solution.Kalium = kalium
  3048. }
  3049. }
  3050. if dataBody["sodium"] != nil {
  3051. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3052. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3053. solution.Sodium = sodium
  3054. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3055. sodium := dataBody["sodium"].(float64)
  3056. solution.Sodium = sodium
  3057. }
  3058. }
  3059. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3060. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3061. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3062. solution.Calcium = calcium
  3063. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3064. calcium := dataBody["calcium"].(float64)
  3065. solution.Calcium = calcium
  3066. }
  3067. }
  3068. if dataBody["bicarbonate"] != nil {
  3069. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3070. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3071. solution.Bicarbonate = bicarbonate
  3072. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3073. bicarbonate := dataBody["bicarbonate"].(float64)
  3074. solution.Bicarbonate = bicarbonate
  3075. }
  3076. }
  3077. if dataBody["glucose"] != nil {
  3078. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3079. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3080. solution.Glucose = glucose
  3081. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3082. glucose := dataBody["glucose"].(float64)
  3083. solution.Glucose = glucose
  3084. }
  3085. }
  3086. // if dataBody["dry_weight"] != nil {
  3087. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3088. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3089. // solution.DryWeight = dryWeight
  3090. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3091. // dryWeight := dataBody["dry_weight"].(float64)
  3092. // solution.DryWeight = dryWeight
  3093. // }
  3094. // }
  3095. if dataBody["dialysate_flow"] != nil {
  3096. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3097. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3098. solution.DialysateFlow = dialysateFlow
  3099. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3100. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3101. solution.DialysateFlow = dialysateFlow
  3102. }
  3103. }
  3104. if dataBody["dialysate_temperature"] != nil {
  3105. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3106. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3107. solution.DialysateTemperature = dialysateTemperature
  3108. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3109. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3110. solution.DialysateTemperature = dialysateTemperature
  3111. }
  3112. }
  3113. if dataBody["conductivity"] != nil {
  3114. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3115. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3116. solution.Conductivity = conductivity
  3117. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3118. conductivity := dataBody["conductivity"].(float64)
  3119. solution.Conductivity = conductivity
  3120. }
  3121. }
  3122. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3123. remark := dataBody["remark"].(string)
  3124. solution.Remark = remark
  3125. }
  3126. if dataBody["dialysis_duration_hour"] != nil {
  3127. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3128. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3129. solution.DialysisDurationHour = dialysisDurationHour
  3130. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3131. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3132. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3133. }
  3134. }
  3135. if dataBody["dialysis_duration_minute"] != nil {
  3136. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3137. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3138. solution.DialysisDurationMinute = dialysisDurationMinute
  3139. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3140. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3141. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3142. }
  3143. }
  3144. if dataBody["target_ultrafiltration"] != nil {
  3145. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3146. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3147. solution.TargetUltrafiltration = targetUltrafiltration
  3148. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3149. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3150. solution.TargetUltrafiltration = targetUltrafiltration
  3151. }
  3152. }
  3153. if dataBody["dialysate_formulation"] != nil {
  3154. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3155. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3156. solution.DialysateFormulation = dialysateFormulation
  3157. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3158. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3159. solution.DialysateFormulation = int64(dialysateFormulation)
  3160. }
  3161. }
  3162. return
  3163. }
  3164. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3165. dataBody := make(map[string]interface{}, 0)
  3166. err := json.Unmarshal(data, &dataBody)
  3167. utils.InfoLog(string(data))
  3168. if err != nil {
  3169. utils.ErrorLog(err.Error())
  3170. code = enums.ErrorCodeParamWrong
  3171. return
  3172. }
  3173. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3174. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3175. evaluation.WeightBefore = weightVefore
  3176. }
  3177. // fmt.Println(dataBody["dry_weight"])
  3178. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3179. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3180. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3181. fmt.Println(additionalWeight)
  3182. evaluation.DryWeight = additionalWeight
  3183. }
  3184. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3185. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3186. fmt.Println(additionalWeight)
  3187. evaluation.AdditionalWeight = additionalWeight
  3188. }
  3189. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3190. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3191. evaluation.Temperature = Temperature
  3192. }
  3193. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3194. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3195. evaluation.SystolicBloodPressure = systolicBloodPressure
  3196. }
  3197. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3198. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3199. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3200. }
  3201. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3202. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3203. evaluation.PulseFrequency = pulseFrequency
  3204. }
  3205. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3206. breathingRate := dataBody["breathing_rate"].(string)
  3207. evaluation.BreathingRate = breathingRate
  3208. }
  3209. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3210. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3211. evaluation.LastPostDialysis = lastPostDialysis
  3212. }
  3213. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3214. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3215. evaluation.DialysisInterphase = dialysisInterphase
  3216. }
  3217. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3218. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3219. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3220. }
  3221. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3222. catheter, _ := dataBody["catheter"].(string)
  3223. evaluation.Catheter = catheter
  3224. }
  3225. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3226. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3227. evaluation.CatheterBend = catheter_bend
  3228. }
  3229. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3230. Complication, _ := dataBody["complication"].(string)
  3231. evaluation.Complication = Complication
  3232. }
  3233. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3234. remark := dataBody["remark"].(string)
  3235. evaluation.Remark = remark
  3236. }
  3237. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3238. machine_type := dataBody["machine_type"].(string)
  3239. evaluation.MachineType = machine_type
  3240. }
  3241. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3242. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3243. evaluation.BloodAccessPartId = blood_access_part_id
  3244. }
  3245. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3246. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3247. // evaluation.BloodAccessPartId = blood_access_part_id
  3248. //}
  3249. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3250. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3251. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3252. }
  3253. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3254. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3255. evaluation.InternalFistula = internal_fistula
  3256. }
  3257. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3258. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3259. evaluation.InternalFistulaSkin = internal_fistula_skin
  3260. }
  3261. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3262. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3263. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3264. evaluation.IsHemorrhage = is_hemorrhage
  3265. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3266. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3267. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3268. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3269. is_hemorrhage = 0
  3270. }
  3271. evaluation.IsHemorrhage = is_hemorrhage
  3272. if is_hemorrhage == 1 {
  3273. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3274. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3275. evaluation.Hemorrhage = hemorrhage
  3276. }
  3277. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3278. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3279. evaluation.HemorrhageOther = hemorrhage_other
  3280. }
  3281. }
  3282. } else {
  3283. evaluation.IsHemorrhage = 0
  3284. }
  3285. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3286. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3287. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3288. }
  3289. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3290. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3291. evaluation.InternalFistulaOther = internal_fistula_other
  3292. }
  3293. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3294. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3295. evaluation.BloodAccessNoise = blood_access_noise
  3296. }
  3297. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3298. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3299. puncture_way := dataBody["puncture_way"].(string)
  3300. evaluation.PunctureWay = puncture_way
  3301. }
  3302. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3303. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3304. evaluation.VenousCatheterization = venous_catheterization
  3305. }
  3306. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3307. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3308. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3309. }
  3310. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3311. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3312. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3313. }
  3314. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3315. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3316. evaluation.DuctusArantii = ductus_arantii
  3317. }
  3318. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3319. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3320. evaluation.EmergencyTreatment = emergency_treatment
  3321. }
  3322. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3323. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3324. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3325. }
  3326. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3327. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3328. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3329. evaluation.DialysisCount = dialysis_count
  3330. }
  3331. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3332. is_infect, _ := dataBody["is_infect"].(string)
  3333. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3334. evaluation.IsInfect = infect
  3335. }
  3336. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3337. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3338. evaluation.Exposed = exposed
  3339. }
  3340. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3341. skin, _ := dataBody["skin"].(string)
  3342. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3343. evaluation.Skin = skin
  3344. }
  3345. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3346. skin_other, _ := dataBody["skin_other"].(string)
  3347. evaluation.SkinOther = skin_other
  3348. }
  3349. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3350. infect_other, _ := dataBody["infect_other"].(string)
  3351. evaluation.InfectOther = infect_other
  3352. }
  3353. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3354. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3355. evaluation.DuctusArantiiOther = ductus_arantii_other
  3356. }
  3357. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3358. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3359. evaluation.PunctureNeedle = punctureNeedle
  3360. }
  3361. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3362. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3363. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3364. }
  3365. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3366. pinholing := dataBody["pinholing"].(string)
  3367. evaluation.Phinholing = pinholing
  3368. }
  3369. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3370. catheter_suture := dataBody["catheter_suture"].(string)
  3371. evaluation.CatheterSuture = catheter_suture
  3372. }
  3373. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3374. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3375. evaluation.CatheterSutureOther = catheter_suture_other
  3376. }
  3377. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3378. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3379. evaluation.UrineVolume = urine_volume
  3380. }
  3381. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3382. edema := dataBody["edema"].(string)
  3383. evaluation.Edema = edema
  3384. }
  3385. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  3386. specialTreatment := dataBody["special_treatment"].(string)
  3387. evaluation.SpecialTreatment = specialTreatment
  3388. }
  3389. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  3390. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  3391. evaluation.CatheterMaintenance = catheter_maintenance
  3392. }
  3393. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  3394. thromubusType := int64(dataBody["thromubus_type"].(float64))
  3395. evaluation.ThromubusType = thromubusType
  3396. }
  3397. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  3398. thrombus_av := dataBody["thrombus_av"].(string)
  3399. evaluation.ThrombusAv = thrombus_av
  3400. }
  3401. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  3402. thromubus_a := dataBody["thromubus_a"].(string)
  3403. evaluation.ThromubusA = thromubus_a
  3404. }
  3405. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  3406. thromubus_v := dataBody["thromubus_v"].(string)
  3407. evaluation.ThromubusV = thromubus_v
  3408. }
  3409. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  3410. dehydration := dataBody["dehydration"].(string)
  3411. evaluation.Dehydration = dehydration
  3412. }
  3413. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  3414. period := int64(dataBody["period"].(float64))
  3415. evaluation.Period = period
  3416. }
  3417. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  3418. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  3419. evaluation.EstimatedFoodIntake = estimated_food_intake
  3420. }
  3421. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  3422. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  3423. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  3424. }
  3425. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  3426. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  3427. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  3428. }
  3429. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  3430. urea_befor := dataBody["urea_befor"].(string)
  3431. evaluation.UreaBefor = urea_befor
  3432. }
  3433. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  3434. suction := dataBody["suction"].(string)
  3435. evaluation.Suction = suction
  3436. }
  3437. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  3438. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  3439. evaluation.WeightBeforRemake = weight_befor_remake
  3440. }
  3441. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  3442. height := dataBody["height"].(string)
  3443. evaluation.Height = height
  3444. }
  3445. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  3446. age := dataBody["age"].(string)
  3447. evaluation.Age = age
  3448. }
  3449. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  3450. his_department := dataBody["his_department"].(string)
  3451. evaluation.HisDepartment = his_department
  3452. }
  3453. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  3454. his_bed := dataBody["his_bed"].(string)
  3455. evaluation.HisBed = his_bed
  3456. }
  3457. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  3458. point_puncture := dataBody["point_puncture"].(string)
  3459. evaluation.PointPuncture = point_puncture
  3460. }
  3461. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  3462. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  3463. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  3464. }
  3465. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  3466. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  3467. evaluation.SkinSiteCatheterization = skin_site_catheterization
  3468. }
  3469. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  3470. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  3471. evaluation.WhetherUnobstructed = whether_unobstructed
  3472. }
  3473. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  3474. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  3475. evaluation.LienNecessary = lien_necessary
  3476. }
  3477. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  3478. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  3479. timeLayout := "2006-01-02"
  3480. loc, _ := time.LoadLocation("Local")
  3481. var startTime int64
  3482. if len(pathway_formation_time) > 0 {
  3483. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  3484. startTime = theTime.Unix()
  3485. }
  3486. evaluation.PathwayFormationTime = startTime
  3487. }
  3488. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  3489. befor_symptoms := dataBody["befor_symptoms"].(string)
  3490. evaluation.BeforSymptoms = befor_symptoms
  3491. }
  3492. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  3493. washing_time, _ := dataBody["washing_time"].(string)
  3494. evaluation.WashingTime = washing_time
  3495. }
  3496. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  3497. warsh_count, _ := dataBody["warsh_count"].(string)
  3498. evaluation.WarshCount = warsh_count
  3499. }
  3500. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  3501. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  3502. evaluation.PunctureNeedleDirection = puncture_needle_direction
  3503. }
  3504. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  3505. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  3506. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  3507. }
  3508. return
  3509. }
  3510. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3511. dataBody := make(map[string]interface{}, 0)
  3512. err := json.Unmarshal(data, &dataBody)
  3513. if err != nil {
  3514. utils.ErrorLog(err.Error())
  3515. code = enums.ErrorCodeParamWrong
  3516. return
  3517. }
  3518. timeLayout := "2006-01-02"
  3519. loc, _ := time.LoadLocation("Local")
  3520. isChild := false
  3521. if action == "create" {
  3522. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3523. utils.ErrorLog("advice_type")
  3524. code = enums.ErrorCodeParamWrong
  3525. return
  3526. }
  3527. adviceType := int64(dataBody["advice_type"].(float64))
  3528. if adviceType != 1 && adviceType != 2 {
  3529. utils.ErrorLog("advice_type != 1&&2")
  3530. code = enums.ErrorCodeParamWrong
  3531. return
  3532. }
  3533. advice.AdviceType = adviceType
  3534. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3535. utils.ErrorLog("advice_date")
  3536. code = enums.ErrorCodeParamWrong
  3537. return
  3538. }
  3539. adviceDate, _ := dataBody["advice_date"].(string)
  3540. if len(adviceDate) == 0 {
  3541. utils.ErrorLog("len(adviceDate) == 0")
  3542. code = enums.ErrorCodeParamWrong
  3543. return
  3544. }
  3545. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3546. if err != nil {
  3547. utils.ErrorLog(err.Error())
  3548. code = enums.ErrorCodeParamWrong
  3549. return
  3550. }
  3551. advice.AdviceDate = theTime.Unix()
  3552. advice.RecordDate = theTime.Unix()
  3553. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3554. parentId := int64(dataBody["parent_id"].(float64))
  3555. advice.ParentId = parentId
  3556. if parentId > 0 {
  3557. isChild = true
  3558. }
  3559. }
  3560. } else {
  3561. isChild = advice.ParentId > 0
  3562. }
  3563. if !isChild {
  3564. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3565. utils.ErrorLog("start_time")
  3566. code = enums.ErrorCodeParamWrong
  3567. return
  3568. }
  3569. startTime, _ := dataBody["start_time"].(string)
  3570. if len(startTime) == 0 {
  3571. utils.ErrorLog("len(start_time) == 0")
  3572. code = enums.ErrorCodeParamWrong
  3573. return
  3574. }
  3575. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3576. if err != nil {
  3577. utils.ErrorLog(err.Error())
  3578. code = enums.ErrorCodeParamWrong
  3579. return
  3580. }
  3581. advice.StartTime = theTime.Unix()
  3582. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3583. deliveryWay, _ := dataBody["delivery_way"].(string)
  3584. advice.DeliveryWay = deliveryWay
  3585. }
  3586. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3587. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3588. advice.ExecutionFrequency = executionFrequency
  3589. }
  3590. }
  3591. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3592. deliveryWay, _ := dataBody["delivery_way"].(string)
  3593. advice.DeliveryWay = deliveryWay
  3594. }
  3595. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3596. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3597. advice.ExecutionFrequency = executionFrequency
  3598. }
  3599. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3600. utils.ErrorLog("advice_name")
  3601. code = enums.ErrorCodeParamWrong
  3602. return
  3603. }
  3604. adviceName, _ := dataBody["advice_name"].(string)
  3605. if len(adviceName) == 0 {
  3606. utils.ErrorLog("len(advice_name) == 0")
  3607. code = enums.ErrorCodeParamWrong
  3608. return
  3609. }
  3610. advice.AdviceName = adviceName
  3611. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3612. adviceDsc, _ := dataBody["advice_desc"].(string)
  3613. advice.AdviceDesc = adviceDsc
  3614. }
  3615. if dataBody["way"] == nil {
  3616. advice.Way = 0
  3617. } else {
  3618. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3619. way := int64(dataBody["way"].(float64))
  3620. advice.Way = way
  3621. }
  3622. }
  3623. if dataBody["drug_id"] == nil {
  3624. advice.DrugId = 0
  3625. } else {
  3626. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3627. drug_id := int64(dataBody["drug_id"].(float64))
  3628. advice.DrugId = drug_id
  3629. }
  3630. }
  3631. if dataBody["drug_name_id"] == nil {
  3632. advice.DrugNameId = 0
  3633. } else {
  3634. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3635. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3636. advice.DrugNameId = drug_name_id
  3637. }
  3638. }
  3639. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3640. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3641. advice.SingleDose = singleDose
  3642. }
  3643. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3644. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3645. advice.SingleDoseUnit = singleDoseUnit
  3646. }
  3647. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3648. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3649. advice.DrugSpec = drugSpec
  3650. }
  3651. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3652. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3653. advice.DrugSpecUnit = drugSpecUnit
  3654. }
  3655. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3656. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3657. advice.PrescribingNumber = prescribingNumber
  3658. }
  3659. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3660. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3661. advice.PrescribingNumberUnit = prescribingNumberUnit
  3662. }
  3663. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3664. remark, _ := dataBody["remark"].(string)
  3665. advice.Remark = remark
  3666. }
  3667. return
  3668. }
  3669. func (c *PatientApiController) GetPatientEducation() {
  3670. patientID, _ := c.GetInt64("patient_id", 0)
  3671. page, _ := c.GetInt64("page", 0)
  3672. limit, _ := c.GetInt64("limit", 0)
  3673. startTime := c.GetString("start_time", "")
  3674. endTime := c.GetString("end_time", "")
  3675. if page <= 0 {
  3676. page = 1
  3677. }
  3678. if limit <= 0 {
  3679. limit = 10
  3680. }
  3681. if patientID <= 0 {
  3682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3683. return
  3684. }
  3685. timeLayout := "2006-01-02"
  3686. loc, _ := time.LoadLocation("Local")
  3687. var theStartTIme int64
  3688. if len(startTime) > 0 {
  3689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3690. if err != nil {
  3691. theStartTIme = 0
  3692. }
  3693. theStartTIme = theTime.Unix()
  3694. }
  3695. var theEndtTIme int64
  3696. if len(endTime) > 0 {
  3697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3698. if err != nil {
  3699. theEndtTIme = 0
  3700. }
  3701. theEndtTIme = theTime.Unix()
  3702. }
  3703. adminUserInfo := c.GetMobileAdminUserInfo()
  3704. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3705. c.ServeSuccessJSON(map[string]interface{}{
  3706. "total": total,
  3707. "edus": edus,
  3708. })
  3709. return
  3710. }
  3711. func (c *PatientApiController) GetPatientSchedulesList() {
  3712. patientID, _ := c.GetInt64("patient_id", 0)
  3713. page, _ := c.GetInt64("page", 0)
  3714. limit, _ := c.GetInt64("limit", 0)
  3715. if patientID <= 0 {
  3716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3717. return
  3718. }
  3719. adminUserInfo := c.GetMobileAdminUserInfo()
  3720. todayTime := time.Now().Format("2006-01-02")
  3721. timeLayout := "2006-01-02 15:04:05"
  3722. loc, _ := time.LoadLocation("Local")
  3723. var theStartTime int64
  3724. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3725. theStartTime = theTime.Unix()
  3726. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3727. if len(schedules) > 0 {
  3728. for index, item := range schedules {
  3729. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3730. schedules[index].Week = int64(week)
  3731. }
  3732. }
  3733. c.ServeSuccessJSON(map[string]interface{}{
  3734. "schedules": schedules,
  3735. })
  3736. return
  3737. }
  3738. func (c *PatientApiController) GetRecords() {
  3739. patientID, _ := c.GetInt64("patient_id", 0)
  3740. page, _ := c.GetInt64("page", 0)
  3741. limit, _ := c.GetInt64("limit", 0)
  3742. startTime := c.GetString("start_time", "")
  3743. endTime := c.GetString("end_time", "")
  3744. mode_id, _ := c.GetInt64("mode_id", 0)
  3745. if page <= 0 {
  3746. page = 1
  3747. }
  3748. if limit <= 0 {
  3749. limit = 10
  3750. }
  3751. if patientID <= 0 {
  3752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. return
  3754. }
  3755. timeLayout := "2006-01-02"
  3756. loc, _ := time.LoadLocation("Local")
  3757. var theStartTIme int64
  3758. if len(startTime) > 0 {
  3759. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3760. if err != nil {
  3761. theStartTIme = 0
  3762. }
  3763. theStartTIme = theTime.Unix()
  3764. }
  3765. var theEndtTIme int64
  3766. if len(endTime) > 0 {
  3767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3768. if err != nil {
  3769. theEndtTIme = 0
  3770. }
  3771. theEndtTIme = theTime.Unix()
  3772. }
  3773. adminUserInfo := c.GetMobileAdminUserInfo()
  3774. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3775. c.ServeSuccessJSON(map[string]interface{}{
  3776. "total": total,
  3777. "records": records,
  3778. })
  3779. return
  3780. }
  3781. func (c *PatientApiController) GetPatientMonitor() {
  3782. partition, _ := c.GetInt64("partition")
  3783. monitorDate := c.GetString("date")
  3784. patient_id, _ := c.GetInt64("patient_id")
  3785. timeLayout := "2006-01-02"
  3786. loc, _ := time.LoadLocation("Local")
  3787. var theStartTime int64
  3788. if len(monitorDate) > 0 {
  3789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3790. if err != nil {
  3791. theStartTime = 0
  3792. }
  3793. theStartTime = theTime.Unix()
  3794. }
  3795. adminInfo := c.GetMobileAdminUserInfo()
  3796. orgID := adminInfo.Org.Id
  3797. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3798. if err != nil {
  3799. c.ErrorLog("获取排班信息失败:%v", err)
  3800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3801. } else {
  3802. if len(monitor) > 0 {
  3803. //获取所有床位
  3804. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3805. //获取所有分区
  3806. zoneList, _ := service.GetAllZoneByList(orgID)
  3807. //获取透析处方
  3808. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3809. //获取透前评估
  3810. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3811. //获取上机
  3812. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3813. //获取透后
  3814. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3815. //获取透后监测
  3816. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3817. //获取所有的患者
  3818. patients, _ := service.GetAllPatientListByListOne(orgID)
  3819. for _, it := range patients {
  3820. if orgID == 10445 {
  3821. if theStartTime <= 1703952000 {
  3822. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  3823. it.TotalDialysis = listOne.Count
  3824. }
  3825. if theStartTime >= 1704038400 {
  3826. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  3827. it.TotalDialysis = listOrder.Count
  3828. }
  3829. }
  3830. }
  3831. //获取所有透析模式
  3832. treatments, _ := service.GetAllTreatModeByList(orgID)
  3833. for key, item := range monitor {
  3834. // 获取床位信息
  3835. for _, it := range numberList {
  3836. if item.BedId == it.ID {
  3837. monitor[key].DeviceNumber = it
  3838. break
  3839. }
  3840. }
  3841. //获取分区信息
  3842. for _, it := range zoneList {
  3843. if item.PartitionId == it.ID {
  3844. monitor[key].DeviceZone = it
  3845. }
  3846. }
  3847. for _, prescription := range prescriptions {
  3848. if item.PatientId == prescription.PatientId {
  3849. monitor[key].Prescription = prescription
  3850. break
  3851. }
  3852. }
  3853. // 透前评估
  3854. for _, assessmentBefore := range assessmentBefores {
  3855. if item.PatientId == assessmentBefore.PatientId {
  3856. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3857. break
  3858. }
  3859. }
  3860. // 透析上下机
  3861. for _, dialysisOrder := range dialysisOrders {
  3862. if item.PatientId == dialysisOrder.PatientId {
  3863. monitor[key].DialysisOrder = dialysisOrder
  3864. break
  3865. }
  3866. }
  3867. // 治疗小节
  3868. for _, afterDislysis := range AssessmentAfterDislysis {
  3869. if item.PatientId == afterDislysis.PatientId {
  3870. monitor[key].AssessmentAfterDislysis = afterDislysis
  3871. break
  3872. }
  3873. }
  3874. for _, it := range monitorlist {
  3875. if item.PatientId == it.PatientId {
  3876. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3877. }
  3878. }
  3879. for _, patient := range patients {
  3880. if item.PatientId == patient.ID {
  3881. monitor[key].MonitorPatients = patient
  3882. break
  3883. }
  3884. }
  3885. for _, treatment := range treatments {
  3886. if item.ModeId == treatment.ID {
  3887. monitor[key].TreatmentMode = treatment
  3888. break
  3889. }
  3890. }
  3891. }
  3892. }
  3893. }
  3894. //获取患者的透析次数
  3895. //count, err := service.GetDialysisCount(orgID, partition)
  3896. patients, err := service.GetAllpatientFourty(orgID)
  3897. if err == nil {
  3898. c.ServeSuccessJSON(map[string]interface{}{
  3899. "monitor": monitor,
  3900. //"patientCount": count,
  3901. "patients": patients,
  3902. })
  3903. } else {
  3904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3905. }
  3906. }
  3907. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3908. // @param keyword:string 病人姓名或透析号
  3909. // @param page:int
  3910. func (this *PatientApiController) SearchMonitorPatient() {
  3911. keyword := this.GetString("keyword")
  3912. page, _ := this.GetInt("page")
  3913. if page <= 0 {
  3914. page = 1
  3915. }
  3916. if len(keyword) == 0 {
  3917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3918. return
  3919. }
  3920. adminUserInfo := this.GetMobileAdminUserInfo()
  3921. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3922. if getMonitorErr != nil {
  3923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3924. return
  3925. } else {
  3926. this.ServeSuccessJSON(map[string]interface{}{
  3927. "monitor": monitors,
  3928. })
  3929. }
  3930. }
  3931. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3932. id, _ := c.GetInt64("id", 0)
  3933. page, _ := c.GetInt64("page", 0)
  3934. limit, _ := c.GetInt64("limit", 0)
  3935. if id <= 0 {
  3936. c.ServeSuccessJSON(map[string]interface{}{
  3937. "solutions": nil,
  3938. })
  3939. return
  3940. }
  3941. if page <= 0 {
  3942. page = 1
  3943. }
  3944. if limit <= 0 {
  3945. limit = 10
  3946. }
  3947. adminInfo := c.GetMobileAdminUserInfo()
  3948. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3949. c.ServeSuccessJSON(map[string]interface{}{
  3950. "solutions": solutions,
  3951. "total": total,
  3952. })
  3953. return
  3954. }
  3955. // GetDoctorAdvices 医嘱列表
  3956. func (c *PatientApiController) GetDoctorAdvices() {
  3957. id, _ := c.GetInt64("id", 0)
  3958. adviceType, _ := c.GetInt64("advice_type", 0)
  3959. stopType, _ := c.GetInt64("stop_state", 0)
  3960. startTime := c.GetString("start_time", "")
  3961. endTime := c.GetString("end_time", "")
  3962. keywords := c.GetString("keywords", "")
  3963. need, _ := c.GetInt64("need_doctor", 0)
  3964. adminUserInfo := c.GetMobileAdminUserInfo()
  3965. timeLayout := "2006-01-02"
  3966. loc, _ := time.LoadLocation("Local")
  3967. var theStartTIme int64
  3968. if len(startTime) > 0 {
  3969. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3970. if err != nil {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3972. return
  3973. }
  3974. theStartTIme = theTime.Unix()
  3975. }
  3976. var theEndtTIme int64
  3977. if len(endTime) > 0 {
  3978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3979. if err != nil {
  3980. utils.ErrorLog(err.Error())
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3982. return
  3983. }
  3984. theEndtTIme = theTime.Unix()
  3985. }
  3986. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  3987. if need == 1 {
  3988. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3989. c.ServeSuccessJSON(map[string]interface{}{
  3990. "advices": advices,
  3991. "total": total,
  3992. "users": users,
  3993. })
  3994. } else {
  3995. c.ServeSuccessJSON(map[string]interface{}{
  3996. "advices": advices,
  3997. "total": total,
  3998. "users": []string{},
  3999. })
  4000. }
  4001. return
  4002. }
  4003. func (c *PatientApiController) GetPrintDialysisOrder() {
  4004. xtno := c.GetString("xtno")
  4005. xtdate := c.GetString("xtdate")
  4006. timeLayout := "2006-01-02"
  4007. loc, _ := time.LoadLocation("Local")
  4008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4009. if err != nil {
  4010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4011. return
  4012. }
  4013. xttime := theTime.Unix()
  4014. //获取当前日期月份的第一天
  4015. firstmonth := service.GetFirstDateOfMonth(theTime)
  4016. firstMonthDate := firstmonth.Unix()
  4017. operatorIDs := make([]int64, 0)
  4018. adminUserInfo := c.GetMobileAdminUserInfo()
  4019. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4020. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4021. //透析单
  4022. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4023. if dialysisOrder != nil {
  4024. if dialysisOrder.FinishNurse > 0 {
  4025. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4026. }
  4027. if dialysisOrder.StartNurse > 0 {
  4028. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4029. }
  4030. }
  4031. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4032. //透前评估
  4033. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4034. //透后评估
  4035. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4036. if AssessmentAfterDislysis.Modifier > 0 {
  4037. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4038. }
  4039. //透析处方
  4040. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4041. if dialysisPrescription.PrescriptionDoctor > 0 {
  4042. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4043. }
  4044. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4045. patientInfo.TotalDialysis = dialysis_count
  4046. //临时医嘱
  4047. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4048. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4049. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4050. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4051. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4052. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4053. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4054. for _, item := range projects {
  4055. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4056. var advice models.HisDoctorAdviceInfo
  4057. advice.ID = item.ID
  4058. advice.Checker = item.Checker
  4059. advice.CheckTime = item.CheckTime
  4060. advice.CheckState = item.CheckState
  4061. advice.ExecutionState = item.ExecutionState
  4062. advice.ExecutionStaff = item.ExecutionStaff
  4063. //advice.PrescribingNumber = float64(item.Count)
  4064. advice.PrescribingNumber = cnt
  4065. advice.PrescribingNumberUnit = item.Unit
  4066. advice.AdviceDoctor = item.Doctor
  4067. if item.Type == 3 {
  4068. advice.AdviceName = item.GoodInfo.GoodName
  4069. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4070. } else if item.Type == 2 {
  4071. advice.AdviceName = item.HisProject.ProjectName
  4072. }
  4073. advice.StartTime = item.StartTime
  4074. hisAdvice = append(hisAdvice, &advice)
  4075. }
  4076. }
  4077. if len(DoctorAdvice) > 0 {
  4078. for _, item := range DoctorAdvice {
  4079. if item.AdviceDoctor > 0 {
  4080. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4081. }
  4082. if item.ExecutionStaff > 0 {
  4083. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4084. }
  4085. if item.Checker > 0 {
  4086. operatorIDs = append(operatorIDs, item.Checker)
  4087. }
  4088. }
  4089. }
  4090. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4091. //透析监测
  4092. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4093. //透析小结
  4094. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4095. //接诊评估
  4096. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4097. //相关操作对应的操作人
  4098. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4099. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4100. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4101. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4102. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4103. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4104. if config.IsOpen == 1 {
  4105. c.ServeSuccessJSON(map[string]interface{}{
  4106. "users": adminUser,
  4107. "patientInfo": patientInfo,
  4108. "PredialysisEvaluation": PredialysisEvaluation,
  4109. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4110. "dialysisPrescription": dialysisPrescription,
  4111. "advices": hisAdvice,
  4112. "monitors": Record,
  4113. "summary": TreatmentSummary,
  4114. "receiverTreatmentAccess": receiverTreatmentAccess,
  4115. "dialysisOrder": dialysisOrder,
  4116. "operators": operators,
  4117. "org_template_info": templateInfo,
  4118. "check": check,
  4119. "dialysiscount": dialysiscount,
  4120. "last_order": last_order,
  4121. "projects": projects,
  4122. "project_config": project_config,
  4123. "lastWeight": lastWeight,
  4124. "lastSchedule": lastSchedule,
  4125. })
  4126. }
  4127. if config.IsOpen == 0 || config.IsOpen == 2 {
  4128. c.ServeSuccessJSON(map[string]interface{}{
  4129. "users": adminUser,
  4130. "patientInfo": patientInfo,
  4131. "PredialysisEvaluation": PredialysisEvaluation,
  4132. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4133. "dialysisPrescription": dialysisPrescription,
  4134. "advices": DoctorAdvice,
  4135. "monitors": Record,
  4136. "summary": TreatmentSummary,
  4137. "receiverTreatmentAccess": receiverTreatmentAccess,
  4138. "dialysisOrder": dialysisOrder,
  4139. "operators": operators,
  4140. "org_template_info": templateInfo,
  4141. "check": check,
  4142. "dialysiscount": dialysiscount,
  4143. "last_order": last_order,
  4144. "projects": projects,
  4145. "project_config": project_config,
  4146. "lastWeight": lastWeight,
  4147. "lastSchedule": lastSchedule,
  4148. })
  4149. }
  4150. }
  4151. func (c *PatientApiController) CreateGroupAdvice() {
  4152. is_child, _ := c.GetInt64("is_child", 0)
  4153. if is_child == 1 {
  4154. patient, _ := c.GetInt64("id", 0)
  4155. if patient <= 0 {
  4156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4157. return
  4158. }
  4159. adminUserInfo := c.GetMobileAdminUserInfo()
  4160. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4161. if patientInfo.ID == 0 {
  4162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4163. return
  4164. }
  4165. group_no, _ := c.GetInt64("group_no")
  4166. if group_no <= 0 {
  4167. group_no = 0
  4168. }
  4169. dataBody := make(map[string]interface{}, 0)
  4170. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4171. if err != nil {
  4172. utils.ErrorLog(err.Error())
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. timeLayout := "2006-01-02"
  4177. loc, _ := time.LoadLocation("Local")
  4178. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4179. utils.ErrorLog("advice_type")
  4180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4181. return
  4182. }
  4183. adviceType := int64(dataBody["advice_type"].(float64))
  4184. if adviceType != 1 && adviceType != 2 {
  4185. utils.ErrorLog("advice_type != 1&&2")
  4186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4187. return
  4188. }
  4189. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4190. utils.ErrorLog("start_time")
  4191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4192. return
  4193. }
  4194. startTime2, _ := dataBody["start_time"].(string)
  4195. time_arr := strings.Split(startTime2, " ")
  4196. if len(time_arr) > 0 {
  4197. startTime2 = time_arr[0]
  4198. }
  4199. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4200. utils.ErrorLog("advice_date")
  4201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4202. return
  4203. }
  4204. advice_date, _ := dataBody["advice_date"].(string)
  4205. var advicedateunix int64
  4206. if len(advice_date) > 0 {
  4207. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4208. if err != nil {
  4209. fmt.Println(err)
  4210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4211. return
  4212. }
  4213. advicedateunix = theTime.Unix()
  4214. }
  4215. adviceDate := startTime2
  4216. if len(adviceDate) == 0 {
  4217. utils.ErrorLog("len(adviceDate) == 0")
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4222. if err != nil {
  4223. utils.ErrorLog(err.Error())
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. AdviceDate := advicedateunix
  4228. RecordDate := advicedateunix
  4229. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4230. utils.ErrorLog("start_time")
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. startTime, _ := dataBody["start_time"].(string)
  4235. if len(startTime) == 0 {
  4236. utils.ErrorLog("len(start_time) == 0")
  4237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4238. return
  4239. }
  4240. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4241. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4242. if err != nil {
  4243. utils.ErrorLog(err.Error())
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4245. return
  4246. }
  4247. StartTime := theTime.Unix()
  4248. Remark := ""
  4249. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4250. remark, _ := dataBody["remark"].(string)
  4251. Remark = remark
  4252. }
  4253. Startdate := int64(dataBody["record_date"].(float64))
  4254. var advices []*models.GroupAdvice
  4255. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4256. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4257. utils.ErrorLog("adviceNames")
  4258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4259. return
  4260. }
  4261. adviceNames := dataBody["adviceNames"].([]interface{})
  4262. for _, adviceNameMap := range adviceNames {
  4263. adviceNameM := adviceNameMap.(map[string]interface{})
  4264. var advice models.GroupAdvice
  4265. advice.Remark = Remark
  4266. advice.AdviceType = adviceType
  4267. advice.StartTime = StartTime
  4268. if adminUserInfo.Org.Id == 10340 {
  4269. advice.AdviceDate = AdviceDate
  4270. advice.RecordDate = RecordDate
  4271. }
  4272. if adminUserInfo.Org.Id != 10340 {
  4273. advice.AdviceDate = theTimeOne.Unix()
  4274. advice.RecordDate = theTimeOne.Unix()
  4275. }
  4276. advice.Status = 1
  4277. advice.CreatedTime = time.Now().Unix()
  4278. advice.UpdatedTime = time.Now().Unix()
  4279. advice.StopState = 2
  4280. advice.ExecutionState = 2
  4281. advice.UserOrgId = adminUserInfo.Org.Id
  4282. advice.PatientId = patientInfo.ID
  4283. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4284. advice.IsSettle = 2
  4285. //入口
  4286. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4287. if errcode > 0 {
  4288. c.ServeFailJSONWithSGJErrorCode(errcode)
  4289. return
  4290. }
  4291. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4292. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4293. if len(subdrugs) > 0 {
  4294. for _, subdrug := range subdrugs {
  4295. var s models.GroupAdvice
  4296. s.Remark = Remark
  4297. s.AdviceType = adviceType
  4298. s.StartTime = StartTime
  4299. s.AdviceDate = AdviceDate
  4300. s.RecordDate = RecordDate
  4301. s.Status = 1
  4302. s.CreatedTime = time.Now().Unix()
  4303. s.UpdatedTime = time.Now().Unix()
  4304. s.StopState = 2
  4305. s.ExecutionState = 2
  4306. s.UserOrgId = adminUserInfo.Org.Id
  4307. s.PatientId = patientInfo.ID
  4308. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4309. s.IsSettle = 2
  4310. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4311. if errcode > 0 {
  4312. c.ServeFailJSONWithSGJErrorCode(errcode)
  4313. return
  4314. }
  4315. advice.Children = append(advice.Children, &s)
  4316. }
  4317. }
  4318. }
  4319. //长沙南雅
  4320. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4321. //查询该患者今日有没有双人核对
  4322. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4323. if check.ID > 0 {
  4324. advice.Checker = check.Modifier
  4325. advice.CheckState = 1
  4326. advice.CheckTime = time.Now().Unix()
  4327. }
  4328. }
  4329. advices = append(advices, &advice)
  4330. }
  4331. // 查询信息规挡的设置天数
  4332. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4333. if infor.ID > 0 && infor.WeekDay > 0 {
  4334. var cha_time int64
  4335. timeNowStr := time.Now().Format("2006-01-02")
  4336. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4337. //今日的日期减去设置的日期
  4338. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4339. if cha_time >= Startdate {
  4340. //查询审核是否允许
  4341. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4342. //申请状态不允许的情况 拒绝修改
  4343. if infor.ApplicationStatus != 1 {
  4344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4345. return
  4346. }
  4347. }
  4348. }
  4349. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4350. for _, item := range advices {
  4351. //记录日志
  4352. byterequest, _ := json.Marshal(item)
  4353. adviceLog := models.XtDoctorAdviceLog{
  4354. UserOrgId: item.UserOrgId,
  4355. PatientId: item.PatientId,
  4356. AdminUserId: adminUserInfo.AdminUser.Id,
  4357. Module: 1,
  4358. ErrLog: string(byterequest),
  4359. Status: 1,
  4360. Ctime: time.Now().Unix(),
  4361. Mtime: 0,
  4362. Source: "手机端新增医嘱",
  4363. RecordDate: item.AdviceDate,
  4364. }
  4365. service.CreateDoctorAdviceLog(adviceLog)
  4366. }
  4367. finish := models.XtDialysisFinish{
  4368. IsFinish: 1,
  4369. UserOrgId: adminUserInfo.Org.Id,
  4370. Status: 1,
  4371. Ctime: time.Now().Unix(),
  4372. Mtime: 0,
  4373. Module: 4,
  4374. RecordDate: advicedateunix,
  4375. Sourse: 1,
  4376. PatientId: patient,
  4377. }
  4378. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4379. if dialysisFinish.ID == 0 {
  4380. service.CreateDialysisFinish(finish)
  4381. }
  4382. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4383. redis := service.RedisClient()
  4384. //清空key 值
  4385. redis.Set(key, "", time.Second)
  4386. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4387. redis.Set(keyOne, "", time.Second)
  4388. defer redis.Close()
  4389. if createErr != nil {
  4390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4391. return
  4392. }
  4393. c.ServeSuccessJSON(map[string]interface{}{
  4394. "msg": "ok",
  4395. "advices": newAdvices,
  4396. })
  4397. return
  4398. } else if is_child == 2 {
  4399. patient, _ := c.GetInt64("id", 0)
  4400. if patient <= 0 {
  4401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4402. return
  4403. }
  4404. adminUserInfo := c.GetMobileAdminUserInfo()
  4405. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4406. if patientInfo.ID == 0 {
  4407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4408. return
  4409. }
  4410. var advice models.DoctorAdvice
  4411. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  4412. if code > 0 {
  4413. c.ServeFailJSONWithSGJErrorCode(code)
  4414. return
  4415. }
  4416. if advice.ParentId > 0 {
  4417. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  4418. if old.ID == 0 || old.PatientId != patient {
  4419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  4420. return
  4421. }
  4422. if old.StopState == 1 || old.ExecutionState == 1 {
  4423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  4424. return
  4425. }
  4426. if old.ParentId > 0 {
  4427. advice.ParentId = old.ParentId
  4428. }
  4429. advice.StartTime = old.StartTime
  4430. advice.AdviceDoctor = old.AdviceDoctor
  4431. advice.DeliveryWay = old.DeliveryWay
  4432. advice.ExecutionFrequency = old.ExecutionFrequency
  4433. advice.GroupNo = old.GroupNo
  4434. }
  4435. advice.Status = 1
  4436. advice.CreatedTime = time.Now().Unix()
  4437. advice.UpdatedTime = time.Now().Unix()
  4438. advice.StopState = 2
  4439. advice.ExecutionState = 2
  4440. advice.UserOrgId = adminUserInfo.Org.Id
  4441. advice.PatientId = patient
  4442. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4443. advice.IsSettle = 2
  4444. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4445. if advice.PrescribingNumber == 0 {
  4446. advice.PrescribingNumber = 1
  4447. }
  4448. //查询该患者今日有没有双人核对
  4449. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  4450. if check.ID > 0 {
  4451. advice.Checker = check.Modifier
  4452. advice.CheckState = 1
  4453. advice.CheckTime = time.Now().Unix()
  4454. }
  4455. }
  4456. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4457. if infor.ID > 0 {
  4458. var cha_time int64
  4459. timeNowStr := time.Now().Format("2006-01-02")
  4460. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4461. //今日的日期减去设置的日期
  4462. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4463. if cha_time >= advice.RecordDate {
  4464. //查询审核是否允许
  4465. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  4466. //申请状态不允许的情况 拒绝修改
  4467. if infor.ApplicationStatus != 1 {
  4468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4469. return
  4470. }
  4471. }
  4472. }
  4473. err := service.CreateDoctorAdvice(&advice)
  4474. //记录日志
  4475. byterequest, _ := json.Marshal(advice)
  4476. adviceLog := models.XtDoctorAdviceLog{
  4477. UserOrgId: advice.UserOrgId,
  4478. PatientId: advice.PatientId,
  4479. AdminUserId: adminUserInfo.Org.Id,
  4480. Module: 1,
  4481. ErrLog: string(byterequest),
  4482. Status: 1,
  4483. Ctime: time.Now().Unix(),
  4484. Mtime: 0,
  4485. Source: "手机端新增医嘱",
  4486. RecordDate: advice.AdviceDate,
  4487. }
  4488. service.CreateDoctorAdviceLog(adviceLog)
  4489. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  4490. redis := service.RedisClient()
  4491. //清空key 值
  4492. redis.Set(key, "", time.Second)
  4493. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  4494. redis.Set(keyOne, "", time.Second)
  4495. defer redis.Close()
  4496. if err != nil {
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4498. return
  4499. }
  4500. c.ServeSuccessJSON(map[string]interface{}{
  4501. "msg": "ok",
  4502. "advice": advice,
  4503. })
  4504. return
  4505. }
  4506. }
  4507. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  4508. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  4509. utils.ErrorLog("advice_name")
  4510. return enums.ErrorCodeParamWrong
  4511. }
  4512. adviceName, _ := json["advice_name"].(string)
  4513. if len(adviceName) == 0 {
  4514. utils.ErrorLog("len(advice_name) == 0")
  4515. return enums.ErrorCodeParamWrong
  4516. }
  4517. advice.AdviceName = adviceName
  4518. adviceDesc, _ := json["advice_desc"].(string)
  4519. advice.AdviceDesc = adviceDesc
  4520. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4521. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4522. advice.DrugSpec = drugSpec
  4523. }
  4524. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4525. remark, _ := json["remark"].(string)
  4526. advice.Remark = remark
  4527. }
  4528. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  4529. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  4530. // advice.Way = src_type
  4531. //}
  4532. if json["way"] == nil {
  4533. advice.Way = 0
  4534. } else {
  4535. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  4536. way := int64(json["way"].(float64))
  4537. advice.Way = way
  4538. }
  4539. }
  4540. if json["drug_id"] == nil {
  4541. advice.DrugId = 0
  4542. } else {
  4543. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  4544. drug_id := int64(json["drug_id"].(float64))
  4545. advice.DrugId = drug_id
  4546. }
  4547. }
  4548. if json["drug_name_id"] == nil {
  4549. advice.DrugNameId = 0
  4550. } else {
  4551. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  4552. drug_name_id := int64(json["drug_name_id"].(float64))
  4553. advice.DrugNameId = drug_name_id
  4554. }
  4555. }
  4556. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  4557. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  4558. advice.DrugSpecUnit = drugSpecUnit
  4559. }
  4560. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4561. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4562. advice.SingleDose = singleDose
  4563. }
  4564. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4565. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4566. advice.SingleDoseUnit = singleDoseUnit
  4567. }
  4568. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4569. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4570. advice.PrescribingNumber = prescribingNumber
  4571. }
  4572. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4573. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4574. advice.PrescribingNumberUnit = prescribingNumberUnit
  4575. }
  4576. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4577. deliveryWay, _ := json["delivery_way"].(string)
  4578. advice.DeliveryWay = deliveryWay
  4579. }
  4580. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4581. executionFrequency, _ := json["execution_frequency"].(string)
  4582. advice.ExecutionFrequency = executionFrequency
  4583. }
  4584. return 0
  4585. }
  4586. func (c *PatientApiController) DelDoctorAdvice() {
  4587. groupno, _ := c.GetInt64("groupno", -1)
  4588. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  4589. patient_id, _ := c.GetInt64("patient_id")
  4590. doc_advice_date, _ := c.GetInt64("advice_date")
  4591. redis := service.RedisClient()
  4592. if is_sub == 1 { //是
  4593. advice_id, _ := c.GetInt64("advice_id")
  4594. adminUserInfo := c.GetMobileAdminUserInfo()
  4595. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4596. if advice.ID == 0 {
  4597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4598. return
  4599. }
  4600. advice.Status = 0
  4601. advice.UpdatedTime = time.Now().Unix()
  4602. advice.Modifier = adminUserInfo.AdminUser.Id
  4603. // 查询信息规挡的设置天数
  4604. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4605. if infor.ID > 0 && infor.WeekDay > 0 {
  4606. var cha_time int64
  4607. timeNowStr := time.Now().Format("2006-01-02")
  4608. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4609. //今日的日期减去设置的日期
  4610. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4611. if cha_time >= advice.AdviceDate {
  4612. //查询审核是否允许
  4613. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4614. //申请状态不允许的情况 拒绝修改
  4615. if infor.ApplicationStatus != 1 {
  4616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4617. return
  4618. }
  4619. }
  4620. }
  4621. err := service.DeleteDoctorAdvice(&advice)
  4622. //记录日志
  4623. byterequest, _ := json.Marshal(advice)
  4624. adviceLog := models.XtDoctorAdviceLog{
  4625. UserOrgId: advice.UserOrgId,
  4626. PatientId: advice.PatientId,
  4627. AdminUserId: adminUserInfo.AdminUser.Id,
  4628. Module: 4,
  4629. ErrLog: string(byterequest),
  4630. Status: 1,
  4631. Ctime: time.Now().Unix(),
  4632. Mtime: 0,
  4633. Source: "手机端删除医嘱",
  4634. RecordDate: advice.RecordDate,
  4635. }
  4636. service.CreateDoctorAdviceLog(adviceLog)
  4637. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4638. redis.Set(key, "", time.Second)
  4639. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4640. redis.Set(keyTwo, "", time.Second)
  4641. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4642. redis.Set(keyThree, "", time.Second)
  4643. redis.Close()
  4644. if err != nil {
  4645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4646. return
  4647. }
  4648. c.ServeSuccessJSON(map[string]interface{}{
  4649. "msg": "ok",
  4650. })
  4651. return
  4652. } else { //
  4653. var ids []string
  4654. if groupno == 0 {
  4655. advice_id := c.GetString("advice_id")
  4656. ids = strings.Split(advice_id, ",")
  4657. if len(ids) <= 0 {
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4659. return
  4660. }
  4661. }
  4662. if groupno < 0 {
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. adminUserInfo := c.GetMobileAdminUserInfo()
  4667. var advice models.DoctorAdvice
  4668. if groupno > 0 {
  4669. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4670. if advice.ID == 0 {
  4671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4672. return
  4673. }
  4674. } else {
  4675. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4676. for _, item := range advices {
  4677. if item.ID == 0 {
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4679. return
  4680. }
  4681. }
  4682. }
  4683. advice.UpdatedTime = time.Now().Unix()
  4684. advice.Status = 0
  4685. advice.GroupNo = groupno
  4686. advice.Modifier = adminUserInfo.AdminUser.Id
  4687. var err error
  4688. if groupno > 0 {
  4689. // 查询信息规挡的设置天数
  4690. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4691. if infor.ID > 0 {
  4692. var cha_time int64
  4693. timeNowStr := time.Now().Format("2006-01-02")
  4694. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4695. //今日的日期减去设置的日期
  4696. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4697. if cha_time >= advice.AdviceDate {
  4698. //查询审核是否允许
  4699. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4700. //申请状态不允许的情况 拒绝修改
  4701. if infor.ApplicationStatus != 1 {
  4702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4703. return
  4704. }
  4705. }
  4706. }
  4707. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4708. //记录日志
  4709. byterequest, _ := json.Marshal(advice)
  4710. adviceLog := models.XtDoctorAdviceLog{
  4711. UserOrgId: advice.UserOrgId,
  4712. PatientId: advice.PatientId,
  4713. AdminUserId: adminUserInfo.AdminUser.Id,
  4714. Module: 4,
  4715. ErrLog: string(byterequest),
  4716. Status: 1,
  4717. Ctime: time.Now().Unix(),
  4718. Mtime: 0,
  4719. Source: "手机端删除医嘱",
  4720. RecordDate: advice.RecordDate,
  4721. }
  4722. service.CreateDoctorAdviceLog(adviceLog)
  4723. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4724. redis.Set(key, "", time.Second)
  4725. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4726. redis.Set(keyTwo, "", time.Second)
  4727. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4728. redis.Set(keyThree, "", time.Second)
  4729. } else {
  4730. // 查询信息规挡的设置天数
  4731. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4732. if infor.ID > 0 {
  4733. var cha_time int64
  4734. timeNowStr := time.Now().Format("2006-01-02")
  4735. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4736. //今日的日期减去设置的日期
  4737. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4738. if cha_time >= advice.AdviceDate {
  4739. //查询审核是否允许
  4740. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4741. //申请状态不允许的情况 拒绝修改
  4742. if infor.ApplicationStatus != 1 {
  4743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4744. return
  4745. }
  4746. }
  4747. }
  4748. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4749. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  4750. for _, item := range advicelist {
  4751. //记录日志
  4752. byterequest, _ := json.Marshal(item)
  4753. adviceLog := models.XtDoctorAdviceLog{
  4754. UserOrgId: item.UserOrgId,
  4755. PatientId: item.PatientId,
  4756. AdminUserId: adminUserInfo.AdminUser.Id,
  4757. Module: 4,
  4758. ErrLog: string(byterequest),
  4759. Status: 1,
  4760. Ctime: time.Now().Unix(),
  4761. Mtime: 0,
  4762. Source: "手机端批量删除医嘱",
  4763. RecordDate: item.RecordDate,
  4764. }
  4765. service.CreateDoctorAdviceLog(adviceLog)
  4766. }
  4767. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4768. redis.Set(key, "", time.Second)
  4769. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4770. redis.Set(keyTwo, "", time.Second)
  4771. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4772. redis.Set(keyThree, "", time.Second)
  4773. redis.Close()
  4774. }
  4775. if err != nil {
  4776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4777. return
  4778. }
  4779. c.ServeSuccessJSON(map[string]interface{}{
  4780. "msg": "ok",
  4781. })
  4782. return
  4783. }
  4784. }
  4785. // /m/api/advice/group/modify_starttime [post]
  4786. // @param group_no:int
  4787. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4788. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4789. group_no, _ := this.GetInt64("group_no")
  4790. start_time_str := this.GetString("start_time")
  4791. if group_no <= 0 || len(start_time_str) == 0 {
  4792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4793. return
  4794. }
  4795. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4796. if parseTimeErr != nil {
  4797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4798. return
  4799. }
  4800. adminUserInfo := this.GetMobileAdminUserInfo()
  4801. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4802. if updateStartTimeErr != nil {
  4803. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4805. return
  4806. }
  4807. this.ServeSuccessJSON(map[string]interface{}{
  4808. "start_time": startTime.Unix(),
  4809. })
  4810. }
  4811. func (this *PatientApiController) DelSubDoctorAdvice() {
  4812. advice_id, _ := this.GetInt64("advice_id")
  4813. adminUserInfo := this.GetMobileAdminUserInfo()
  4814. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4815. if advice.ID == 0 {
  4816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4817. return
  4818. }
  4819. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4820. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4821. // return
  4822. //}
  4823. advice.Status = 0
  4824. advice.UpdatedTime = time.Now().Unix()
  4825. advice.Modifier = adminUserInfo.AdminUser.Id
  4826. err := service.DeleteDoctorAdvice(&advice)
  4827. if err != nil {
  4828. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4829. return
  4830. }
  4831. this.ServeSuccessJSON(map[string]interface{}{
  4832. "msg": "ok",
  4833. })
  4834. return
  4835. }
  4836. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4837. //adminUserInfo := this.GetMobileAdminUserInfo()
  4838. //service.FindUnReadDoctorAdviceMessage()
  4839. }
  4840. func (this *PatientApiController) GetPatientsByKeyWord() {
  4841. keyWord := this.GetString("keyword")
  4842. adminUserInfo := this.GetMobileAdminUserInfo()
  4843. today := utils.ZeroHourTimeOfDay(time.Now())
  4844. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4845. if err != nil {
  4846. utils.ErrorLog(err.Error())
  4847. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4848. return
  4849. }
  4850. this.ServeSuccessJSON(map[string]interface{}{
  4851. "patient": patient,
  4852. })
  4853. }
  4854. func (this *PatientApiController) GetSearchPatient() {
  4855. keyWord := this.GetString("keyword")
  4856. adminUserInfo := this.GetMobileAdminUserInfo()
  4857. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4858. if err != nil {
  4859. utils.ErrorLog(err.Error())
  4860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4861. return
  4862. }
  4863. this.ServeSuccessJSON(map[string]interface{}{
  4864. "patient": patient,
  4865. })
  4866. }
  4867. func (c *PatientApiController) ExecProject() {
  4868. execution_time := c.GetString("execution_time")
  4869. project_id, _ := c.GetInt64("project_id")
  4870. team_id, _ := c.GetInt64("team_id")
  4871. is_check_team, _ := c.GetInt64("is_check_team")
  4872. if len(execution_time) <= 0 {
  4873. utils.ErrorLog("execution_time")
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. timeLayout2 := "2006-01-02 15:04:05"
  4878. loc, _ := time.LoadLocation("Local")
  4879. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4880. if errs != nil {
  4881. utils.ErrorLog(errs.Error())
  4882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4883. return
  4884. }
  4885. adminInfo := c.GetMobileAdminUserInfo()
  4886. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4887. if project.Type == 3 {
  4888. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4889. if good.IsUser != 1 {
  4890. //查询开关是否开启
  4891. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4892. //开关已经开启
  4893. if stockSetting.IsType == 1 {
  4894. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4895. scheduleDateStart := theTime.Format("2006-01-02")
  4896. timeLayout3 := "2006-01-02"
  4897. loc, _ := time.LoadLocation("Local")
  4898. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4899. //查询该耗材是否已经出库
  4900. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4901. if auto.ID == 0 {
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4903. return
  4904. }
  4905. }
  4906. }
  4907. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4908. //查询开关是否开启
  4909. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4910. //开关已经开启
  4911. if stockSetting.IsType == 1 {
  4912. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4913. scheduleDateStart := theTime.Format("2006-01-02")
  4914. timeLayout3 := "2006-01-02"
  4915. loc, _ := time.LoadLocation("Local")
  4916. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4917. //查询该耗材是否已经出库
  4918. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4919. if auto.ID == 0 {
  4920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4921. return
  4922. }
  4923. }
  4924. }
  4925. }
  4926. if project.ExecutionState == 1 {
  4927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4928. return
  4929. }
  4930. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4932. return
  4933. }
  4934. project.ExecutionState = 1
  4935. project.ExecutionStaff = adminInfo.AdminUser.Id
  4936. project.ExecutionTime = theTime.Unix()
  4937. if team_id == 0 {
  4938. // 查询信息规挡的设置天数
  4939. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4940. if infor.ID > 0 {
  4941. var cha_time int64
  4942. timeNowStr := time.Now().Format("2006-01-02")
  4943. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4944. //今日的日期减去设置的日期
  4945. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4946. if cha_time >= project.RecordDate {
  4947. //查询审核是否允许
  4948. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4949. //申请状态不允许的情况 拒绝修改
  4950. if infor.ApplicationStatus != 1 {
  4951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4952. return
  4953. }
  4954. }
  4955. }
  4956. err := service.SaveHisProject(&project)
  4957. if err == nil {
  4958. c.ServeSuccessJSON(map[string]interface{}{
  4959. "project": project,
  4960. })
  4961. } else {
  4962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4963. return
  4964. }
  4965. } else {
  4966. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4967. // 查询信息规挡的设置天数
  4968. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4969. if infor.ID > 0 {
  4970. var cha_time int64
  4971. timeNowStr := time.Now().Format("2006-01-02")
  4972. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4973. //今日的日期减去设置的日期
  4974. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4975. if cha_time >= project.RecordDate {
  4976. //查询审核是否允许
  4977. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4978. //申请状态不允许的情况 拒绝修改
  4979. if infor.ApplicationStatus != 1 {
  4980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4981. return
  4982. }
  4983. }
  4984. }
  4985. err := service.SaveHisProject(&project)
  4986. if err == nil {
  4987. c.ServeSuccessJSON(map[string]interface{}{
  4988. "project": project,
  4989. })
  4990. } else {
  4991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4992. return
  4993. }
  4994. } else {
  4995. // 查询信息规挡的设置天数
  4996. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4997. if infor.ID > 0 {
  4998. var cha_time int64
  4999. timeNowStr := time.Now().Format("2006-01-02")
  5000. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5001. //今日的日期减去设置的日期
  5002. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5003. if cha_time >= project.RecordDate {
  5004. //查询审核是否允许
  5005. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5006. //申请状态不允许的情况 拒绝修改
  5007. if infor.ApplicationStatus != 1 {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5009. return
  5010. }
  5011. }
  5012. }
  5013. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5014. var ids []int64
  5015. for _, items := range ps {
  5016. ids = append(ids, items.ID)
  5017. }
  5018. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5019. if err == nil {
  5020. c.ServeSuccessJSON(map[string]interface{}{
  5021. "project": project,
  5022. })
  5023. } else {
  5024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5025. return
  5026. }
  5027. }
  5028. }
  5029. }
  5030. func (c *PatientApiController) CheckProject() {
  5031. adminInfo := c.GetMobileAdminUserInfo()
  5032. project_id, _ := c.GetInt64("project_id")
  5033. team_id, _ := c.GetInt64("team_id")
  5034. is_check_team, _ := c.GetInt64("is_check_team")
  5035. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5036. if project.CheckState == 1 {
  5037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5038. return
  5039. }
  5040. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5042. return
  5043. }
  5044. project.Checker = adminInfo.AdminUser.Id
  5045. project.CheckTime = time.Now().Unix()
  5046. project.CheckState = 1
  5047. if team_id == 0 {
  5048. // 查询信息规挡的设置天数
  5049. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5050. if infor.ID > 0 {
  5051. var cha_time int64
  5052. timeNowStr := time.Now().Format("2006-01-02")
  5053. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5054. //今日的日期减去设置的日期
  5055. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5056. if cha_time >= project.RecordDate {
  5057. //查询审核是否允许
  5058. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5059. //申请状态不允许的情况 拒绝修改
  5060. if infor.ApplicationStatus != 1 {
  5061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5062. return
  5063. }
  5064. }
  5065. }
  5066. err := service.SaveHisProject(&project)
  5067. if err == nil {
  5068. c.ServeSuccessJSON(map[string]interface{}{
  5069. "msg": "ok",
  5070. "project": project,
  5071. })
  5072. } else {
  5073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5074. return
  5075. }
  5076. } else {
  5077. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5078. // 查询信息规挡的设置天数
  5079. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5080. if infor.ID > 0 {
  5081. var cha_time int64
  5082. timeNowStr := time.Now().Format("2006-01-02")
  5083. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5084. //今日的日期减去设置的日期
  5085. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5086. if cha_time >= project.RecordDate {
  5087. //查询审核是否允许
  5088. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5089. //申请状态不允许的情况 拒绝修改
  5090. if infor.ApplicationStatus != 1 {
  5091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5092. return
  5093. }
  5094. }
  5095. }
  5096. err := service.SaveHisProject(&project)
  5097. if err == nil {
  5098. c.ServeSuccessJSON(map[string]interface{}{
  5099. "msg": "ok",
  5100. "project": project,
  5101. })
  5102. } else {
  5103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5104. return
  5105. }
  5106. } else {
  5107. // 查询信息规挡的设置天数
  5108. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5109. if infor.ID > 0 {
  5110. var cha_time int64
  5111. timeNowStr := time.Now().Format("2006-01-02")
  5112. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5113. //今日的日期减去设置的日期
  5114. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5115. if cha_time >= project.RecordDate {
  5116. //查询审核是否允许
  5117. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5118. //申请状态不允许的情况 拒绝修改
  5119. if infor.ApplicationStatus != 1 {
  5120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5121. return
  5122. }
  5123. }
  5124. }
  5125. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5126. var ids []int64
  5127. for _, items := range ps {
  5128. ids = append(ids, items.ID)
  5129. }
  5130. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5131. if err == nil {
  5132. c.ServeSuccessJSON(map[string]interface{}{
  5133. "project": project,
  5134. })
  5135. } else {
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5137. return
  5138. }
  5139. }
  5140. }
  5141. }