patient_api_controller.go 188KB

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