patient_api_controller.go 184KB

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