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. service.DrugsDelivery(item.UserOrgId, item)
  1422. //if item.Way == 1 {
  1423. // out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
  1424. // if err == gorm.ErrRecordNotFound {
  1425. // //没有记录,则创建出库单
  1426. // timeStr := time.Now().Format("2006-01-02")
  1427. // timeArr := strings.Split(timeStr, "-")
  1428. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1429. // total = total + 1
  1430. // warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1431. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1432. // number = number + total
  1433. // warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1434. // creater := adminUserInfo.AdminUser.Id
  1435. // warehouseOut := models.DrugWarehouseOut{
  1436. // WarehouseOutOrderNumber: warehousing_out_order,
  1437. // OperationTime: time.Now().Unix(),
  1438. // OrgId: adminUserInfo.CurrentOrgId,
  1439. // Creater: creater,
  1440. // Ctime: time.Now().Unix(),
  1441. // Status: 1,
  1442. // WarehouseOutTime: item.RecordDate,
  1443. // Dealer: 0,
  1444. // Manufacturer: 0,
  1445. // Type: 1,
  1446. // IsSys: 1,
  1447. // }
  1448. //
  1449. // err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  1450. // if err != nil {
  1451. // utils.TraceLog("创建出库单失败 err = %v", err)
  1452. // } else {
  1453. // if item.Way == 1 {
  1454. // if item.PrescribingNumber > 0 {
  1455. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1456. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1457. // WarehouseOutId: warehouseOut.ID,
  1458. // Status: 1,
  1459. // Ctime: time.Now().Unix(),
  1460. // Remark: "",
  1461. // OrgId: adminUserInfo.CurrentOrgId,
  1462. // Type: 1,
  1463. // Manufacturer: 0,
  1464. // Dealer: 0,
  1465. // IsSys: 1,
  1466. // SysRecordTime: item.RecordDate,
  1467. // DrugId: item.DrugId,
  1468. // }
  1469. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1470. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1471. // warehouseOutInfo.Count = count
  1472. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1473. // warehouseOutInfo.Price = stockInInfo.Price
  1474. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1475. // if err == nil {
  1476. // details := &models.DrugAutomaticReduceDetail{
  1477. // WarehouseOutId: warehouseOutInfo.ID,
  1478. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1479. // PatientId: item.PatientId,
  1480. // Ctime: time.Now().Unix(),
  1481. // Mtime: time.Now().Unix(),
  1482. // Status: 1,
  1483. // RecordTime: item.RecordDate,
  1484. // OrgId: adminUserInfo.CurrentOrgId,
  1485. // DrugId: item.DrugId,
  1486. // Count: count,
  1487. // }
  1488. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1489. // if err != nil {
  1490. // utils.TraceLog("创建出库单失败 err = %v", err)
  1491. // } else {
  1492. // if item.Way == 1 {
  1493. // if item.PrescribingNumber > 0 {
  1494. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1495. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1496. // WarehouseOutId: warehouseOut.ID,
  1497. // Status: 1,
  1498. // Ctime: time.Now().Unix(),
  1499. // Remark: "",
  1500. // OrgId: adminUserInfo.CurrentOrgId,
  1501. // Type: 1,
  1502. // Manufacturer: 0,
  1503. // Dealer: 0,
  1504. // IsSys: 1,
  1505. // SysRecordTime: item.RecordDate,
  1506. // DrugId: item.DrugId,
  1507. // }
  1508. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1509. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1510. // warehouseOutInfo.Count = count
  1511. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1512. // warehouseOutInfo.Price = stockInInfo.Price
  1513. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1514. // if err == nil {
  1515. // details := &models.DrugAutomaticReduceDetail{
  1516. // WarehouseOutId: warehouseOutInfo.ID,
  1517. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1518. // PatientId: item.PatientId,
  1519. // Ctime: time.Now().Unix(),
  1520. // Mtime: time.Now().Unix(),
  1521. // Status: 1,
  1522. // RecordTime: item.RecordDate,
  1523. // OrgId: adminUserInfo.CurrentOrgId,
  1524. // DrugId: item.DrugId,
  1525. // Count: count,
  1526. // }
  1527. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1528. // }
  1529. // }
  1530. // }
  1531. // }
  1532. //
  1533. // }
  1534. // }
  1535. // }
  1536. // }
  1537. // } else if err == nil {
  1538. // if item.Way == 1 {
  1539. // outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  1540. // if err == gorm.ErrRecordNotFound {
  1541. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1542. // WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1543. // WarehouseOutId: out.ID,
  1544. // Status: 1,
  1545. // Ctime: time.Now().Unix(),
  1546. // Remark: "",
  1547. // OrgId: adminUserInfo.CurrentOrgId,
  1548. // Type: 1,
  1549. // Manufacturer: 0,
  1550. // Dealer: 0,
  1551. // IsSys: 1,
  1552. // SysRecordTime: item.RecordDate,
  1553. // }
  1554. //
  1555. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1556. // warehouseOutInfo.Price = stockInInfo.Price
  1557. // warehouseOutInfo.DrugId = item.DrugId
  1558. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1559. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1560. // warehouseOutInfo.Count = count
  1561. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1562. // if err == nil {
  1563. // details := &models.DrugAutomaticReduceDetail{
  1564. // WarehouseOutId: warehouseOutInfo.ID,
  1565. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1566. // PatientId: item.PatientId,
  1567. // Ctime: time.Now().Unix(),
  1568. // Mtime: time.Now().Unix(),
  1569. // Status: 1,
  1570. // RecordTime: item.RecordDate,
  1571. // OrgId: adminUserInfo.CurrentOrgId,
  1572. // DrugId: item.DrugId,
  1573. // Count: count,
  1574. // }
  1575. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1576. // }
  1577. //
  1578. // } else if err == nil { //记录存在,则将增加数量
  1579. // if outInfo.ID > 0 {
  1580. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1581. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1582. // service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
  1583. // }
  1584. //
  1585. // count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
  1586. // if count == 0 {
  1587. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1588. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1589. // details := &models.DrugAutomaticReduceDetail{
  1590. // WarehouseOutId: outInfo.ID,
  1591. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1592. // PatientId: item.PatientId,
  1593. // Ctime: time.Now().Unix(),
  1594. // Mtime: time.Now().Unix(),
  1595. // Status: 1,
  1596. // RecordTime: item.RecordDate,
  1597. // OrgId: adminUserInfo.CurrentOrgId,
  1598. // DrugId: item.DrugId,
  1599. // Count: count,
  1600. // }
  1601. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1602. // } else if count == 1 {
  1603. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1604. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1605. // service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
  1606. // }
  1607. //
  1608. // }
  1609. // }
  1610. // }
  1611. //}
  1612. }
  1613. }
  1614. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1615. for _, item := range advices {
  1616. if item.Way == 2 {
  1617. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1618. //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1619. if item.ExecutionState == 1 {
  1620. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1621. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1622. timeStr := time.Now().Format("2006-01-02")
  1623. timeArr := strings.Split(timeStr, "-")
  1624. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1625. total = total + 1
  1626. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1627. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1628. number = number + total
  1629. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1630. //插入自备药出库单
  1631. outStock := models.XtSelfOutStock{
  1632. DrugName: item.AdviceName,
  1633. DrugNameId: item.DrugId,
  1634. DrugSpec: item.AdviceDesc,
  1635. OutstoreNumber: count,
  1636. AdminUserId: adminUserInfo.AdminUser.Id,
  1637. StorckTime: item.RecordDate,
  1638. UserOrgId: adminUserInfo.CurrentOrgId,
  1639. CreatedTime: time.Now().Unix(),
  1640. Status: 1,
  1641. PatientId: item.PatientId,
  1642. ExitMode: 2,
  1643. MedicId: item.DrugId,
  1644. StockOutNumber: warehousing_out_order,
  1645. }
  1646. service.CreateOutStock(&outStock)
  1647. }
  1648. }
  1649. }
  1650. }
  1651. c.ServeSuccessJSON(map[string]interface{}{
  1652. "msg": "ok",
  1653. "advice": advice,
  1654. })
  1655. return
  1656. } else {
  1657. if id <= 0 || patient <= 0 {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1659. return
  1660. }
  1661. if len(executionTime) <= 0 {
  1662. utils.ErrorLog("execution_time")
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1664. return
  1665. }
  1666. adminUserInfo := c.GetAdminUserInfo()
  1667. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1668. if advice.ID == 0 || advice.PatientId != patient {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1670. return
  1671. }
  1672. //医嘱已执行
  1673. if advice.ExecutionState == 1 {
  1674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1675. return
  1676. }
  1677. executionStaff := adminUserInfo.AdminUser.Id
  1678. // checker := adminUserInfo.AdminUser.Id
  1679. timeLayout := "2006-01-02 15:04:05"
  1680. loc, _ := time.LoadLocation("Local")
  1681. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1682. if err != nil {
  1683. utils.ErrorLog(err.Error())
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1685. return
  1686. }
  1687. if advice.StartTime > theTime.Unix() {
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1689. return
  1690. }
  1691. exceAdvice := models.HisDoctorAdviceInfo{
  1692. ExecutionStaff: executionStaff,
  1693. ExecutionTime: theTime.Unix(),
  1694. // Checker: checker,
  1695. UpdatedTime: time.Now().Unix(),
  1696. }
  1697. if advice.ParentId > 0 {
  1698. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1699. } else {
  1700. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1701. }
  1702. if err != nil {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1704. return
  1705. }
  1706. advice.ExecutionStaff = executionStaff
  1707. advice.ExecutionTime = theTime.Unix()
  1708. // advice.Checker = checker
  1709. //处理出库相关逻辑
  1710. //1.判断是否启用药品管理和自备药出库功能
  1711. //药品管理信息
  1712. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1713. if drugStockConfig.IsOpen == 1 {
  1714. //查询已经执行的医嘱
  1715. advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1716. for _, item := range advices {
  1717. out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
  1718. if err == gorm.ErrRecordNotFound {
  1719. //没有记录,则创建出库单
  1720. timeStr := time.Now().Format("2006-01-02")
  1721. timeArr := strings.Split(timeStr, "-")
  1722. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1723. total = total + 1
  1724. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1725. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1726. number = number + total
  1727. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1728. creater := adminUserInfo.AdminUser.Id
  1729. warehouseOut := models.DrugWarehouseOut{
  1730. WarehouseOutOrderNumber: warehousing_out_order,
  1731. OperationTime: time.Now().Unix(),
  1732. OrgId: adminUserInfo.CurrentOrgId,
  1733. Creater: creater,
  1734. Ctime: time.Now().Unix(),
  1735. Status: 1,
  1736. WarehouseOutTime: item.RecordDate,
  1737. Dealer: 0,
  1738. Manufacturer: 0,
  1739. Type: 1,
  1740. IsSys: 1,
  1741. }
  1742. err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  1743. if err != nil {
  1744. utils.TraceLog("创建出库单失败 err = %v", err)
  1745. } else {
  1746. if item.PrescribingNumber > 0 {
  1747. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1748. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1749. WarehouseOutId: warehouseOut.ID,
  1750. Status: 1,
  1751. Ctime: time.Now().Unix(),
  1752. Remark: "",
  1753. OrgId: adminUserInfo.CurrentOrgId,
  1754. Type: 1,
  1755. Manufacturer: 0,
  1756. Dealer: 0,
  1757. IsSys: 1,
  1758. SysRecordTime: item.RecordDate,
  1759. DrugId: item.DrugId,
  1760. }
  1761. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1762. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1763. warehouseOutInfo.Count = count
  1764. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1765. warehouseOutInfo.Price = stockInInfo.Price
  1766. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1767. if err == nil {
  1768. details := &models.DrugAutomaticReduceDetail{
  1769. WarehouseOutId: warehouseOutInfo.ID,
  1770. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1771. PatientId: item.PatientId,
  1772. Ctime: time.Now().Unix(),
  1773. Mtime: time.Now().Unix(),
  1774. Status: 1,
  1775. RecordTime: item.RecordDate,
  1776. OrgId: adminUserInfo.CurrentOrgId,
  1777. DrugId: item.DrugId,
  1778. Count: count,
  1779. }
  1780. service.AddSigleDrugAutoReduceRecordInfo(details)
  1781. if err != nil {
  1782. utils.TraceLog("创建出库单失败 err = %v", err)
  1783. } else {
  1784. if item.PrescribingNumber > 0 {
  1785. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1786. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1787. WarehouseOutId: warehouseOut.ID,
  1788. Status: 1,
  1789. Ctime: time.Now().Unix(),
  1790. Remark: "",
  1791. OrgId: adminUserInfo.CurrentOrgId,
  1792. Type: 1,
  1793. Manufacturer: 0,
  1794. Dealer: 0,
  1795. IsSys: 1,
  1796. SysRecordTime: item.RecordDate,
  1797. DrugId: item.DrugId,
  1798. }
  1799. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1800. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1801. warehouseOutInfo.Count = count
  1802. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1803. warehouseOutInfo.Price = stockInInfo.Price
  1804. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1805. if err == nil {
  1806. details := &models.DrugAutomaticReduceDetail{
  1807. WarehouseOutId: warehouseOutInfo.ID,
  1808. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1809. PatientId: item.PatientId,
  1810. Ctime: time.Now().Unix(),
  1811. Mtime: time.Now().Unix(),
  1812. Status: 1,
  1813. RecordTime: item.RecordDate,
  1814. OrgId: adminUserInfo.CurrentOrgId,
  1815. DrugId: item.DrugId,
  1816. Count: count,
  1817. }
  1818. service.AddSigleDrugAutoReduceRecordInfo(details)
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. } else if err == nil {
  1826. outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  1827. if err == gorm.ErrRecordNotFound {
  1828. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1829. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1830. WarehouseOutId: out.ID,
  1831. Status: 1,
  1832. Ctime: time.Now().Unix(),
  1833. Remark: "",
  1834. OrgId: adminUserInfo.CurrentOrgId,
  1835. Type: 1,
  1836. Manufacturer: 0,
  1837. Dealer: 0,
  1838. IsSys: 1,
  1839. SysRecordTime: item.RecordDate,
  1840. }
  1841. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1842. warehouseOutInfo.Price = stockInInfo.Price
  1843. warehouseOutInfo.DrugId = item.DrugId
  1844. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1845. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1846. warehouseOutInfo.Count = count
  1847. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1848. if err == nil {
  1849. details := &models.DrugAutomaticReduceDetail{
  1850. WarehouseOutId: warehouseOutInfo.ID,
  1851. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1852. PatientId: item.PatientId,
  1853. Ctime: time.Now().Unix(),
  1854. Mtime: time.Now().Unix(),
  1855. Status: 1,
  1856. RecordTime: item.RecordDate,
  1857. OrgId: adminUserInfo.CurrentOrgId,
  1858. DrugId: item.DrugId,
  1859. Count: count,
  1860. }
  1861. service.AddSigleDrugAutoReduceRecordInfo(details)
  1862. }
  1863. } else if err == nil { //记录存在,则将增加数量
  1864. if outInfo.ID > 0 {
  1865. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1866. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1867. service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
  1868. }
  1869. count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
  1870. if count == 0 {
  1871. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1872. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1873. details := &models.DrugAutomaticReduceDetail{
  1874. WarehouseOutId: outInfo.ID,
  1875. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1876. PatientId: item.PatientId,
  1877. Ctime: time.Now().Unix(),
  1878. Mtime: time.Now().Unix(),
  1879. Status: 1,
  1880. RecordTime: item.RecordDate,
  1881. OrgId: adminUserInfo.CurrentOrgId,
  1882. DrugId: item.DrugId,
  1883. Count: count,
  1884. }
  1885. service.AddSigleDrugAutoReduceRecordInfo(details)
  1886. } else if count == 1 {
  1887. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1888. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1889. service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
  1890. }
  1891. }
  1892. }
  1893. }
  1894. }
  1895. c.ServeSuccessJSON(map[string]interface{}{
  1896. "msg": "ok",
  1897. "advice": advice,
  1898. })
  1899. return
  1900. }
  1901. }
  1902. func (c *PatientApiController) CheckGroupAdvice() {
  1903. groupno, _ := c.GetInt64("groupno", 0)
  1904. if groupno <= 0 {
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1906. return
  1907. }
  1908. adminUserInfo := c.GetAdminUserInfo()
  1909. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1910. if advice.ID == 0 {
  1911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1912. return
  1913. }
  1914. if advice.CheckState == 1 {
  1915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1916. return
  1917. }
  1918. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1920. return
  1921. }
  1922. checker := adminUserInfo.AdminUser.Id
  1923. theTime := time.Now()
  1924. exceAdvice := models.DoctorAdvice{
  1925. Checker: checker,
  1926. CheckTime: theTime.Unix(),
  1927. UpdatedTime: time.Now().Unix(),
  1928. }
  1929. var err error
  1930. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1931. if err != nil {
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1933. return
  1934. }
  1935. // advice.ExecutionStaff = executionStaff
  1936. // advice.ExecutionTime = theTime.Unix()
  1937. advice.Checker = checker
  1938. advice.CheckTime = theTime.Unix()
  1939. c.ServeSuccessJSON(map[string]interface{}{
  1940. "msg": "ok",
  1941. "advice": advice,
  1942. })
  1943. return
  1944. }
  1945. func (c *PatientApiController) CheckDoctorAdvice() {
  1946. patient, _ := c.GetInt64("patient", 0)
  1947. id, _ := c.GetInt64("id", 0)
  1948. origin, _ := c.GetInt64("origin", 0)
  1949. if origin != 2 {
  1950. // executionTime := c.GetString("execution_time")
  1951. if id <= 0 || patient <= 0 {
  1952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1953. return
  1954. }
  1955. adminUserInfo := c.GetAdminUserInfo()
  1956. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1957. if advice.ID == 0 || advice.PatientId != patient {
  1958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1959. return
  1960. }
  1961. if advice.CheckState == 1 {
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1963. return
  1964. }
  1965. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1967. return
  1968. }
  1969. // executionStaff := adminUserInfo.AdminUser.Id
  1970. checker := adminUserInfo.AdminUser.Id
  1971. // timeLayout := "2006-01-02 15:04:05"
  1972. // loc, _ := time.LoadLocation("Local")
  1973. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1974. // if err != nil {
  1975. // utils.ErrorLog(err.Error())
  1976. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1977. // return
  1978. // }
  1979. theTime := time.Now()
  1980. if advice.ExecutionTime > theTime.Unix() {
  1981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1982. return
  1983. }
  1984. exceAdvice := models.DoctorAdvice{
  1985. Checker: checker,
  1986. CheckTime: theTime.Unix(),
  1987. UpdatedTime: time.Now().Unix(),
  1988. }
  1989. var err error
  1990. if advice.ParentId > 0 {
  1991. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1992. } else {
  1993. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1994. }
  1995. if err != nil {
  1996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1997. return
  1998. }
  1999. // advice.ExecutionStaff = executionStaff
  2000. // advice.ExecutionTime = theTime.Unix()
  2001. advice.Checker = checker
  2002. advice.CheckTime = theTime.Unix()
  2003. c.ServeSuccessJSON(map[string]interface{}{
  2004. "msg": "ok",
  2005. "advice": advice,
  2006. })
  2007. return
  2008. } else {
  2009. if id <= 0 || patient <= 0 {
  2010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2011. return
  2012. }
  2013. adminUserInfo := c.GetAdminUserInfo()
  2014. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2015. if advice.ID == 0 || advice.PatientId != patient {
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2017. return
  2018. }
  2019. if advice.CheckState == 1 {
  2020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2021. return
  2022. }
  2023. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2025. return
  2026. }
  2027. checker := adminUserInfo.AdminUser.Id
  2028. theTime := time.Now()
  2029. if advice.ExecutionTime > theTime.Unix() {
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2031. return
  2032. }
  2033. exceAdvice := models.HisDoctorAdviceInfo{
  2034. Checker: checker,
  2035. CheckTime: theTime.Unix(),
  2036. UpdatedTime: time.Now().Unix(),
  2037. }
  2038. var err error
  2039. if advice.ParentId > 0 {
  2040. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2041. } else {
  2042. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2043. }
  2044. if err != nil {
  2045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2046. return
  2047. }
  2048. // advice.ExecutionStaff = executionStaff
  2049. // advice.ExecutionTime = theTime.Unix()
  2050. advice.Checker = checker
  2051. advice.CheckTime = theTime.Unix()
  2052. c.ServeSuccessJSON(map[string]interface{}{
  2053. "msg": "ok",
  2054. "advice": advice,
  2055. })
  2056. return
  2057. }
  2058. }
  2059. func (c *PatientApiController) UpdateDoctorAdvice() {
  2060. patient, _ := c.GetInt64("patient", 0)
  2061. id, _ := c.GetInt64("id", 0)
  2062. if id <= 0 || patient <= 0 {
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2064. return
  2065. }
  2066. adminUserInfo := c.GetAdminUserInfo()
  2067. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2068. if advice.ID == 0 || advice.PatientId != patient {
  2069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2070. return
  2071. }
  2072. //if advice.AdviceType == 1 {
  2073. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2074. // return
  2075. //}
  2076. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2078. return
  2079. }
  2080. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2081. //if appRole.UserType == 3 {
  2082. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2083. // if getPermissionErr != nil {
  2084. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2085. // return
  2086. // } else if headNursePermission == nil {
  2087. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2088. // return
  2089. // }
  2090. //}
  2091. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2092. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2093. // return
  2094. //}
  2095. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2096. if code > 0 {
  2097. c.ServeFailJSONWithSGJErrorCode(code)
  2098. return
  2099. }
  2100. advice.UpdatedTime = time.Now().Unix()
  2101. advice.Modifier = adminUserInfo.AdminUser.Id
  2102. err := service.UpdateDoctorAdvice(&advice)
  2103. if err != nil {
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2105. return
  2106. }
  2107. c.ServeSuccessJSON(map[string]interface{}{
  2108. "msg": "ok",
  2109. "advice": advice,
  2110. })
  2111. return
  2112. }
  2113. func (c *PatientApiController) StopGroupAdvice() {
  2114. groupNo, _ := c.GetInt64("groupno", 0)
  2115. if groupNo <= 0 {
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2117. return
  2118. }
  2119. adminUserInfo := c.GetAdminUserInfo()
  2120. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2121. if advice.ID == 0 {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2123. return
  2124. }
  2125. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2127. return
  2128. }
  2129. dataBody := make(map[string]interface{}, 0)
  2130. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2131. if err != nil {
  2132. utils.ErrorLog(err.Error())
  2133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2134. return
  2135. }
  2136. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2137. utils.ErrorLog("stop_time")
  2138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2139. return
  2140. }
  2141. stopTime, _ := dataBody["stop_time"].(string)
  2142. if len(stopTime) == 0 {
  2143. utils.ErrorLog("len(stop_time) == 0")
  2144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2145. return
  2146. }
  2147. timeLayout := "2006-01-02"
  2148. loc, _ := time.LoadLocation("Local")
  2149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2150. if err != nil {
  2151. utils.ErrorLog(err.Error())
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2153. return
  2154. }
  2155. advice.StopTime = theTime.Unix()
  2156. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2157. stopReason, _ := dataBody["stop_reason"].(string)
  2158. advice.StopReason = stopReason
  2159. }
  2160. advice.UpdatedTime = time.Now().Unix()
  2161. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2162. advice.StopState = 1
  2163. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2164. if err != nil {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2166. return
  2167. }
  2168. c.ServeSuccessJSON(map[string]interface{}{
  2169. "msg": "ok",
  2170. })
  2171. return
  2172. }
  2173. func (c *PatientApiController) StopDoctorAdvice() {
  2174. id, _ := c.GetInt64("id", 0)
  2175. if id <= 0 {
  2176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2177. return
  2178. }
  2179. adminUserInfo := c.GetAdminUserInfo()
  2180. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2181. //
  2182. //if appRole.UserType == 3 {
  2183. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2184. // if getPermissionErr != nil {
  2185. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2186. // return
  2187. // } else if headNursePermission == nil {
  2188. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2189. // return
  2190. // }
  2191. //}
  2192. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2193. if advice.ID == 0 {
  2194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2195. return
  2196. }
  2197. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2199. return
  2200. }
  2201. dataBody := make(map[string]interface{}, 0)
  2202. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2203. if err != nil {
  2204. utils.ErrorLog(err.Error())
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2209. utils.ErrorLog("stop_time")
  2210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2211. return
  2212. }
  2213. stopTime, _ := dataBody["stop_time"].(string)
  2214. if len(stopTime) == 0 {
  2215. utils.ErrorLog("len(stop_time) == 0")
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2217. return
  2218. }
  2219. timeLayout := "2006-01-02"
  2220. loc, _ := time.LoadLocation("Local")
  2221. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2222. if err != nil {
  2223. utils.ErrorLog(err.Error())
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. advice.StopTime = theTime.Unix()
  2228. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2229. stopReason, _ := dataBody["stop_reason"].(string)
  2230. advice.StopReason = stopReason
  2231. }
  2232. advice.UpdatedTime = time.Now().Unix()
  2233. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2234. advice.StopState = 1
  2235. err = service.StopDoctorAdvice(&advice)
  2236. if err != nil {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2238. return
  2239. }
  2240. c.ServeSuccessJSON(map[string]interface{}{
  2241. "msg": "ok",
  2242. "advice": advice,
  2243. })
  2244. return
  2245. }
  2246. func (c *PatientApiController) DeleteDoctorAdvice() {
  2247. id, _ := c.GetInt64("id", 0)
  2248. if id <= 0 {
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. adminUserInfo := c.GetAdminUserInfo()
  2253. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2254. if advice.ID == 0 {
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2256. return
  2257. }
  2258. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2259. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2260. // return
  2261. //}
  2262. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2263. //
  2264. //if appRole.UserType == 3 {
  2265. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2266. // if getPermissionErr != nil {
  2267. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2268. // return
  2269. // } else if headNursePermission == nil {
  2270. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2271. // return
  2272. // }
  2273. //}
  2274. advice.UpdatedTime = time.Now().Unix()
  2275. advice.Status = 0
  2276. advice.Modifier = adminUserInfo.AdminUser.Id
  2277. err := service.DeleteDoctorAdvice(&advice)
  2278. if err != nil {
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2280. return
  2281. }
  2282. c.ServeSuccessJSON(map[string]interface{}{
  2283. "msg": "ok",
  2284. })
  2285. return
  2286. }
  2287. func (c *PatientApiController) DeleteGroupAdvice() {
  2288. groupNo, _ := c.GetInt64("groupno", 0)
  2289. if groupNo <= 0 {
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2291. return
  2292. }
  2293. adminUserInfo := c.GetAdminUserInfo()
  2294. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2295. if advice.ID == 0 {
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2297. return
  2298. }
  2299. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2300. //if appRole.UserType == 3 {
  2301. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2302. // if getPermissionErr != nil {
  2303. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2304. // return
  2305. // } else if headNursePermission == nil {
  2306. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2307. // return
  2308. // }
  2309. //}
  2310. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2311. if err != nil {
  2312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2313. return
  2314. }
  2315. c.ServeSuccessJSON(map[string]interface{}{
  2316. "msg": "ok",
  2317. })
  2318. return
  2319. }
  2320. //GetDoctorAdvices 医嘱列表
  2321. func (c *PatientApiController) GetDoctorAdvices() {
  2322. id, _ := c.GetInt64("id", 0)
  2323. adviceType, _ := c.GetInt64("advice_type", 0)
  2324. stopType, _ := c.GetInt64("stop_state", 0)
  2325. startTime := c.GetString("start_time", "")
  2326. endTime := c.GetString("end_time", "")
  2327. keywords := c.GetString("keywords", "")
  2328. page, _ := c.GetInt64("page")
  2329. fmt.Println("page", page)
  2330. limit, _ := c.GetInt64("limit")
  2331. fmt.Println("limit", limit)
  2332. adminUserInfo := c.GetAdminUserInfo()
  2333. operatorIDs := make([]int64, 0)
  2334. timeLayout := "2006-01-02"
  2335. loc, _ := time.LoadLocation("Local")
  2336. var theStartTIme int64
  2337. if len(startTime) > 0 {
  2338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2339. if err != nil {
  2340. utils.ErrorLog(err.Error())
  2341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2342. return
  2343. }
  2344. theStartTIme = theTime.Unix()
  2345. }
  2346. var theEndtTIme int64
  2347. if len(endTime) > 0 {
  2348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2349. if err != nil {
  2350. utils.ErrorLog(err.Error())
  2351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2352. return
  2353. }
  2354. theEndtTIme = theTime.Unix()
  2355. }
  2356. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2357. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2358. if len(advices) > 0 {
  2359. for _, item := range advices {
  2360. if item.AdviceDoctor > 0 {
  2361. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2362. }
  2363. if item.ExecutionStaff > 0 {
  2364. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2365. }
  2366. if item.Checker > 0 {
  2367. operatorIDs = append(operatorIDs, item.Checker)
  2368. }
  2369. if item.StopDoctor > 0 {
  2370. operatorIDs = append(operatorIDs, item.StopDoctor)
  2371. }
  2372. }
  2373. }
  2374. //相关操作对应的操作人
  2375. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2376. c.ServeSuccessJSON(map[string]interface{}{
  2377. "advices": advices,
  2378. "operators": operators,
  2379. "total": total,
  2380. "advicetwo": advicestwo,
  2381. })
  2382. return
  2383. }
  2384. func (c *PatientApiController) GetPatientSchedules() {
  2385. id, _ := c.GetInt64("id", 0)
  2386. if id <= 0 {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2388. return
  2389. }
  2390. adminUserInfo := c.GetAdminUserInfo()
  2391. todayTime := time.Now().Format("2006-01-02")
  2392. timeLayout := "2006-01-02 15:04:05"
  2393. loc, _ := time.LoadLocation("Local")
  2394. var theStartTime int64
  2395. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2396. theStartTime = theTime.Unix()
  2397. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2398. if len(schedules) > 0 {
  2399. for index, item := range schedules {
  2400. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2401. schedules[index].Week = int64(week)
  2402. }
  2403. }
  2404. c.ServeSuccessJSON(map[string]interface{}{
  2405. "schedules": schedules,
  2406. })
  2407. return
  2408. }
  2409. func (c *PatientApiController) GetPatientDialysisRecords() {
  2410. patientID, _ := c.GetInt64("patient_id", 0)
  2411. page, _ := c.GetInt64("page", 0)
  2412. limit, _ := c.GetInt64("limit", 0)
  2413. startTime := c.GetString("start_time", "")
  2414. endTime := c.GetString("end_time", "")
  2415. mode_id, _ := c.GetInt64("mode_id", 0)
  2416. if page <= 0 {
  2417. page = 1
  2418. }
  2419. if limit <= 0 {
  2420. limit = 10
  2421. }
  2422. if patientID <= 0 {
  2423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2424. return
  2425. }
  2426. timeLayout := "2006-01-02"
  2427. loc, _ := time.LoadLocation("Local")
  2428. var theStartTIme int64
  2429. if len(startTime) > 0 {
  2430. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2431. if err != nil {
  2432. theStartTIme = 0
  2433. }
  2434. theStartTIme = theTime.Unix()
  2435. }
  2436. var theEndtTIme int64
  2437. if len(endTime) > 0 {
  2438. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2439. if err != nil {
  2440. theEndtTIme = 0
  2441. }
  2442. theEndtTIme = theTime.Unix()
  2443. }
  2444. adminInfo := c.GetAdminUserInfo()
  2445. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2446. c.ServeSuccessJSON(map[string]interface{}{
  2447. "total": total,
  2448. "records": records,
  2449. })
  2450. return
  2451. }
  2452. func (c *PatientApiController) ProEducation() {
  2453. patientID, _ := c.GetInt64("patient_id", 0)
  2454. page, _ := c.GetInt64("page", 0)
  2455. limit, _ := c.GetInt64("limit", 0)
  2456. startTime := c.GetString("start_time", "")
  2457. endTime := c.GetString("end_time", "")
  2458. if page <= 0 {
  2459. page = 1
  2460. }
  2461. if limit <= 0 {
  2462. limit = 10
  2463. }
  2464. if patientID <= 0 {
  2465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2466. return
  2467. }
  2468. timeLayout := "2006-01-02"
  2469. loc, _ := time.LoadLocation("Local")
  2470. var theStartTIme int64
  2471. if len(startTime) > 0 {
  2472. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2473. if err != nil {
  2474. theStartTIme = 0
  2475. }
  2476. theStartTIme = theTime.Unix()
  2477. }
  2478. var theEndtTIme int64
  2479. if len(endTime) > 0 {
  2480. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2481. if err != nil {
  2482. theEndtTIme = 0
  2483. }
  2484. theEndtTIme = theTime.Unix()
  2485. }
  2486. adminInfo := c.GetAdminUserInfo()
  2487. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2488. c.ServeSuccessJSON(map[string]interface{}{
  2489. "total": total,
  2490. "edus": edus,
  2491. })
  2492. return
  2493. }
  2494. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2495. dataBody := make(map[string]interface{}, 0)
  2496. err := json.Unmarshal(data, &dataBody)
  2497. if err != nil {
  2498. utils.ErrorLog(err.Error())
  2499. code = enums.ErrorCodeParamWrong
  2500. return
  2501. }
  2502. timeLayout := "2006-01-02"
  2503. loc, _ := time.LoadLocation("Local")
  2504. isChild := false
  2505. if action == "create" {
  2506. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2507. utils.ErrorLog("advice_type")
  2508. code = enums.ErrorCodeParamWrong
  2509. return
  2510. }
  2511. adviceType := int64(dataBody["advice_type"].(float64))
  2512. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2513. utils.ErrorLog("advice_type != 1&&2")
  2514. code = enums.ErrorCodeParamWrong
  2515. return
  2516. }
  2517. advice.AdviceType = adviceType
  2518. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2519. utils.ErrorLog("advice_date")
  2520. code = enums.ErrorCodeParamWrong
  2521. return
  2522. }
  2523. adviceDate, _ := dataBody["advice_date"].(string)
  2524. if len(adviceDate) == 0 {
  2525. utils.ErrorLog("len(adviceDate) == 0")
  2526. code = enums.ErrorCodeParamWrong
  2527. return
  2528. }
  2529. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2530. if err != nil {
  2531. utils.ErrorLog(err.Error())
  2532. code = enums.ErrorCodeParamWrong
  2533. return
  2534. }
  2535. advice.AdviceDate = theTime.Unix()
  2536. advice.RecordDate = theTime.Unix()
  2537. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2538. parentId := int64(dataBody["parent_id"].(float64))
  2539. advice.ParentId = parentId
  2540. if parentId > 0 {
  2541. isChild = true
  2542. }
  2543. }
  2544. }
  2545. if !isChild {
  2546. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2547. utils.ErrorLog("start_time")
  2548. code = enums.ErrorCodeParamWrong
  2549. return
  2550. }
  2551. startTime, _ := dataBody["start_time"].(string)
  2552. if len(startTime) == 0 {
  2553. utils.ErrorLog("len(start_time) == 0")
  2554. code = enums.ErrorCodeParamWrong
  2555. return
  2556. }
  2557. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2558. if err != nil {
  2559. utils.ErrorLog(err.Error())
  2560. code = enums.ErrorCodeParamWrong
  2561. return
  2562. }
  2563. advice.StartTime = theTime.Unix()
  2564. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2565. // utils.ErrorLog("advice_doctor")
  2566. // code = enums.ErrorCodeParamWrong
  2567. // return
  2568. // }
  2569. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2570. // if adviceDoctor <= 0 {
  2571. // utils.ErrorLog("advice_doctor <=0")
  2572. // code = enums.ErrorCodeParamWrong
  2573. // return
  2574. // }
  2575. // advice.AdviceDoctor = adviceDoctor
  2576. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2577. deliveryWay, _ := dataBody["delivery_way"].(string)
  2578. advice.DeliveryWay = deliveryWay
  2579. }
  2580. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2581. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2582. advice.ExecutionFrequency = executionFrequency
  2583. }
  2584. if advice.AdviceType == 1 && advice.ParentId == 0 {
  2585. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  2586. frequency_type := int64(dataBody["frequency_type"].(float64))
  2587. advice.FrequencyType = frequency_type
  2588. }
  2589. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  2590. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  2591. advice.DayCount = day_count
  2592. }
  2593. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  2594. week_day, _ := dataBody["week_days"].(string)
  2595. advice.WeekDay = week_day
  2596. }
  2597. }
  2598. }
  2599. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2600. utils.ErrorLog("advice_name")
  2601. code = enums.ErrorCodeParamWrong
  2602. return
  2603. }
  2604. adviceName, _ := dataBody["advice_name"].(string)
  2605. if len(adviceName) == 0 {
  2606. utils.ErrorLog("len(advice_name) == 0")
  2607. code = enums.ErrorCodeParamWrong
  2608. return
  2609. }
  2610. advice.AdviceName = adviceName
  2611. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2612. adviceDsc, _ := dataBody["advice_desc"].(string)
  2613. advice.AdviceDesc = adviceDsc
  2614. }
  2615. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2616. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2617. advice.DialysisOrderId = int64(dialysisOrderId)
  2618. }
  2619. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2620. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2621. advice.SingleDose = singleDose
  2622. }
  2623. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2624. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2625. advice.SingleDoseUnit = singleDoseUnit
  2626. }
  2627. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2628. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2629. advice.DrugSpec = drugSpec
  2630. }
  2631. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2632. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2633. advice.DrugSpecUnit = drugSpecUnit
  2634. }
  2635. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2636. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2637. advice.PrescribingNumber = prescribingNumber
  2638. }
  2639. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2640. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2641. advice.PrescribingNumberUnit = prescribingNumberUnit
  2642. }
  2643. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2644. remark, _ := dataBody["remark"].(string)
  2645. advice.Remark = remark
  2646. }
  2647. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2648. drug_id, _ := dataBody["drug_id"].(float64)
  2649. advice.DrugId = int64(drug_id)
  2650. }
  2651. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2652. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  2653. advice.DrugNameId = int64(drug_name_id)
  2654. }
  2655. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2656. way, _ := dataBody["way"].(float64)
  2657. advice.Way = int64(way)
  2658. }
  2659. return
  2660. }
  2661. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2662. dataBody := make(map[string]interface{}, 0)
  2663. err := json.Unmarshal(data, &dataBody)
  2664. utils.InfoLog(string(data))
  2665. if err != nil {
  2666. utils.ErrorLog(err.Error())
  2667. code = enums.ErrorCodeParamWrong
  2668. return
  2669. }
  2670. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2671. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2672. solution.DialysisDuration = dialysisDuration
  2673. }
  2674. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2675. replacementWay := int64(dataBody["replacement_way"].(float64))
  2676. solution.ReplacementWay = replacementWay
  2677. }
  2678. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2679. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2680. solution.BloodFlowVolume = bloodFlowVolume
  2681. }
  2682. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2683. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2684. solution.HemodialysisMachine = hemodialysisMachine
  2685. }
  2686. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2687. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2688. solution.BloodFilter = bloodFilter
  2689. }
  2690. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2691. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2692. solution.PerfusionApparatus = perfusionApparatus
  2693. }
  2694. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2695. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2696. solution.DialysateFlow = dialysateFlow
  2697. }
  2698. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2699. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2700. solution.Kalium = kalium
  2701. }
  2702. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2703. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2704. solution.Sodium = sodium
  2705. }
  2706. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2707. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2708. solution.Calcium = calcium
  2709. }
  2710. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2711. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2712. solution.Bicarbonate = bicarbonate
  2713. }
  2714. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2715. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2716. solution.Anticoagulant = anticoagulant
  2717. }
  2718. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2719. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2720. solution.AnticoagulantShouji = anticoagulantShouji
  2721. }
  2722. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2723. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2724. solution.AnticoagulantWeichi = anticoagulantWeichi
  2725. }
  2726. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2727. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2728. solution.AnticoagulantZongliang = anticoagulantZongliang
  2729. }
  2730. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2731. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2732. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2733. }
  2734. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2735. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2736. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2737. }
  2738. return
  2739. }
  2740. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2741. dataBody := make(map[string]interface{}, 0)
  2742. err := json.Unmarshal(data, &dataBody)
  2743. utils.InfoLog(string(data))
  2744. if err != nil {
  2745. utils.ErrorLog(err.Error())
  2746. code = enums.ErrorCodeParamWrong
  2747. return
  2748. }
  2749. if method == "create" {
  2750. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2751. utils.ErrorLog("mode")
  2752. code = enums.ErrorCodeParamWrong
  2753. return
  2754. }
  2755. mode := int64(dataBody["mode"].(float64))
  2756. if mode <= 0 {
  2757. utils.ErrorLog("mode <= 0")
  2758. code = enums.ErrorCodeParamWrong
  2759. return
  2760. }
  2761. solution.ModeId = mode
  2762. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2763. utils.ErrorLog("mode_name")
  2764. code = enums.ErrorCodeParamWrong
  2765. return
  2766. }
  2767. modeName, _ := dataBody["mode_name"].(string)
  2768. if len(modeName) == 0 {
  2769. utils.ErrorLog("len(mode_name) == 0")
  2770. code = enums.ErrorCodeParamWrong
  2771. return
  2772. }
  2773. solution.ModeName = modeName
  2774. solution.Name = modeName
  2775. }
  2776. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2777. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2778. solution.DialysisDuration = dialysisDuration
  2779. }
  2780. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2781. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2782. solution.TargetUltrafiltration = targetUltrafiltration
  2783. }
  2784. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2785. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2786. solution.DialysateFormulation = dialysateFormulation
  2787. }
  2788. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2789. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2790. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2791. }
  2792. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2793. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2794. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2795. }
  2796. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2797. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2798. solution.HemodialysisMachine = hemodialysisMachine
  2799. }
  2800. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2801. dialyzer := int64(dataBody["dialyzer"].(float64))
  2802. solution.Dialyzer = dialyzer
  2803. }
  2804. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2805. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2806. solution.PerfusionApparatus = perfusionApparatus
  2807. }
  2808. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2809. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2810. solution.BloodFlowVolume = bloodFlowVolume
  2811. }
  2812. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2813. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2814. solution.Dewater = dewater
  2815. }
  2816. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2817. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2818. solution.DisplaceLiqui = displaceLiqui
  2819. }
  2820. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2821. replacementWay := int64(dataBody["replacement_way"].(float64))
  2822. solution.ReplacementWay = replacementWay
  2823. }
  2824. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2825. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2826. solution.Anticoagulant = anticoagulant
  2827. }
  2828. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2829. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2830. solution.AnticoagulantShouji = anticoagulantShouji
  2831. }
  2832. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2833. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2834. solution.AnticoagulantWeichi = anticoagulantWeichi
  2835. }
  2836. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2837. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2838. solution.AnticoagulantZongliang = anticoagulantZongliang
  2839. }
  2840. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2841. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2842. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2843. }
  2844. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2845. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2846. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2847. }
  2848. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2849. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2850. solution.Kalium = kalium
  2851. }
  2852. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2853. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2854. solution.Sodium = sodium
  2855. }
  2856. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2857. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2858. solution.Calcium = calcium
  2859. }
  2860. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2861. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2862. solution.Bicarbonate = bicarbonate
  2863. }
  2864. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2865. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2866. solution.Glucose = glucose
  2867. }
  2868. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2869. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2870. // solution.DryWeight = dryWeight
  2871. // }
  2872. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2873. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2874. solution.DialysateFlow = dialysateFlow
  2875. }
  2876. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2877. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2878. solution.DialysateTemperature = dialysateTemperature
  2879. }
  2880. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2881. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2882. solution.Conductivity = conductivity
  2883. }
  2884. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2885. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2886. solution.ReplacementTotal = replacementTotal
  2887. }
  2888. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2889. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2890. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2891. }
  2892. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2893. body_fluid := int64(dataBody["body_fluid"].(float64))
  2894. solution.BodyFluid = body_fluid
  2895. }
  2896. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2897. body_fluid_other := dataBody["body_fluid_other"].(string)
  2898. solution.BodyFluidOther = body_fluid_other
  2899. }
  2900. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2901. special_medicine := int64(dataBody["special_medicine"].(float64))
  2902. solution.SpecialMedicine = special_medicine
  2903. }
  2904. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2905. special_medicine_other := dataBody["special_medicine_other"].(string)
  2906. solution.SpecialMedicineOther = special_medicine_other
  2907. }
  2908. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2909. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2910. solution.DisplaceLiquiPart = displace_liqui_part
  2911. }
  2912. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2913. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2914. solution.DisplaceLiquiValue = displace_liqui_value
  2915. }
  2916. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2917. blood_access := int64(dataBody["blood_access"].(float64))
  2918. solution.BloodAccess = blood_access
  2919. }
  2920. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2921. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2922. solution.Ultrafiltration = ultrafiltration
  2923. }
  2924. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2925. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2926. solution.TargetKtv = target_ktv
  2927. }
  2928. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2929. remark := dataBody["remark"].(string)
  2930. solution.Remark = remark
  2931. }
  2932. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  2933. created_time := int64(dataBody["created_time"].(float64))
  2934. solution.CreatedTime = created_time
  2935. }
  2936. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  2937. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  2938. solution.DialysisDialyszers = dialysisDialyszers
  2939. }
  2940. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  2941. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  2942. solution.DialysisIrrigation = dialysisIrrigation
  2943. }
  2944. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  2945. plasmaSeparator := dataBody["plasma_separator"].(string)
  2946. solution.PlasmaSeparator = plasmaSeparator
  2947. }
  2948. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  2949. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  2950. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  2951. }
  2952. return
  2953. }
  2954. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2955. dataBody := make(map[string]interface{}, 0)
  2956. err := json.Unmarshal(data, &dataBody)
  2957. utils.InfoLog(string(data))
  2958. if err != nil {
  2959. utils.ErrorLog(err.Error())
  2960. code = enums.ErrorCodeParamWrong
  2961. return
  2962. }
  2963. if method == "create" {
  2964. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2965. utils.ErrorLog("parent_id")
  2966. code = enums.ErrorCodeParamWrong
  2967. return
  2968. }
  2969. parentID := int64(dataBody["parent_id"].(float64))
  2970. if parentID <= 0 {
  2971. utils.ErrorLog("parentID <= 0")
  2972. code = enums.ErrorCodeParamWrong
  2973. return
  2974. }
  2975. solution.ParentId = parentID
  2976. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2977. utils.ErrorLog("sub_name")
  2978. code = enums.ErrorCodeParamWrong
  2979. return
  2980. }
  2981. subName, _ := dataBody["sub_name"].(string)
  2982. if len(subName) == 0 {
  2983. utils.ErrorLog("len(sub_name) == 0")
  2984. code = enums.ErrorCodeParamWrong
  2985. return
  2986. }
  2987. solution.SubName = subName
  2988. }
  2989. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2990. utils.ErrorLog("initiate_mode")
  2991. code = enums.ErrorCodeParamWrong
  2992. return
  2993. }
  2994. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2995. if initiateMode != 1 && initiateMode != 2 {
  2996. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2997. code = enums.ErrorCodeParamWrong
  2998. return
  2999. }
  3000. solution.InitiateMode = initiateMode
  3001. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3002. utils.ErrorLog("doctor")
  3003. code = enums.ErrorCodeParamWrong
  3004. return
  3005. }
  3006. doctor := int64(dataBody["doctor"].(float64))
  3007. if doctor <= 0 {
  3008. utils.ErrorLog("doctor <= 0")
  3009. code = enums.ErrorCodeParamWrong
  3010. return
  3011. }
  3012. solution.Doctor = doctor
  3013. return
  3014. }
  3015. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  3016. patientBody := make(map[string]interface{}, 0)
  3017. err := json.Unmarshal(data, &patientBody)
  3018. if err != nil {
  3019. utils.ErrorLog(err.Error())
  3020. code = enums.ErrorCodeParamWrong
  3021. return
  3022. }
  3023. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  3024. formItem, _ := patientBody["formItem"].([]interface{})
  3025. if len(formItem) > 0 {
  3026. for _, item := range formItem {
  3027. items := item.(map[string]interface{})
  3028. project_name, _ := items["project_name"].(string)
  3029. fmt.Println(project_name)
  3030. range_type := int64(items["range_type"].(float64))
  3031. fmt.Println(range_type)
  3032. project_id := int64(items["project_id"].(float64))
  3033. fmt.Println(project_id)
  3034. item_id := int64(items["item_id"].(float64))
  3035. fmt.Println(item_id)
  3036. item, _ := items["item"].(string)
  3037. fmt.Println(items["item"].(string))
  3038. item_name, _ := items["item_name"].(string)
  3039. fmt.Println(item_name)
  3040. value, _ := items["value"].(string)
  3041. fmt.Println(items["value"].(string))
  3042. var form models.FormItem
  3043. form.ProjectName = project_name
  3044. form.RangeType = range_type
  3045. form.ProjectId = project_id
  3046. form.ItemId = item_id
  3047. form.Item = item
  3048. form.ItemName = item_name
  3049. form.Value = value
  3050. formItems = append(formItems, &form)
  3051. }
  3052. }
  3053. }
  3054. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  3055. utils.ErrorLog("avatar")
  3056. code = enums.ErrorCodeParamWrong
  3057. return
  3058. }
  3059. avatar, _ := patientBody["avatar"].(string)
  3060. if len(avatar) == 0 {
  3061. utils.ErrorLog("len(avatar) == 0")
  3062. code = enums.ErrorCodeParamWrong
  3063. return
  3064. }
  3065. patient.Avatar = avatar
  3066. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  3067. utils.ErrorLog("name")
  3068. code = enums.ErrorCodeParamWrong
  3069. return
  3070. }
  3071. name, _ := patientBody["name"].(string)
  3072. if len(name) == 0 {
  3073. utils.ErrorLog("len(name) == 0")
  3074. code = enums.ErrorCodeParamWrong
  3075. return
  3076. }
  3077. patient.Name = name
  3078. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  3079. alias := patientBody["alias"].(string)
  3080. patient.Alias = alias
  3081. }
  3082. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  3083. nation := patientBody["nation"].(string)
  3084. patient.Nation = nation
  3085. }
  3086. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  3087. native_place := patientBody["native_place"].(string)
  3088. patient.NativePlace = native_place
  3089. }
  3090. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  3091. utils.ErrorLog("idCardNo")
  3092. code = enums.ErrorCodeParamWrong
  3093. return
  3094. }
  3095. idCardNo, _ := patientBody["idCardNo"].(string)
  3096. if len(idCardNo) == 0 {
  3097. utils.ErrorLog("len(idCardNo) == 0")
  3098. code = enums.ErrorCodeParamWrong
  3099. return
  3100. }
  3101. patient.IdCardNo = idCardNo
  3102. patient.PatientType = 1
  3103. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  3104. utils.ErrorLog("dialysisNo")
  3105. code = enums.ErrorCodeParamWrong
  3106. return
  3107. }
  3108. dialysisNo, _ := patientBody["dialysisNo"].(string)
  3109. if len(dialysisNo) == 0 {
  3110. utils.ErrorLog("len(dialysisNo) == 0")
  3111. code = enums.ErrorCodeParamWrong
  3112. return
  3113. }
  3114. patient.DialysisNo = dialysisNo
  3115. // }
  3116. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  3117. utils.ErrorLog("lapseto")
  3118. code = enums.ErrorCodeParamWrong
  3119. return
  3120. }
  3121. lapseto := int64(patientBody["lapseto"].(float64))
  3122. if lapseto <= 0 {
  3123. utils.ErrorLog("lapseto == 0")
  3124. code = enums.ErrorCodeParamWrong
  3125. return
  3126. }
  3127. patient.Lapseto = lapseto
  3128. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  3129. utils.ErrorLog("gender")
  3130. code = enums.ErrorCodeParamWrong
  3131. return
  3132. }
  3133. gender := int64(patientBody["gender"].(float64))
  3134. if gender <= 0 {
  3135. utils.ErrorLog("gender <= 0")
  3136. code = enums.ErrorCodeParamWrong
  3137. return
  3138. }
  3139. patient.Gender = gender
  3140. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  3141. response_result := patientBody["response_result"].(string)
  3142. patient.ResponseResult = response_result
  3143. }
  3144. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  3145. utils.ErrorLog("age")
  3146. code = enums.ErrorCodeParamWrong
  3147. return
  3148. }
  3149. age := int64(patientBody["age"].(float64))
  3150. patient.Age = age
  3151. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  3152. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  3153. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  3154. patient.UserSysBeforeCount = count
  3155. }
  3156. timeLayout := "2006-01-02"
  3157. loc, _ := time.LoadLocation("Local")
  3158. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  3159. utils.ErrorLog("birth")
  3160. code = enums.ErrorCodeParamWrong
  3161. return
  3162. }
  3163. birth, _ := patientBody["birth"].(string)
  3164. if len(birth) == 0 {
  3165. utils.ErrorLog("len(birth) == 0")
  3166. code = enums.ErrorCodeParamWrong
  3167. return
  3168. }
  3169. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  3170. if err != nil {
  3171. utils.ErrorLog("birthTime")
  3172. code = enums.ErrorCodeParamWrong
  3173. return
  3174. }
  3175. patient.Birthday = birthTime.Unix()
  3176. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  3177. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  3178. patient.Height = height
  3179. }
  3180. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  3181. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3182. patient.MaritalStatus = maritalStatus
  3183. }
  3184. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3185. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3186. patient.Children = children
  3187. }
  3188. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3189. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3190. patient.AdmissionNumber = admissionNumber
  3191. }
  3192. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3193. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3194. patient.ReimbursementWayId = reimbursementWayID
  3195. }
  3196. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3197. healthCareNo := patientBody["healthCareNo"].(string)
  3198. patient.HealthCareNo = healthCareNo
  3199. }
  3200. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3201. utils.ErrorLog("phone")
  3202. code = enums.ErrorCodeParamWrong
  3203. return
  3204. }
  3205. phone := patientBody["phone"].(string)
  3206. if len(phone) == 0 {
  3207. utils.ErrorLog("len(phone) == 0")
  3208. code = enums.ErrorCodeParamWrong
  3209. return
  3210. }
  3211. if !utils.CheckMobile(phone) {
  3212. utils.ErrorLog("!phone")
  3213. code = enums.ErrorCodeMobileFormat
  3214. return
  3215. }
  3216. patient.Phone = phone
  3217. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3218. homeTelephone := patientBody["homeTelephone"].(string)
  3219. patient.HomeTelephone = homeTelephone
  3220. }
  3221. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3222. relativePhone := patientBody["relative_phone"].(string)
  3223. patient.RelativePhone = relativePhone
  3224. }
  3225. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3226. relativeRelations := patientBody["relative_relations"].(string)
  3227. patient.RelativeRelations = relativeRelations
  3228. }
  3229. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3230. homeAddress := patientBody["homeAddress"].(string)
  3231. patient.HomeAddress = homeAddress
  3232. }
  3233. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3234. work := patientBody["work"].(string)
  3235. patient.WorkUnit = work
  3236. }
  3237. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3238. unitAddress := patientBody["unit_address"].(string)
  3239. patient.UnitAddress = unitAddress
  3240. }
  3241. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3242. profession := int64(patientBody["profession"].(float64))
  3243. patient.Profession = profession
  3244. }
  3245. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3246. education := int64(patientBody["education"].(float64))
  3247. patient.EducationLevel = education
  3248. }
  3249. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3250. utils.ErrorLog("source")
  3251. code = enums.ErrorCodeParamWrong
  3252. return
  3253. }
  3254. source := int64(patientBody["source"].(float64))
  3255. if source <= 0 {
  3256. utils.ErrorLog("source <= 0")
  3257. code = enums.ErrorCodeParamWrong
  3258. return
  3259. }
  3260. patient.Source = source
  3261. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3262. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3263. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3264. }
  3265. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3266. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3267. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3268. if err == nil {
  3269. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3270. }
  3271. }
  3272. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3273. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3274. patient.FirstDialysisHospital = firstDialysisHospital
  3275. }
  3276. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3277. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3278. if len(thePredialysisCondition) > 0 {
  3279. conditions := make([]string, 0)
  3280. for _, item := range thePredialysisCondition {
  3281. if reflect.TypeOf(item).String() != "string" {
  3282. continue
  3283. }
  3284. condition := item.(string)
  3285. if len(condition) > 0 {
  3286. conditions = append(conditions, condition)
  3287. }
  3288. }
  3289. patient.PredialysisCondition = strings.Join(conditions, ",")
  3290. }
  3291. }
  3292. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3293. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3294. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3295. }
  3296. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3297. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3298. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3299. }
  3300. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3301. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3302. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3303. if err == nil {
  3304. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3305. }
  3306. }
  3307. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3308. partition := int64(patientBody["partition"].(float64))
  3309. patient.PartitionId = partition
  3310. }
  3311. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3312. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3313. patient.BedId = bed
  3314. }
  3315. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3316. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3317. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3318. if err == nil {
  3319. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3320. }
  3321. }
  3322. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3323. blood := int64(patientBody["blood"].(float64))
  3324. patient.BloodType = blood
  3325. }
  3326. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3327. rh := int64(patientBody["rh"].(float64))
  3328. patient.Rh = rh
  3329. }
  3330. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3331. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3332. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3333. if err == nil {
  3334. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3335. }
  3336. }
  3337. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3338. receivingDate := patientBody["receivingDate"].(string)
  3339. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3340. if err == nil {
  3341. patient.ReceivingDate = receivingDateTime.Unix()
  3342. }
  3343. }
  3344. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3345. induction := int64(patientBody["induction"].(float64))
  3346. patient.InductionPeriod = induction
  3347. }
  3348. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3349. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3350. patient.InitialDialysis = initial
  3351. }
  3352. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3353. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3354. patient.TotalDialysis = dialysisTotal
  3355. }
  3356. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3357. thisContagions, _ := patientBody["contagions"].([]interface{})
  3358. if len(thisContagions) > 0 {
  3359. for _, item := range thisContagions {
  3360. if reflect.TypeOf(item).String() != "float64" {
  3361. continue
  3362. }
  3363. contagion := int64(item.(float64))
  3364. if contagion > 0 {
  3365. contagions = append(contagions, contagion)
  3366. }
  3367. }
  3368. }
  3369. }
  3370. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3371. doctor := int64(patientBody["doctor"].(float64))
  3372. patient.AttendingDoctorId = doctor
  3373. }
  3374. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3375. nurse := int64(patientBody["nurse"].(float64))
  3376. patient.HeadNurseId = nurse
  3377. }
  3378. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3379. assessment := patientBody["assessment"].(string)
  3380. patient.Evaluate = assessment
  3381. }
  3382. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3383. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3384. if len(thisDiseases) > 0 {
  3385. for _, item := range thisDiseases {
  3386. if reflect.TypeOf(item).String() != "float64" {
  3387. continue
  3388. }
  3389. disease := int64(item.(float64))
  3390. if disease > 0 {
  3391. diseases = append(diseases, disease)
  3392. }
  3393. }
  3394. }
  3395. }
  3396. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3397. diagnose := patientBody["diagnose"].(string)
  3398. patient.Diagnose = diagnose
  3399. }
  3400. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3401. remark := patientBody["remark"].(string)
  3402. patient.Remark = remark
  3403. }
  3404. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3405. sch_remark := patientBody["sch_remark"].(string)
  3406. patient.SchRemark = sch_remark
  3407. }
  3408. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3409. patient_complains := patientBody["patient_complains"].(string)
  3410. patient.PatientComplains = patient_complains
  3411. }
  3412. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3413. present_history := patientBody["present_history"].(string)
  3414. patient.PresentHistory = present_history
  3415. }
  3416. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3417. past_history := patientBody["past_history"].(string)
  3418. patient.PastHistory = past_history
  3419. }
  3420. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3421. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3422. patient.Temperature = temperature
  3423. }
  3424. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3425. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3426. patient.Pulse = pulse
  3427. }
  3428. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3429. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3430. patient.Respiratory = respiratory
  3431. }
  3432. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3433. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3434. patient.SBP = sbp
  3435. }
  3436. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3437. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3438. patient.DBP = dbp
  3439. }
  3440. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3441. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3442. patient.DialysisAge = dialysis_age
  3443. }
  3444. fmt.Println(patient.DialysisAge)
  3445. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3446. first_treatment_date := patientBody["first_treatment_date"].(string)
  3447. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3448. if err == nil {
  3449. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3450. }
  3451. }
  3452. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3453. expense_kind := int64(patientBody["expense_kind"].(float64))
  3454. patient.ExpenseKind = expense_kind
  3455. }
  3456. fmt.Println(patient.ExpenseKind)
  3457. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3458. tell_phone := patientBody["tell_phone"].(string)
  3459. patient.TellPhone = tell_phone
  3460. }
  3461. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3462. contact_name := patientBody["contact_name"].(string)
  3463. patient.ContactName = contact_name
  3464. }
  3465. return
  3466. }
  3467. func (c *PatientApiController) GetPatientsByKeyWord() {
  3468. keyWord := c.GetString("keyword")
  3469. adminUserInfo := c.GetAdminUserInfo()
  3470. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3471. if err != nil {
  3472. utils.ErrorLog(err.Error())
  3473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3474. return
  3475. }
  3476. c.ServeSuccessJSON(map[string]interface{}{
  3477. "patient": patient,
  3478. })
  3479. }
  3480. func (c *PatientApiController) QueryPatientById() {
  3481. id, _ := c.GetInt64("id")
  3482. fmt.Println(id)
  3483. patientInfo := service.QueryPatientById(id)
  3484. c.ServeSuccessJSON(map[string]interface{}{
  3485. "patient": patientInfo,
  3486. })
  3487. return
  3488. }
  3489. func (c *PatientApiController) GetRemindPatientList() {
  3490. page, _ := c.GetInt64("page", 1)
  3491. limit, _ := c.GetInt64("limit", 10)
  3492. adminUserInfo := c.GetAdminUserInfo()
  3493. total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  3494. if err != nil {
  3495. utils.ErrorLog(err.Error())
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3497. return
  3498. }
  3499. c.ServeSuccessJSON(map[string]interface{}{
  3500. "total": total,
  3501. "patients": patients,
  3502. })
  3503. }
  3504. func (c *PatientApiController) PostIsOpenRemind() {
  3505. patient_id, _ := c.GetInt64("id", 1)
  3506. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  3507. adminUserInfo := c.GetAdminUserInfo()
  3508. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  3509. if err == nil {
  3510. c.ServeSuccessJSON(map[string]interface{}{
  3511. "msg": "成功",
  3512. "is_open_remind": is_open_remind,
  3513. })
  3514. } else if err != nil {
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3516. }
  3517. }
  3518. func (c *PatientApiController) GetPatientScheduleOne() {
  3519. id, _ := c.GetInt64("id")
  3520. //查询该病人是否当天是排班
  3521. nowDateTime := time.Now()
  3522. nowDate := nowDateTime.Format("2006-01-02")
  3523. nowDate += " 00:00:00"
  3524. timeLayout := "2006-01-02"
  3525. loc, _ := time.LoadLocation("Local")
  3526. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  3527. nowdate := theTime.Unix()
  3528. fmt.Println("nowdate", nowdate)
  3529. adminUser := c.GetAdminUserInfo()
  3530. orgId := adminUser.CurrentOrgId
  3531. fmt.Println("orgid", orgId)
  3532. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  3533. if err != nil {
  3534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3535. return
  3536. }
  3537. c.ServeSuccessJSON(map[string]interface{}{
  3538. "scheduls": scheduls,
  3539. })
  3540. }
  3541. func (c *PatientApiController) ExportPatients() {
  3542. dataBody := make(map[string]interface{}, 0)
  3543. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  3544. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  3545. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  3546. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3547. if err != nil {
  3548. utils.ErrorLog(err.Error())
  3549. return
  3550. }
  3551. utils.ErrorLog("%v", dataBody)
  3552. export_time := time.Now().Unix()
  3553. var patients []*models.Patients
  3554. var total_patients []interface{}
  3555. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  3556. tempPatients := dataBody["patients"].([]interface{})
  3557. total_patients = tempPatients
  3558. for index, patientMap := range tempPatients {
  3559. patientNameM := patientMap.(map[string]interface{})
  3560. var patient models.Patients
  3561. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  3562. utils.ErrorLog("name")
  3563. return
  3564. }
  3565. name, _ := patientNameM["name"].(string)
  3566. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3567. err_log := models.ExportErrLog{
  3568. LogType: 1,
  3569. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3570. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  3571. Status: 1,
  3572. CreateTime: time.Now().Unix(),
  3573. UpdateTime: time.Now().Unix(),
  3574. ExportTime: export_time,
  3575. }
  3576. service.CreateExportErrLog(&err_log)
  3577. continue
  3578. }
  3579. patient.Name = name
  3580. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  3581. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  3582. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  3583. err_log := models.ExportErrLog{
  3584. LogType: 1,
  3585. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3586. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  3587. Status: 1,
  3588. CreateTime: time.Now().Unix(),
  3589. UpdateTime: time.Now().Unix(),
  3590. ExportTime: export_time,
  3591. }
  3592. service.CreateExportErrLog(&err_log)
  3593. continue
  3594. } else {
  3595. patient.Gender = gender
  3596. }
  3597. }
  3598. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  3599. phone, _ := patientNameM["phone"].(string)
  3600. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  3601. if len(phone) == 0 {
  3602. err_log := models.ExportErrLog{
  3603. LogType: 1,
  3604. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3605. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  3606. Status: 1,
  3607. CreateTime: time.Now().Unix(),
  3608. UpdateTime: time.Now().Unix(),
  3609. ExportTime: export_time,
  3610. }
  3611. service.CreateExportErrLog(&err_log)
  3612. continue
  3613. } else {
  3614. err_log := models.ExportErrLog{
  3615. LogType: 1,
  3616. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3617. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  3618. Status: 1,
  3619. CreateTime: time.Now().Unix(),
  3620. UpdateTime: time.Now().Unix(),
  3621. ExportTime: export_time,
  3622. }
  3623. service.CreateExportErrLog(&err_log)
  3624. continue
  3625. }
  3626. } else {
  3627. //var tempPatient *models.Patients
  3628. //for _, item := range all_patient {
  3629. // if item.Phone == phone {
  3630. // tempPatient = item
  3631. // }
  3632. //}
  3633. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  3634. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  3635. if count >= 1 {
  3636. err_log := models.ExportErrLog{
  3637. LogType: 1,
  3638. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3639. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3640. Status: 1,
  3641. CreateTime: time.Now().Unix(),
  3642. UpdateTime: time.Now().Unix(),
  3643. ExportTime: export_time,
  3644. }
  3645. service.CreateExportErrLog(&err_log)
  3646. continue
  3647. }
  3648. patient.Phone = phone
  3649. }
  3650. }
  3651. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3652. id_card_no, _ := patientNameM["id_card_no"].(string)
  3653. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3654. if len(id_card_no) == 0 {
  3655. err_log := models.ExportErrLog{
  3656. LogType: 1,
  3657. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3658. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3659. Status: 1,
  3660. CreateTime: time.Now().Unix(),
  3661. UpdateTime: time.Now().Unix(),
  3662. ExportTime: export_time,
  3663. }
  3664. service.CreateExportErrLog(&err_log)
  3665. continue
  3666. } else {
  3667. err_log := models.ExportErrLog{
  3668. LogType: 1,
  3669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3671. Status: 1,
  3672. CreateTime: time.Now().Unix(),
  3673. UpdateTime: time.Now().Unix(),
  3674. ExportTime: export_time,
  3675. }
  3676. service.CreateExportErrLog(&err_log)
  3677. continue
  3678. }
  3679. } else {
  3680. //var tempPatient *models.Patients
  3681. //for _, item := range all_patient {
  3682. // if item.IdCardNo == id_card_no {
  3683. // tempPatient = item
  3684. // }
  3685. //}
  3686. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3687. if count >= 1 {
  3688. //if tempPatient != nil && tempPatient.ID > 0 {
  3689. err_log := models.ExportErrLog{
  3690. LogType: 1,
  3691. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3692. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3693. Status: 1,
  3694. CreateTime: time.Now().Unix(),
  3695. UpdateTime: time.Now().Unix(),
  3696. ExportTime: export_time,
  3697. }
  3698. service.CreateExportErrLog(&err_log)
  3699. continue
  3700. }
  3701. //}
  3702. patient.IdCardNo = id_card_no
  3703. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3704. if GetBirthDay(id_card_no) == nil {
  3705. patient.Birthday = 0
  3706. } else {
  3707. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3708. }
  3709. }
  3710. }
  3711. fmt.Println("111112222")
  3712. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3713. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3714. timeLayout := "2006/01/02"
  3715. loc, _ := time.LoadLocation("Local")
  3716. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3717. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3718. if len(first_treatment_date) == 0 {
  3719. err_log := models.ExportErrLog{
  3720. LogType: 1,
  3721. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3722. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3723. Status: 1,
  3724. CreateTime: time.Now().Unix(),
  3725. UpdateTime: time.Now().Unix(),
  3726. ExportTime: export_time,
  3727. }
  3728. service.CreateExportErrLog(&err_log)
  3729. continue
  3730. } else {
  3731. err_log := models.ExportErrLog{
  3732. LogType: 1,
  3733. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3734. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3735. Status: 1,
  3736. CreateTime: time.Now().Unix(),
  3737. UpdateTime: time.Now().Unix(),
  3738. ExportTime: export_time,
  3739. }
  3740. service.CreateExportErrLog(&err_log)
  3741. continue
  3742. }
  3743. } else {
  3744. if len(first_treatment_date) == 0 {
  3745. err_log := models.ExportErrLog{
  3746. LogType: 1,
  3747. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3748. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3749. Status: 1,
  3750. CreateTime: time.Now().Unix(),
  3751. UpdateTime: time.Now().Unix(),
  3752. ExportTime: export_time,
  3753. }
  3754. service.CreateExportErrLog(&err_log)
  3755. continue
  3756. } else {
  3757. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3758. err_log := models.ExportErrLog{
  3759. LogType: 1,
  3760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3761. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3762. Status: 1,
  3763. CreateTime: time.Now().Unix(),
  3764. UpdateTime: time.Now().Unix(),
  3765. ExportTime: export_time,
  3766. }
  3767. service.CreateExportErrLog(&err_log)
  3768. continue
  3769. } else {
  3770. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3771. }
  3772. }
  3773. }
  3774. }
  3775. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3776. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3777. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  3778. err_log := models.ExportErrLog{
  3779. LogType: 1,
  3780. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3781. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  3782. Status: 1,
  3783. CreateTime: time.Now().Unix(),
  3784. UpdateTime: time.Now().Unix(),
  3785. ExportTime: export_time,
  3786. }
  3787. service.CreateExportErrLog(&err_log)
  3788. continue
  3789. } else if source == 3 {
  3790. err_log := models.ExportErrLog{
  3791. LogType: 1,
  3792. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3793. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  3794. Status: 1,
  3795. CreateTime: time.Now().Unix(),
  3796. UpdateTime: time.Now().Unix(),
  3797. ExportTime: export_time,
  3798. }
  3799. service.CreateExportErrLog(&err_log)
  3800. continue
  3801. } else {
  3802. patient.Source = source
  3803. }
  3804. }
  3805. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  3806. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  3807. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  3808. err_log := models.ExportErrLog{
  3809. LogType: 1,
  3810. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3811. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  3812. Status: 1,
  3813. CreateTime: time.Now().Unix(),
  3814. UpdateTime: time.Now().Unix(),
  3815. ExportTime: export_time,
  3816. }
  3817. service.CreateExportErrLog(&err_log)
  3818. continue
  3819. } else if lapseto == 3 {
  3820. err_log := models.ExportErrLog{
  3821. LogType: 1,
  3822. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3823. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  3824. Status: 1,
  3825. CreateTime: time.Now().Unix(),
  3826. UpdateTime: time.Now().Unix(),
  3827. ExportTime: export_time,
  3828. }
  3829. service.CreateExportErrLog(&err_log)
  3830. continue
  3831. } else {
  3832. patient.Lapseto = lapseto
  3833. }
  3834. }
  3835. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  3836. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  3837. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  3838. err_log := models.ExportErrLog{
  3839. LogType: 1,
  3840. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3841. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  3842. Status: 1,
  3843. CreateTime: time.Now().Unix(),
  3844. UpdateTime: time.Now().Unix(),
  3845. ExportTime: export_time,
  3846. }
  3847. service.CreateExportErrLog(&err_log)
  3848. continue
  3849. } else if is_infectious == 3 {
  3850. err_log := models.ExportErrLog{
  3851. LogType: 1,
  3852. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3853. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  3854. Status: 1,
  3855. CreateTime: time.Now().Unix(),
  3856. UpdateTime: time.Now().Unix(),
  3857. ExportTime: export_time,
  3858. }
  3859. service.CreateExportErrLog(&err_log)
  3860. continue
  3861. } else {
  3862. patient.IsInfectious = is_infectious
  3863. }
  3864. }
  3865. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  3866. var contagions []int64
  3867. thisContagions, _ := patientNameM["contagions"].([]interface{})
  3868. if len(thisContagions) > 0 {
  3869. for _, item := range thisContagions {
  3870. if reflect.TypeOf(item).String() != "float64" {
  3871. continue
  3872. }
  3873. contagion := int64(item.(float64))
  3874. if contagion > 0 {
  3875. contagions = append(contagions, contagion)
  3876. }
  3877. }
  3878. }
  3879. patient.ContagionIds = contagions
  3880. }
  3881. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  3882. diagnose, _ := patientNameM["diagnose"].(string)
  3883. patient.Diagnose = diagnose
  3884. }
  3885. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  3886. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  3887. var tempPatient *models.Patients
  3888. for _, item := range all_patient {
  3889. if item.DialysisNo == dialysis_no {
  3890. tempPatient = item
  3891. }
  3892. }
  3893. if tempPatient != nil && tempPatient.ID > 0 {
  3894. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  3895. } else {
  3896. patient.DialysisNo = dialysis_no
  3897. }
  3898. }
  3899. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  3900. height, _ := patientNameM["height"].(string)
  3901. heights, _ := strconv.ParseFloat(height, 64)
  3902. patient.Height = int64(heights)
  3903. }
  3904. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  3905. home_address, _ := patientNameM["home_address"].(string)
  3906. patient.HomeAddress = home_address
  3907. }
  3908. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  3909. dry_weight, _ := patientNameM["dry_weight"].(string)
  3910. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  3911. patient.DryWeight = dry_weights
  3912. }
  3913. patient.CreatedTime = time.Now().Unix()
  3914. patient.UpdatedTime = time.Now().Unix()
  3915. patient.Status = 1
  3916. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  3917. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  3918. patient.IsExcelExport = 1
  3919. patient.PatientType = 1
  3920. patients = append(patients, &patient)
  3921. }
  3922. }
  3923. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3924. if len(patients) > 0 {
  3925. for _, item := range patients {
  3926. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  3927. }
  3928. log := models.ExportLog{
  3929. LogType: 1,
  3930. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3931. TotalNum: int64(len(total_patients)),
  3932. FailNum: int64(len(errLogs)),
  3933. SuccessNum: int64(len(patients)),
  3934. CreateTime: time.Now().Unix(),
  3935. UpdateTime: time.Now().Unix(),
  3936. ExportTime: export_time,
  3937. Status: 1,
  3938. }
  3939. service.CreateExportLog(&log)
  3940. c.ServeSuccessJSON(map[string]interface{}{
  3941. "msg": "导入成功",
  3942. "total_num": len(total_patients),
  3943. "success_num": len(patients),
  3944. "fail_num": int64(len(errLogs)),
  3945. })
  3946. } else {
  3947. log := models.ExportLog{
  3948. LogType: 1,
  3949. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3950. TotalNum: int64(len(total_patients)),
  3951. FailNum: int64(len(errLogs)),
  3952. SuccessNum: int64(len(patients)),
  3953. CreateTime: time.Now().Unix(),
  3954. UpdateTime: time.Now().Unix(),
  3955. ExportTime: export_time,
  3956. Status: 1,
  3957. }
  3958. service.CreateExportLog(&log)
  3959. c.ServeSuccessJSON(map[string]interface{}{
  3960. "msg": "导入成功",
  3961. "total_num": len(total_patients),
  3962. "success_num": len(patients),
  3963. "fail_num": int64(len(errLogs)),
  3964. })
  3965. }
  3966. }
  3967. func GetBirthDay(IDCardNo string) *time.Time {
  3968. dayStr := IDCardNo[6:14]
  3969. birthDay, err := time.Parse("20060102", dayStr)
  3970. if err != nil {
  3971. fmt.Println(err)
  3972. return nil
  3973. }
  3974. return &birthDay
  3975. }
  3976. func IsIdCard(id string) (res bool) {
  3977. id = strings.ToUpper(id)
  3978. if len(id) != 15 && len(id) != 18 {
  3979. fmt.Println("1111111")
  3980. return false
  3981. }
  3982. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  3983. if !r.MatchString(id) {
  3984. fmt.Println("222222")
  3985. return false
  3986. }
  3987. if len(id) == 15 {
  3988. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  3989. if tm2.Unix() == 0 {
  3990. fmt.Println("44444443333")
  3991. return false
  3992. }
  3993. return true
  3994. } else {
  3995. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  3996. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  3997. fmt.Println(tm2.Unix())
  3998. if tm2.Unix() == 0 {
  3999. fmt.Println("44445555555")
  4000. return false
  4001. }
  4002. //检验18位身份证的校验码是否正确。
  4003. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  4004. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  4005. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  4006. sign := 0
  4007. for k, v := range arr_int {
  4008. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  4009. sign += int_temp * v
  4010. }
  4011. n := sign % 11
  4012. val_num := arr_ch[n]
  4013. if val_num != string([]byte(id)[17:18]) {
  4014. fmt.Println("5556666666")
  4015. return false
  4016. }
  4017. return true
  4018. }
  4019. }
  4020. func (c *PatientApiController) SaveEditAdvices() {
  4021. adminInfo := c.GetAdminUserInfo()
  4022. orgid := adminInfo.CurrentOrgId
  4023. startTime := c.GetString("start_time")
  4024. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  4025. groupno, _ := c.GetInt64("groupno")
  4026. fmt.Println("组", groupno)
  4027. date, _ := c.GetInt64("date")
  4028. fmt.Println("date", date)
  4029. patient_id, _ := c.GetInt64("patient_id")
  4030. fmt.Println("paitent_id", patient_id)
  4031. advice := models.XtDoctorAdvice{
  4032. StartTime: theTime.Unix(),
  4033. }
  4034. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  4035. if err != nil {
  4036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4037. return
  4038. }
  4039. c.ServeSuccessJSON(map[string]interface{}{
  4040. "advice": advice,
  4041. })
  4042. }
  4043. func (c *PatientApiController) GetMaxDialysisNo() {
  4044. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  4045. c.ServeSuccessJSON(map[string]interface{}{
  4046. "dialysis_no": dialysisNo,
  4047. })
  4048. }
  4049. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  4050. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  4051. var tempPatient *models.Patients
  4052. for _, item := range patients {
  4053. if item.DialysisNo == dialysisNo2 {
  4054. tempPatient = item
  4055. }
  4056. }
  4057. if tempPatient == nil || tempPatient.ID == 0 {
  4058. return dialysisNo2
  4059. }
  4060. return GenerateDialysisNoTwo(patients)
  4061. }