patient_api_controller.go 209KB

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