patient_api_controller.go 160KB

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