patient_api_controller.go 208KB

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