patient_api_controller.go 163KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/jinzhu/gorm"
  9. //"github.com/jinzhu/gorm"
  10. "math"
  11. "math/rand"
  12. "reflect"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "fmt"
  18. "github.com/astaxie/beego"
  19. )
  20. type PatientApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func PatientApiRegistRouters() {
  24. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  25. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  26. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  27. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  28. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  29. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  30. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  31. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  33. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  34. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  35. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  36. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  37. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  38. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  39. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  40. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  41. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  42. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  43. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  44. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  45. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  46. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  47. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  48. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  49. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  50. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  51. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  52. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  53. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  54. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  55. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  56. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  57. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  58. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  59. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  60. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  61. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  62. beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
  63. }
  64. //GetPatientsList 取患者列表
  65. func (c *PatientApiController) GetPatientsList() {
  66. page, _ := c.GetInt64("page", 1)
  67. limit, _ := c.GetInt64("limit", 10)
  68. schedulType, _ := c.GetInt64("schedul_type", 0)
  69. bindingState, _ := c.GetInt64("binding_state", 0)
  70. lapseto, _ := c.GetInt64("lapseto", 0)
  71. source, _ := c.GetInt64("source", 0)
  72. startTime := c.GetString("start_time", "")
  73. endTime := c.GetString("end_time", "")
  74. keywords := c.GetString("keywords", "")
  75. contagion, _ := c.GetInt64("contagion", 0)
  76. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  77. isscheduling, _ := c.GetInt64("isscheduling", 0)
  78. isprescription, _ := c.GetInt64("isprescription", 0)
  79. if page <= 0 {
  80. page = 1
  81. }
  82. if limit <= 0 {
  83. limit = 10
  84. }
  85. adminUserInfo := c.GetAdminUserInfo()
  86. timeLayout := "2006-01-02"
  87. loc, _ := time.LoadLocation("Local")
  88. var isStartTime bool
  89. var theStartTIme int64
  90. if len(startTime) > 0 {
  91. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  92. if err != nil {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. isStartTime = true
  97. theStartTIme = theTime.Unix()
  98. }
  99. var isEndTime bool
  100. var theEndtTIme int64
  101. if len(endTime) > 0 {
  102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  103. if err != nil {
  104. utils.ErrorLog(err.Error())
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. isEndTime = true
  109. theEndtTIme = theTime.Unix()
  110. }
  111. patients, total, _ := service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
  112. c.ServeSuccessJSON(map[string]interface{}{
  113. "patients": patients,
  114. "total": total,
  115. })
  116. return
  117. }
  118. //GetPatientTotal
  119. func (c *PatientApiController) GetPatientTotal() {
  120. adminUserInfo := c.GetAdminUserInfo()
  121. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "total": total,
  124. })
  125. return
  126. }
  127. func (c *PatientApiController) GetPatientsAllList() {
  128. adminUserInfo := c.GetAdminUserInfo()
  129. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  130. c.ServeSuccessJSON(map[string]interface{}{
  131. "patients": patients,
  132. "total": total,
  133. })
  134. return
  135. }
  136. //GenerateDialysisNo 生成透析号
  137. func (c *PatientApiController) GenerateDialysisNo() {
  138. adminUserInfo := c.GetAdminUserInfo()
  139. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  140. if dialysisNo == 0 {
  141. dialysisNo = 1
  142. } else {
  143. dialysisNo++
  144. }
  145. no := strconv.FormatInt(dialysisNo, 10)
  146. rep := 3 - len(no)
  147. if rep > 0 {
  148. no = strings.Repeat("0", rep) + no
  149. }
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "no": no,
  152. })
  153. return
  154. }
  155. //CreatePatient 创建患者
  156. func (c *PatientApiController) CreatePatient() {
  157. record_date := c.GetString("record_date")
  158. is_infectious, _ := c.GetInt64("is_infectious")
  159. remind_cycle, _ := c.GetInt64("remind_cycle")
  160. adminUserInfo := c.GetAdminUserInfo()
  161. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  162. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  163. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  164. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  165. // return
  166. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  168. // return
  169. //}
  170. var patient models.Patients
  171. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  172. fmt.Println(code)
  173. fmt.Println(patient)
  174. fmt.Println("contagions是什么", contagions)
  175. if code > 0 {
  176. c.ServeFailJSONWithSGJErrorCode(code)
  177. return
  178. }
  179. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  180. if thisPatient.ID > 0 {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  182. return
  183. }
  184. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  185. if thisPatient.ID > 0 {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  187. return
  188. }
  189. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  190. if thisPatient.ID > 0 {
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  192. return
  193. }
  194. patient.RemindCycle = remind_cycle
  195. patient.IsInfectious = is_infectious
  196. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  197. patient.Status = 1
  198. patient.CreatedTime = time.Now().Unix()
  199. patient.UserOrgId = adminUserInfo.CurrentOrgId
  200. patient.UpdatedTime = time.Now().Unix()
  201. patient.BindingState = 2
  202. // patient.Lapseto = 1
  203. err := service.CreatePatient(&patient, contagions, diseases)
  204. fmt.Println("创建病人失败err")
  205. if err != nil {
  206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  207. return
  208. }
  209. //获取老表的最后一条数据
  210. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  211. patientsNew := models.XtPatientsNew{
  212. UserOrgId: adminUserInfo.CurrentOrgId,
  213. UserId: 0,
  214. Avatar: patients.Avatar,
  215. PatientType: patients.PatientType,
  216. DialysisNo: patients.DialysisNo,
  217. AdmissionNumber: patients.AdmissionNumber,
  218. Source: patients.Source,
  219. Lapseto: patients.Lapseto,
  220. PartitionId: patients.PartitionId,
  221. BedId: patients.BedId,
  222. Name: patients.Name,
  223. Alias: patients.Alias,
  224. Gender: patients.Gender,
  225. MaritalStatus: patients.MaritalStatus,
  226. IdCardNo: patients.IdCardNo,
  227. Birthday: patients.Birthday,
  228. ReimbursementWayId: patients.ReimbursementWayId,
  229. HealthCareType: patients.HealthCareType,
  230. HealthCareNo: patients.HealthCareNo,
  231. HealthCareDueDate: patients.HealthCareDueDate,
  232. Height: patients.Height,
  233. BloodType: patients.BloodType,
  234. Rh: patients.Rh,
  235. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  236. EducationLevel: patients.EducationLevel,
  237. Profession: patients.Profession,
  238. Phone: patients.Phone,
  239. HomeTelephone: patients.HomeTelephone,
  240. RelativePhone: patients.RelativePhone,
  241. RelativeRelations: patients.RelativeRelations,
  242. HomeAddress: patients.HomeAddress,
  243. WorkUnit: patients.WorkUnit,
  244. UnitAddress: patients.UnitAddress,
  245. Children: patients.Children,
  246. ReceivingDate: patients.ReceivingDate,
  247. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  248. FirstDialysisDate: patients.FirstDialysisDate,
  249. FirstDialysisHospital: patients.FirstDialysisHospital,
  250. PredialysisCondition: patients.PredialysisCondition,
  251. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  252. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  253. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  254. InductionPeriod: patients.InductionPeriod,
  255. InitialDialysis: patients.InitialDialysis,
  256. TotalDialysis: patients.TotalDialysis,
  257. AttendingDoctorId: patients.AttendingDoctorId,
  258. HeadNurseId: patients.HeadNurseId,
  259. Evaluate: patients.Evaluate,
  260. Diagnose: patients.Diagnose,
  261. Remark: patients.Remark,
  262. RegistrarsId: patients.RegistrarsId,
  263. Registrars: patients.Registrars,
  264. QrCode: patients.QrCode,
  265. BindingState: patients.BindingState,
  266. PatientComplains: patients.PatientComplains,
  267. PresentHistory: patients.PresentHistory,
  268. PastHistory: patients.PresentHistory,
  269. Temperature: patients.Temperature,
  270. Pulse: patients.Pulse,
  271. Respiratory: patients.Respiratory,
  272. Sbp: patients.SBP,
  273. Dbp: patients.DBP,
  274. Status: patients.Status,
  275. CreatedTime: patients.CreatedTime,
  276. UpdatedTime: patients.UpdatedTime,
  277. Nation: patients.Nation,
  278. NativePlace: patients.NativePlace,
  279. Age: patients.Age,
  280. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  281. IsInfectious: patients.IsInfectious,
  282. RemindCycle: patients.RemindCycle,
  283. ResponseResult: patients.ResponseResult,
  284. IsOpenRemind: patients.IsOpenRemind,
  285. FirstTreatmentDate: patients.FirstTreatmentDate,
  286. DialysisAge: patients.DialysisAge,
  287. ExpenseKind: patients.ExpenseKind,
  288. TellPhone: patients.TellPhone,
  289. ContactName: patients.ContactName,
  290. BloodPatients: 1,
  291. SlowPatients: 0,
  292. MemberPatients: 0,
  293. EcommerPatients: "",
  294. BloodId: patients.ID,
  295. SlowId: 0,
  296. MemberId: 0,
  297. MemberFistdate: 0,
  298. MemberPatienttype: 0,
  299. MemberTreatement: 0,
  300. EquitmentId: "",
  301. UserSysBeforeCount: patient.UserSysBeforeCount,
  302. }
  303. err = service.CreatePatientsNew(&patientsNew)
  304. fmt.Print("创建失败", err)
  305. if len(record_date) > 0 {
  306. var recordTime int64
  307. timeLayout := "2006-01-02"
  308. loc, _ := time.LoadLocation("Local")
  309. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  310. if err != nil {
  311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  312. return
  313. }
  314. recordTime = theTime.Unix()
  315. inspections := make([]models.Inspection, 0)
  316. for _, item := range formItems {
  317. var inspection models.Inspection
  318. inspection.OrgId = adminUserInfo.CurrentOrgId
  319. inspection.PatientId = patient.ID
  320. inspection.ProjectId = item.ProjectId
  321. inspection.ItemId = item.ItemId
  322. inspection.ItemName = item.ItemName
  323. inspection.ProjectName = item.ProjectName
  324. inspection.InspectType = item.RangeType
  325. inspection.InspectValue = item.Value
  326. inspection.InspectDate = recordTime
  327. inspection.Status = 1
  328. inspection.CreatedTime = time.Now().Unix()
  329. inspection.UpdatedTime = time.Now().Unix()
  330. inspections = append(inspections, inspection)
  331. }
  332. err = service.CreatePatientInspection(inspections)
  333. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  334. var record_time int64
  335. switch remind_cycle {
  336. case 1: //1个月
  337. ts := time.Unix(infectiousRecord.InspectDate, 0)
  338. record_time = ts.AddDate(0, 1, 0).Unix()
  339. break
  340. case 2: //2个月
  341. ts := time.Unix(infectiousRecord.InspectDate, 0)
  342. record_time = ts.AddDate(0, 2, 0).Unix()
  343. break
  344. case 3: //3个月
  345. ts := time.Unix(infectiousRecord.InspectDate, 0)
  346. record_time = ts.AddDate(0, 3, 0).Unix()
  347. break
  348. case 4: //6个月
  349. ts := time.Unix(infectiousRecord.InspectDate, 0)
  350. record_time = ts.AddDate(0, 6, 0).Unix()
  351. break
  352. case 5: //12个月
  353. ts := time.Unix(infectiousRecord.InspectDate, 0)
  354. record_time = ts.AddDate(0, 12, 0).Unix()
  355. break
  356. }
  357. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  358. if errs != nil {
  359. utils.ErrorLog("更新日期出错:%v", errs)
  360. }
  361. }
  362. redis := service.RedisClient()
  363. defer redis.Close()
  364. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  365. c.ServeSuccessJSON(map[string]interface{}{
  366. "msg": "ok",
  367. })
  368. return
  369. }
  370. //EditPatient 修改
  371. func (c *PatientApiController) EditPatient() {
  372. id, _ := c.GetInt64("id", 0)
  373. record_date := c.GetString("record_date")
  374. is_infectious, _ := c.GetInt64("is_infectious")
  375. remind_cycle, _ := c.GetInt64("remind_cycle")
  376. if id <= 0 {
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  378. return
  379. }
  380. adminUserInfo := c.GetAdminUserInfo()
  381. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  382. if patient.ID == 0 {
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  384. return
  385. }
  386. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  387. if code > 0 {
  388. c.ServeFailJSONWithSGJErrorCode(code)
  389. return
  390. }
  391. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  392. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  394. return
  395. }
  396. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  397. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  399. return
  400. }
  401. patient.UpdatedTime = time.Now().Unix()
  402. patient.IsInfectious = is_infectious
  403. patient.RemindCycle = remind_cycle
  404. fmt.Println("hhhhh2h32322323332323232323232322323", patient.RemindCycle)
  405. err := service.UpdatePatient(&patient, contagions, diseases)
  406. if err != nil {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  408. return
  409. }
  410. ////更新转归状态
  411. //lapseto := models.PatientLapseto{
  412. // LapsetoType: patient.Lapseto,
  413. // LapsetoTime: time.Now().Unix(),
  414. // UpdatedTime: time.Now().Unix(),
  415. //}
  416. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  417. //fmt.Println("更新转归失败", err)
  418. if err != nil {
  419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  420. return
  421. }
  422. patientsNew := models.XtPatientsNew{
  423. UserOrgId: patient.UserOrgId,
  424. UserId: patient.UserId,
  425. Avatar: patient.Avatar,
  426. PatientType: patient.PatientType,
  427. DialysisNo: patient.DialysisNo,
  428. AdmissionNumber: patient.AdmissionNumber,
  429. Source: patient.Source,
  430. PartitionId: patient.PartitionId,
  431. BedId: patient.BedId,
  432. Name: patient.Name,
  433. Alias: patient.Alias,
  434. Gender: patient.Gender,
  435. MaritalStatus: patient.MaritalStatus,
  436. IdCardNo: patient.IdCardNo,
  437. Birthday: patient.Birthday,
  438. ReimbursementWayId: patient.ReimbursementWayId,
  439. HealthCareType: patient.HealthCareType,
  440. HealthCareNo: patient.HealthCareNo,
  441. HealthCareDueDate: patient.HealthCareDueDate,
  442. Height: patient.Height,
  443. BloodType: patient.BloodType,
  444. Rh: patient.Rh,
  445. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  446. EducationLevel: patient.EducationLevel,
  447. Profession: patient.Profession,
  448. Phone: patient.Phone,
  449. HomeTelephone: patient.HomeTelephone,
  450. RelativePhone: patient.RelativePhone,
  451. RelativeRelations: patient.RelativeRelations,
  452. HomeAddress: patient.HomeAddress,
  453. WorkUnit: patient.WorkUnit,
  454. UnitAddress: patient.UnitAddress,
  455. Children: patient.Children,
  456. ReceivingDate: patient.ReceivingDate,
  457. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  458. FirstDialysisDate: patient.FirstDialysisDate,
  459. FirstDialysisHospital: patient.FirstDialysisHospital,
  460. PredialysisCondition: patient.PredialysisCondition,
  461. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  462. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  463. InductionPeriod: patient.InductionPeriod,
  464. InitialDialysis: patient.InitialDialysis,
  465. TotalDialysis: patient.TotalDialysis,
  466. AttendingDoctorId: patient.AttendingDoctorId,
  467. HeadNurseId: patient.HeadNurseId,
  468. Evaluate: patient.Evaluate,
  469. Diagnose: patient.Diagnose,
  470. Remark: patient.Remark,
  471. RegistrarsId: patient.RegistrarsId,
  472. Registrars: patient.Registrars,
  473. QrCode: patient.QrCode,
  474. BindingState: patient.BindingState,
  475. PatientComplains: patient.PatientComplains,
  476. PresentHistory: patient.PresentHistory,
  477. PastHistory: patient.PastHistory,
  478. Temperature: patient.Temperature,
  479. Pulse: patient.Pulse,
  480. Respiratory: patient.Respiratory,
  481. Sbp: patient.SBP,
  482. Dbp: patient.DBP,
  483. Nation: patient.Nation,
  484. NativePlace: patient.NativePlace,
  485. Age: patient.Age,
  486. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  487. IsInfectious: patient.IsInfectious,
  488. RemindCycle: patient.RemindCycle,
  489. ResponseResult: patient.ResponseResult,
  490. IsOpenRemind: patient.IsOpenRemind,
  491. FirstTreatmentDate: patient.FirstTreatmentDate,
  492. DialysisAge: patient.DialysisAge,
  493. ExpenseKind: patient.ExpenseKind,
  494. TellPhone: patient.TellPhone,
  495. ContactName: patient.ContactName,
  496. UpdatedTime: time.Now().Unix(),
  497. BloodPatients: 1,
  498. Lapseto: patient.Lapseto,
  499. }
  500. // //更新病人ID获取新表病人ID
  501. err = service.UpdatepatientTwo(&patientsNew, id)
  502. if len(record_date) > 0 {
  503. var recordTime int64
  504. timeLayout := "2006-01-02"
  505. loc, _ := time.LoadLocation("Local")
  506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  507. if err != nil {
  508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  509. return
  510. }
  511. recordTime = theTime.Unix()
  512. inspections := make([]models.Inspection, 0)
  513. for _, item := range formItems {
  514. var inspection models.Inspection
  515. inspection.OrgId = adminUserInfo.CurrentOrgId
  516. inspection.PatientId = patient.ID
  517. inspection.ProjectId = item.ProjectId
  518. inspection.ItemId = item.ItemId
  519. inspection.ItemName = item.ItemName
  520. inspection.ProjectName = item.ProjectName
  521. inspection.InspectType = item.RangeType
  522. inspection.InspectValue = item.Value
  523. inspection.InspectDate = recordTime
  524. inspection.Status = 1
  525. inspection.CreatedTime = time.Now().Unix()
  526. inspection.UpdatedTime = time.Now().Unix()
  527. inspections = append(inspections, inspection)
  528. }
  529. err = service.CreatePatientInspection(inspections)
  530. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  531. var record_time int64
  532. switch remind_cycle {
  533. case 1: //1个月
  534. ts := time.Unix(infectiousRecord.InspectDate, 0)
  535. record_time = ts.AddDate(0, 1, 0).Unix()
  536. break
  537. case 2: //2个月
  538. ts := time.Unix(infectiousRecord.InspectDate, 0)
  539. record_time = ts.AddDate(0, 2, 0).Unix()
  540. break
  541. case 3: //3个月
  542. ts := time.Unix(infectiousRecord.InspectDate, 0)
  543. record_time = ts.AddDate(0, 3, 0).Unix()
  544. break
  545. case 4: //6个月
  546. ts := time.Unix(infectiousRecord.InspectDate, 0)
  547. record_time = ts.AddDate(0, 6, 0).Unix()
  548. break
  549. case 5: //12个月
  550. ts := time.Unix(infectiousRecord.InspectDate, 0)
  551. record_time = ts.AddDate(0, 12, 0).Unix()
  552. break
  553. }
  554. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  555. if errs != nil {
  556. utils.ErrorLog("更新日期出错:%v", errs)
  557. }
  558. }
  559. c.ServeSuccessJSON(map[string]interface{}{
  560. "msg": "ok",
  561. })
  562. return
  563. }
  564. func (c *PatientApiController) EditLapseto() {
  565. id, _ := c.GetInt64("id", 0)
  566. if id <= 0 {
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  568. return
  569. }
  570. adminUserInfo := c.GetAdminUserInfo()
  571. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  572. if patient.ID == 0 {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  574. return
  575. }
  576. patientBody := make(map[string]interface{}, 0)
  577. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  578. if err != nil {
  579. utils.ErrorLog(err.Error())
  580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  581. return
  582. }
  583. var lapseto models.PatientLapseto
  584. lapseto.PatientId = patient.ID
  585. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  586. utils.ErrorLog("lapseto_type")
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  591. if lapsetoType <= 0 || lapsetoType > 3 {
  592. utils.ErrorLog("lapsetoType <= 0 || lapsetoType > 3")
  593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  594. return
  595. }
  596. lapseto.LapsetoType = lapsetoType
  597. timeLayout := "2006-01-02 15:04:05"
  598. loc, _ := time.LoadLocation("Local")
  599. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  600. utils.ErrorLog("lapseto_time")
  601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  602. return
  603. }
  604. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  605. if len(lapsetoTime) == 0 {
  606. utils.ErrorLog("len(lapsetoTime) == 0")
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  608. return
  609. }
  610. out_reason, _ := patientBody["out_reason"].(string)
  611. //if len(out_reason) == 0 {
  612. // utils.ErrorLog("len(out_reason) == 0")
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  614. // return
  615. //}
  616. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  617. if err != nil {
  618. utils.ErrorLog("lapsetoTimeUnix")
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  620. return
  621. }
  622. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  623. lapseto.UpdatedTime = time.Now().Unix()
  624. lapseto.CreatedTime = time.Now().Unix()
  625. lapseto.Status = 1
  626. patient.Lapseto = lapseto.LapsetoType
  627. patient.OutReason = out_reason
  628. patient.DeathTime = lapsetoTimeUnix.Unix()
  629. //if patient.Lapseto == 1 {
  630. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  631. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  632. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  634. // return
  635. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  636. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  637. // return
  638. // }
  639. //}
  640. err = service.EditPatientLapseto(&patient, &lapseto)
  641. if lapseto.LapsetoType == 3 {
  642. service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
  643. service.UpdateScheduleItemByPatientId(id)
  644. }
  645. if err != nil {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  647. return
  648. }
  649. c.ServeSuccessJSON(map[string]interface{}{
  650. "msg": "ok",
  651. })
  652. return
  653. }
  654. func (c *PatientApiController) GetPatient() {
  655. id, _ := c.GetInt64("id", 0)
  656. if id <= 0 {
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  658. return
  659. }
  660. adminUserInfo := c.GetAdminUserInfo()
  661. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  662. if patient.ID == 0 {
  663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  664. return
  665. }
  666. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  667. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  668. diseases := service.GetPatientDiseases(patient.ID)
  669. contagions := service.GetPatientContagions(patient.ID)
  670. c.ServeSuccessJSON(map[string]interface{}{
  671. "patient": patient,
  672. "diseases": diseases,
  673. "contagions": contagions,
  674. "infections": infections,
  675. })
  676. return
  677. }
  678. func (c *PatientApiController) CreateDialysisSolution() {
  679. id, _ := c.GetInt64("patient", 0)
  680. if id <= 0 {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. adminUserInfo := c.GetAdminUserInfo()
  685. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  686. if patient.ID == 0 {
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  688. return
  689. }
  690. var solution models.DialysisSolution
  691. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  692. if code > 0 {
  693. c.ServeFailJSONWithSGJErrorCode(code)
  694. return
  695. }
  696. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  697. //if thisSolution.ID > 0 {
  698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  699. // return
  700. //}
  701. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  702. solution.Doctor = adminUserInfo.AdminUser.Id
  703. solution.Status = 1
  704. solution.PatientId = id
  705. solution.CreatedTime = time.Now().Unix()
  706. solution.UserOrgId = adminUserInfo.CurrentOrgId
  707. solution.UpdatedTime = time.Now().Unix()
  708. solution.SubName = ""
  709. solution.ParentId = 0
  710. err := service.CreatePatientDialysisSolution(&solution)
  711. if err != nil {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  713. return
  714. }
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "msg": "ok",
  717. "solution": solution,
  718. })
  719. return
  720. }
  721. func (c *PatientApiController) UpdateDialysisSolution() {
  722. patient, _ := c.GetInt64("patient", 0)
  723. id, _ := c.GetInt64("id", 0)
  724. if id <= 0 || patient <= 0 {
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. adminUserInfo := c.GetAdminUserInfo()
  729. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  730. if solution.ID == 0 || solution.PatientId != patient {
  731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  732. return
  733. }
  734. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  735. if code > 0 {
  736. c.ServeFailJSONWithSGJErrorCode(code)
  737. return
  738. }
  739. solution.UpdatedTime = time.Now().Unix()
  740. err := service.UpdatePatientDialysisSolution(&solution)
  741. nowTimeUinx := time.Now()
  742. today := nowTimeUinx.Format("2006-01-02")
  743. timeLayout := "2006-01-02"
  744. loc, _ := time.LoadLocation("Local")
  745. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  746. prescription := models.DialysisPrescription{
  747. Dialyzer: solution.Dialyzer,
  748. Anticoagulant: solution.Anticoagulant,
  749. AnticoagulantShouji: solution.AnticoagulantShouji,
  750. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  751. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  752. ModeId: solution.ModeId,
  753. DialysisDurationHour: solution.DialysisDurationHour,
  754. Kalium: solution.Kalium,
  755. Sodium: solution.Sodium,
  756. Calcium: solution.Calcium,
  757. TargetUltrafiltration: solution.TargetUltrafiltration,
  758. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  759. BloodAccess: solution.BloodAccess,
  760. DialysateFlow: solution.DialysateFlow,
  761. DialysateTemperature: solution.DialysateTemperature,
  762. DialysisIrrigation: solution.DialysisIrrigation,
  763. DialysisDialyszers: solution.DialysisDialyszers,
  764. PlasmaSeparator: solution.PlasmaSeparator,
  765. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  766. OxygenUptake: solution.OxygenUptake,
  767. OxygenFlow: solution.OxygenFlow,
  768. OxygenTime: solution.OxygenTime,
  769. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  770. }
  771. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  772. if err != nil {
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  774. return
  775. }
  776. c.ServeSuccessJSON(map[string]interface{}{
  777. "msg": "ok",
  778. "solution": solution,
  779. })
  780. return
  781. }
  782. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  783. patient, _ := c.GetInt64("patient", 0)
  784. id, _ := c.GetInt64("id", 0)
  785. if id <= 0 || patient <= 0 {
  786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  787. return
  788. }
  789. adminUserInfo := c.GetAdminUserInfo()
  790. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  791. if solution.ID == 0 || solution.PatientId != patient {
  792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  793. return
  794. }
  795. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  796. if code > 0 {
  797. c.ServeFailJSONWithSGJErrorCode(code)
  798. return
  799. }
  800. solution.UpdatedTime = time.Now().Unix()
  801. solution.AffirmState = 1
  802. err := service.UpdatePatientDialysisSolution(&solution)
  803. if err != nil {
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  805. return
  806. }
  807. c.ServeSuccessJSON(map[string]interface{}{
  808. "msg": "ok",
  809. "solution": solution,
  810. })
  811. return
  812. }
  813. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  814. id, _ := c.GetInt64("id", 0)
  815. page, _ := c.GetInt64("page", 0)
  816. limit, _ := c.GetInt64("limit", 0)
  817. if id <= 0 {
  818. c.ServeSuccessJSON(map[string]interface{}{
  819. "solutions": nil,
  820. })
  821. return
  822. }
  823. if page <= 0 {
  824. page = 1
  825. }
  826. if limit <= 0 {
  827. limit = 10
  828. }
  829. adminUserInfo := c.GetAdminUserInfo()
  830. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  831. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  832. c.ServeSuccessJSON(map[string]interface{}{
  833. "solutions": solutions,
  834. "total": total,
  835. "stockType": stockType,
  836. })
  837. return
  838. }
  839. func (c *PatientApiController) DeleteDialysisSolution() {
  840. id, _ := c.GetInt64("id", 0)
  841. if id <= 0 {
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  843. return
  844. }
  845. adminUserInfo := c.GetAdminUserInfo()
  846. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  847. if solution.ID == 0 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  849. return
  850. }
  851. if solution.UseState == 1 {
  852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  853. return
  854. }
  855. solution.UpdatedTime = time.Now().Unix()
  856. solution.Status = 0
  857. err := service.DeleteSolution(&solution)
  858. if err != nil {
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  860. return
  861. }
  862. c.ServeSuccessJSON(map[string]interface{}{
  863. "msg": "ok",
  864. })
  865. return
  866. }
  867. //GetDryWeights 取患者干体重调整铺
  868. func (c *PatientApiController) GetDryWeights() {
  869. page, _ := c.GetInt64("page", 1)
  870. limit, _ := c.GetInt64("limit", 10)
  871. id, _ := c.GetInt64("id", 0)
  872. if id <= 0 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  874. return
  875. }
  876. adminUserInfo := c.GetAdminUserInfo()
  877. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  878. c.ServeSuccessJSON(map[string]interface{}{
  879. "weights": weights,
  880. "total": total,
  881. })
  882. return
  883. }
  884. func (c *PatientApiController) CreateDryWeights() {
  885. patient, _ := c.GetInt64("id", 0)
  886. if patient <= 0 {
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. adminUserInfo := c.GetAdminUserInfo()
  891. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  892. if patientInfo.ID == 0 {
  893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  894. return
  895. }
  896. var theWeight models.DryWeightAdjust
  897. dataBody := make(map[string]interface{}, 0)
  898. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  899. if err != nil {
  900. utils.ErrorLog(err.Error())
  901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  902. return
  903. }
  904. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. return
  907. }
  908. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  909. theWeight.Weight = weight
  910. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  911. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. // return
  913. // }
  914. // doctor := int64(dataBody["doctor"].(float64))
  915. // theWeight.Doctor = doctor
  916. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  917. remark, _ := dataBody["remark"].(string)
  918. theWeight.Remark = remark
  919. }
  920. theWeight.CreatedTime = time.Now().Unix()
  921. theWeight.UpdatedTime = time.Now().Unix()
  922. theWeight.Status = 1
  923. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  924. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  925. theWeight.PatientId = patient
  926. theWeight.Doctor = adminUserInfo.AdminUser.Id
  927. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  928. if old.ID > 0 {
  929. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  930. }
  931. err = service.CreateDryWeightAdjust(&theWeight)
  932. if err != nil {
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  934. return
  935. }
  936. c.ServeSuccessJSON(map[string]interface{}{
  937. "msg": "ok",
  938. "weight": theWeight,
  939. })
  940. return
  941. }
  942. func (c *PatientApiController) CreateGroupAdvice() {
  943. patient, _ := c.GetInt64("id", 0)
  944. groupNo, _ := c.GetInt64("groupno", 0)
  945. if patient <= 0 {
  946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  947. return
  948. }
  949. adminUserInfo := c.GetAdminUserInfo()
  950. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  951. if patientInfo.ID == 0 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  953. return
  954. }
  955. dataBody := make(map[string]interface{}, 0)
  956. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  957. if err != nil {
  958. utils.ErrorLog(err.Error())
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. utils.ErrorLog("%v", dataBody)
  963. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  964. if appRole.UserType == 3 {
  965. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  966. if getPermissionErr != nil {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  968. return
  969. } else if headNursePermission == nil {
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  971. return
  972. }
  973. }
  974. timeLayout := "2006-01-02"
  975. loc, _ := time.LoadLocation("Local")
  976. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  977. utils.ErrorLog("advice_type")
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  979. return
  980. }
  981. adviceType := int64(dataBody["advice_type"].(float64))
  982. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  983. utils.ErrorLog("advice_type != 1&&2")
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  988. utils.ErrorLog("advice_date")
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  990. return
  991. }
  992. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  993. utils.ErrorLog("start_time")
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  995. return
  996. }
  997. startTime2, _ := dataBody["start_time"].(string)
  998. time_arr := strings.Split(startTime2, " ")
  999. if len(time_arr) > 0 {
  1000. startTime2 = time_arr[0]
  1001. }
  1002. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1003. utils.ErrorLog("advice_date")
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adviceDate := startTime2
  1008. if len(adviceDate) == 0 {
  1009. utils.ErrorLog("len(adviceDate) == 0")
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1014. if err != nil {
  1015. utils.ErrorLog(err.Error())
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. AdviceDate := theTime.Unix()
  1020. RecordDate := theTime.Unix()
  1021. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1022. utils.ErrorLog("start_time")
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. startTime, _ := dataBody["start_time"].(string)
  1027. if len(startTime) == 0 {
  1028. utils.ErrorLog("len(start_time) == 0")
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1030. return
  1031. }
  1032. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1033. if err != nil {
  1034. utils.ErrorLog(err.Error())
  1035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. StartTime := theTime.Unix()
  1039. Remark := ""
  1040. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1041. remark, _ := dataBody["remark"].(string)
  1042. Remark = remark
  1043. }
  1044. var advices []*models.GroupAdvice
  1045. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1046. utils.ErrorLog("adviceNames")
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1048. return
  1049. }
  1050. adviceNames := dataBody["adviceNames"].([]interface{})
  1051. for _, adviceNameMap := range adviceNames {
  1052. adviceNameM := adviceNameMap.(map[string]interface{})
  1053. var advice models.GroupAdvice
  1054. advice.Remark = Remark
  1055. advice.AdviceType = adviceType
  1056. advice.StartTime = StartTime
  1057. advice.AdviceDate = AdviceDate
  1058. advice.RecordDate = RecordDate
  1059. advice.Status = 1
  1060. advice.CreatedTime = time.Now().Unix()
  1061. advice.UpdatedTime = time.Now().Unix()
  1062. advice.StopState = 2
  1063. advice.ExecutionState = 2
  1064. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1065. advice.PatientId = patientInfo.ID
  1066. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1067. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1068. utils.ErrorLog("advice_name")
  1069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1070. return
  1071. }
  1072. adviceName, _ := adviceNameM["advice_name"].(string)
  1073. if len(adviceName) == 0 {
  1074. utils.ErrorLog("len(advice_name) == 0")
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1076. return
  1077. }
  1078. advice.AdviceName = adviceName
  1079. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1080. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1081. advice.DrugSpec = drugSpec
  1082. }
  1083. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1084. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1085. advice.AdviceDesc = adviceDesc
  1086. }
  1087. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1088. template_id, _ := adviceNameM["template_id"].(string)
  1089. advice.TemplateId = template_id
  1090. }
  1091. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1092. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1093. advice.DrugSpecUnit = drugSpecUnit
  1094. }
  1095. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1096. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1097. advice.SingleDose = singleDose
  1098. }
  1099. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1100. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1101. advice.SingleDoseUnit = singleDoseUnit
  1102. }
  1103. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1104. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1105. advice.PrescribingNumber = prescribingNumber
  1106. }
  1107. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1108. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1109. advice.PrescribingNumberUnit = prescribingNumberUnit
  1110. }
  1111. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1112. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1113. advice.DeliveryWay = deliveryWay
  1114. }
  1115. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1116. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1117. advice.ExecutionFrequency = executionFrequency
  1118. }
  1119. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1120. way := int64(adviceNameM["way"].(float64))
  1121. advice.Way = way
  1122. }
  1123. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1124. drug_id := int64(adviceNameM["drug_id"].(float64))
  1125. advice.DrugId = drug_id
  1126. }
  1127. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1128. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1129. advice.DrugNameId = drug_name_id
  1130. }
  1131. if adviceType == 1 {
  1132. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1133. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1134. advice.FrequencyType = frequency_type
  1135. }
  1136. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1137. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1138. advice.DayCount = day_count
  1139. }
  1140. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1141. week_day, _ := adviceNameM["week_days"].(string)
  1142. advice.WeekDay = week_day
  1143. }
  1144. }
  1145. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1146. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1147. advice.ExecutionFrequency = executionFrequency
  1148. }
  1149. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1150. children := adviceNameM["children"].([]interface{})
  1151. if len(children) > 0 {
  1152. for _, childrenMap := range children {
  1153. childMap := childrenMap.(map[string]interface{})
  1154. var child models.GroupAdvice
  1155. child.Remark = Remark
  1156. child.AdviceType = adviceType
  1157. child.StartTime = StartTime
  1158. child.AdviceDate = AdviceDate
  1159. child.RecordDate = RecordDate
  1160. child.Status = 1
  1161. child.CreatedTime = time.Now().Unix()
  1162. child.UpdatedTime = time.Now().Unix()
  1163. child.StopState = 2
  1164. child.ExecutionState = 2
  1165. child.UserOrgId = adminUserInfo.CurrentOrgId
  1166. child.PatientId = patientInfo.ID
  1167. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1168. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1169. utils.ErrorLog("child advice_name")
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. childAdviceName, _ := childMap["advice_name"].(string)
  1174. if len(childAdviceName) == 0 {
  1175. utils.ErrorLog("len(child advice_name) == 0")
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1177. return
  1178. }
  1179. child.AdviceName = childAdviceName
  1180. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1181. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1182. child.AdviceDesc = childAdviceDesc
  1183. }
  1184. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1185. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1186. child.DrugSpec = childDrugSpec
  1187. }
  1188. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1189. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1190. child.DrugSpecUnit = childDrugSpecUnit
  1191. }
  1192. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1193. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1194. child.SingleDose = childSingleDose
  1195. }
  1196. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1197. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1198. child.SingleDoseUnit = childSingleDoseUnit
  1199. }
  1200. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1201. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1202. child.PrescribingNumber = childPrescribingNumber
  1203. }
  1204. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1205. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1206. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1207. }
  1208. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1209. drug_id := int64(childMap["drug_id"].(float64))
  1210. child.DrugId = drug_id
  1211. }
  1212. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1213. way := int64(childMap["way"].(float64))
  1214. child.Way = way
  1215. }
  1216. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1217. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1218. child.DrugNameId = drug_name_id
  1219. }
  1220. child.DeliveryWay = advice.DeliveryWay
  1221. child.ExecutionFrequency = advice.ExecutionFrequency
  1222. advice.Children = append(advice.Children, &child)
  1223. }
  1224. }
  1225. }
  1226. advices = append(advices, &advice)
  1227. }
  1228. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1229. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1230. //fmt.Println("key23323323232323223233223232323",key)
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. redis.Set(key, "", time.Second)
  1234. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1235. redis.Set(keyOne, "", time.Second)
  1236. //fmt.Println("keyOne23322322323232323233232332",keyOne)
  1237. if err != nil {
  1238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1239. return
  1240. }
  1241. c.ServeSuccessJSON(map[string]interface{}{
  1242. "msg": "ok",
  1243. "advices": list,
  1244. })
  1245. return
  1246. }
  1247. func (c *PatientApiController) CreateDoctorAdvice() {
  1248. patient, _ := c.GetInt64("id", 0)
  1249. if patient <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetAdminUserInfo()
  1254. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1255. if patientInfo.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1260. if appRole.UserType == 3 {
  1261. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1262. if getPermissionErr != nil {
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1264. return
  1265. } else if headNursePermission == nil {
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1267. return
  1268. }
  1269. }
  1270. var advice models.DoctorAdvice
  1271. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1272. if code > 0 {
  1273. c.ServeFailJSONWithSGJErrorCode(code)
  1274. return
  1275. }
  1276. if advice.ParentId > 0 {
  1277. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1278. if old.ID == 0 || old.PatientId != patient {
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1280. return
  1281. }
  1282. if old.StopState == 1 || old.ExecutionState == 1 {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1284. return
  1285. }
  1286. if old.ParentId > 0 {
  1287. advice.ParentId = old.ParentId
  1288. }
  1289. advice.StartTime = old.StartTime
  1290. advice.AdviceDoctor = old.AdviceDoctor
  1291. advice.DeliveryWay = old.DeliveryWay
  1292. advice.ExecutionFrequency = old.ExecutionFrequency
  1293. advice.GroupNo = old.GroupNo
  1294. }
  1295. advice.Status = 1
  1296. advice.CreatedTime = time.Now().Unix()
  1297. advice.UpdatedTime = time.Now().Unix()
  1298. advice.StopState = 2
  1299. advice.ExecutionState = 2
  1300. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1301. advice.PatientId = patient
  1302. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1303. err := service.CreateDoctorAdvice(&advice)
  1304. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1305. redis := service.RedisClient()
  1306. defer redis.Close()
  1307. redis.Set(key, "", time.Second)
  1308. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1309. redis.Set(keyOne, "", time.Second)
  1310. if err != nil {
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1312. return
  1313. }
  1314. c.ServeSuccessJSON(map[string]interface{}{
  1315. "msg": "ok",
  1316. "advice": advice,
  1317. })
  1318. return
  1319. }
  1320. func (c *PatientApiController) ExecGroupAdvice() {
  1321. groupNo, _ := c.GetInt64("groupno", 0)
  1322. executionTime := c.GetString("execution_time")
  1323. if groupNo <= 0 {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. if len(executionTime) <= 0 {
  1328. utils.ErrorLog("execution_time")
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. adminUserInfo := c.GetAdminUserInfo()
  1333. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1334. if advice.ID == 0 {
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1336. return
  1337. }
  1338. if advice.ExecutionState == 1 {
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1340. return
  1341. }
  1342. executionStaff := adminUserInfo.AdminUser.Id
  1343. // checker := adminUserInfo.AdminUser.Id
  1344. timeLayout := "2006-01-02 15:04:05"
  1345. loc, _ := time.LoadLocation("Local")
  1346. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1347. if err != nil {
  1348. utils.ErrorLog(err.Error())
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. if advice.StartTime > theTime.Unix() {
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1354. return
  1355. }
  1356. exceAdvice := models.DoctorAdvice{
  1357. ExecutionStaff: executionStaff,
  1358. ExecutionTime: theTime.Unix(),
  1359. // Checker: checker,
  1360. UpdatedTime: time.Now().Unix(),
  1361. }
  1362. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1363. if err != nil {
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1365. return
  1366. }
  1367. advice.ExecutionStaff = executionStaff
  1368. advice.ExecutionTime = theTime.Unix()
  1369. // advice.Checker = checker
  1370. c.ServeSuccessJSON(map[string]interface{}{
  1371. "msg": "ok",
  1372. "advice": advice,
  1373. })
  1374. return
  1375. }
  1376. func (c *PatientApiController) ExecDoctorAdvice() {
  1377. origin, _ := c.GetInt64("origin", 0)
  1378. patient, _ := c.GetInt64("patient", 0)
  1379. id, _ := c.GetInt64("id", 0)
  1380. executionTime := c.GetString("execution_time")
  1381. if origin != 2 {
  1382. if id <= 0 || patient <= 0 {
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. if len(executionTime) <= 0 {
  1387. utils.ErrorLog("execution_time")
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. adminUserInfo := c.GetAdminUserInfo()
  1392. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1393. if advice.ID == 0 || advice.PatientId != patient {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1395. return
  1396. }
  1397. //医嘱已执行
  1398. if advice.ExecutionState == 1 {
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1400. return
  1401. }
  1402. executionStaff := adminUserInfo.AdminUser.Id
  1403. // checker := adminUserInfo.AdminUser.Id
  1404. timeLayout := "2006-01-02 15:04:05"
  1405. loc, _ := time.LoadLocation("Local")
  1406. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1407. if err != nil {
  1408. utils.ErrorLog(err.Error())
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1410. return
  1411. }
  1412. if advice.StartTime > theTime.Unix() {
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1414. return
  1415. }
  1416. exceAdvice := models.DoctorAdvice{
  1417. ExecutionStaff: executionStaff,
  1418. ExecutionTime: theTime.Unix(),
  1419. // Checker: checker,
  1420. UpdatedTime: time.Now().Unix(),
  1421. }
  1422. if advice.ParentId > 0 {
  1423. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1424. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1425. redis := service.RedisClient()
  1426. //清空key 值
  1427. redis.Set(key, "", time.Second)
  1428. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1429. redis.Set(keyTwo, "", time.Second)
  1430. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1431. redis.Set(keyThree, "", time.Second)
  1432. theTimes := theTime.Format("2006-01-02")
  1433. fmt.Println("theTIME", theTime)
  1434. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1435. redis.Set(keyFour, "", time.Second)
  1436. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1437. redis.Set(keyFive, "", time.Second)
  1438. defer redis.Close()
  1439. } else {
  1440. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1441. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1442. redis := service.RedisClient()
  1443. //清空key 值
  1444. redis.Set(key, "", time.Second)
  1445. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1446. redis.Set(keyTwo, "", time.Second)
  1447. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1448. redis.Set(keyThree, "", time.Second)
  1449. theTimes := theTime.Format("2006-01-02")
  1450. fmt.Println("theTIME", theTime)
  1451. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1452. redis.Set(keyFour, "", time.Second)
  1453. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1454. redis.Set(keyFive, "", time.Second)
  1455. defer redis.Close()
  1456. }
  1457. if err != nil {
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1459. return
  1460. }
  1461. advice.ExecutionStaff = executionStaff
  1462. advice.ExecutionTime = theTime.Unix()
  1463. // advice.Checker = checker
  1464. //处理出库相关逻辑
  1465. //1.判断是否启用药品管理和自备药出库功能
  1466. //药品管理信息
  1467. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1468. //自备药信息
  1469. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  1470. if drugStockConfig.IsOpen == 1 {
  1471. var total int64
  1472. var prescribing_number_total int64
  1473. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1474. for _, item := range advices {
  1475. //查询该药品是否有库存
  1476. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  1477. //查询改药品信息
  1478. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1479. //判断单位是否相等
  1480. if medical.MaxUnit == item.PrescribingNumberUnit {
  1481. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1482. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1483. //转化为最小单位
  1484. total = list.Count*medical.MinNumber + list.StockMinNumber
  1485. prescribing_number_total = count * medical.MinNumber
  1486. }
  1487. if medical.MinUnit == item.PrescribingNumberUnit {
  1488. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1489. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1490. total = list.Count*medical.MinNumber + list.StockMinNumber
  1491. prescribing_number_total = count
  1492. }
  1493. fmt.Println("数量一", prescribing_number_total)
  1494. fmt.Println("数量二", total)
  1495. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1496. c.ServeSuccessJSON(map[string]interface{}{
  1497. "msg": "3",
  1498. "advice": advice,
  1499. })
  1500. return
  1501. }
  1502. if prescribing_number_total > total {
  1503. c.ServeSuccessJSON(map[string]interface{}{
  1504. "msg": "2",
  1505. "advice": advice,
  1506. })
  1507. return
  1508. }
  1509. if prescribing_number_total <= total {
  1510. if medical.IsUse == 2 {
  1511. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1512. break
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "msg": "1",
  1515. "advice": advice,
  1516. })
  1517. return
  1518. }
  1519. if medical.IsUse == 1 {
  1520. c.ServeSuccessJSON(map[string]interface{}{
  1521. "msg": "1",
  1522. "advice": advice,
  1523. })
  1524. return
  1525. }
  1526. }
  1527. }
  1528. }
  1529. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1530. for _, item := range advices {
  1531. if item.Way == 2 {
  1532. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1533. //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1534. if item.ExecutionState == 1 {
  1535. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1536. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1537. timeStr := time.Now().Format("2006-01-02")
  1538. timeArr := strings.Split(timeStr, "-")
  1539. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1540. total = total + 1
  1541. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1542. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1543. number = number + total
  1544. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1545. //插入自备药出库单
  1546. outStock := models.XtSelfOutStock{
  1547. DrugName: item.AdviceName,
  1548. DrugNameId: item.DrugId,
  1549. DrugSpec: item.AdviceDesc,
  1550. OutstoreNumber: count,
  1551. AdminUserId: adminUserInfo.AdminUser.Id,
  1552. StorckTime: item.RecordDate,
  1553. UserOrgId: adminUserInfo.CurrentOrgId,
  1554. CreatedTime: time.Now().Unix(),
  1555. Status: 1,
  1556. PatientId: item.PatientId,
  1557. ExitMode: 2,
  1558. MedicId: item.DrugId,
  1559. StockOutNumber: warehousing_out_order,
  1560. }
  1561. service.CreateOutStock(&outStock)
  1562. }
  1563. }
  1564. }
  1565. }
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "msg": "1",
  1568. "advice": advice,
  1569. })
  1570. return
  1571. } else {
  1572. if id <= 0 || patient <= 0 {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. if len(executionTime) <= 0 {
  1577. utils.ErrorLog("execution_time")
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1579. return
  1580. }
  1581. adminUserInfo := c.GetAdminUserInfo()
  1582. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1583. if advice.ID == 0 || advice.PatientId != patient {
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1585. return
  1586. }
  1587. //医嘱已执行
  1588. if advice.ExecutionState == 1 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1590. return
  1591. }
  1592. executionStaff := adminUserInfo.AdminUser.Id
  1593. timeLayout := "2006-01-02 15:04:05"
  1594. loc, _ := time.LoadLocation("Local")
  1595. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1596. if err != nil {
  1597. utils.ErrorLog(err.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. if advice.StartTime > theTime.Unix() {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. exceAdvice := models.HisDoctorAdviceInfo{
  1606. ExecutionStaff: executionStaff,
  1607. ExecutionTime: theTime.Unix(),
  1608. // Checker: checker,
  1609. UpdatedTime: time.Now().Unix(),
  1610. }
  1611. if advice.ParentId > 0 {
  1612. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1613. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1614. redis := service.RedisClient()
  1615. //清空key 值
  1616. redis.Set(key, "", time.Second)
  1617. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1618. redis.Set(keyTwo, "", time.Second)
  1619. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1620. redis.Set(keyThree, "", time.Second)
  1621. theTimes := theTime.Format("2006-01-02")
  1622. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1623. redis.Set(keyFour, "", time.Second)
  1624. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1625. redis.Set(keyFive, "", time.Second)
  1626. defer redis.Close()
  1627. } else {
  1628. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1629. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1630. redis := service.RedisClient()
  1631. //清空key 值
  1632. redis.Set(key, "", time.Second)
  1633. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1634. redis.Set(keyTwo, "", time.Second)
  1635. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1636. redis.Set(keyThree, "", time.Second)
  1637. theTimes := theTime.Format("2006-01-02")
  1638. fmt.Println("theTIME", theTime)
  1639. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1640. redis.Set(keyFour, "", time.Second)
  1641. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1642. redis.Set(keyFive, "", time.Second)
  1643. defer redis.Close()
  1644. }
  1645. if err != nil {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1647. return
  1648. }
  1649. advice.ExecutionStaff = executionStaff
  1650. advice.ExecutionTime = theTime.Unix()
  1651. // advice.Checker = checker
  1652. //处理出库相关逻辑
  1653. //1.判断是否启用药品管理和自备药出库功能
  1654. //药品管理信息
  1655. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1656. if drugStockConfig.IsOpen == 1 {
  1657. //查询已经执行的医嘱
  1658. advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1659. for _, item := range advices {
  1660. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1661. //查询这个患者这个患者这个药已经出库的所有数量
  1662. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1663. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1664. var total_count int64
  1665. var drug_count int64
  1666. for _, it := range advicelist {
  1667. if it.PrescribingNumberUnit == medical.MaxUnit {
  1668. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1669. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1670. total_count += prenumber * medical.MinNumber
  1671. }
  1672. if it.PrescribingNumberUnit == medical.MinUnit {
  1673. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1674. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1675. total_count += prenumber
  1676. }
  1677. }
  1678. for _, its := range drugoutlist {
  1679. if its.CountUnit == medical.MaxUnit {
  1680. drug_count += its.Count * medical.MinNumber
  1681. }
  1682. if its.CountUnit == medical.MinUnit {
  1683. drug_count += its.Count
  1684. }
  1685. }
  1686. if total_count == drug_count {
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "msg": "1",
  1689. "advice": advice,
  1690. })
  1691. return
  1692. }
  1693. var total int64
  1694. var prescribing_number_total int64
  1695. //查询该药品是否有库存
  1696. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  1697. //判断单位是否相等
  1698. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1699. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1700. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1701. //转化为最小单位
  1702. total = list.Count*medical.MinNumber + list.StockMinNumber
  1703. prescribing_number_total = count * medical.MinNumber
  1704. }
  1705. if medical.MinUnit == advice.PrescribingNumberUnit {
  1706. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1707. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1708. total = list.Count*medical.MinNumber + list.StockMinNumber
  1709. prescribing_number_total = count
  1710. }
  1711. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1712. c.ServeSuccessJSON(map[string]interface{}{
  1713. "msg": "3",
  1714. "advice": advice,
  1715. })
  1716. return
  1717. }
  1718. if prescribing_number_total > total {
  1719. c.ServeSuccessJSON(map[string]interface{}{
  1720. "msg": "2",
  1721. "advice": advice,
  1722. })
  1723. return
  1724. }
  1725. if prescribing_number_total <= total {
  1726. if medical.IsUse == 2 {
  1727. service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
  1728. break
  1729. c.ServeSuccessJSON(map[string]interface{}{
  1730. "msg": "1",
  1731. "advice": advice,
  1732. })
  1733. return
  1734. }
  1735. if medical.IsUse == 1 {
  1736. c.ServeSuccessJSON(map[string]interface{}{
  1737. "msg": "1",
  1738. "advice": advice,
  1739. })
  1740. return
  1741. }
  1742. }
  1743. }
  1744. }
  1745. c.ServeSuccessJSON(map[string]interface{}{
  1746. "msg": "1",
  1747. "advice": advice,
  1748. })
  1749. return
  1750. }
  1751. }
  1752. func (c *PatientApiController) CheckGroupAdvice() {
  1753. groupno, _ := c.GetInt64("groupno", 0)
  1754. if groupno <= 0 {
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1756. return
  1757. }
  1758. adminUserInfo := c.GetAdminUserInfo()
  1759. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1760. if advice.ID == 0 {
  1761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1762. return
  1763. }
  1764. if advice.CheckState == 1 {
  1765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1766. return
  1767. }
  1768. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1770. return
  1771. }
  1772. checker := adminUserInfo.AdminUser.Id
  1773. theTime := time.Now()
  1774. exceAdvice := models.DoctorAdvice{
  1775. Checker: checker,
  1776. CheckTime: theTime.Unix(),
  1777. UpdatedTime: time.Now().Unix(),
  1778. }
  1779. var err error
  1780. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1781. if err != nil {
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1783. return
  1784. }
  1785. // advice.ExecutionStaff = executionStaff
  1786. // advice.ExecutionTime = theTime.Unix()
  1787. advice.Checker = checker
  1788. advice.CheckTime = theTime.Unix()
  1789. c.ServeSuccessJSON(map[string]interface{}{
  1790. "msg": "ok",
  1791. "advice": advice,
  1792. })
  1793. return
  1794. }
  1795. func (c *PatientApiController) CheckDoctorAdvice() {
  1796. patient, _ := c.GetInt64("patient", 0)
  1797. id, _ := c.GetInt64("id", 0)
  1798. origin, _ := c.GetInt64("origin", 0)
  1799. if origin != 2 {
  1800. // executionTime := c.GetString("execution_time")
  1801. if id <= 0 || patient <= 0 {
  1802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1803. return
  1804. }
  1805. adminUserInfo := c.GetAdminUserInfo()
  1806. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1807. if advice.ID == 0 || advice.PatientId != patient {
  1808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1809. return
  1810. }
  1811. if advice.CheckState == 1 {
  1812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1813. return
  1814. }
  1815. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1817. return
  1818. }
  1819. // executionStaff := adminUserInfo.AdminUser.Id
  1820. checker := adminUserInfo.AdminUser.Id
  1821. // timeLayout := "2006-01-02 15:04:05"
  1822. // loc, _ := time.LoadLocation("Local")
  1823. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1824. // if err != nil {
  1825. // utils.ErrorLog(err.Error())
  1826. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1827. // return
  1828. // }
  1829. theTime := time.Now()
  1830. if advice.ExecutionTime > theTime.Unix() {
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1832. return
  1833. }
  1834. exceAdvice := models.DoctorAdvice{
  1835. Checker: checker,
  1836. CheckTime: theTime.Unix(),
  1837. UpdatedTime: time.Now().Unix(),
  1838. }
  1839. var err error
  1840. if advice.ParentId > 0 {
  1841. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1842. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1843. redis := service.RedisClient()
  1844. //清空key 值
  1845. redis.Set(key, "", time.Second)
  1846. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1847. redis.Set(keyTwo, "", time.Second)
  1848. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1849. redis.Set(keyThree, "", time.Second)
  1850. recordDate := theTime.Format("2006-01-02")
  1851. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1852. redis.Set(keyFour, "", time.Second)
  1853. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1854. redis.Set(keyFive, "", time.Second)
  1855. } else {
  1856. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1857. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1858. redis := service.RedisClient()
  1859. //清空key 值
  1860. redis.Set(key, "", time.Second)
  1861. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1862. redis.Set(keyTwo, "", time.Second)
  1863. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1864. redis.Set(keyThree, "", time.Second)
  1865. recordDate := theTime.Format("2006-01-02")
  1866. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1867. redis.Set(keyFour, "", time.Second)
  1868. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1869. redis.Set(keyFive, "", time.Second)
  1870. }
  1871. if err != nil {
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1873. return
  1874. }
  1875. // advice.ExecutionStaff = executionStaff
  1876. // advice.ExecutionTime = theTime.Unix()
  1877. advice.Checker = checker
  1878. advice.CheckTime = theTime.Unix()
  1879. c.ServeSuccessJSON(map[string]interface{}{
  1880. "msg": "ok",
  1881. "advice": advice,
  1882. })
  1883. return
  1884. } else {
  1885. if id <= 0 || patient <= 0 {
  1886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1887. return
  1888. }
  1889. adminUserInfo := c.GetAdminUserInfo()
  1890. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1891. if advice.ID == 0 || advice.PatientId != patient {
  1892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1893. return
  1894. }
  1895. if advice.CheckState == 1 {
  1896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1897. return
  1898. }
  1899. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1901. return
  1902. }
  1903. checker := adminUserInfo.AdminUser.Id
  1904. theTime := time.Now()
  1905. if advice.ExecutionTime > theTime.Unix() {
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1907. return
  1908. }
  1909. exceAdvice := models.HisDoctorAdviceInfo{
  1910. Checker: checker,
  1911. CheckTime: theTime.Unix(),
  1912. UpdatedTime: time.Now().Unix(),
  1913. }
  1914. var err error
  1915. if advice.ParentId > 0 {
  1916. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1917. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1918. redis := service.RedisClient()
  1919. //清空key 值
  1920. redis.Set(key, "", time.Second)
  1921. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1922. redis.Set(keyTwo, "", time.Second)
  1923. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1924. redis.Set(keyThree, "", time.Second)
  1925. recordDate := theTime.Format("2006-01-02")
  1926. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1927. redis.Set(keyFour, "", time.Second)
  1928. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1929. redis.Set(keyFive, "", time.Second)
  1930. } else {
  1931. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  1932. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1933. redis := service.RedisClient()
  1934. //清空key 值
  1935. redis.Set(key, "", time.Second)
  1936. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1937. redis.Set(keyTwo, "", time.Second)
  1938. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1939. redis.Set(keyThree, "", time.Second)
  1940. recordDate := theTime.Format("2006-01-02")
  1941. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1942. redis.Set(keyFour, "", time.Second)
  1943. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1944. redis.Set(keyFive, "", time.Second)
  1945. }
  1946. if err != nil {
  1947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1948. return
  1949. }
  1950. // advice.ExecutionStaff = executionStaff
  1951. // advice.ExecutionTime = theTime.Unix()
  1952. advice.Checker = checker
  1953. advice.CheckTime = theTime.Unix()
  1954. c.ServeSuccessJSON(map[string]interface{}{
  1955. "msg": "ok",
  1956. "advice": advice,
  1957. })
  1958. return
  1959. }
  1960. }
  1961. func (c *PatientApiController) UpdateDoctorAdvice() {
  1962. patient, _ := c.GetInt64("patient", 0)
  1963. id, _ := c.GetInt64("id", 0)
  1964. if id <= 0 || patient <= 0 {
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. adminUserInfo := c.GetAdminUserInfo()
  1969. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1970. if advice.ID == 0 || advice.PatientId != patient {
  1971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1972. return
  1973. }
  1974. //if advice.AdviceType == 1 {
  1975. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  1976. // return
  1977. //}
  1978. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1980. return
  1981. }
  1982. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1983. //if appRole.UserType == 3 {
  1984. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1985. // if getPermissionErr != nil {
  1986. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1987. // return
  1988. // } else if headNursePermission == nil {
  1989. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1990. // return
  1991. // }
  1992. //}
  1993. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1994. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  1995. // return
  1996. //}
  1997. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  1998. if code > 0 {
  1999. c.ServeFailJSONWithSGJErrorCode(code)
  2000. return
  2001. }
  2002. advice.UpdatedTime = time.Now().Unix()
  2003. advice.Modifier = adminUserInfo.AdminUser.Id
  2004. err := service.UpdateDoctorAdvice(&advice)
  2005. redis := service.RedisClient()
  2006. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2007. redis.Set(key, "", time.Second)
  2008. fmt.Println("key2332233232322332", key)
  2009. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2010. redis.Set(keyOne, "", time.Second)
  2011. fmt.Println("key3333333333333333", keyOne)
  2012. defer redis.Close()
  2013. if err != nil {
  2014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2015. return
  2016. }
  2017. c.ServeSuccessJSON(map[string]interface{}{
  2018. "msg": "ok",
  2019. "advice": advice,
  2020. })
  2021. return
  2022. }
  2023. func (c *PatientApiController) StopGroupAdvice() {
  2024. groupNo, _ := c.GetInt64("groupno", 0)
  2025. if groupNo <= 0 {
  2026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2027. return
  2028. }
  2029. adminUserInfo := c.GetAdminUserInfo()
  2030. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2031. if advice.ID == 0 {
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2033. return
  2034. }
  2035. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2037. return
  2038. }
  2039. dataBody := make(map[string]interface{}, 0)
  2040. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2041. if err != nil {
  2042. utils.ErrorLog(err.Error())
  2043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2044. return
  2045. }
  2046. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2047. utils.ErrorLog("stop_time")
  2048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2049. return
  2050. }
  2051. stopTime, _ := dataBody["stop_time"].(string)
  2052. if len(stopTime) == 0 {
  2053. utils.ErrorLog("len(stop_time) == 0")
  2054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2055. return
  2056. }
  2057. timeLayout := "2006-01-02"
  2058. loc, _ := time.LoadLocation("Local")
  2059. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2060. if err != nil {
  2061. utils.ErrorLog(err.Error())
  2062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2063. return
  2064. }
  2065. advice.StopTime = theTime.Unix()
  2066. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2067. stopReason, _ := dataBody["stop_reason"].(string)
  2068. advice.StopReason = stopReason
  2069. }
  2070. advice.UpdatedTime = time.Now().Unix()
  2071. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2072. advice.StopState = 1
  2073. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2074. if err != nil {
  2075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2076. return
  2077. }
  2078. c.ServeSuccessJSON(map[string]interface{}{
  2079. "msg": "ok",
  2080. })
  2081. return
  2082. }
  2083. func (c *PatientApiController) StopDoctorAdvice() {
  2084. id, _ := c.GetInt64("id", 0)
  2085. if id <= 0 {
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2087. return
  2088. }
  2089. adminUserInfo := c.GetAdminUserInfo()
  2090. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2091. //
  2092. //if appRole.UserType == 3 {
  2093. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2094. // if getPermissionErr != nil {
  2095. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2096. // return
  2097. // } else if headNursePermission == nil {
  2098. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2099. // return
  2100. // }
  2101. //}
  2102. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2103. if advice.ID == 0 {
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2105. return
  2106. }
  2107. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2109. return
  2110. }
  2111. dataBody := make(map[string]interface{}, 0)
  2112. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2113. if err != nil {
  2114. utils.ErrorLog(err.Error())
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2116. return
  2117. }
  2118. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2119. utils.ErrorLog("stop_time")
  2120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2121. return
  2122. }
  2123. stopTime, _ := dataBody["stop_time"].(string)
  2124. if len(stopTime) == 0 {
  2125. utils.ErrorLog("len(stop_time) == 0")
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2127. return
  2128. }
  2129. timeLayout := "2006-01-02"
  2130. loc, _ := time.LoadLocation("Local")
  2131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2132. if err != nil {
  2133. utils.ErrorLog(err.Error())
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2135. return
  2136. }
  2137. advice.StopTime = theTime.Unix()
  2138. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2139. stopReason, _ := dataBody["stop_reason"].(string)
  2140. advice.StopReason = stopReason
  2141. }
  2142. advice.UpdatedTime = time.Now().Unix()
  2143. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2144. advice.StopState = 1
  2145. err = service.StopDoctorAdvice(&advice)
  2146. if err != nil {
  2147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2148. return
  2149. }
  2150. c.ServeSuccessJSON(map[string]interface{}{
  2151. "msg": "ok",
  2152. "advice": advice,
  2153. })
  2154. return
  2155. }
  2156. func (c *PatientApiController) DeleteDoctorAdvice() {
  2157. id, _ := c.GetInt64("id", 0)
  2158. if id <= 0 {
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. adminUserInfo := c.GetAdminUserInfo()
  2163. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2164. if advice.ID == 0 {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2166. return
  2167. }
  2168. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2170. // return
  2171. //}
  2172. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2173. //
  2174. //if appRole.UserType == 3 {
  2175. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2176. // if getPermissionErr != nil {
  2177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2178. // return
  2179. // } else if headNursePermission == nil {
  2180. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2181. // return
  2182. // }
  2183. //}
  2184. advice.UpdatedTime = time.Now().Unix()
  2185. advice.Status = 0
  2186. advice.Modifier = adminUserInfo.AdminUser.Id
  2187. err := service.DeleteDoctorAdvice(&advice)
  2188. redis := service.RedisClient()
  2189. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2190. redis.Set(keyOne, "", time.Second)
  2191. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2192. redis.Set(key, "", time.Second)
  2193. redis.Close()
  2194. if err != nil {
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2196. return
  2197. }
  2198. c.ServeSuccessJSON(map[string]interface{}{
  2199. "msg": "ok",
  2200. })
  2201. return
  2202. }
  2203. func (c *PatientApiController) DeleteGroupAdvice() {
  2204. groupNo, _ := c.GetInt64("groupno", 0)
  2205. if groupNo <= 0 {
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2207. return
  2208. }
  2209. adminUserInfo := c.GetAdminUserInfo()
  2210. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2211. if advice.ID == 0 {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2213. return
  2214. }
  2215. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2216. //if appRole.UserType == 3 {
  2217. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2218. // if getPermissionErr != nil {
  2219. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2220. // return
  2221. // } else if headNursePermission == nil {
  2222. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2223. // return
  2224. // }
  2225. //}
  2226. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2227. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2228. redis := service.RedisClient()
  2229. redis.Set(key, "", time.Second)
  2230. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2231. redis.Set(keyOne, "", time.Second)
  2232. defer redis.Close()
  2233. if err != nil {
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2235. return
  2236. }
  2237. c.ServeSuccessJSON(map[string]interface{}{
  2238. "msg": "ok",
  2239. })
  2240. return
  2241. }
  2242. //GetDoctorAdvices 医嘱列表
  2243. func (c *PatientApiController) GetDoctorAdvices() {
  2244. id, _ := c.GetInt64("id", 0)
  2245. adviceType, _ := c.GetInt64("advice_type", 0)
  2246. stopType, _ := c.GetInt64("stop_state", 0)
  2247. startTime := c.GetString("start_time", "")
  2248. endTime := c.GetString("end_time", "")
  2249. keywords := c.GetString("keywords", "")
  2250. page, _ := c.GetInt64("page")
  2251. fmt.Println("page", page)
  2252. limit, _ := c.GetInt64("limit")
  2253. fmt.Println("limit", limit)
  2254. adminUserInfo := c.GetAdminUserInfo()
  2255. operatorIDs := make([]int64, 0)
  2256. timeLayout := "2006-01-02"
  2257. loc, _ := time.LoadLocation("Local")
  2258. var theStartTIme int64
  2259. if len(startTime) > 0 {
  2260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2261. if err != nil {
  2262. utils.ErrorLog(err.Error())
  2263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2264. return
  2265. }
  2266. theStartTIme = theTime.Unix()
  2267. }
  2268. var theEndtTIme int64
  2269. if len(endTime) > 0 {
  2270. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2271. if err != nil {
  2272. utils.ErrorLog(err.Error())
  2273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2274. return
  2275. }
  2276. theEndtTIme = theTime.Unix()
  2277. }
  2278. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2279. if hisconfig.IsOpen == 1 {
  2280. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2281. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2282. if len(advices) > 0 {
  2283. for _, item := range advices {
  2284. if item.AdviceDoctor > 0 {
  2285. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2286. }
  2287. if item.ExecutionStaff > 0 {
  2288. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2289. }
  2290. if item.Checker > 0 {
  2291. operatorIDs = append(operatorIDs, item.Checker)
  2292. }
  2293. if item.StopDoctor > 0 {
  2294. operatorIDs = append(operatorIDs, item.StopDoctor)
  2295. }
  2296. }
  2297. }
  2298. //相关操作对应的操作人
  2299. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2300. c.ServeSuccessJSON(map[string]interface{}{
  2301. "advices": advices,
  2302. "operators": operators,
  2303. "total": total,
  2304. "advicetwo": advicestwo,
  2305. })
  2306. return
  2307. } else {
  2308. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2309. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2310. if len(advices) > 0 {
  2311. for _, item := range advices {
  2312. if item.AdviceDoctor > 0 {
  2313. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2314. }
  2315. if item.ExecutionStaff > 0 {
  2316. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2317. }
  2318. if item.Checker > 0 {
  2319. operatorIDs = append(operatorIDs, item.Checker)
  2320. }
  2321. if item.StopDoctor > 0 {
  2322. operatorIDs = append(operatorIDs, item.StopDoctor)
  2323. }
  2324. }
  2325. }
  2326. //相关操作对应的操作人
  2327. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2328. c.ServeSuccessJSON(map[string]interface{}{
  2329. "advices": advices,
  2330. "operators": operators,
  2331. "total": total,
  2332. "advicetwo": advicestwo,
  2333. })
  2334. return
  2335. }
  2336. }
  2337. func (c *PatientApiController) GetPatientSchedules() {
  2338. id, _ := c.GetInt64("id", 0)
  2339. if id <= 0 {
  2340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2341. return
  2342. }
  2343. adminUserInfo := c.GetAdminUserInfo()
  2344. todayTime := time.Now().Format("2006-01-02")
  2345. timeLayout := "2006-01-02 15:04:05"
  2346. loc, _ := time.LoadLocation("Local")
  2347. var theStartTime int64
  2348. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2349. theStartTime = theTime.Unix()
  2350. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2351. if len(schedules) > 0 {
  2352. for index, item := range schedules {
  2353. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2354. schedules[index].Week = int64(week)
  2355. }
  2356. }
  2357. c.ServeSuccessJSON(map[string]interface{}{
  2358. "schedules": schedules,
  2359. })
  2360. return
  2361. }
  2362. func (c *PatientApiController) GetPatientDialysisRecords() {
  2363. patientID, _ := c.GetInt64("patient_id", 0)
  2364. page, _ := c.GetInt64("page", 0)
  2365. limit, _ := c.GetInt64("limit", 0)
  2366. startTime := c.GetString("start_time", "")
  2367. endTime := c.GetString("end_time", "")
  2368. mode_id, _ := c.GetInt64("mode_id", 0)
  2369. if page <= 0 {
  2370. page = 1
  2371. }
  2372. if limit <= 0 {
  2373. limit = 10
  2374. }
  2375. if patientID <= 0 {
  2376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2377. return
  2378. }
  2379. timeLayout := "2006-01-02"
  2380. loc, _ := time.LoadLocation("Local")
  2381. var theStartTIme int64
  2382. if len(startTime) > 0 {
  2383. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2384. if err != nil {
  2385. theStartTIme = 0
  2386. }
  2387. theStartTIme = theTime.Unix()
  2388. }
  2389. var theEndtTIme int64
  2390. if len(endTime) > 0 {
  2391. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2392. if err != nil {
  2393. theEndtTIme = 0
  2394. }
  2395. theEndtTIme = theTime.Unix()
  2396. }
  2397. adminInfo := c.GetAdminUserInfo()
  2398. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2399. c.ServeSuccessJSON(map[string]interface{}{
  2400. "total": total,
  2401. "records": records,
  2402. })
  2403. return
  2404. }
  2405. func (c *PatientApiController) ProEducation() {
  2406. patientID, _ := c.GetInt64("patient_id", 0)
  2407. page, _ := c.GetInt64("page", 0)
  2408. limit, _ := c.GetInt64("limit", 0)
  2409. startTime := c.GetString("start_time", "")
  2410. endTime := c.GetString("end_time", "")
  2411. if page <= 0 {
  2412. page = 1
  2413. }
  2414. if limit <= 0 {
  2415. limit = 10
  2416. }
  2417. if patientID <= 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2419. return
  2420. }
  2421. timeLayout := "2006-01-02"
  2422. loc, _ := time.LoadLocation("Local")
  2423. var theStartTIme int64
  2424. if len(startTime) > 0 {
  2425. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2426. if err != nil {
  2427. theStartTIme = 0
  2428. }
  2429. theStartTIme = theTime.Unix()
  2430. }
  2431. var theEndtTIme int64
  2432. if len(endTime) > 0 {
  2433. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2434. if err != nil {
  2435. theEndtTIme = 0
  2436. }
  2437. theEndtTIme = theTime.Unix()
  2438. }
  2439. adminInfo := c.GetAdminUserInfo()
  2440. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2441. c.ServeSuccessJSON(map[string]interface{}{
  2442. "total": total,
  2443. "edus": edus,
  2444. })
  2445. return
  2446. }
  2447. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2448. dataBody := make(map[string]interface{}, 0)
  2449. err := json.Unmarshal(data, &dataBody)
  2450. if err != nil {
  2451. utils.ErrorLog(err.Error())
  2452. code = enums.ErrorCodeParamWrong
  2453. return
  2454. }
  2455. timeLayout := "2006-01-02"
  2456. loc, _ := time.LoadLocation("Local")
  2457. isChild := false
  2458. if action == "create" {
  2459. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2460. utils.ErrorLog("advice_type")
  2461. code = enums.ErrorCodeParamWrong
  2462. return
  2463. }
  2464. adviceType := int64(dataBody["advice_type"].(float64))
  2465. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2466. utils.ErrorLog("advice_type != 1&&2")
  2467. code = enums.ErrorCodeParamWrong
  2468. return
  2469. }
  2470. advice.AdviceType = adviceType
  2471. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2472. utils.ErrorLog("advice_date")
  2473. code = enums.ErrorCodeParamWrong
  2474. return
  2475. }
  2476. adviceDate, _ := dataBody["advice_date"].(string)
  2477. if len(adviceDate) == 0 {
  2478. utils.ErrorLog("len(adviceDate) == 0")
  2479. code = enums.ErrorCodeParamWrong
  2480. return
  2481. }
  2482. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2483. if err != nil {
  2484. utils.ErrorLog(err.Error())
  2485. code = enums.ErrorCodeParamWrong
  2486. return
  2487. }
  2488. advice.AdviceDate = theTime.Unix()
  2489. advice.RecordDate = theTime.Unix()
  2490. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2491. parentId := int64(dataBody["parent_id"].(float64))
  2492. advice.ParentId = parentId
  2493. if parentId > 0 {
  2494. isChild = true
  2495. }
  2496. }
  2497. }
  2498. if !isChild {
  2499. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2500. utils.ErrorLog("start_time")
  2501. code = enums.ErrorCodeParamWrong
  2502. return
  2503. }
  2504. startTime, _ := dataBody["start_time"].(string)
  2505. if len(startTime) == 0 {
  2506. utils.ErrorLog("len(start_time) == 0")
  2507. code = enums.ErrorCodeParamWrong
  2508. return
  2509. }
  2510. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2511. if err != nil {
  2512. utils.ErrorLog(err.Error())
  2513. code = enums.ErrorCodeParamWrong
  2514. return
  2515. }
  2516. advice.StartTime = theTime.Unix()
  2517. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2518. // utils.ErrorLog("advice_doctor")
  2519. // code = enums.ErrorCodeParamWrong
  2520. // return
  2521. // }
  2522. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2523. // if adviceDoctor <= 0 {
  2524. // utils.ErrorLog("advice_doctor <=0")
  2525. // code = enums.ErrorCodeParamWrong
  2526. // return
  2527. // }
  2528. // advice.AdviceDoctor = adviceDoctor
  2529. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2530. deliveryWay, _ := dataBody["delivery_way"].(string)
  2531. advice.DeliveryWay = deliveryWay
  2532. }
  2533. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2534. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2535. advice.ExecutionFrequency = executionFrequency
  2536. }
  2537. if advice.AdviceType == 1 && advice.ParentId == 0 {
  2538. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  2539. frequency_type := int64(dataBody["frequency_type"].(float64))
  2540. advice.FrequencyType = frequency_type
  2541. }
  2542. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  2543. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  2544. advice.DayCount = day_count
  2545. }
  2546. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  2547. week_day, _ := dataBody["week_days"].(string)
  2548. advice.WeekDay = week_day
  2549. }
  2550. }
  2551. }
  2552. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2553. utils.ErrorLog("advice_name")
  2554. code = enums.ErrorCodeParamWrong
  2555. return
  2556. }
  2557. adviceName, _ := dataBody["advice_name"].(string)
  2558. if len(adviceName) == 0 {
  2559. utils.ErrorLog("len(advice_name) == 0")
  2560. code = enums.ErrorCodeParamWrong
  2561. return
  2562. }
  2563. advice.AdviceName = adviceName
  2564. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2565. adviceDsc, _ := dataBody["advice_desc"].(string)
  2566. advice.AdviceDesc = adviceDsc
  2567. }
  2568. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2569. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2570. advice.DialysisOrderId = int64(dialysisOrderId)
  2571. }
  2572. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2573. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2574. advice.SingleDose = singleDose
  2575. }
  2576. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2577. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2578. advice.SingleDoseUnit = singleDoseUnit
  2579. }
  2580. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2581. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2582. advice.DrugSpec = drugSpec
  2583. }
  2584. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2585. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2586. advice.DrugSpecUnit = drugSpecUnit
  2587. }
  2588. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2589. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2590. advice.PrescribingNumber = prescribingNumber
  2591. }
  2592. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2593. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2594. advice.PrescribingNumberUnit = prescribingNumberUnit
  2595. }
  2596. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2597. remark, _ := dataBody["remark"].(string)
  2598. advice.Remark = remark
  2599. }
  2600. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2601. drug_id, _ := dataBody["drug_id"].(float64)
  2602. advice.DrugId = int64(drug_id)
  2603. }
  2604. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2605. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  2606. advice.DrugNameId = int64(drug_name_id)
  2607. }
  2608. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2609. way, _ := dataBody["way"].(float64)
  2610. advice.Way = int64(way)
  2611. }
  2612. return
  2613. }
  2614. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2615. dataBody := make(map[string]interface{}, 0)
  2616. err := json.Unmarshal(data, &dataBody)
  2617. utils.InfoLog(string(data))
  2618. if err != nil {
  2619. utils.ErrorLog(err.Error())
  2620. code = enums.ErrorCodeParamWrong
  2621. return
  2622. }
  2623. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2624. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2625. solution.DialysisDuration = dialysisDuration
  2626. }
  2627. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2628. replacementWay := int64(dataBody["replacement_way"].(float64))
  2629. solution.ReplacementWay = replacementWay
  2630. }
  2631. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2632. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2633. solution.BloodFlowVolume = bloodFlowVolume
  2634. }
  2635. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2636. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2637. solution.HemodialysisMachine = hemodialysisMachine
  2638. }
  2639. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2640. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2641. solution.BloodFilter = bloodFilter
  2642. }
  2643. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2644. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2645. solution.PerfusionApparatus = perfusionApparatus
  2646. }
  2647. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2648. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2649. solution.DialysateFlow = dialysateFlow
  2650. }
  2651. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2652. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2653. solution.Kalium = kalium
  2654. }
  2655. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2656. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2657. solution.Sodium = sodium
  2658. }
  2659. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2660. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2661. solution.Calcium = calcium
  2662. }
  2663. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2664. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2665. solution.Bicarbonate = bicarbonate
  2666. }
  2667. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2668. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2669. solution.Anticoagulant = anticoagulant
  2670. }
  2671. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2672. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2673. solution.AnticoagulantShouji = anticoagulantShouji
  2674. }
  2675. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2676. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2677. solution.AnticoagulantWeichi = anticoagulantWeichi
  2678. }
  2679. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2680. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2681. solution.AnticoagulantZongliang = anticoagulantZongliang
  2682. }
  2683. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2684. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2685. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2686. }
  2687. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2688. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2689. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2690. }
  2691. return
  2692. }
  2693. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2694. dataBody := make(map[string]interface{}, 0)
  2695. err := json.Unmarshal(data, &dataBody)
  2696. utils.InfoLog(string(data))
  2697. if err != nil {
  2698. utils.ErrorLog(err.Error())
  2699. code = enums.ErrorCodeParamWrong
  2700. return
  2701. }
  2702. if method == "create" {
  2703. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2704. utils.ErrorLog("mode")
  2705. code = enums.ErrorCodeParamWrong
  2706. return
  2707. }
  2708. mode := int64(dataBody["mode"].(float64))
  2709. if mode <= 0 {
  2710. utils.ErrorLog("mode <= 0")
  2711. code = enums.ErrorCodeParamWrong
  2712. return
  2713. }
  2714. solution.ModeId = mode
  2715. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2716. utils.ErrorLog("mode_name")
  2717. code = enums.ErrorCodeParamWrong
  2718. return
  2719. }
  2720. modeName, _ := dataBody["mode_name"].(string)
  2721. if len(modeName) == 0 {
  2722. utils.ErrorLog("len(mode_name) == 0")
  2723. code = enums.ErrorCodeParamWrong
  2724. return
  2725. }
  2726. solution.ModeName = modeName
  2727. solution.Name = modeName
  2728. }
  2729. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2730. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2731. solution.DialysisDuration = dialysisDuration
  2732. }
  2733. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2734. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2735. solution.TargetUltrafiltration = targetUltrafiltration
  2736. }
  2737. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2738. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2739. solution.DialysateFormulation = dialysateFormulation
  2740. }
  2741. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2742. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2743. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2744. }
  2745. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2746. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2747. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2748. }
  2749. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2750. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2751. solution.HemodialysisMachine = hemodialysisMachine
  2752. }
  2753. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2754. dialyzer := int64(dataBody["dialyzer"].(float64))
  2755. solution.Dialyzer = dialyzer
  2756. }
  2757. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2758. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2759. solution.PerfusionApparatus = perfusionApparatus
  2760. }
  2761. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2762. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2763. solution.BloodFlowVolume = bloodFlowVolume
  2764. }
  2765. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2766. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2767. solution.Dewater = dewater
  2768. }
  2769. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2770. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2771. solution.DisplaceLiqui = displaceLiqui
  2772. }
  2773. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2774. replacementWay := int64(dataBody["replacement_way"].(float64))
  2775. solution.ReplacementWay = replacementWay
  2776. }
  2777. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2778. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2779. solution.Anticoagulant = anticoagulant
  2780. }
  2781. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2782. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2783. solution.AnticoagulantShouji = anticoagulantShouji
  2784. }
  2785. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2786. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2787. solution.AnticoagulantWeichi = anticoagulantWeichi
  2788. }
  2789. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2790. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2791. solution.AnticoagulantZongliang = anticoagulantZongliang
  2792. }
  2793. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2794. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2795. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2796. }
  2797. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2798. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2799. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2800. }
  2801. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2802. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2803. solution.Kalium = kalium
  2804. }
  2805. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2806. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2807. solution.Sodium = sodium
  2808. }
  2809. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2810. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2811. solution.Calcium = calcium
  2812. }
  2813. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2814. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2815. solution.Bicarbonate = bicarbonate
  2816. }
  2817. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2818. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2819. solution.Glucose = glucose
  2820. }
  2821. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2822. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2823. // solution.DryWeight = dryWeight
  2824. // }
  2825. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2826. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2827. solution.DialysateFlow = dialysateFlow
  2828. }
  2829. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2830. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2831. solution.DialysateTemperature = dialysateTemperature
  2832. }
  2833. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2834. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2835. solution.Conductivity = conductivity
  2836. }
  2837. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2838. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2839. solution.ReplacementTotal = replacementTotal
  2840. }
  2841. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2842. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2843. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2844. }
  2845. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2846. body_fluid := int64(dataBody["body_fluid"].(float64))
  2847. solution.BodyFluid = body_fluid
  2848. }
  2849. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2850. body_fluid_other := dataBody["body_fluid_other"].(string)
  2851. solution.BodyFluidOther = body_fluid_other
  2852. }
  2853. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2854. special_medicine := int64(dataBody["special_medicine"].(float64))
  2855. solution.SpecialMedicine = special_medicine
  2856. }
  2857. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2858. special_medicine_other := dataBody["special_medicine_other"].(string)
  2859. solution.SpecialMedicineOther = special_medicine_other
  2860. }
  2861. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2862. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2863. solution.DisplaceLiquiPart = displace_liqui_part
  2864. }
  2865. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2866. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2867. solution.DisplaceLiquiValue = displace_liqui_value
  2868. }
  2869. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2870. blood_access := int64(dataBody["blood_access"].(float64))
  2871. solution.BloodAccess = blood_access
  2872. }
  2873. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2874. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2875. solution.Ultrafiltration = ultrafiltration
  2876. }
  2877. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2878. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2879. solution.TargetKtv = target_ktv
  2880. }
  2881. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2882. remark := dataBody["remark"].(string)
  2883. solution.Remark = remark
  2884. }
  2885. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  2886. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  2887. solution.HemodialysisPipelines = hemodialysis_pipelines
  2888. }
  2889. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  2890. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  2891. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  2892. }
  2893. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2894. puncture_needle := dataBody["puncture_needle"].(string)
  2895. solution.PunctureNeedle = puncture_needle
  2896. }
  2897. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  2898. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  2899. solution.PunctureNeedleCount = puncture_needle_count
  2900. }
  2901. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  2902. epo := dataBody["epo"].(string)
  2903. solution.Epo = epo
  2904. }
  2905. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  2906. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  2907. solution.EpoCount = epo_count
  2908. }
  2909. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  2910. created_time := int64(dataBody["created_time"].(float64))
  2911. solution.CreatedTime = created_time
  2912. }
  2913. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  2914. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  2915. solution.DialysisDialyszers = dialysisDialyszers
  2916. }
  2917. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  2918. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  2919. solution.DialysisIrrigation = dialysisIrrigation
  2920. }
  2921. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  2922. plasmaSeparator := dataBody["plasma_separator"].(string)
  2923. solution.PlasmaSeparator = plasmaSeparator
  2924. }
  2925. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  2926. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  2927. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  2928. }
  2929. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  2930. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  2931. solution.OxygenUptake = oxygen_uptake
  2932. }
  2933. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  2934. oxygen_flow := dataBody["oxygen_flow"].(string)
  2935. solution.OxygenFlow = oxygen_flow
  2936. }
  2937. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  2938. oxygen_time := dataBody["oxygen_time"].(string)
  2939. solution.OxygenTime = oxygen_time
  2940. }
  2941. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  2942. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  2943. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  2944. }
  2945. return
  2946. }
  2947. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2948. dataBody := make(map[string]interface{}, 0)
  2949. err := json.Unmarshal(data, &dataBody)
  2950. utils.InfoLog(string(data))
  2951. if err != nil {
  2952. utils.ErrorLog(err.Error())
  2953. code = enums.ErrorCodeParamWrong
  2954. return
  2955. }
  2956. if method == "create" {
  2957. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2958. utils.ErrorLog("parent_id")
  2959. code = enums.ErrorCodeParamWrong
  2960. return
  2961. }
  2962. parentID := int64(dataBody["parent_id"].(float64))
  2963. if parentID <= 0 {
  2964. utils.ErrorLog("parentID <= 0")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. solution.ParentId = parentID
  2969. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2970. utils.ErrorLog("sub_name")
  2971. code = enums.ErrorCodeParamWrong
  2972. return
  2973. }
  2974. subName, _ := dataBody["sub_name"].(string)
  2975. if len(subName) == 0 {
  2976. utils.ErrorLog("len(sub_name) == 0")
  2977. code = enums.ErrorCodeParamWrong
  2978. return
  2979. }
  2980. solution.SubName = subName
  2981. }
  2982. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2983. utils.ErrorLog("initiate_mode")
  2984. code = enums.ErrorCodeParamWrong
  2985. return
  2986. }
  2987. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2988. if initiateMode != 1 && initiateMode != 2 {
  2989. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2990. code = enums.ErrorCodeParamWrong
  2991. return
  2992. }
  2993. solution.InitiateMode = initiateMode
  2994. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  2995. utils.ErrorLog("doctor")
  2996. code = enums.ErrorCodeParamWrong
  2997. return
  2998. }
  2999. doctor := int64(dataBody["doctor"].(float64))
  3000. if doctor <= 0 {
  3001. utils.ErrorLog("doctor <= 0")
  3002. code = enums.ErrorCodeParamWrong
  3003. return
  3004. }
  3005. solution.Doctor = doctor
  3006. return
  3007. }
  3008. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  3009. patientBody := make(map[string]interface{}, 0)
  3010. err := json.Unmarshal(data, &patientBody)
  3011. if err != nil {
  3012. utils.ErrorLog(err.Error())
  3013. code = enums.ErrorCodeParamWrong
  3014. return
  3015. }
  3016. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  3017. formItem, _ := patientBody["formItem"].([]interface{})
  3018. if len(formItem) > 0 {
  3019. for _, item := range formItem {
  3020. items := item.(map[string]interface{})
  3021. project_name, _ := items["project_name"].(string)
  3022. fmt.Println(project_name)
  3023. range_type := int64(items["range_type"].(float64))
  3024. fmt.Println(range_type)
  3025. project_id := int64(items["project_id"].(float64))
  3026. fmt.Println(project_id)
  3027. item_id := int64(items["item_id"].(float64))
  3028. fmt.Println(item_id)
  3029. item, _ := items["item"].(string)
  3030. fmt.Println(items["item"].(string))
  3031. item_name, _ := items["item_name"].(string)
  3032. fmt.Println(item_name)
  3033. value, _ := items["value"].(string)
  3034. fmt.Println(items["value"].(string))
  3035. var form models.FormItem
  3036. form.ProjectName = project_name
  3037. form.RangeType = range_type
  3038. form.ProjectId = project_id
  3039. form.ItemId = item_id
  3040. form.Item = item
  3041. form.ItemName = item_name
  3042. form.Value = value
  3043. formItems = append(formItems, &form)
  3044. }
  3045. }
  3046. }
  3047. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  3048. utils.ErrorLog("avatar")
  3049. code = enums.ErrorCodeParamWrong
  3050. return
  3051. }
  3052. avatar, _ := patientBody["avatar"].(string)
  3053. if len(avatar) == 0 {
  3054. utils.ErrorLog("len(avatar) == 0")
  3055. code = enums.ErrorCodeParamWrong
  3056. return
  3057. }
  3058. patient.Avatar = avatar
  3059. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  3060. utils.ErrorLog("name")
  3061. code = enums.ErrorCodeParamWrong
  3062. return
  3063. }
  3064. name, _ := patientBody["name"].(string)
  3065. if len(name) == 0 {
  3066. utils.ErrorLog("len(name) == 0")
  3067. code = enums.ErrorCodeParamWrong
  3068. return
  3069. }
  3070. patient.Name = name
  3071. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  3072. alias := patientBody["alias"].(string)
  3073. patient.Alias = alias
  3074. }
  3075. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  3076. nation := patientBody["nation"].(string)
  3077. patient.Nation = nation
  3078. }
  3079. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  3080. native_place := patientBody["native_place"].(string)
  3081. patient.NativePlace = native_place
  3082. }
  3083. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  3084. utils.ErrorLog("idCardNo")
  3085. code = enums.ErrorCodeParamWrong
  3086. return
  3087. }
  3088. idCardNo, _ := patientBody["idCardNo"].(string)
  3089. if len(idCardNo) == 0 {
  3090. utils.ErrorLog("len(idCardNo) == 0")
  3091. code = enums.ErrorCodeParamWrong
  3092. return
  3093. }
  3094. patient.IdCardNo = idCardNo
  3095. patient.PatientType = 1
  3096. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  3097. utils.ErrorLog("dialysisNo")
  3098. code = enums.ErrorCodeParamWrong
  3099. return
  3100. }
  3101. dialysisNo, _ := patientBody["dialysisNo"].(string)
  3102. if len(dialysisNo) == 0 {
  3103. utils.ErrorLog("len(dialysisNo) == 0")
  3104. code = enums.ErrorCodeParamWrong
  3105. return
  3106. }
  3107. patient.DialysisNo = dialysisNo
  3108. // }
  3109. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  3110. utils.ErrorLog("lapseto")
  3111. code = enums.ErrorCodeParamWrong
  3112. return
  3113. }
  3114. lapseto := int64(patientBody["lapseto"].(float64))
  3115. if lapseto <= 0 {
  3116. utils.ErrorLog("lapseto == 0")
  3117. code = enums.ErrorCodeParamWrong
  3118. return
  3119. }
  3120. patient.Lapseto = lapseto
  3121. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  3122. utils.ErrorLog("gender")
  3123. code = enums.ErrorCodeParamWrong
  3124. return
  3125. }
  3126. gender := int64(patientBody["gender"].(float64))
  3127. if gender <= 0 {
  3128. utils.ErrorLog("gender <= 0")
  3129. code = enums.ErrorCodeParamWrong
  3130. return
  3131. }
  3132. patient.Gender = gender
  3133. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  3134. response_result := patientBody["response_result"].(string)
  3135. patient.ResponseResult = response_result
  3136. }
  3137. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  3138. utils.ErrorLog("age")
  3139. code = enums.ErrorCodeParamWrong
  3140. return
  3141. }
  3142. age := int64(patientBody["age"].(float64))
  3143. patient.Age = age
  3144. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  3145. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  3146. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  3147. patient.UserSysBeforeCount = count
  3148. }
  3149. timeLayout := "2006-01-02"
  3150. loc, _ := time.LoadLocation("Local")
  3151. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  3152. utils.ErrorLog("birth")
  3153. code = enums.ErrorCodeParamWrong
  3154. return
  3155. }
  3156. birth, _ := patientBody["birth"].(string)
  3157. if len(birth) == 0 {
  3158. utils.ErrorLog("len(birth) == 0")
  3159. code = enums.ErrorCodeParamWrong
  3160. return
  3161. }
  3162. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  3163. if err != nil {
  3164. utils.ErrorLog("birthTime")
  3165. code = enums.ErrorCodeParamWrong
  3166. return
  3167. }
  3168. patient.Birthday = birthTime.Unix()
  3169. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  3170. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  3171. patient.Height = height
  3172. }
  3173. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  3174. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3175. patient.MaritalStatus = maritalStatus
  3176. }
  3177. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3178. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3179. patient.Children = children
  3180. }
  3181. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3182. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3183. patient.AdmissionNumber = admissionNumber
  3184. }
  3185. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3186. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3187. patient.ReimbursementWayId = reimbursementWayID
  3188. }
  3189. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3190. healthCareNo := patientBody["healthCareNo"].(string)
  3191. patient.HealthCareNo = healthCareNo
  3192. }
  3193. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3194. utils.ErrorLog("phone")
  3195. code = enums.ErrorCodeParamWrong
  3196. return
  3197. }
  3198. phone := patientBody["phone"].(string)
  3199. if len(phone) == 0 {
  3200. utils.ErrorLog("len(phone) == 0")
  3201. code = enums.ErrorCodeParamWrong
  3202. return
  3203. }
  3204. if !utils.CheckMobile(phone) {
  3205. utils.ErrorLog("!phone")
  3206. code = enums.ErrorCodeMobileFormat
  3207. return
  3208. }
  3209. patient.Phone = phone
  3210. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3211. homeTelephone := patientBody["homeTelephone"].(string)
  3212. patient.HomeTelephone = homeTelephone
  3213. }
  3214. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3215. relativePhone := patientBody["relative_phone"].(string)
  3216. patient.RelativePhone = relativePhone
  3217. }
  3218. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3219. relativeRelations := patientBody["relative_relations"].(string)
  3220. patient.RelativeRelations = relativeRelations
  3221. }
  3222. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3223. homeAddress := patientBody["homeAddress"].(string)
  3224. patient.HomeAddress = homeAddress
  3225. }
  3226. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3227. work := patientBody["work"].(string)
  3228. patient.WorkUnit = work
  3229. }
  3230. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3231. unitAddress := patientBody["unit_address"].(string)
  3232. patient.UnitAddress = unitAddress
  3233. }
  3234. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3235. profession := int64(patientBody["profession"].(float64))
  3236. patient.Profession = profession
  3237. }
  3238. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3239. education := int64(patientBody["education"].(float64))
  3240. patient.EducationLevel = education
  3241. }
  3242. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3243. utils.ErrorLog("source")
  3244. code = enums.ErrorCodeParamWrong
  3245. return
  3246. }
  3247. source := int64(patientBody["source"].(float64))
  3248. if source <= 0 {
  3249. utils.ErrorLog("source <= 0")
  3250. code = enums.ErrorCodeParamWrong
  3251. return
  3252. }
  3253. patient.Source = source
  3254. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3255. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3256. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3257. }
  3258. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3259. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3260. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3261. if err == nil {
  3262. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3263. }
  3264. }
  3265. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3266. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3267. patient.FirstDialysisHospital = firstDialysisHospital
  3268. }
  3269. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3270. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3271. if len(thePredialysisCondition) > 0 {
  3272. conditions := make([]string, 0)
  3273. for _, item := range thePredialysisCondition {
  3274. if reflect.TypeOf(item).String() != "string" {
  3275. continue
  3276. }
  3277. condition := item.(string)
  3278. if len(condition) > 0 {
  3279. conditions = append(conditions, condition)
  3280. }
  3281. }
  3282. patient.PredialysisCondition = strings.Join(conditions, ",")
  3283. }
  3284. }
  3285. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3286. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3287. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3288. }
  3289. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3290. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3291. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3292. }
  3293. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3294. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3295. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3296. if err == nil {
  3297. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3298. }
  3299. }
  3300. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3301. partition := int64(patientBody["partition"].(float64))
  3302. patient.PartitionId = partition
  3303. }
  3304. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3305. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3306. patient.BedId = bed
  3307. }
  3308. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3309. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3310. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3311. if err == nil {
  3312. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3313. }
  3314. }
  3315. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3316. blood := int64(patientBody["blood"].(float64))
  3317. patient.BloodType = blood
  3318. }
  3319. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3320. rh := int64(patientBody["rh"].(float64))
  3321. patient.Rh = rh
  3322. }
  3323. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3324. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3325. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3326. if err == nil {
  3327. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3328. }
  3329. }
  3330. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3331. receivingDate := patientBody["receivingDate"].(string)
  3332. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3333. if err == nil {
  3334. patient.ReceivingDate = receivingDateTime.Unix()
  3335. }
  3336. }
  3337. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3338. induction := int64(patientBody["induction"].(float64))
  3339. patient.InductionPeriod = induction
  3340. }
  3341. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3342. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3343. patient.InitialDialysis = initial
  3344. }
  3345. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3346. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3347. patient.TotalDialysis = dialysisTotal
  3348. }
  3349. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3350. thisContagions, _ := patientBody["contagions"].([]interface{})
  3351. if len(thisContagions) > 0 {
  3352. for _, item := range thisContagions {
  3353. if reflect.TypeOf(item).String() != "float64" {
  3354. continue
  3355. }
  3356. contagion := int64(item.(float64))
  3357. if contagion > 0 {
  3358. contagions = append(contagions, contagion)
  3359. }
  3360. }
  3361. }
  3362. }
  3363. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3364. doctor := int64(patientBody["doctor"].(float64))
  3365. patient.AttendingDoctorId = doctor
  3366. }
  3367. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3368. nurse := int64(patientBody["nurse"].(float64))
  3369. patient.HeadNurseId = nurse
  3370. }
  3371. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3372. assessment := patientBody["assessment"].(string)
  3373. patient.Evaluate = assessment
  3374. }
  3375. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3376. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3377. if len(thisDiseases) > 0 {
  3378. for _, item := range thisDiseases {
  3379. if reflect.TypeOf(item).String() != "float64" {
  3380. continue
  3381. }
  3382. disease := int64(item.(float64))
  3383. if disease > 0 {
  3384. diseases = append(diseases, disease)
  3385. }
  3386. }
  3387. }
  3388. }
  3389. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3390. diagnose := patientBody["diagnose"].(string)
  3391. patient.Diagnose = diagnose
  3392. }
  3393. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3394. remark := patientBody["remark"].(string)
  3395. patient.Remark = remark
  3396. }
  3397. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3398. sch_remark := patientBody["sch_remark"].(string)
  3399. patient.SchRemark = sch_remark
  3400. }
  3401. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3402. patient_complains := patientBody["patient_complains"].(string)
  3403. patient.PatientComplains = patient_complains
  3404. }
  3405. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3406. present_history := patientBody["present_history"].(string)
  3407. patient.PresentHistory = present_history
  3408. }
  3409. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3410. past_history := patientBody["past_history"].(string)
  3411. patient.PastHistory = past_history
  3412. }
  3413. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3414. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3415. patient.Temperature = temperature
  3416. }
  3417. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3418. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3419. patient.Pulse = pulse
  3420. }
  3421. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3422. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3423. patient.Respiratory = respiratory
  3424. }
  3425. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3426. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3427. patient.SBP = sbp
  3428. }
  3429. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3430. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3431. patient.DBP = dbp
  3432. }
  3433. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3434. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3435. patient.DialysisAge = dialysis_age
  3436. }
  3437. fmt.Println(patient.DialysisAge)
  3438. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3439. first_treatment_date := patientBody["first_treatment_date"].(string)
  3440. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3441. if err == nil {
  3442. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3443. }
  3444. }
  3445. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3446. expense_kind := int64(patientBody["expense_kind"].(float64))
  3447. patient.ExpenseKind = expense_kind
  3448. }
  3449. fmt.Println(patient.ExpenseKind)
  3450. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3451. tell_phone := patientBody["tell_phone"].(string)
  3452. patient.TellPhone = tell_phone
  3453. }
  3454. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3455. contact_name := patientBody["contact_name"].(string)
  3456. patient.ContactName = contact_name
  3457. }
  3458. return
  3459. }
  3460. func (c *PatientApiController) GetPatientsByKeyWord() {
  3461. keyWord := c.GetString("keyword")
  3462. adminUserInfo := c.GetAdminUserInfo()
  3463. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3464. if err != nil {
  3465. utils.ErrorLog(err.Error())
  3466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3467. return
  3468. }
  3469. c.ServeSuccessJSON(map[string]interface{}{
  3470. "patient": patient,
  3471. })
  3472. }
  3473. func (c *PatientApiController) QueryPatientById() {
  3474. id, _ := c.GetInt64("id")
  3475. fmt.Println(id)
  3476. patientInfo := service.QueryPatientById(id)
  3477. c.ServeSuccessJSON(map[string]interface{}{
  3478. "patient": patientInfo,
  3479. })
  3480. return
  3481. }
  3482. func (c *PatientApiController) GetRemindPatientList() {
  3483. page, _ := c.GetInt64("page", 1)
  3484. limit, _ := c.GetInt64("limit", 10)
  3485. adminUserInfo := c.GetAdminUserInfo()
  3486. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  3487. fmt.Println("机构ID2222222222222", c.GetAdminUserInfo().CurrentOrgId)
  3488. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  3489. fmt.Println("机构ID2222222222222", errcode)
  3490. if errcode == gorm.ErrRecordNotFound {
  3491. information, err := service.GetAdminUserRoleInformation(0)
  3492. if err != nil {
  3493. utils.ErrorLog(err.Error())
  3494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3495. return
  3496. }
  3497. c.ServeSuccessJSON(map[string]interface{}{
  3498. "total": total,
  3499. "patients": patients,
  3500. "information": information,
  3501. })
  3502. } else if errcode == nil {
  3503. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  3504. if err != nil {
  3505. utils.ErrorLog(err.Error())
  3506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3507. return
  3508. }
  3509. c.ServeSuccessJSON(map[string]interface{}{
  3510. "total": total,
  3511. "patients": patients,
  3512. "information": information,
  3513. })
  3514. }
  3515. }
  3516. func (c *PatientApiController) PostIsOpenRemind() {
  3517. patient_id, _ := c.GetInt64("id", 1)
  3518. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  3519. adminUserInfo := c.GetAdminUserInfo()
  3520. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  3521. if err == nil {
  3522. c.ServeSuccessJSON(map[string]interface{}{
  3523. "msg": "成功",
  3524. "is_open_remind": is_open_remind,
  3525. })
  3526. } else if err != nil {
  3527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3528. }
  3529. }
  3530. func (c *PatientApiController) GetPatientScheduleOne() {
  3531. id, _ := c.GetInt64("id")
  3532. //查询该病人是否当天是排班
  3533. nowDateTime := time.Now()
  3534. nowDate := nowDateTime.Format("2006-01-02")
  3535. nowDate += " 00:00:00"
  3536. timeLayout := "2006-01-02"
  3537. loc, _ := time.LoadLocation("Local")
  3538. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  3539. nowdate := theTime.Unix()
  3540. fmt.Println("nowdate", nowdate)
  3541. adminUser := c.GetAdminUserInfo()
  3542. orgId := adminUser.CurrentOrgId
  3543. fmt.Println("orgid", orgId)
  3544. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  3545. if err != nil {
  3546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3547. return
  3548. }
  3549. c.ServeSuccessJSON(map[string]interface{}{
  3550. "scheduls": scheduls,
  3551. })
  3552. }
  3553. func (c *PatientApiController) ExportPatients() {
  3554. dataBody := make(map[string]interface{}, 0)
  3555. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  3556. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  3557. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  3558. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3559. if err != nil {
  3560. utils.ErrorLog(err.Error())
  3561. return
  3562. }
  3563. utils.ErrorLog("%v", dataBody)
  3564. export_time := time.Now().Unix()
  3565. var patients []*models.Patients
  3566. var total_patients []interface{}
  3567. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  3568. tempPatients := dataBody["patients"].([]interface{})
  3569. total_patients = tempPatients
  3570. for index, patientMap := range tempPatients {
  3571. patientNameM := patientMap.(map[string]interface{})
  3572. var patient models.Patients
  3573. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  3574. utils.ErrorLog("name")
  3575. return
  3576. }
  3577. name, _ := patientNameM["name"].(string)
  3578. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3579. err_log := models.ExportErrLog{
  3580. LogType: 1,
  3581. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3582. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  3583. Status: 1,
  3584. CreateTime: time.Now().Unix(),
  3585. UpdateTime: time.Now().Unix(),
  3586. ExportTime: export_time,
  3587. }
  3588. service.CreateExportErrLog(&err_log)
  3589. continue
  3590. }
  3591. patient.Name = name
  3592. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  3593. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  3594. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  3595. err_log := models.ExportErrLog{
  3596. LogType: 1,
  3597. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3598. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  3599. Status: 1,
  3600. CreateTime: time.Now().Unix(),
  3601. UpdateTime: time.Now().Unix(),
  3602. ExportTime: export_time,
  3603. }
  3604. service.CreateExportErrLog(&err_log)
  3605. continue
  3606. } else {
  3607. patient.Gender = gender
  3608. }
  3609. }
  3610. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  3611. phone, _ := patientNameM["phone"].(string)
  3612. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  3613. if len(phone) == 0 {
  3614. err_log := models.ExportErrLog{
  3615. LogType: 1,
  3616. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3617. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  3618. Status: 1,
  3619. CreateTime: time.Now().Unix(),
  3620. UpdateTime: time.Now().Unix(),
  3621. ExportTime: export_time,
  3622. }
  3623. service.CreateExportErrLog(&err_log)
  3624. continue
  3625. } else {
  3626. err_log := models.ExportErrLog{
  3627. LogType: 1,
  3628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3629. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  3630. Status: 1,
  3631. CreateTime: time.Now().Unix(),
  3632. UpdateTime: time.Now().Unix(),
  3633. ExportTime: export_time,
  3634. }
  3635. service.CreateExportErrLog(&err_log)
  3636. continue
  3637. }
  3638. } else {
  3639. //var tempPatient *models.Patients
  3640. //for _, item := range all_patient {
  3641. // if item.Phone == phone {
  3642. // tempPatient = item
  3643. // }
  3644. //}
  3645. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  3646. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  3647. if count >= 1 {
  3648. err_log := models.ExportErrLog{
  3649. LogType: 1,
  3650. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3651. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3652. Status: 1,
  3653. CreateTime: time.Now().Unix(),
  3654. UpdateTime: time.Now().Unix(),
  3655. ExportTime: export_time,
  3656. }
  3657. service.CreateExportErrLog(&err_log)
  3658. continue
  3659. }
  3660. patient.Phone = phone
  3661. }
  3662. }
  3663. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3664. id_card_no, _ := patientNameM["id_card_no"].(string)
  3665. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3666. if len(id_card_no) == 0 {
  3667. err_log := models.ExportErrLog{
  3668. LogType: 1,
  3669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3671. Status: 1,
  3672. CreateTime: time.Now().Unix(),
  3673. UpdateTime: time.Now().Unix(),
  3674. ExportTime: export_time,
  3675. }
  3676. service.CreateExportErrLog(&err_log)
  3677. continue
  3678. } else {
  3679. err_log := models.ExportErrLog{
  3680. LogType: 1,
  3681. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3682. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3683. Status: 1,
  3684. CreateTime: time.Now().Unix(),
  3685. UpdateTime: time.Now().Unix(),
  3686. ExportTime: export_time,
  3687. }
  3688. service.CreateExportErrLog(&err_log)
  3689. continue
  3690. }
  3691. } else {
  3692. //var tempPatient *models.Patients
  3693. //for _, item := range all_patient {
  3694. // if item.IdCardNo == id_card_no {
  3695. // tempPatient = item
  3696. // }
  3697. //}
  3698. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3699. if count >= 1 {
  3700. //if tempPatient != nil && tempPatient.ID > 0 {
  3701. err_log := models.ExportErrLog{
  3702. LogType: 1,
  3703. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3704. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3705. Status: 1,
  3706. CreateTime: time.Now().Unix(),
  3707. UpdateTime: time.Now().Unix(),
  3708. ExportTime: export_time,
  3709. }
  3710. service.CreateExportErrLog(&err_log)
  3711. continue
  3712. }
  3713. //}
  3714. patient.IdCardNo = id_card_no
  3715. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3716. if GetBirthDay(id_card_no) == nil {
  3717. patient.Birthday = 0
  3718. } else {
  3719. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3720. }
  3721. }
  3722. }
  3723. fmt.Println("111112222")
  3724. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3725. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3726. timeLayout := "2006/01/02"
  3727. loc, _ := time.LoadLocation("Local")
  3728. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3729. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3730. if len(first_treatment_date) == 0 {
  3731. err_log := models.ExportErrLog{
  3732. LogType: 1,
  3733. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3734. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3735. Status: 1,
  3736. CreateTime: time.Now().Unix(),
  3737. UpdateTime: time.Now().Unix(),
  3738. ExportTime: export_time,
  3739. }
  3740. service.CreateExportErrLog(&err_log)
  3741. continue
  3742. } else {
  3743. err_log := models.ExportErrLog{
  3744. LogType: 1,
  3745. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3746. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3747. Status: 1,
  3748. CreateTime: time.Now().Unix(),
  3749. UpdateTime: time.Now().Unix(),
  3750. ExportTime: export_time,
  3751. }
  3752. service.CreateExportErrLog(&err_log)
  3753. continue
  3754. }
  3755. } else {
  3756. if len(first_treatment_date) == 0 {
  3757. err_log := models.ExportErrLog{
  3758. LogType: 1,
  3759. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3760. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3761. Status: 1,
  3762. CreateTime: time.Now().Unix(),
  3763. UpdateTime: time.Now().Unix(),
  3764. ExportTime: export_time,
  3765. }
  3766. service.CreateExportErrLog(&err_log)
  3767. continue
  3768. } else {
  3769. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3770. err_log := models.ExportErrLog{
  3771. LogType: 1,
  3772. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3773. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3774. Status: 1,
  3775. CreateTime: time.Now().Unix(),
  3776. UpdateTime: time.Now().Unix(),
  3777. ExportTime: export_time,
  3778. }
  3779. service.CreateExportErrLog(&err_log)
  3780. continue
  3781. } else {
  3782. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3783. }
  3784. }
  3785. }
  3786. }
  3787. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3788. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3789. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  3790. err_log := models.ExportErrLog{
  3791. LogType: 1,
  3792. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3793. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  3794. Status: 1,
  3795. CreateTime: time.Now().Unix(),
  3796. UpdateTime: time.Now().Unix(),
  3797. ExportTime: export_time,
  3798. }
  3799. service.CreateExportErrLog(&err_log)
  3800. continue
  3801. } else if source == 3 {
  3802. err_log := models.ExportErrLog{
  3803. LogType: 1,
  3804. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3805. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  3806. Status: 1,
  3807. CreateTime: time.Now().Unix(),
  3808. UpdateTime: time.Now().Unix(),
  3809. ExportTime: export_time,
  3810. }
  3811. service.CreateExportErrLog(&err_log)
  3812. continue
  3813. } else {
  3814. patient.Source = source
  3815. }
  3816. }
  3817. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  3818. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  3819. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  3820. err_log := models.ExportErrLog{
  3821. LogType: 1,
  3822. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3823. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  3824. Status: 1,
  3825. CreateTime: time.Now().Unix(),
  3826. UpdateTime: time.Now().Unix(),
  3827. ExportTime: export_time,
  3828. }
  3829. service.CreateExportErrLog(&err_log)
  3830. continue
  3831. } else if lapseto == 3 {
  3832. err_log := models.ExportErrLog{
  3833. LogType: 1,
  3834. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3835. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  3836. Status: 1,
  3837. CreateTime: time.Now().Unix(),
  3838. UpdateTime: time.Now().Unix(),
  3839. ExportTime: export_time,
  3840. }
  3841. service.CreateExportErrLog(&err_log)
  3842. continue
  3843. } else {
  3844. patient.Lapseto = lapseto
  3845. }
  3846. }
  3847. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  3848. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  3849. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  3850. err_log := models.ExportErrLog{
  3851. LogType: 1,
  3852. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3853. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  3854. Status: 1,
  3855. CreateTime: time.Now().Unix(),
  3856. UpdateTime: time.Now().Unix(),
  3857. ExportTime: export_time,
  3858. }
  3859. service.CreateExportErrLog(&err_log)
  3860. continue
  3861. } else if is_infectious == 3 {
  3862. err_log := models.ExportErrLog{
  3863. LogType: 1,
  3864. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3865. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  3866. Status: 1,
  3867. CreateTime: time.Now().Unix(),
  3868. UpdateTime: time.Now().Unix(),
  3869. ExportTime: export_time,
  3870. }
  3871. service.CreateExportErrLog(&err_log)
  3872. continue
  3873. } else {
  3874. patient.IsInfectious = is_infectious
  3875. }
  3876. }
  3877. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  3878. var contagions []int64
  3879. thisContagions, _ := patientNameM["contagions"].([]interface{})
  3880. if len(thisContagions) > 0 {
  3881. for _, item := range thisContagions {
  3882. if reflect.TypeOf(item).String() != "float64" {
  3883. continue
  3884. }
  3885. contagion := int64(item.(float64))
  3886. if contagion > 0 {
  3887. contagions = append(contagions, contagion)
  3888. }
  3889. }
  3890. }
  3891. patient.ContagionIds = contagions
  3892. }
  3893. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  3894. diagnose, _ := patientNameM["diagnose"].(string)
  3895. patient.Diagnose = diagnose
  3896. }
  3897. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  3898. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  3899. var tempPatient *models.Patients
  3900. for _, item := range all_patient {
  3901. if item.DialysisNo == dialysis_no {
  3902. tempPatient = item
  3903. }
  3904. }
  3905. if tempPatient != nil && tempPatient.ID > 0 {
  3906. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  3907. } else {
  3908. patient.DialysisNo = dialysis_no
  3909. }
  3910. }
  3911. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  3912. height, _ := patientNameM["height"].(string)
  3913. heights, _ := strconv.ParseFloat(height, 64)
  3914. patient.Height = int64(heights)
  3915. }
  3916. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  3917. home_address, _ := patientNameM["home_address"].(string)
  3918. patient.HomeAddress = home_address
  3919. }
  3920. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  3921. dry_weight, _ := patientNameM["dry_weight"].(string)
  3922. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  3923. patient.DryWeight = dry_weights
  3924. }
  3925. patient.CreatedTime = time.Now().Unix()
  3926. patient.UpdatedTime = time.Now().Unix()
  3927. patient.Status = 1
  3928. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  3929. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  3930. patient.IsExcelExport = 1
  3931. patient.PatientType = 1
  3932. patients = append(patients, &patient)
  3933. }
  3934. }
  3935. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3936. if len(patients) > 0 {
  3937. for _, item := range patients {
  3938. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  3939. }
  3940. log := models.ExportLog{
  3941. LogType: 1,
  3942. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3943. TotalNum: int64(len(total_patients)),
  3944. FailNum: int64(len(errLogs)),
  3945. SuccessNum: int64(len(patients)),
  3946. CreateTime: time.Now().Unix(),
  3947. UpdateTime: time.Now().Unix(),
  3948. ExportTime: export_time,
  3949. Status: 1,
  3950. }
  3951. service.CreateExportLog(&log)
  3952. c.ServeSuccessJSON(map[string]interface{}{
  3953. "msg": "导入成功",
  3954. "total_num": len(total_patients),
  3955. "success_num": len(patients),
  3956. "fail_num": int64(len(errLogs)),
  3957. })
  3958. } else {
  3959. log := models.ExportLog{
  3960. LogType: 1,
  3961. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3962. TotalNum: int64(len(total_patients)),
  3963. FailNum: int64(len(errLogs)),
  3964. SuccessNum: int64(len(patients)),
  3965. CreateTime: time.Now().Unix(),
  3966. UpdateTime: time.Now().Unix(),
  3967. ExportTime: export_time,
  3968. Status: 1,
  3969. }
  3970. service.CreateExportLog(&log)
  3971. c.ServeSuccessJSON(map[string]interface{}{
  3972. "msg": "导入成功",
  3973. "total_num": len(total_patients),
  3974. "success_num": len(patients),
  3975. "fail_num": int64(len(errLogs)),
  3976. })
  3977. }
  3978. }
  3979. func GetBirthDay(IDCardNo string) *time.Time {
  3980. dayStr := IDCardNo[6:14]
  3981. birthDay, err := time.Parse("20060102", dayStr)
  3982. if err != nil {
  3983. fmt.Println(err)
  3984. return nil
  3985. }
  3986. return &birthDay
  3987. }
  3988. func IsIdCard(id string) (res bool) {
  3989. id = strings.ToUpper(id)
  3990. if len(id) != 15 && len(id) != 18 {
  3991. fmt.Println("1111111")
  3992. return false
  3993. }
  3994. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  3995. if !r.MatchString(id) {
  3996. fmt.Println("222222")
  3997. return false
  3998. }
  3999. if len(id) == 15 {
  4000. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  4001. if tm2.Unix() == 0 {
  4002. fmt.Println("44444443333")
  4003. return false
  4004. }
  4005. return true
  4006. } else {
  4007. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  4008. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  4009. fmt.Println(tm2.Unix())
  4010. if tm2.Unix() == 0 {
  4011. fmt.Println("44445555555")
  4012. return false
  4013. }
  4014. //检验18位身份证的校验码是否正确。
  4015. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  4016. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  4017. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  4018. sign := 0
  4019. for k, v := range arr_int {
  4020. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  4021. sign += int_temp * v
  4022. }
  4023. n := sign % 11
  4024. val_num := arr_ch[n]
  4025. if val_num != string([]byte(id)[17:18]) {
  4026. fmt.Println("5556666666")
  4027. return false
  4028. }
  4029. return true
  4030. }
  4031. }
  4032. func (c *PatientApiController) SaveEditAdvices() {
  4033. adminInfo := c.GetAdminUserInfo()
  4034. orgid := adminInfo.CurrentOrgId
  4035. startTime := c.GetString("start_time")
  4036. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  4037. groupno, _ := c.GetInt64("groupno")
  4038. fmt.Println("组", groupno)
  4039. date, _ := c.GetInt64("date")
  4040. fmt.Println("date", date)
  4041. patient_id, _ := c.GetInt64("patient_id")
  4042. fmt.Println("paitent_id", patient_id)
  4043. advice := models.XtDoctorAdvice{
  4044. StartTime: theTime.Unix(),
  4045. }
  4046. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  4047. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  4048. redis := service.RedisClient()
  4049. redis.Set(key, "", time.Second)
  4050. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  4051. redis.Set(keyOne, "", time.Second)
  4052. scheduleTime := theTime.Format("2006-01-02")
  4053. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  4054. fmt.Println("keyFour323223323232323232", keyFour)
  4055. redis.Set(keyFour, "", time.Second)
  4056. defer redis.Close()
  4057. if err != nil {
  4058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4059. return
  4060. }
  4061. c.ServeSuccessJSON(map[string]interface{}{
  4062. "advice": advice,
  4063. })
  4064. }
  4065. func (c *PatientApiController) GetMaxDialysisNo() {
  4066. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  4067. c.ServeSuccessJSON(map[string]interface{}{
  4068. "dialysis_no": dialysisNo,
  4069. })
  4070. }
  4071. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  4072. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  4073. var tempPatient *models.Patients
  4074. for _, item := range patients {
  4075. if item.DialysisNo == dialysisNo2 {
  4076. tempPatient = item
  4077. }
  4078. }
  4079. if tempPatient == nil || tempPatient.ID == 0 {
  4080. return dialysisNo2
  4081. }
  4082. return GenerateDialysisNoTwo(patients)
  4083. }
  4084. func (c *PatientApiController) GetBanner() {
  4085. orgId := c.GetAdminUserInfo().CurrentOrgId
  4086. _, errcodes := service.GetOrgFollowIsExist(orgId)
  4087. if errcodes == gorm.ErrRecordNotFound {
  4088. information, err := service.GetAdminUserRoleInformation(0)
  4089. if err != nil {
  4090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4091. return
  4092. }
  4093. c.ServeSuccessJSON(map[string]interface{}{
  4094. "information": information,
  4095. })
  4096. } else if errcodes == nil {
  4097. information, err := service.GetAdminUserRoleInformation(orgId)
  4098. if err != nil {
  4099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4100. return
  4101. }
  4102. c.ServeSuccessJSON(map[string]interface{}{
  4103. "information": information,
  4104. })
  4105. }
  4106. }