patient_api_controller.go 171KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907
  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. OxygenUptake: solution.OxygenUptake,
  760. OxygenFlow: solution.OxygenFlow,
  761. OxygenTime: solution.OxygenTime,
  762. }
  763. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  764. if err != nil {
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  766. return
  767. }
  768. c.ServeSuccessJSON(map[string]interface{}{
  769. "msg": "ok",
  770. "solution": solution,
  771. })
  772. return
  773. }
  774. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  775. patient, _ := c.GetInt64("patient", 0)
  776. id, _ := c.GetInt64("id", 0)
  777. if id <= 0 || patient <= 0 {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminUserInfo := c.GetAdminUserInfo()
  782. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  783. if solution.ID == 0 || solution.PatientId != patient {
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  785. return
  786. }
  787. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  788. if code > 0 {
  789. c.ServeFailJSONWithSGJErrorCode(code)
  790. return
  791. }
  792. solution.UpdatedTime = time.Now().Unix()
  793. solution.AffirmState = 1
  794. err := service.UpdatePatientDialysisSolution(&solution)
  795. if err != nil {
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  797. return
  798. }
  799. c.ServeSuccessJSON(map[string]interface{}{
  800. "msg": "ok",
  801. "solution": solution,
  802. })
  803. return
  804. }
  805. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  806. id, _ := c.GetInt64("id", 0)
  807. page, _ := c.GetInt64("page", 0)
  808. limit, _ := c.GetInt64("limit", 0)
  809. if id <= 0 {
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "solutions": nil,
  812. })
  813. return
  814. }
  815. if page <= 0 {
  816. page = 1
  817. }
  818. if limit <= 0 {
  819. limit = 10
  820. }
  821. adminUserInfo := c.GetAdminUserInfo()
  822. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  823. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  824. c.ServeSuccessJSON(map[string]interface{}{
  825. "solutions": solutions,
  826. "total": total,
  827. "stockType": stockType,
  828. })
  829. return
  830. }
  831. func (c *PatientApiController) DeleteDialysisSolution() {
  832. id, _ := c.GetInt64("id", 0)
  833. if id <= 0 {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. adminUserInfo := c.GetAdminUserInfo()
  838. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  839. if solution.ID == 0 {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  841. return
  842. }
  843. if solution.UseState == 1 {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  845. return
  846. }
  847. solution.UpdatedTime = time.Now().Unix()
  848. solution.Status = 0
  849. err := service.DeleteSolution(&solution)
  850. if err != nil {
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  852. return
  853. }
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "msg": "ok",
  856. })
  857. return
  858. }
  859. //GetDryWeights 取患者干体重调整铺
  860. func (c *PatientApiController) GetDryWeights() {
  861. page, _ := c.GetInt64("page", 1)
  862. limit, _ := c.GetInt64("limit", 10)
  863. id, _ := c.GetInt64("id", 0)
  864. if id <= 0 {
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  866. return
  867. }
  868. adminUserInfo := c.GetAdminUserInfo()
  869. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  870. c.ServeSuccessJSON(map[string]interface{}{
  871. "weights": weights,
  872. "total": total,
  873. })
  874. return
  875. }
  876. func (c *PatientApiController) CreateDryWeights() {
  877. patient, _ := c.GetInt64("id", 0)
  878. if patient <= 0 {
  879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. adminUserInfo := c.GetAdminUserInfo()
  883. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  884. if patientInfo.ID == 0 {
  885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  886. return
  887. }
  888. var theWeight models.DryWeightAdjust
  889. dataBody := make(map[string]interface{}, 0)
  890. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  891. if err != nil {
  892. utils.ErrorLog(err.Error())
  893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  898. return
  899. }
  900. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  901. theWeight.Weight = weight
  902. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  903. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  904. // return
  905. // }
  906. // doctor := int64(dataBody["doctor"].(float64))
  907. // theWeight.Doctor = doctor
  908. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  909. remark, _ := dataBody["remark"].(string)
  910. theWeight.Remark = remark
  911. }
  912. theWeight.CreatedTime = time.Now().Unix()
  913. theWeight.UpdatedTime = time.Now().Unix()
  914. theWeight.Status = 1
  915. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  916. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  917. theWeight.PatientId = patient
  918. theWeight.Doctor = adminUserInfo.AdminUser.Id
  919. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  920. if old.ID > 0 {
  921. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  922. }
  923. err = service.CreateDryWeightAdjust(&theWeight)
  924. if err != nil {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  926. return
  927. }
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "msg": "ok",
  930. "weight": theWeight,
  931. })
  932. return
  933. }
  934. func (c *PatientApiController) CreateGroupAdvice() {
  935. patient, _ := c.GetInt64("id", 0)
  936. groupNo, _ := c.GetInt64("groupno", 0)
  937. if patient <= 0 {
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  939. return
  940. }
  941. adminUserInfo := c.GetAdminUserInfo()
  942. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  943. if patientInfo.ID == 0 {
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  945. return
  946. }
  947. dataBody := make(map[string]interface{}, 0)
  948. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  949. if err != nil {
  950. utils.ErrorLog(err.Error())
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. utils.ErrorLog("%v", dataBody)
  955. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  956. if appRole.UserType == 3 {
  957. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  958. if getPermissionErr != nil {
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  960. return
  961. } else if headNursePermission == nil {
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  963. return
  964. }
  965. }
  966. timeLayout := "2006-01-02"
  967. loc, _ := time.LoadLocation("Local")
  968. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  969. utils.ErrorLog("advice_type")
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. adviceType := int64(dataBody["advice_type"].(float64))
  974. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  975. utils.ErrorLog("advice_type != 1&&2")
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  980. utils.ErrorLog("advice_date")
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  982. return
  983. }
  984. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  985. utils.ErrorLog("start_time")
  986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  987. return
  988. }
  989. startTime2, _ := dataBody["start_time"].(string)
  990. time_arr := strings.Split(startTime2, " ")
  991. if len(time_arr) > 0 {
  992. startTime2 = time_arr[0]
  993. }
  994. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  995. utils.ErrorLog("advice_date")
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  997. return
  998. }
  999. adviceDate := startTime2
  1000. if len(adviceDate) == 0 {
  1001. utils.ErrorLog("len(adviceDate) == 0")
  1002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1003. return
  1004. }
  1005. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1006. if err != nil {
  1007. utils.ErrorLog(err.Error())
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. AdviceDate := theTime.Unix()
  1012. RecordDate := theTime.Unix()
  1013. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1014. utils.ErrorLog("start_time")
  1015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1016. return
  1017. }
  1018. startTime, _ := dataBody["start_time"].(string)
  1019. if len(startTime) == 0 {
  1020. utils.ErrorLog("len(start_time) == 0")
  1021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1022. return
  1023. }
  1024. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1025. if err != nil {
  1026. utils.ErrorLog(err.Error())
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1028. return
  1029. }
  1030. StartTime := theTime.Unix()
  1031. Remark := ""
  1032. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1033. remark, _ := dataBody["remark"].(string)
  1034. Remark = remark
  1035. }
  1036. var advices []*models.GroupAdvice
  1037. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1038. utils.ErrorLog("adviceNames")
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1040. return
  1041. }
  1042. adviceNames := dataBody["adviceNames"].([]interface{})
  1043. for _, adviceNameMap := range adviceNames {
  1044. adviceNameM := adviceNameMap.(map[string]interface{})
  1045. var advice models.GroupAdvice
  1046. advice.Remark = Remark
  1047. advice.AdviceType = adviceType
  1048. advice.StartTime = StartTime
  1049. advice.AdviceDate = AdviceDate
  1050. advice.RecordDate = RecordDate
  1051. advice.Status = 1
  1052. advice.CreatedTime = time.Now().Unix()
  1053. advice.UpdatedTime = time.Now().Unix()
  1054. advice.StopState = 2
  1055. advice.ExecutionState = 2
  1056. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1057. advice.PatientId = patientInfo.ID
  1058. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1059. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1060. utils.ErrorLog("advice_name")
  1061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1062. return
  1063. }
  1064. adviceName, _ := adviceNameM["advice_name"].(string)
  1065. if len(adviceName) == 0 {
  1066. utils.ErrorLog("len(advice_name) == 0")
  1067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1068. return
  1069. }
  1070. advice.AdviceName = adviceName
  1071. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1072. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1073. advice.DrugSpec = drugSpec
  1074. }
  1075. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1076. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1077. advice.AdviceDesc = adviceDesc
  1078. }
  1079. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1080. template_id, _ := adviceNameM["template_id"].(string)
  1081. advice.TemplateId = template_id
  1082. }
  1083. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1084. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1085. advice.DrugSpecUnit = drugSpecUnit
  1086. }
  1087. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1088. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1089. advice.SingleDose = singleDose
  1090. }
  1091. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1092. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1093. advice.SingleDoseUnit = singleDoseUnit
  1094. }
  1095. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1096. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1097. advice.PrescribingNumber = prescribingNumber
  1098. }
  1099. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1100. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1101. advice.PrescribingNumberUnit = prescribingNumberUnit
  1102. }
  1103. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1104. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1105. advice.DeliveryWay = deliveryWay
  1106. }
  1107. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1108. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1109. advice.ExecutionFrequency = executionFrequency
  1110. }
  1111. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1112. way := int64(adviceNameM["way"].(float64))
  1113. advice.Way = way
  1114. }
  1115. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1116. drug_id := int64(adviceNameM["drug_id"].(float64))
  1117. advice.DrugId = drug_id
  1118. }
  1119. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1120. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1121. advice.DrugNameId = drug_name_id
  1122. }
  1123. if adviceType == 1 {
  1124. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1125. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1126. advice.FrequencyType = frequency_type
  1127. }
  1128. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1129. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1130. advice.DayCount = day_count
  1131. }
  1132. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1133. week_day, _ := adviceNameM["week_days"].(string)
  1134. advice.WeekDay = week_day
  1135. }
  1136. }
  1137. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1138. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1139. advice.ExecutionFrequency = executionFrequency
  1140. }
  1141. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1142. children := adviceNameM["children"].([]interface{})
  1143. if len(children) > 0 {
  1144. for _, childrenMap := range children {
  1145. childMap := childrenMap.(map[string]interface{})
  1146. var child models.GroupAdvice
  1147. child.Remark = Remark
  1148. child.AdviceType = adviceType
  1149. child.StartTime = StartTime
  1150. child.AdviceDate = AdviceDate
  1151. child.RecordDate = RecordDate
  1152. child.Status = 1
  1153. child.CreatedTime = time.Now().Unix()
  1154. child.UpdatedTime = time.Now().Unix()
  1155. child.StopState = 2
  1156. child.ExecutionState = 2
  1157. child.UserOrgId = adminUserInfo.CurrentOrgId
  1158. child.PatientId = patientInfo.ID
  1159. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1160. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1161. utils.ErrorLog("child advice_name")
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1163. return
  1164. }
  1165. childAdviceName, _ := childMap["advice_name"].(string)
  1166. if len(childAdviceName) == 0 {
  1167. utils.ErrorLog("len(child advice_name) == 0")
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1169. return
  1170. }
  1171. child.AdviceName = childAdviceName
  1172. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1173. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1174. child.AdviceDesc = childAdviceDesc
  1175. }
  1176. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1177. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1178. child.DrugSpec = childDrugSpec
  1179. }
  1180. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1181. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1182. child.DrugSpecUnit = childDrugSpecUnit
  1183. }
  1184. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1185. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1186. child.SingleDose = childSingleDose
  1187. }
  1188. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1189. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1190. child.SingleDoseUnit = childSingleDoseUnit
  1191. }
  1192. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1193. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1194. child.PrescribingNumber = childPrescribingNumber
  1195. }
  1196. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1197. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1198. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1199. }
  1200. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1201. drug_id := int64(childMap["drug_id"].(float64))
  1202. child.DrugId = drug_id
  1203. }
  1204. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1205. way := int64(childMap["way"].(float64))
  1206. child.Way = way
  1207. }
  1208. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1209. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1210. child.DrugNameId = drug_name_id
  1211. }
  1212. child.DeliveryWay = advice.DeliveryWay
  1213. child.ExecutionFrequency = advice.ExecutionFrequency
  1214. advice.Children = append(advice.Children, &child)
  1215. }
  1216. }
  1217. }
  1218. advices = append(advices, &advice)
  1219. }
  1220. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1221. if err != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1223. return
  1224. }
  1225. c.ServeSuccessJSON(map[string]interface{}{
  1226. "msg": "ok",
  1227. "advices": list,
  1228. })
  1229. return
  1230. }
  1231. func (c *PatientApiController) CreateDoctorAdvice() {
  1232. patient, _ := c.GetInt64("id", 0)
  1233. if patient <= 0 {
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1235. return
  1236. }
  1237. adminUserInfo := c.GetAdminUserInfo()
  1238. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1239. if patientInfo.ID == 0 {
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1241. return
  1242. }
  1243. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1244. if appRole.UserType == 3 {
  1245. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1246. if getPermissionErr != nil {
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1248. return
  1249. } else if headNursePermission == nil {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1251. return
  1252. }
  1253. }
  1254. var advice models.DoctorAdvice
  1255. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1256. if code > 0 {
  1257. c.ServeFailJSONWithSGJErrorCode(code)
  1258. return
  1259. }
  1260. if advice.ParentId > 0 {
  1261. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1262. if old.ID == 0 || old.PatientId != patient {
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1264. return
  1265. }
  1266. if old.StopState == 1 || old.ExecutionState == 1 {
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1268. return
  1269. }
  1270. if old.ParentId > 0 {
  1271. advice.ParentId = old.ParentId
  1272. }
  1273. advice.StartTime = old.StartTime
  1274. advice.AdviceDoctor = old.AdviceDoctor
  1275. advice.DeliveryWay = old.DeliveryWay
  1276. advice.ExecutionFrequency = old.ExecutionFrequency
  1277. advice.GroupNo = old.GroupNo
  1278. }
  1279. advice.Status = 1
  1280. advice.CreatedTime = time.Now().Unix()
  1281. advice.UpdatedTime = time.Now().Unix()
  1282. advice.StopState = 2
  1283. advice.ExecutionState = 2
  1284. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1285. advice.PatientId = patient
  1286. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1287. err := service.CreateDoctorAdvice(&advice)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1290. return
  1291. }
  1292. c.ServeSuccessJSON(map[string]interface{}{
  1293. "msg": "ok",
  1294. "advice": advice,
  1295. })
  1296. return
  1297. }
  1298. func (c *PatientApiController) ExecGroupAdvice() {
  1299. groupNo, _ := c.GetInt64("groupno", 0)
  1300. executionTime := c.GetString("execution_time")
  1301. if groupNo <= 0 {
  1302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1303. return
  1304. }
  1305. if len(executionTime) <= 0 {
  1306. utils.ErrorLog("execution_time")
  1307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1308. return
  1309. }
  1310. adminUserInfo := c.GetAdminUserInfo()
  1311. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1312. if advice.ID == 0 {
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1314. return
  1315. }
  1316. if advice.ExecutionState == 1 {
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1318. return
  1319. }
  1320. executionStaff := adminUserInfo.AdminUser.Id
  1321. // checker := adminUserInfo.AdminUser.Id
  1322. timeLayout := "2006-01-02 15:04:05"
  1323. loc, _ := time.LoadLocation("Local")
  1324. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1325. if err != nil {
  1326. utils.ErrorLog(err.Error())
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1328. return
  1329. }
  1330. if advice.StartTime > theTime.Unix() {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1332. return
  1333. }
  1334. exceAdvice := models.DoctorAdvice{
  1335. ExecutionStaff: executionStaff,
  1336. ExecutionTime: theTime.Unix(),
  1337. // Checker: checker,
  1338. UpdatedTime: time.Now().Unix(),
  1339. }
  1340. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1341. if err != nil {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1343. return
  1344. }
  1345. advice.ExecutionStaff = executionStaff
  1346. advice.ExecutionTime = theTime.Unix()
  1347. // advice.Checker = checker
  1348. c.ServeSuccessJSON(map[string]interface{}{
  1349. "msg": "ok",
  1350. "advice": advice,
  1351. })
  1352. return
  1353. }
  1354. func (c *PatientApiController) ExecDoctorAdvice() {
  1355. fmt.Println("hhhhhhhhhhhhhhh9999999999")
  1356. origin, _ := c.GetInt64("origin", 0)
  1357. patient, _ := c.GetInt64("patient", 0)
  1358. id, _ := c.GetInt64("id", 0)
  1359. executionTime := c.GetString("execution_time")
  1360. if origin != 2 {
  1361. if id <= 0 || patient <= 0 {
  1362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1363. return
  1364. }
  1365. if len(executionTime) <= 0 {
  1366. utils.ErrorLog("execution_time")
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1368. return
  1369. }
  1370. adminUserInfo := c.GetAdminUserInfo()
  1371. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1372. if advice.ID == 0 || advice.PatientId != patient {
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1374. return
  1375. }
  1376. //医嘱已执行
  1377. if advice.ExecutionState == 1 {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1379. return
  1380. }
  1381. executionStaff := adminUserInfo.AdminUser.Id
  1382. // checker := adminUserInfo.AdminUser.Id
  1383. timeLayout := "2006-01-02 15:04:05"
  1384. loc, _ := time.LoadLocation("Local")
  1385. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1386. if err != nil {
  1387. utils.ErrorLog(err.Error())
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. if advice.StartTime > theTime.Unix() {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1393. return
  1394. }
  1395. exceAdvice := models.DoctorAdvice{
  1396. ExecutionStaff: executionStaff,
  1397. ExecutionTime: theTime.Unix(),
  1398. // Checker: checker,
  1399. UpdatedTime: time.Now().Unix(),
  1400. }
  1401. if advice.ParentId > 0 {
  1402. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1403. } else {
  1404. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1405. }
  1406. if err != nil {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1408. return
  1409. }
  1410. advice.ExecutionStaff = executionStaff
  1411. advice.ExecutionTime = theTime.Unix()
  1412. // advice.Checker = checker
  1413. //处理出库相关逻辑
  1414. //1.判断是否启用药品管理和自备药出库功能
  1415. //药品管理信息
  1416. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1417. //自备药信息
  1418. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  1419. fmt.Println("9999999999999999999999999", drugStockConfig.IsOpen)
  1420. if drugStockConfig.IsOpen == 1 {
  1421. //查询已经执行的医嘱
  1422. //advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1423. //for _, item := range advices {
  1424. //
  1425. // //调用药品出库接口
  1426. // //service.DrugsDelivery(item.UserOrgId, item)
  1427. //
  1428. // //if item.Way == 1 {
  1429. // // out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
  1430. // // if err == gorm.ErrRecordNotFound {
  1431. // // //没有记录,则创建出库单
  1432. // // timeStr := time.Now().Format("2006-01-02")
  1433. // // timeArr := strings.Split(timeStr, "-")
  1434. // // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1435. // // total = total + 1
  1436. // // warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1437. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1438. // // number = number + total
  1439. // // warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1440. // // creater := adminUserInfo.AdminUser.Id
  1441. // // warehouseOut := models.DrugWarehouseOut{
  1442. // // WarehouseOutOrderNumber: warehousing_out_order,
  1443. // // OperationTime: time.Now().Unix(),
  1444. // // OrgId: adminUserInfo.CurrentOrgId,
  1445. // // Creater: creater,
  1446. // // Ctime: time.Now().Unix(),
  1447. // // Status: 1,
  1448. // // WarehouseOutTime: item.RecordDate,
  1449. // // Dealer: 0,
  1450. // // Manufacturer: 0,
  1451. // // Type: 1,
  1452. // // IsSys: 1,
  1453. // // }
  1454. // //
  1455. // // err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  1456. // // if err != nil {
  1457. // // utils.TraceLog("创建出库单失败 err = %v", err)
  1458. // // } else {
  1459. // // if item.Way == 1 {
  1460. // // if item.PrescribingNumber > 0 {
  1461. // // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1462. // // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1463. // // WarehouseOutId: warehouseOut.ID,
  1464. // // Status: 1,
  1465. // // Ctime: time.Now().Unix(),
  1466. // // Remark: "",
  1467. // // OrgId: adminUserInfo.CurrentOrgId,
  1468. // // Type: 1,
  1469. // // Manufacturer: 0,
  1470. // // Dealer: 0,
  1471. // // IsSys: 1,
  1472. // // SysRecordTime: item.RecordDate,
  1473. // // DrugId: item.DrugId,
  1474. // // }
  1475. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1476. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1477. // // warehouseOutInfo.Count = count
  1478. // // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1479. // // warehouseOutInfo.Price = stockInInfo.Price
  1480. // // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1481. // // if err == nil {
  1482. // // details := &models.DrugAutomaticReduceDetail{
  1483. // // WarehouseOutId: warehouseOutInfo.ID,
  1484. // // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1485. // // PatientId: item.PatientId,
  1486. // // Ctime: time.Now().Unix(),
  1487. // // Mtime: time.Now().Unix(),
  1488. // // Status: 1,
  1489. // // RecordTime: item.RecordDate,
  1490. // // OrgId: adminUserInfo.CurrentOrgId,
  1491. // // DrugId: item.DrugId,
  1492. // // Count: count,
  1493. // // }
  1494. // // service.AddSigleDrugAutoReduceRecordInfo(details)
  1495. // // if err != nil {
  1496. // // utils.TraceLog("创建出库单失败 err = %v", err)
  1497. // // } else {
  1498. // // if item.Way == 1 {
  1499. // // if item.PrescribingNumber > 0 {
  1500. // // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1501. // // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1502. // // WarehouseOutId: warehouseOut.ID,
  1503. // // Status: 1,
  1504. // // Ctime: time.Now().Unix(),
  1505. // // Remark: "",
  1506. // // OrgId: adminUserInfo.CurrentOrgId,
  1507. // // Type: 1,
  1508. // // Manufacturer: 0,
  1509. // // Dealer: 0,
  1510. // // IsSys: 1,
  1511. // // SysRecordTime: item.RecordDate,
  1512. // // DrugId: item.DrugId,
  1513. // // }
  1514. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1515. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1516. // // warehouseOutInfo.Count = count
  1517. // // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1518. // // warehouseOutInfo.Price = stockInInfo.Price
  1519. // // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1520. // // if err == nil {
  1521. // // details := &models.DrugAutomaticReduceDetail{
  1522. // // WarehouseOutId: warehouseOutInfo.ID,
  1523. // // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1524. // // PatientId: item.PatientId,
  1525. // // Ctime: time.Now().Unix(),
  1526. // // Mtime: time.Now().Unix(),
  1527. // // Status: 1,
  1528. // // RecordTime: item.RecordDate,
  1529. // // OrgId: adminUserInfo.CurrentOrgId,
  1530. // // DrugId: item.DrugId,
  1531. // // Count: count,
  1532. // // }
  1533. // // service.AddSigleDrugAutoReduceRecordInfo(details)
  1534. // // }
  1535. // // }
  1536. // // }
  1537. // // }
  1538. // //
  1539. // // }
  1540. // // }
  1541. // // }
  1542. // // }
  1543. // // } else if err == nil {
  1544. // // if item.Way == 1 {
  1545. // // outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  1546. // // if err == gorm.ErrRecordNotFound {
  1547. // // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1548. // // WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1549. // // WarehouseOutId: out.ID,
  1550. // // Status: 1,
  1551. // // Ctime: time.Now().Unix(),
  1552. // // Remark: "",
  1553. // // OrgId: adminUserInfo.CurrentOrgId,
  1554. // // Type: 1,
  1555. // // Manufacturer: 0,
  1556. // // Dealer: 0,
  1557. // // IsSys: 1,
  1558. // // SysRecordTime: item.RecordDate,
  1559. // // }
  1560. // //
  1561. // // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1562. // // warehouseOutInfo.Price = stockInInfo.Price
  1563. // // warehouseOutInfo.DrugId = item.DrugId
  1564. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1565. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1566. // // warehouseOutInfo.Count = count
  1567. // // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1568. // // if err == nil {
  1569. // // details := &models.DrugAutomaticReduceDetail{
  1570. // // WarehouseOutId: warehouseOutInfo.ID,
  1571. // // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1572. // // PatientId: item.PatientId,
  1573. // // Ctime: time.Now().Unix(),
  1574. // // Mtime: time.Now().Unix(),
  1575. // // Status: 1,
  1576. // // RecordTime: item.RecordDate,
  1577. // // OrgId: adminUserInfo.CurrentOrgId,
  1578. // // DrugId: item.DrugId,
  1579. // // Count: count,
  1580. // // }
  1581. // // service.AddSigleDrugAutoReduceRecordInfo(details)
  1582. // // }
  1583. // //
  1584. // // } else if err == nil { //记录存在,则将增加数量
  1585. // // if outInfo.ID > 0 {
  1586. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1587. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1588. // // service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
  1589. // // }
  1590. // //
  1591. // // count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
  1592. // // if count == 0 {
  1593. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1594. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1595. // // details := &models.DrugAutomaticReduceDetail{
  1596. // // WarehouseOutId: outInfo.ID,
  1597. // // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1598. // // PatientId: item.PatientId,
  1599. // // Ctime: time.Now().Unix(),
  1600. // // Mtime: time.Now().Unix(),
  1601. // // Status: 1,
  1602. // // RecordTime: item.RecordDate,
  1603. // // OrgId: adminUserInfo.CurrentOrgId,
  1604. // // DrugId: item.DrugId,
  1605. // // Count: count,
  1606. // // }
  1607. // // service.AddSigleDrugAutoReduceRecordInfo(details)
  1608. // // } else if count == 1 {
  1609. // // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1610. // // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1611. // // service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
  1612. // // }
  1613. // //
  1614. // // }
  1615. // // }
  1616. // // }
  1617. // //}
  1618. //}
  1619. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1620. for _, item := range advices {
  1621. fmt.Println("imte00000000000000", item.PrescribingNumber)
  1622. //调用药品出库接口
  1623. service.DrugsDelivery(item.UserOrgId, item)
  1624. //if item.Way == 1 {
  1625. // out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
  1626. // if err == gorm.ErrRecordNotFound {
  1627. // //没有记录,则创建出库单
  1628. // timeStr := time.Now().Format("2006-01-02")
  1629. // timeArr := strings.Split(timeStr, "-")
  1630. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1631. // total = total + 1
  1632. // warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1633. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1634. // number = number + total
  1635. // warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1636. // creater := adminUserInfo.AdminUser.Id
  1637. // warehouseOut := models.DrugWarehouseOut{
  1638. // WarehouseOutOrderNumber: warehousing_out_order,
  1639. // OperationTime: time.Now().Unix(),
  1640. // OrgId: adminUserInfo.CurrentOrgId,
  1641. // Creater: creater,
  1642. // Ctime: time.Now().Unix(),
  1643. // Status: 1,
  1644. // WarehouseOutTime: item.RecordDate,
  1645. // Dealer: 0,
  1646. // Manufacturer: 0,
  1647. // Type: 1,
  1648. // IsSys: 1,
  1649. // }
  1650. //
  1651. // err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  1652. // if err != nil {
  1653. // utils.TraceLog("创建出库单失败 err = %v", err)
  1654. // } else {
  1655. // if item.Way == 1 {
  1656. // if item.PrescribingNumber > 0 {
  1657. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1658. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1659. // WarehouseOutId: warehouseOut.ID,
  1660. // Status: 1,
  1661. // Ctime: time.Now().Unix(),
  1662. // Remark: "",
  1663. // OrgId: adminUserInfo.CurrentOrgId,
  1664. // Type: 1,
  1665. // Manufacturer: 0,
  1666. // Dealer: 0,
  1667. // IsSys: 1,
  1668. // SysRecordTime: item.RecordDate,
  1669. // DrugId: item.DrugId,
  1670. // }
  1671. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1672. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1673. // warehouseOutInfo.Count = count
  1674. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1675. // warehouseOutInfo.Price = stockInInfo.Price
  1676. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1677. // if err == nil {
  1678. // details := &models.DrugAutomaticReduceDetail{
  1679. // WarehouseOutId: warehouseOutInfo.ID,
  1680. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1681. // PatientId: item.PatientId,
  1682. // Ctime: time.Now().Unix(),
  1683. // Mtime: time.Now().Unix(),
  1684. // Status: 1,
  1685. // RecordTime: item.RecordDate,
  1686. // OrgId: adminUserInfo.CurrentOrgId,
  1687. // DrugId: item.DrugId,
  1688. // Count: count,
  1689. // }
  1690. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1691. // if err != nil {
  1692. // utils.TraceLog("创建出库单失败 err = %v", err)
  1693. // } else {
  1694. // if item.Way == 1 {
  1695. // if item.PrescribingNumber > 0 {
  1696. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1697. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1698. // WarehouseOutId: warehouseOut.ID,
  1699. // Status: 1,
  1700. // Ctime: time.Now().Unix(),
  1701. // Remark: "",
  1702. // OrgId: adminUserInfo.CurrentOrgId,
  1703. // Type: 1,
  1704. // Manufacturer: 0,
  1705. // Dealer: 0,
  1706. // IsSys: 1,
  1707. // SysRecordTime: item.RecordDate,
  1708. // DrugId: item.DrugId,
  1709. // }
  1710. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1711. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1712. // warehouseOutInfo.Count = count
  1713. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1714. // warehouseOutInfo.Price = stockInInfo.Price
  1715. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1716. // if err == nil {
  1717. // details := &models.DrugAutomaticReduceDetail{
  1718. // WarehouseOutId: warehouseOutInfo.ID,
  1719. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1720. // PatientId: item.PatientId,
  1721. // Ctime: time.Now().Unix(),
  1722. // Mtime: time.Now().Unix(),
  1723. // Status: 1,
  1724. // RecordTime: item.RecordDate,
  1725. // OrgId: adminUserInfo.CurrentOrgId,
  1726. // DrugId: item.DrugId,
  1727. // Count: count,
  1728. // }
  1729. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1730. // }
  1731. // }
  1732. // }
  1733. // }
  1734. //
  1735. // }
  1736. // }
  1737. // }
  1738. // }
  1739. // } else if err == nil {
  1740. // if item.Way == 1 {
  1741. // outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  1742. // if err == gorm.ErrRecordNotFound {
  1743. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1744. // WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1745. // WarehouseOutId: out.ID,
  1746. // Status: 1,
  1747. // Ctime: time.Now().Unix(),
  1748. // Remark: "",
  1749. // OrgId: adminUserInfo.CurrentOrgId,
  1750. // Type: 1,
  1751. // Manufacturer: 0,
  1752. // Dealer: 0,
  1753. // IsSys: 1,
  1754. // SysRecordTime: item.RecordDate,
  1755. // }
  1756. //
  1757. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1758. // warehouseOutInfo.Price = stockInInfo.Price
  1759. // warehouseOutInfo.DrugId = item.DrugId
  1760. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1761. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1762. // warehouseOutInfo.Count = count
  1763. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1764. // if err == nil {
  1765. // details := &models.DrugAutomaticReduceDetail{
  1766. // WarehouseOutId: warehouseOutInfo.ID,
  1767. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1768. // PatientId: item.PatientId,
  1769. // Ctime: time.Now().Unix(),
  1770. // Mtime: time.Now().Unix(),
  1771. // Status: 1,
  1772. // RecordTime: item.RecordDate,
  1773. // OrgId: adminUserInfo.CurrentOrgId,
  1774. // DrugId: item.DrugId,
  1775. // Count: count,
  1776. // }
  1777. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1778. // }
  1779. //
  1780. // } else if err == nil { //记录存在,则将增加数量
  1781. // if outInfo.ID > 0 {
  1782. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1783. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1784. // service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
  1785. // }
  1786. //
  1787. // count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
  1788. // if count == 0 {
  1789. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1790. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1791. // details := &models.DrugAutomaticReduceDetail{
  1792. // WarehouseOutId: outInfo.ID,
  1793. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  1794. // PatientId: item.PatientId,
  1795. // Ctime: time.Now().Unix(),
  1796. // Mtime: time.Now().Unix(),
  1797. // Status: 1,
  1798. // RecordTime: item.RecordDate,
  1799. // OrgId: adminUserInfo.CurrentOrgId,
  1800. // DrugId: item.DrugId,
  1801. // Count: count,
  1802. // }
  1803. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1804. // } else if count == 1 {
  1805. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1806. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1807. // service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
  1808. // }
  1809. //
  1810. // }
  1811. // }
  1812. // }
  1813. //}
  1814. }
  1815. }
  1816. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1817. for _, item := range advices {
  1818. if item.Way == 2 {
  1819. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1820. //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1821. if item.ExecutionState == 1 {
  1822. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1823. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1824. timeStr := time.Now().Format("2006-01-02")
  1825. timeArr := strings.Split(timeStr, "-")
  1826. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1827. total = total + 1
  1828. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1829. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1830. number = number + total
  1831. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1832. //插入自备药出库单
  1833. outStock := models.XtSelfOutStock{
  1834. DrugName: item.AdviceName,
  1835. DrugNameId: item.DrugId,
  1836. DrugSpec: item.AdviceDesc,
  1837. OutstoreNumber: count,
  1838. AdminUserId: adminUserInfo.AdminUser.Id,
  1839. StorckTime: item.RecordDate,
  1840. UserOrgId: adminUserInfo.CurrentOrgId,
  1841. CreatedTime: time.Now().Unix(),
  1842. Status: 1,
  1843. PatientId: item.PatientId,
  1844. ExitMode: 2,
  1845. MedicId: item.DrugId,
  1846. StockOutNumber: warehousing_out_order,
  1847. }
  1848. service.CreateOutStock(&outStock)
  1849. }
  1850. }
  1851. }
  1852. }
  1853. c.ServeSuccessJSON(map[string]interface{}{
  1854. "msg": "ok",
  1855. "advice": advice,
  1856. })
  1857. return
  1858. } else {
  1859. if id <= 0 || patient <= 0 {
  1860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1861. return
  1862. }
  1863. if len(executionTime) <= 0 {
  1864. utils.ErrorLog("execution_time")
  1865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1866. return
  1867. }
  1868. adminUserInfo := c.GetAdminUserInfo()
  1869. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1870. if advice.ID == 0 || advice.PatientId != patient {
  1871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1872. return
  1873. }
  1874. //医嘱已执行
  1875. if advice.ExecutionState == 1 {
  1876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1877. return
  1878. }
  1879. executionStaff := adminUserInfo.AdminUser.Id
  1880. // checker := adminUserInfo.AdminUser.Id
  1881. timeLayout := "2006-01-02 15:04:05"
  1882. loc, _ := time.LoadLocation("Local")
  1883. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1884. if err != nil {
  1885. utils.ErrorLog(err.Error())
  1886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1887. return
  1888. }
  1889. if advice.StartTime > theTime.Unix() {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1891. return
  1892. }
  1893. exceAdvice := models.HisDoctorAdviceInfo{
  1894. ExecutionStaff: executionStaff,
  1895. ExecutionTime: theTime.Unix(),
  1896. // Checker: checker,
  1897. UpdatedTime: time.Now().Unix(),
  1898. }
  1899. if advice.ParentId > 0 {
  1900. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1901. } else {
  1902. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1903. }
  1904. if err != nil {
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1906. return
  1907. }
  1908. advice.ExecutionStaff = executionStaff
  1909. advice.ExecutionTime = theTime.Unix()
  1910. // advice.Checker = checker
  1911. //处理出库相关逻辑
  1912. //1.判断是否启用药品管理和自备药出库功能
  1913. //药品管理信息
  1914. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1915. fmt.Println("000000000000000000000000000000000000", drugStockConfig.IsOpen)
  1916. if drugStockConfig.IsOpen == 1 {
  1917. //查询已经执行的医嘱
  1918. advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1919. for _, item := range advices {
  1920. service.HisDrugsDelivery(item.UserOrgId, item)
  1921. //out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
  1922. //if err == gorm.ErrRecordNotFound {
  1923. // //没有记录,则创建出库单
  1924. // timeStr := time.Now().Format("2006-01-02")
  1925. // timeArr := strings.Split(timeStr, "-")
  1926. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1927. // total = total + 1
  1928. // warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1929. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1930. // number = number + total
  1931. // warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1932. // creater := adminUserInfo.AdminUser.Id
  1933. // warehouseOut := models.DrugWarehouseOut{
  1934. // WarehouseOutOrderNumber: warehousing_out_order,
  1935. // OperationTime: time.Now().Unix(),
  1936. // OrgId: adminUserInfo.CurrentOrgId,
  1937. // Creater: creater,
  1938. // Ctime: time.Now().Unix(),
  1939. // Status: 1,
  1940. // WarehouseOutTime: item.RecordDate,
  1941. // Dealer: 0,
  1942. // Manufacturer: 0,
  1943. // Type: 1,
  1944. // IsSys: 1,
  1945. // }
  1946. //
  1947. // err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  1948. // if err != nil {
  1949. // utils.TraceLog("创建出库单失败 err = %v", err)
  1950. // } else {
  1951. // if item.PrescribingNumber > 0 {
  1952. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1953. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1954. // WarehouseOutId: warehouseOut.ID,
  1955. // Status: 1,
  1956. // Ctime: time.Now().Unix(),
  1957. // Remark: "",
  1958. // OrgId: adminUserInfo.CurrentOrgId,
  1959. // Type: 1,
  1960. // Manufacturer: 0,
  1961. // Dealer: 0,
  1962. // IsSys: 1,
  1963. // SysRecordTime: item.RecordDate,
  1964. // DrugId: item.DrugId,
  1965. // }
  1966. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1967. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1968. // warehouseOutInfo.Count = count
  1969. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  1970. // warehouseOutInfo.Price = stockInInfo.Price
  1971. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  1972. // if err == nil {
  1973. // details := &models.DrugAutomaticReduceDetail{
  1974. // WarehouseOutId: warehouseOutInfo.ID,
  1975. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1976. // PatientId: item.PatientId,
  1977. // Ctime: time.Now().Unix(),
  1978. // Mtime: time.Now().Unix(),
  1979. // Status: 1,
  1980. // RecordTime: item.RecordDate,
  1981. // OrgId: adminUserInfo.CurrentOrgId,
  1982. // DrugId: item.DrugId,
  1983. // Count: count,
  1984. // }
  1985. // service.AddSigleDrugAutoReduceRecordInfo(details)
  1986. // if err != nil {
  1987. // utils.TraceLog("创建出库单失败 err = %v", err)
  1988. // } else {
  1989. // if item.PrescribingNumber > 0 {
  1990. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1991. // WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1992. // WarehouseOutId: warehouseOut.ID,
  1993. // Status: 1,
  1994. // Ctime: time.Now().Unix(),
  1995. // Remark: "",
  1996. // OrgId: adminUserInfo.CurrentOrgId,
  1997. // Type: 1,
  1998. // Manufacturer: 0,
  1999. // Dealer: 0,
  2000. // IsSys: 1,
  2001. // SysRecordTime: item.RecordDate,
  2002. // DrugId: item.DrugId,
  2003. // }
  2004. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2005. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2006. // warehouseOutInfo.Count = count
  2007. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  2008. // warehouseOutInfo.Price = stockInInfo.Price
  2009. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  2010. // if err == nil {
  2011. // details := &models.DrugAutomaticReduceDetail{
  2012. // WarehouseOutId: warehouseOutInfo.ID,
  2013. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2014. // PatientId: item.PatientId,
  2015. // Ctime: time.Now().Unix(),
  2016. // Mtime: time.Now().Unix(),
  2017. // Status: 1,
  2018. // RecordTime: item.RecordDate,
  2019. // OrgId: adminUserInfo.CurrentOrgId,
  2020. // DrugId: item.DrugId,
  2021. // Count: count,
  2022. // }
  2023. // service.AddSigleDrugAutoReduceRecordInfo(details)
  2024. // }
  2025. // }
  2026. // }
  2027. //
  2028. // }
  2029. // }
  2030. // }
  2031. //} else if err == nil {
  2032. // outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  2033. // if err == gorm.ErrRecordNotFound {
  2034. // warehouseOutInfo := &models.DrugWarehouseOutInfo{
  2035. // WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2036. // WarehouseOutId: out.ID,
  2037. // Status: 1,
  2038. // Ctime: time.Now().Unix(),
  2039. // Remark: "",
  2040. // OrgId: adminUserInfo.CurrentOrgId,
  2041. // Type: 1,
  2042. // Manufacturer: 0,
  2043. // Dealer: 0,
  2044. // IsSys: 1,
  2045. // SysRecordTime: item.RecordDate,
  2046. // }
  2047. //
  2048. // stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
  2049. // warehouseOutInfo.Price = stockInInfo.Price
  2050. // warehouseOutInfo.DrugId = item.DrugId
  2051. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2052. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2053. // warehouseOutInfo.Count = count
  2054. // err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  2055. // if err == nil {
  2056. // details := &models.DrugAutomaticReduceDetail{
  2057. // WarehouseOutId: warehouseOutInfo.ID,
  2058. // WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2059. // PatientId: item.PatientId,
  2060. // Ctime: time.Now().Unix(),
  2061. // Mtime: time.Now().Unix(),
  2062. // Status: 1,
  2063. // RecordTime: item.RecordDate,
  2064. // OrgId: adminUserInfo.CurrentOrgId,
  2065. // DrugId: item.DrugId,
  2066. // Count: count,
  2067. // }
  2068. // service.AddSigleDrugAutoReduceRecordInfo(details)
  2069. // }
  2070. //
  2071. // } else if err == nil { //记录存在,则将增加数量
  2072. // if outInfo.ID > 0 {
  2073. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2074. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2075. // service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
  2076. // }
  2077. //
  2078. // count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
  2079. // if count == 0 {
  2080. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2081. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2082. // details := &models.DrugAutomaticReduceDetail{
  2083. // WarehouseOutId: outInfo.ID,
  2084. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  2085. // PatientId: item.PatientId,
  2086. // Ctime: time.Now().Unix(),
  2087. // Mtime: time.Now().Unix(),
  2088. // Status: 1,
  2089. // RecordTime: item.RecordDate,
  2090. // OrgId: adminUserInfo.CurrentOrgId,
  2091. // DrugId: item.DrugId,
  2092. // Count: count,
  2093. // }
  2094. // service.AddSigleDrugAutoReduceRecordInfo(details)
  2095. // } else if count == 1 {
  2096. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2097. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2098. // service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
  2099. // }
  2100. //
  2101. // }
  2102. //}
  2103. }
  2104. }
  2105. c.ServeSuccessJSON(map[string]interface{}{
  2106. "msg": "ok",
  2107. "advice": advice,
  2108. })
  2109. return
  2110. }
  2111. }
  2112. func (c *PatientApiController) CheckGroupAdvice() {
  2113. groupno, _ := c.GetInt64("groupno", 0)
  2114. if groupno <= 0 {
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2116. return
  2117. }
  2118. adminUserInfo := c.GetAdminUserInfo()
  2119. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2120. if advice.ID == 0 {
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2122. return
  2123. }
  2124. if advice.CheckState == 1 {
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2126. return
  2127. }
  2128. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2130. return
  2131. }
  2132. checker := adminUserInfo.AdminUser.Id
  2133. theTime := time.Now()
  2134. exceAdvice := models.DoctorAdvice{
  2135. Checker: checker,
  2136. CheckTime: theTime.Unix(),
  2137. UpdatedTime: time.Now().Unix(),
  2138. }
  2139. var err error
  2140. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2141. if err != nil {
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2143. return
  2144. }
  2145. // advice.ExecutionStaff = executionStaff
  2146. // advice.ExecutionTime = theTime.Unix()
  2147. advice.Checker = checker
  2148. advice.CheckTime = theTime.Unix()
  2149. c.ServeSuccessJSON(map[string]interface{}{
  2150. "msg": "ok",
  2151. "advice": advice,
  2152. })
  2153. return
  2154. }
  2155. func (c *PatientApiController) CheckDoctorAdvice() {
  2156. patient, _ := c.GetInt64("patient", 0)
  2157. id, _ := c.GetInt64("id", 0)
  2158. origin, _ := c.GetInt64("origin", 0)
  2159. if origin != 2 {
  2160. // executionTime := c.GetString("execution_time")
  2161. if id <= 0 || patient <= 0 {
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2163. return
  2164. }
  2165. adminUserInfo := c.GetAdminUserInfo()
  2166. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2167. if advice.ID == 0 || advice.PatientId != patient {
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2169. return
  2170. }
  2171. if advice.CheckState == 1 {
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2173. return
  2174. }
  2175. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2177. return
  2178. }
  2179. // executionStaff := adminUserInfo.AdminUser.Id
  2180. checker := adminUserInfo.AdminUser.Id
  2181. // timeLayout := "2006-01-02 15:04:05"
  2182. // loc, _ := time.LoadLocation("Local")
  2183. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2184. // if err != nil {
  2185. // utils.ErrorLog(err.Error())
  2186. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2187. // return
  2188. // }
  2189. theTime := time.Now()
  2190. if advice.ExecutionTime > theTime.Unix() {
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2192. return
  2193. }
  2194. exceAdvice := models.DoctorAdvice{
  2195. Checker: checker,
  2196. CheckTime: theTime.Unix(),
  2197. UpdatedTime: time.Now().Unix(),
  2198. }
  2199. var err error
  2200. if advice.ParentId > 0 {
  2201. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2202. } else {
  2203. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2204. }
  2205. if err != nil {
  2206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2207. return
  2208. }
  2209. // advice.ExecutionStaff = executionStaff
  2210. // advice.ExecutionTime = theTime.Unix()
  2211. advice.Checker = checker
  2212. advice.CheckTime = theTime.Unix()
  2213. c.ServeSuccessJSON(map[string]interface{}{
  2214. "msg": "ok",
  2215. "advice": advice,
  2216. })
  2217. return
  2218. } else {
  2219. if id <= 0 || patient <= 0 {
  2220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2221. return
  2222. }
  2223. adminUserInfo := c.GetAdminUserInfo()
  2224. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2225. if advice.ID == 0 || advice.PatientId != patient {
  2226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2227. return
  2228. }
  2229. if advice.CheckState == 1 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2231. return
  2232. }
  2233. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2235. return
  2236. }
  2237. checker := adminUserInfo.AdminUser.Id
  2238. theTime := time.Now()
  2239. if advice.ExecutionTime > theTime.Unix() {
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2241. return
  2242. }
  2243. exceAdvice := models.HisDoctorAdviceInfo{
  2244. Checker: checker,
  2245. CheckTime: theTime.Unix(),
  2246. UpdatedTime: time.Now().Unix(),
  2247. }
  2248. var err error
  2249. if advice.ParentId > 0 {
  2250. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2251. } else {
  2252. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2253. }
  2254. if err != nil {
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2256. return
  2257. }
  2258. // advice.ExecutionStaff = executionStaff
  2259. // advice.ExecutionTime = theTime.Unix()
  2260. advice.Checker = checker
  2261. advice.CheckTime = theTime.Unix()
  2262. c.ServeSuccessJSON(map[string]interface{}{
  2263. "msg": "ok",
  2264. "advice": advice,
  2265. })
  2266. return
  2267. }
  2268. }
  2269. func (c *PatientApiController) UpdateDoctorAdvice() {
  2270. patient, _ := c.GetInt64("patient", 0)
  2271. id, _ := c.GetInt64("id", 0)
  2272. if id <= 0 || patient <= 0 {
  2273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2274. return
  2275. }
  2276. adminUserInfo := c.GetAdminUserInfo()
  2277. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2278. if advice.ID == 0 || advice.PatientId != patient {
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2280. return
  2281. }
  2282. //if advice.AdviceType == 1 {
  2283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2284. // return
  2285. //}
  2286. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2288. return
  2289. }
  2290. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2291. //if appRole.UserType == 3 {
  2292. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2293. // if getPermissionErr != nil {
  2294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2295. // return
  2296. // } else if headNursePermission == nil {
  2297. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2298. // return
  2299. // }
  2300. //}
  2301. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2302. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2303. // return
  2304. //}
  2305. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2306. if code > 0 {
  2307. c.ServeFailJSONWithSGJErrorCode(code)
  2308. return
  2309. }
  2310. advice.UpdatedTime = time.Now().Unix()
  2311. advice.Modifier = adminUserInfo.AdminUser.Id
  2312. err := service.UpdateDoctorAdvice(&advice)
  2313. if err != nil {
  2314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2315. return
  2316. }
  2317. c.ServeSuccessJSON(map[string]interface{}{
  2318. "msg": "ok",
  2319. "advice": advice,
  2320. })
  2321. return
  2322. }
  2323. func (c *PatientApiController) StopGroupAdvice() {
  2324. groupNo, _ := c.GetInt64("groupno", 0)
  2325. if groupNo <= 0 {
  2326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2327. return
  2328. }
  2329. adminUserInfo := c.GetAdminUserInfo()
  2330. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2331. if advice.ID == 0 {
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2333. return
  2334. }
  2335. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2337. return
  2338. }
  2339. dataBody := make(map[string]interface{}, 0)
  2340. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2341. if err != nil {
  2342. utils.ErrorLog(err.Error())
  2343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2344. return
  2345. }
  2346. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2347. utils.ErrorLog("stop_time")
  2348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2349. return
  2350. }
  2351. stopTime, _ := dataBody["stop_time"].(string)
  2352. if len(stopTime) == 0 {
  2353. utils.ErrorLog("len(stop_time) == 0")
  2354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2355. return
  2356. }
  2357. timeLayout := "2006-01-02"
  2358. loc, _ := time.LoadLocation("Local")
  2359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2360. if err != nil {
  2361. utils.ErrorLog(err.Error())
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2363. return
  2364. }
  2365. advice.StopTime = theTime.Unix()
  2366. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2367. stopReason, _ := dataBody["stop_reason"].(string)
  2368. advice.StopReason = stopReason
  2369. }
  2370. advice.UpdatedTime = time.Now().Unix()
  2371. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2372. advice.StopState = 1
  2373. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2374. if err != nil {
  2375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2376. return
  2377. }
  2378. c.ServeSuccessJSON(map[string]interface{}{
  2379. "msg": "ok",
  2380. })
  2381. return
  2382. }
  2383. func (c *PatientApiController) StopDoctorAdvice() {
  2384. id, _ := c.GetInt64("id", 0)
  2385. if id <= 0 {
  2386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2387. return
  2388. }
  2389. adminUserInfo := c.GetAdminUserInfo()
  2390. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2391. //
  2392. //if appRole.UserType == 3 {
  2393. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2394. // if getPermissionErr != nil {
  2395. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2396. // return
  2397. // } else if headNursePermission == nil {
  2398. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2399. // return
  2400. // }
  2401. //}
  2402. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2403. if advice.ID == 0 {
  2404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2405. return
  2406. }
  2407. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2409. return
  2410. }
  2411. dataBody := make(map[string]interface{}, 0)
  2412. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2413. if err != nil {
  2414. utils.ErrorLog(err.Error())
  2415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2416. return
  2417. }
  2418. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2419. utils.ErrorLog("stop_time")
  2420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2421. return
  2422. }
  2423. stopTime, _ := dataBody["stop_time"].(string)
  2424. if len(stopTime) == 0 {
  2425. utils.ErrorLog("len(stop_time) == 0")
  2426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2427. return
  2428. }
  2429. timeLayout := "2006-01-02"
  2430. loc, _ := time.LoadLocation("Local")
  2431. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2432. if err != nil {
  2433. utils.ErrorLog(err.Error())
  2434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2435. return
  2436. }
  2437. advice.StopTime = theTime.Unix()
  2438. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2439. stopReason, _ := dataBody["stop_reason"].(string)
  2440. advice.StopReason = stopReason
  2441. }
  2442. advice.UpdatedTime = time.Now().Unix()
  2443. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2444. advice.StopState = 1
  2445. err = service.StopDoctorAdvice(&advice)
  2446. if err != nil {
  2447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2448. return
  2449. }
  2450. c.ServeSuccessJSON(map[string]interface{}{
  2451. "msg": "ok",
  2452. "advice": advice,
  2453. })
  2454. return
  2455. }
  2456. func (c *PatientApiController) DeleteDoctorAdvice() {
  2457. id, _ := c.GetInt64("id", 0)
  2458. if id <= 0 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2460. return
  2461. }
  2462. adminUserInfo := c.GetAdminUserInfo()
  2463. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2464. if advice.ID == 0 {
  2465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2466. return
  2467. }
  2468. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2469. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2470. // return
  2471. //}
  2472. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2473. //
  2474. //if appRole.UserType == 3 {
  2475. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2476. // if getPermissionErr != nil {
  2477. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2478. // return
  2479. // } else if headNursePermission == nil {
  2480. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2481. // return
  2482. // }
  2483. //}
  2484. advice.UpdatedTime = time.Now().Unix()
  2485. advice.Status = 0
  2486. advice.Modifier = adminUserInfo.AdminUser.Id
  2487. err := service.DeleteDoctorAdvice(&advice)
  2488. if err != nil {
  2489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2490. return
  2491. }
  2492. c.ServeSuccessJSON(map[string]interface{}{
  2493. "msg": "ok",
  2494. })
  2495. return
  2496. }
  2497. func (c *PatientApiController) DeleteGroupAdvice() {
  2498. groupNo, _ := c.GetInt64("groupno", 0)
  2499. if groupNo <= 0 {
  2500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2501. return
  2502. }
  2503. adminUserInfo := c.GetAdminUserInfo()
  2504. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2505. if advice.ID == 0 {
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2507. return
  2508. }
  2509. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2510. //if appRole.UserType == 3 {
  2511. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2512. // if getPermissionErr != nil {
  2513. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2514. // return
  2515. // } else if headNursePermission == nil {
  2516. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2517. // return
  2518. // }
  2519. //}
  2520. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2521. if err != nil {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2523. return
  2524. }
  2525. c.ServeSuccessJSON(map[string]interface{}{
  2526. "msg": "ok",
  2527. })
  2528. return
  2529. }
  2530. //GetDoctorAdvices 医嘱列表
  2531. func (c *PatientApiController) GetDoctorAdvices() {
  2532. id, _ := c.GetInt64("id", 0)
  2533. adviceType, _ := c.GetInt64("advice_type", 0)
  2534. stopType, _ := c.GetInt64("stop_state", 0)
  2535. startTime := c.GetString("start_time", "")
  2536. endTime := c.GetString("end_time", "")
  2537. keywords := c.GetString("keywords", "")
  2538. page, _ := c.GetInt64("page")
  2539. fmt.Println("page", page)
  2540. limit, _ := c.GetInt64("limit")
  2541. fmt.Println("limit", limit)
  2542. adminUserInfo := c.GetAdminUserInfo()
  2543. operatorIDs := make([]int64, 0)
  2544. timeLayout := "2006-01-02"
  2545. loc, _ := time.LoadLocation("Local")
  2546. var theStartTIme int64
  2547. if len(startTime) > 0 {
  2548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2549. if err != nil {
  2550. utils.ErrorLog(err.Error())
  2551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2552. return
  2553. }
  2554. theStartTIme = theTime.Unix()
  2555. }
  2556. var theEndtTIme int64
  2557. if len(endTime) > 0 {
  2558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2559. if err != nil {
  2560. utils.ErrorLog(err.Error())
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2562. return
  2563. }
  2564. theEndtTIme = theTime.Unix()
  2565. }
  2566. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2567. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2568. if len(advices) > 0 {
  2569. for _, item := range advices {
  2570. if item.AdviceDoctor > 0 {
  2571. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2572. }
  2573. if item.ExecutionStaff > 0 {
  2574. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2575. }
  2576. if item.Checker > 0 {
  2577. operatorIDs = append(operatorIDs, item.Checker)
  2578. }
  2579. if item.StopDoctor > 0 {
  2580. operatorIDs = append(operatorIDs, item.StopDoctor)
  2581. }
  2582. }
  2583. }
  2584. //相关操作对应的操作人
  2585. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2586. c.ServeSuccessJSON(map[string]interface{}{
  2587. "advices": advices,
  2588. "operators": operators,
  2589. "total": total,
  2590. "advicetwo": advicestwo,
  2591. })
  2592. return
  2593. }
  2594. func (c *PatientApiController) GetPatientSchedules() {
  2595. id, _ := c.GetInt64("id", 0)
  2596. if id <= 0 {
  2597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2598. return
  2599. }
  2600. adminUserInfo := c.GetAdminUserInfo()
  2601. todayTime := time.Now().Format("2006-01-02")
  2602. timeLayout := "2006-01-02 15:04:05"
  2603. loc, _ := time.LoadLocation("Local")
  2604. var theStartTime int64
  2605. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2606. theStartTime = theTime.Unix()
  2607. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2608. if len(schedules) > 0 {
  2609. for index, item := range schedules {
  2610. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2611. schedules[index].Week = int64(week)
  2612. }
  2613. }
  2614. c.ServeSuccessJSON(map[string]interface{}{
  2615. "schedules": schedules,
  2616. })
  2617. return
  2618. }
  2619. func (c *PatientApiController) GetPatientDialysisRecords() {
  2620. patientID, _ := c.GetInt64("patient_id", 0)
  2621. page, _ := c.GetInt64("page", 0)
  2622. limit, _ := c.GetInt64("limit", 0)
  2623. startTime := c.GetString("start_time", "")
  2624. endTime := c.GetString("end_time", "")
  2625. mode_id, _ := c.GetInt64("mode_id", 0)
  2626. if page <= 0 {
  2627. page = 1
  2628. }
  2629. if limit <= 0 {
  2630. limit = 10
  2631. }
  2632. if patientID <= 0 {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2634. return
  2635. }
  2636. timeLayout := "2006-01-02"
  2637. loc, _ := time.LoadLocation("Local")
  2638. var theStartTIme int64
  2639. if len(startTime) > 0 {
  2640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2641. if err != nil {
  2642. theStartTIme = 0
  2643. }
  2644. theStartTIme = theTime.Unix()
  2645. }
  2646. var theEndtTIme int64
  2647. if len(endTime) > 0 {
  2648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2649. if err != nil {
  2650. theEndtTIme = 0
  2651. }
  2652. theEndtTIme = theTime.Unix()
  2653. }
  2654. adminInfo := c.GetAdminUserInfo()
  2655. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "total": total,
  2658. "records": records,
  2659. })
  2660. return
  2661. }
  2662. func (c *PatientApiController) ProEducation() {
  2663. patientID, _ := c.GetInt64("patient_id", 0)
  2664. page, _ := c.GetInt64("page", 0)
  2665. limit, _ := c.GetInt64("limit", 0)
  2666. startTime := c.GetString("start_time", "")
  2667. endTime := c.GetString("end_time", "")
  2668. if page <= 0 {
  2669. page = 1
  2670. }
  2671. if limit <= 0 {
  2672. limit = 10
  2673. }
  2674. if patientID <= 0 {
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2676. return
  2677. }
  2678. timeLayout := "2006-01-02"
  2679. loc, _ := time.LoadLocation("Local")
  2680. var theStartTIme int64
  2681. if len(startTime) > 0 {
  2682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2683. if err != nil {
  2684. theStartTIme = 0
  2685. }
  2686. theStartTIme = theTime.Unix()
  2687. }
  2688. var theEndtTIme int64
  2689. if len(endTime) > 0 {
  2690. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2691. if err != nil {
  2692. theEndtTIme = 0
  2693. }
  2694. theEndtTIme = theTime.Unix()
  2695. }
  2696. adminInfo := c.GetAdminUserInfo()
  2697. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2698. c.ServeSuccessJSON(map[string]interface{}{
  2699. "total": total,
  2700. "edus": edus,
  2701. })
  2702. return
  2703. }
  2704. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2705. dataBody := make(map[string]interface{}, 0)
  2706. err := json.Unmarshal(data, &dataBody)
  2707. if err != nil {
  2708. utils.ErrorLog(err.Error())
  2709. code = enums.ErrorCodeParamWrong
  2710. return
  2711. }
  2712. timeLayout := "2006-01-02"
  2713. loc, _ := time.LoadLocation("Local")
  2714. isChild := false
  2715. if action == "create" {
  2716. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2717. utils.ErrorLog("advice_type")
  2718. code = enums.ErrorCodeParamWrong
  2719. return
  2720. }
  2721. adviceType := int64(dataBody["advice_type"].(float64))
  2722. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2723. utils.ErrorLog("advice_type != 1&&2")
  2724. code = enums.ErrorCodeParamWrong
  2725. return
  2726. }
  2727. advice.AdviceType = adviceType
  2728. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2729. utils.ErrorLog("advice_date")
  2730. code = enums.ErrorCodeParamWrong
  2731. return
  2732. }
  2733. adviceDate, _ := dataBody["advice_date"].(string)
  2734. if len(adviceDate) == 0 {
  2735. utils.ErrorLog("len(adviceDate) == 0")
  2736. code = enums.ErrorCodeParamWrong
  2737. return
  2738. }
  2739. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2740. if err != nil {
  2741. utils.ErrorLog(err.Error())
  2742. code = enums.ErrorCodeParamWrong
  2743. return
  2744. }
  2745. advice.AdviceDate = theTime.Unix()
  2746. advice.RecordDate = theTime.Unix()
  2747. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2748. parentId := int64(dataBody["parent_id"].(float64))
  2749. advice.ParentId = parentId
  2750. if parentId > 0 {
  2751. isChild = true
  2752. }
  2753. }
  2754. }
  2755. if !isChild {
  2756. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2757. utils.ErrorLog("start_time")
  2758. code = enums.ErrorCodeParamWrong
  2759. return
  2760. }
  2761. startTime, _ := dataBody["start_time"].(string)
  2762. if len(startTime) == 0 {
  2763. utils.ErrorLog("len(start_time) == 0")
  2764. code = enums.ErrorCodeParamWrong
  2765. return
  2766. }
  2767. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2768. if err != nil {
  2769. utils.ErrorLog(err.Error())
  2770. code = enums.ErrorCodeParamWrong
  2771. return
  2772. }
  2773. advice.StartTime = theTime.Unix()
  2774. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2775. // utils.ErrorLog("advice_doctor")
  2776. // code = enums.ErrorCodeParamWrong
  2777. // return
  2778. // }
  2779. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2780. // if adviceDoctor <= 0 {
  2781. // utils.ErrorLog("advice_doctor <=0")
  2782. // code = enums.ErrorCodeParamWrong
  2783. // return
  2784. // }
  2785. // advice.AdviceDoctor = adviceDoctor
  2786. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2787. deliveryWay, _ := dataBody["delivery_way"].(string)
  2788. advice.DeliveryWay = deliveryWay
  2789. }
  2790. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2791. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2792. advice.ExecutionFrequency = executionFrequency
  2793. }
  2794. if advice.AdviceType == 1 && advice.ParentId == 0 {
  2795. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  2796. frequency_type := int64(dataBody["frequency_type"].(float64))
  2797. advice.FrequencyType = frequency_type
  2798. }
  2799. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  2800. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  2801. advice.DayCount = day_count
  2802. }
  2803. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  2804. week_day, _ := dataBody["week_days"].(string)
  2805. advice.WeekDay = week_day
  2806. }
  2807. }
  2808. }
  2809. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2810. utils.ErrorLog("advice_name")
  2811. code = enums.ErrorCodeParamWrong
  2812. return
  2813. }
  2814. adviceName, _ := dataBody["advice_name"].(string)
  2815. if len(adviceName) == 0 {
  2816. utils.ErrorLog("len(advice_name) == 0")
  2817. code = enums.ErrorCodeParamWrong
  2818. return
  2819. }
  2820. advice.AdviceName = adviceName
  2821. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2822. adviceDsc, _ := dataBody["advice_desc"].(string)
  2823. advice.AdviceDesc = adviceDsc
  2824. }
  2825. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2826. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2827. advice.DialysisOrderId = int64(dialysisOrderId)
  2828. }
  2829. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2830. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2831. advice.SingleDose = singleDose
  2832. }
  2833. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2834. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2835. advice.SingleDoseUnit = singleDoseUnit
  2836. }
  2837. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2838. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2839. advice.DrugSpec = drugSpec
  2840. }
  2841. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2842. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2843. advice.DrugSpecUnit = drugSpecUnit
  2844. }
  2845. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2846. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2847. advice.PrescribingNumber = prescribingNumber
  2848. }
  2849. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2850. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2851. advice.PrescribingNumberUnit = prescribingNumberUnit
  2852. }
  2853. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2854. remark, _ := dataBody["remark"].(string)
  2855. advice.Remark = remark
  2856. }
  2857. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2858. drug_id, _ := dataBody["drug_id"].(float64)
  2859. advice.DrugId = int64(drug_id)
  2860. }
  2861. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2862. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  2863. advice.DrugNameId = int64(drug_name_id)
  2864. }
  2865. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2866. way, _ := dataBody["way"].(float64)
  2867. advice.Way = int64(way)
  2868. }
  2869. return
  2870. }
  2871. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2872. dataBody := make(map[string]interface{}, 0)
  2873. err := json.Unmarshal(data, &dataBody)
  2874. utils.InfoLog(string(data))
  2875. if err != nil {
  2876. utils.ErrorLog(err.Error())
  2877. code = enums.ErrorCodeParamWrong
  2878. return
  2879. }
  2880. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2881. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2882. solution.DialysisDuration = dialysisDuration
  2883. }
  2884. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2885. replacementWay := int64(dataBody["replacement_way"].(float64))
  2886. solution.ReplacementWay = replacementWay
  2887. }
  2888. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2889. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2890. solution.BloodFlowVolume = bloodFlowVolume
  2891. }
  2892. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2893. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2894. solution.HemodialysisMachine = hemodialysisMachine
  2895. }
  2896. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2897. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2898. solution.BloodFilter = bloodFilter
  2899. }
  2900. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2901. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2902. solution.PerfusionApparatus = perfusionApparatus
  2903. }
  2904. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2905. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2906. solution.DialysateFlow = dialysateFlow
  2907. }
  2908. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2909. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2910. solution.Kalium = kalium
  2911. }
  2912. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2913. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2914. solution.Sodium = sodium
  2915. }
  2916. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2917. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2918. solution.Calcium = calcium
  2919. }
  2920. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2921. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2922. solution.Bicarbonate = bicarbonate
  2923. }
  2924. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2925. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2926. solution.Anticoagulant = anticoagulant
  2927. }
  2928. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2929. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2930. solution.AnticoagulantShouji = anticoagulantShouji
  2931. }
  2932. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2933. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2934. solution.AnticoagulantWeichi = anticoagulantWeichi
  2935. }
  2936. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2937. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2938. solution.AnticoagulantZongliang = anticoagulantZongliang
  2939. }
  2940. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2941. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2942. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2943. }
  2944. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2945. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2946. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2947. }
  2948. return
  2949. }
  2950. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2951. dataBody := make(map[string]interface{}, 0)
  2952. err := json.Unmarshal(data, &dataBody)
  2953. utils.InfoLog(string(data))
  2954. if err != nil {
  2955. utils.ErrorLog(err.Error())
  2956. code = enums.ErrorCodeParamWrong
  2957. return
  2958. }
  2959. if method == "create" {
  2960. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2961. utils.ErrorLog("mode")
  2962. code = enums.ErrorCodeParamWrong
  2963. return
  2964. }
  2965. mode := int64(dataBody["mode"].(float64))
  2966. if mode <= 0 {
  2967. utils.ErrorLog("mode <= 0")
  2968. code = enums.ErrorCodeParamWrong
  2969. return
  2970. }
  2971. solution.ModeId = mode
  2972. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2973. utils.ErrorLog("mode_name")
  2974. code = enums.ErrorCodeParamWrong
  2975. return
  2976. }
  2977. modeName, _ := dataBody["mode_name"].(string)
  2978. if len(modeName) == 0 {
  2979. utils.ErrorLog("len(mode_name) == 0")
  2980. code = enums.ErrorCodeParamWrong
  2981. return
  2982. }
  2983. solution.ModeName = modeName
  2984. solution.Name = modeName
  2985. }
  2986. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2987. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2988. solution.DialysisDuration = dialysisDuration
  2989. }
  2990. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2991. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2992. solution.TargetUltrafiltration = targetUltrafiltration
  2993. }
  2994. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2995. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2996. solution.DialysateFormulation = dialysateFormulation
  2997. }
  2998. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2999. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3000. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3001. }
  3002. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3003. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3004. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3005. }
  3006. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3007. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3008. solution.HemodialysisMachine = hemodialysisMachine
  3009. }
  3010. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3011. dialyzer := int64(dataBody["dialyzer"].(float64))
  3012. solution.Dialyzer = dialyzer
  3013. }
  3014. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3015. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3016. solution.PerfusionApparatus = perfusionApparatus
  3017. }
  3018. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3019. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3020. solution.BloodFlowVolume = bloodFlowVolume
  3021. }
  3022. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3023. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3024. solution.Dewater = dewater
  3025. }
  3026. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3027. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3028. solution.DisplaceLiqui = displaceLiqui
  3029. }
  3030. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3031. replacementWay := int64(dataBody["replacement_way"].(float64))
  3032. solution.ReplacementWay = replacementWay
  3033. }
  3034. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3035. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3036. solution.Anticoagulant = anticoagulant
  3037. }
  3038. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3039. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3040. solution.AnticoagulantShouji = anticoagulantShouji
  3041. }
  3042. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3043. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3044. solution.AnticoagulantWeichi = anticoagulantWeichi
  3045. }
  3046. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3047. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3048. solution.AnticoagulantZongliang = anticoagulantZongliang
  3049. }
  3050. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3051. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3052. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3053. }
  3054. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3055. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3056. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3057. }
  3058. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3059. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3060. solution.Kalium = kalium
  3061. }
  3062. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3063. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3064. solution.Sodium = sodium
  3065. }
  3066. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3067. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3068. solution.Calcium = calcium
  3069. }
  3070. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3071. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3072. solution.Bicarbonate = bicarbonate
  3073. }
  3074. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3075. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3076. solution.Glucose = glucose
  3077. }
  3078. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3079. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3080. // solution.DryWeight = dryWeight
  3081. // }
  3082. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3083. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3084. solution.DialysateFlow = dialysateFlow
  3085. }
  3086. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3087. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3088. solution.DialysateTemperature = dialysateTemperature
  3089. }
  3090. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3091. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3092. solution.Conductivity = conductivity
  3093. }
  3094. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3095. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3096. solution.ReplacementTotal = replacementTotal
  3097. }
  3098. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3099. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3100. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3101. }
  3102. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3103. body_fluid := int64(dataBody["body_fluid"].(float64))
  3104. solution.BodyFluid = body_fluid
  3105. }
  3106. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3107. body_fluid_other := dataBody["body_fluid_other"].(string)
  3108. solution.BodyFluidOther = body_fluid_other
  3109. }
  3110. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3111. special_medicine := int64(dataBody["special_medicine"].(float64))
  3112. solution.SpecialMedicine = special_medicine
  3113. }
  3114. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3115. special_medicine_other := dataBody["special_medicine_other"].(string)
  3116. solution.SpecialMedicineOther = special_medicine_other
  3117. }
  3118. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3119. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3120. solution.DisplaceLiquiPart = displace_liqui_part
  3121. }
  3122. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3123. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3124. solution.DisplaceLiquiValue = displace_liqui_value
  3125. }
  3126. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3127. blood_access := int64(dataBody["blood_access"].(float64))
  3128. solution.BloodAccess = blood_access
  3129. }
  3130. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3131. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3132. solution.Ultrafiltration = ultrafiltration
  3133. }
  3134. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3135. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3136. solution.TargetKtv = target_ktv
  3137. }
  3138. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3139. remark := dataBody["remark"].(string)
  3140. solution.Remark = remark
  3141. }
  3142. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3143. created_time := int64(dataBody["created_time"].(float64))
  3144. solution.CreatedTime = created_time
  3145. }
  3146. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3147. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3148. solution.DialysisDialyszers = dialysisDialyszers
  3149. }
  3150. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3151. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3152. solution.DialysisIrrigation = dialysisIrrigation
  3153. }
  3154. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3155. plasmaSeparator := dataBody["plasma_separator"].(string)
  3156. solution.PlasmaSeparator = plasmaSeparator
  3157. }
  3158. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3159. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3160. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3161. }
  3162. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3163. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3164. solution.OxygenUptake = oxygen_uptake
  3165. }
  3166. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3167. oxygen_flow := dataBody["oxygen_flow"].(string)
  3168. solution.OxygenFlow = oxygen_flow
  3169. }
  3170. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3171. oxygen_time := dataBody["oxygen_time"].(string)
  3172. solution.OxygenTime = oxygen_time
  3173. }
  3174. return
  3175. }
  3176. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3177. dataBody := make(map[string]interface{}, 0)
  3178. err := json.Unmarshal(data, &dataBody)
  3179. utils.InfoLog(string(data))
  3180. if err != nil {
  3181. utils.ErrorLog(err.Error())
  3182. code = enums.ErrorCodeParamWrong
  3183. return
  3184. }
  3185. if method == "create" {
  3186. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3187. utils.ErrorLog("parent_id")
  3188. code = enums.ErrorCodeParamWrong
  3189. return
  3190. }
  3191. parentID := int64(dataBody["parent_id"].(float64))
  3192. if parentID <= 0 {
  3193. utils.ErrorLog("parentID <= 0")
  3194. code = enums.ErrorCodeParamWrong
  3195. return
  3196. }
  3197. solution.ParentId = parentID
  3198. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3199. utils.ErrorLog("sub_name")
  3200. code = enums.ErrorCodeParamWrong
  3201. return
  3202. }
  3203. subName, _ := dataBody["sub_name"].(string)
  3204. if len(subName) == 0 {
  3205. utils.ErrorLog("len(sub_name) == 0")
  3206. code = enums.ErrorCodeParamWrong
  3207. return
  3208. }
  3209. solution.SubName = subName
  3210. }
  3211. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  3212. utils.ErrorLog("initiate_mode")
  3213. code = enums.ErrorCodeParamWrong
  3214. return
  3215. }
  3216. initiateMode := int64(dataBody["initiate_mode"].(float64))
  3217. if initiateMode != 1 && initiateMode != 2 {
  3218. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  3219. code = enums.ErrorCodeParamWrong
  3220. return
  3221. }
  3222. solution.InitiateMode = initiateMode
  3223. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3224. utils.ErrorLog("doctor")
  3225. code = enums.ErrorCodeParamWrong
  3226. return
  3227. }
  3228. doctor := int64(dataBody["doctor"].(float64))
  3229. if doctor <= 0 {
  3230. utils.ErrorLog("doctor <= 0")
  3231. code = enums.ErrorCodeParamWrong
  3232. return
  3233. }
  3234. solution.Doctor = doctor
  3235. return
  3236. }
  3237. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  3238. patientBody := make(map[string]interface{}, 0)
  3239. err := json.Unmarshal(data, &patientBody)
  3240. if err != nil {
  3241. utils.ErrorLog(err.Error())
  3242. code = enums.ErrorCodeParamWrong
  3243. return
  3244. }
  3245. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  3246. formItem, _ := patientBody["formItem"].([]interface{})
  3247. if len(formItem) > 0 {
  3248. for _, item := range formItem {
  3249. items := item.(map[string]interface{})
  3250. project_name, _ := items["project_name"].(string)
  3251. fmt.Println(project_name)
  3252. range_type := int64(items["range_type"].(float64))
  3253. fmt.Println(range_type)
  3254. project_id := int64(items["project_id"].(float64))
  3255. fmt.Println(project_id)
  3256. item_id := int64(items["item_id"].(float64))
  3257. fmt.Println(item_id)
  3258. item, _ := items["item"].(string)
  3259. fmt.Println(items["item"].(string))
  3260. item_name, _ := items["item_name"].(string)
  3261. fmt.Println(item_name)
  3262. value, _ := items["value"].(string)
  3263. fmt.Println(items["value"].(string))
  3264. var form models.FormItem
  3265. form.ProjectName = project_name
  3266. form.RangeType = range_type
  3267. form.ProjectId = project_id
  3268. form.ItemId = item_id
  3269. form.Item = item
  3270. form.ItemName = item_name
  3271. form.Value = value
  3272. formItems = append(formItems, &form)
  3273. }
  3274. }
  3275. }
  3276. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  3277. utils.ErrorLog("avatar")
  3278. code = enums.ErrorCodeParamWrong
  3279. return
  3280. }
  3281. avatar, _ := patientBody["avatar"].(string)
  3282. if len(avatar) == 0 {
  3283. utils.ErrorLog("len(avatar) == 0")
  3284. code = enums.ErrorCodeParamWrong
  3285. return
  3286. }
  3287. patient.Avatar = avatar
  3288. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  3289. utils.ErrorLog("name")
  3290. code = enums.ErrorCodeParamWrong
  3291. return
  3292. }
  3293. name, _ := patientBody["name"].(string)
  3294. if len(name) == 0 {
  3295. utils.ErrorLog("len(name) == 0")
  3296. code = enums.ErrorCodeParamWrong
  3297. return
  3298. }
  3299. patient.Name = name
  3300. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  3301. alias := patientBody["alias"].(string)
  3302. patient.Alias = alias
  3303. }
  3304. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  3305. nation := patientBody["nation"].(string)
  3306. patient.Nation = nation
  3307. }
  3308. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  3309. native_place := patientBody["native_place"].(string)
  3310. patient.NativePlace = native_place
  3311. }
  3312. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  3313. utils.ErrorLog("idCardNo")
  3314. code = enums.ErrorCodeParamWrong
  3315. return
  3316. }
  3317. idCardNo, _ := patientBody["idCardNo"].(string)
  3318. if len(idCardNo) == 0 {
  3319. utils.ErrorLog("len(idCardNo) == 0")
  3320. code = enums.ErrorCodeParamWrong
  3321. return
  3322. }
  3323. patient.IdCardNo = idCardNo
  3324. patient.PatientType = 1
  3325. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  3326. utils.ErrorLog("dialysisNo")
  3327. code = enums.ErrorCodeParamWrong
  3328. return
  3329. }
  3330. dialysisNo, _ := patientBody["dialysisNo"].(string)
  3331. if len(dialysisNo) == 0 {
  3332. utils.ErrorLog("len(dialysisNo) == 0")
  3333. code = enums.ErrorCodeParamWrong
  3334. return
  3335. }
  3336. patient.DialysisNo = dialysisNo
  3337. // }
  3338. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  3339. utils.ErrorLog("lapseto")
  3340. code = enums.ErrorCodeParamWrong
  3341. return
  3342. }
  3343. lapseto := int64(patientBody["lapseto"].(float64))
  3344. if lapseto <= 0 {
  3345. utils.ErrorLog("lapseto == 0")
  3346. code = enums.ErrorCodeParamWrong
  3347. return
  3348. }
  3349. patient.Lapseto = lapseto
  3350. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  3351. utils.ErrorLog("gender")
  3352. code = enums.ErrorCodeParamWrong
  3353. return
  3354. }
  3355. gender := int64(patientBody["gender"].(float64))
  3356. if gender <= 0 {
  3357. utils.ErrorLog("gender <= 0")
  3358. code = enums.ErrorCodeParamWrong
  3359. return
  3360. }
  3361. patient.Gender = gender
  3362. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  3363. response_result := patientBody["response_result"].(string)
  3364. patient.ResponseResult = response_result
  3365. }
  3366. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  3367. utils.ErrorLog("age")
  3368. code = enums.ErrorCodeParamWrong
  3369. return
  3370. }
  3371. age := int64(patientBody["age"].(float64))
  3372. patient.Age = age
  3373. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  3374. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  3375. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  3376. patient.UserSysBeforeCount = count
  3377. }
  3378. timeLayout := "2006-01-02"
  3379. loc, _ := time.LoadLocation("Local")
  3380. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  3381. utils.ErrorLog("birth")
  3382. code = enums.ErrorCodeParamWrong
  3383. return
  3384. }
  3385. birth, _ := patientBody["birth"].(string)
  3386. if len(birth) == 0 {
  3387. utils.ErrorLog("len(birth) == 0")
  3388. code = enums.ErrorCodeParamWrong
  3389. return
  3390. }
  3391. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  3392. if err != nil {
  3393. utils.ErrorLog("birthTime")
  3394. code = enums.ErrorCodeParamWrong
  3395. return
  3396. }
  3397. patient.Birthday = birthTime.Unix()
  3398. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  3399. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  3400. patient.Height = height
  3401. }
  3402. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  3403. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3404. patient.MaritalStatus = maritalStatus
  3405. }
  3406. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3407. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3408. patient.Children = children
  3409. }
  3410. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3411. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3412. patient.AdmissionNumber = admissionNumber
  3413. }
  3414. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3415. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3416. patient.ReimbursementWayId = reimbursementWayID
  3417. }
  3418. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3419. healthCareNo := patientBody["healthCareNo"].(string)
  3420. patient.HealthCareNo = healthCareNo
  3421. }
  3422. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3423. utils.ErrorLog("phone")
  3424. code = enums.ErrorCodeParamWrong
  3425. return
  3426. }
  3427. phone := patientBody["phone"].(string)
  3428. if len(phone) == 0 {
  3429. utils.ErrorLog("len(phone) == 0")
  3430. code = enums.ErrorCodeParamWrong
  3431. return
  3432. }
  3433. if !utils.CheckMobile(phone) {
  3434. utils.ErrorLog("!phone")
  3435. code = enums.ErrorCodeMobileFormat
  3436. return
  3437. }
  3438. patient.Phone = phone
  3439. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3440. homeTelephone := patientBody["homeTelephone"].(string)
  3441. patient.HomeTelephone = homeTelephone
  3442. }
  3443. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3444. relativePhone := patientBody["relative_phone"].(string)
  3445. patient.RelativePhone = relativePhone
  3446. }
  3447. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3448. relativeRelations := patientBody["relative_relations"].(string)
  3449. patient.RelativeRelations = relativeRelations
  3450. }
  3451. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3452. homeAddress := patientBody["homeAddress"].(string)
  3453. patient.HomeAddress = homeAddress
  3454. }
  3455. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3456. work := patientBody["work"].(string)
  3457. patient.WorkUnit = work
  3458. }
  3459. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3460. unitAddress := patientBody["unit_address"].(string)
  3461. patient.UnitAddress = unitAddress
  3462. }
  3463. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3464. profession := int64(patientBody["profession"].(float64))
  3465. patient.Profession = profession
  3466. }
  3467. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3468. education := int64(patientBody["education"].(float64))
  3469. patient.EducationLevel = education
  3470. }
  3471. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3472. utils.ErrorLog("source")
  3473. code = enums.ErrorCodeParamWrong
  3474. return
  3475. }
  3476. source := int64(patientBody["source"].(float64))
  3477. if source <= 0 {
  3478. utils.ErrorLog("source <= 0")
  3479. code = enums.ErrorCodeParamWrong
  3480. return
  3481. }
  3482. patient.Source = source
  3483. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3484. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3485. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3486. }
  3487. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3488. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3489. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3490. if err == nil {
  3491. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3492. }
  3493. }
  3494. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3495. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3496. patient.FirstDialysisHospital = firstDialysisHospital
  3497. }
  3498. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3499. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3500. if len(thePredialysisCondition) > 0 {
  3501. conditions := make([]string, 0)
  3502. for _, item := range thePredialysisCondition {
  3503. if reflect.TypeOf(item).String() != "string" {
  3504. continue
  3505. }
  3506. condition := item.(string)
  3507. if len(condition) > 0 {
  3508. conditions = append(conditions, condition)
  3509. }
  3510. }
  3511. patient.PredialysisCondition = strings.Join(conditions, ",")
  3512. }
  3513. }
  3514. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3515. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3516. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3517. }
  3518. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3519. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3520. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3521. }
  3522. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3523. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3524. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3525. if err == nil {
  3526. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3527. }
  3528. }
  3529. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3530. partition := int64(patientBody["partition"].(float64))
  3531. patient.PartitionId = partition
  3532. }
  3533. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3534. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3535. patient.BedId = bed
  3536. }
  3537. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3538. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3539. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3540. if err == nil {
  3541. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3542. }
  3543. }
  3544. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3545. blood := int64(patientBody["blood"].(float64))
  3546. patient.BloodType = blood
  3547. }
  3548. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3549. rh := int64(patientBody["rh"].(float64))
  3550. patient.Rh = rh
  3551. }
  3552. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3553. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3554. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3555. if err == nil {
  3556. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3557. }
  3558. }
  3559. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3560. receivingDate := patientBody["receivingDate"].(string)
  3561. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3562. if err == nil {
  3563. patient.ReceivingDate = receivingDateTime.Unix()
  3564. }
  3565. }
  3566. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3567. induction := int64(patientBody["induction"].(float64))
  3568. patient.InductionPeriod = induction
  3569. }
  3570. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3571. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3572. patient.InitialDialysis = initial
  3573. }
  3574. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3575. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3576. patient.TotalDialysis = dialysisTotal
  3577. }
  3578. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3579. thisContagions, _ := patientBody["contagions"].([]interface{})
  3580. if len(thisContagions) > 0 {
  3581. for _, item := range thisContagions {
  3582. if reflect.TypeOf(item).String() != "float64" {
  3583. continue
  3584. }
  3585. contagion := int64(item.(float64))
  3586. if contagion > 0 {
  3587. contagions = append(contagions, contagion)
  3588. }
  3589. }
  3590. }
  3591. }
  3592. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3593. doctor := int64(patientBody["doctor"].(float64))
  3594. patient.AttendingDoctorId = doctor
  3595. }
  3596. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3597. nurse := int64(patientBody["nurse"].(float64))
  3598. patient.HeadNurseId = nurse
  3599. }
  3600. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3601. assessment := patientBody["assessment"].(string)
  3602. patient.Evaluate = assessment
  3603. }
  3604. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3605. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3606. if len(thisDiseases) > 0 {
  3607. for _, item := range thisDiseases {
  3608. if reflect.TypeOf(item).String() != "float64" {
  3609. continue
  3610. }
  3611. disease := int64(item.(float64))
  3612. if disease > 0 {
  3613. diseases = append(diseases, disease)
  3614. }
  3615. }
  3616. }
  3617. }
  3618. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3619. diagnose := patientBody["diagnose"].(string)
  3620. patient.Diagnose = diagnose
  3621. }
  3622. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3623. remark := patientBody["remark"].(string)
  3624. patient.Remark = remark
  3625. }
  3626. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3627. sch_remark := patientBody["sch_remark"].(string)
  3628. patient.SchRemark = sch_remark
  3629. }
  3630. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3631. patient_complains := patientBody["patient_complains"].(string)
  3632. patient.PatientComplains = patient_complains
  3633. }
  3634. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3635. present_history := patientBody["present_history"].(string)
  3636. patient.PresentHistory = present_history
  3637. }
  3638. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3639. past_history := patientBody["past_history"].(string)
  3640. patient.PastHistory = past_history
  3641. }
  3642. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3643. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3644. patient.Temperature = temperature
  3645. }
  3646. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3647. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3648. patient.Pulse = pulse
  3649. }
  3650. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3651. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3652. patient.Respiratory = respiratory
  3653. }
  3654. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3655. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3656. patient.SBP = sbp
  3657. }
  3658. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3659. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3660. patient.DBP = dbp
  3661. }
  3662. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3663. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3664. patient.DialysisAge = dialysis_age
  3665. }
  3666. fmt.Println(patient.DialysisAge)
  3667. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3668. first_treatment_date := patientBody["first_treatment_date"].(string)
  3669. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3670. if err == nil {
  3671. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3672. }
  3673. }
  3674. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3675. expense_kind := int64(patientBody["expense_kind"].(float64))
  3676. patient.ExpenseKind = expense_kind
  3677. }
  3678. fmt.Println(patient.ExpenseKind)
  3679. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3680. tell_phone := patientBody["tell_phone"].(string)
  3681. patient.TellPhone = tell_phone
  3682. }
  3683. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3684. contact_name := patientBody["contact_name"].(string)
  3685. patient.ContactName = contact_name
  3686. }
  3687. return
  3688. }
  3689. func (c *PatientApiController) GetPatientsByKeyWord() {
  3690. keyWord := c.GetString("keyword")
  3691. adminUserInfo := c.GetAdminUserInfo()
  3692. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3693. if err != nil {
  3694. utils.ErrorLog(err.Error())
  3695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3696. return
  3697. }
  3698. c.ServeSuccessJSON(map[string]interface{}{
  3699. "patient": patient,
  3700. })
  3701. }
  3702. func (c *PatientApiController) QueryPatientById() {
  3703. id, _ := c.GetInt64("id")
  3704. fmt.Println(id)
  3705. patientInfo := service.QueryPatientById(id)
  3706. c.ServeSuccessJSON(map[string]interface{}{
  3707. "patient": patientInfo,
  3708. })
  3709. return
  3710. }
  3711. func (c *PatientApiController) GetRemindPatientList() {
  3712. page, _ := c.GetInt64("page", 1)
  3713. limit, _ := c.GetInt64("limit", 10)
  3714. adminUserInfo := c.GetAdminUserInfo()
  3715. total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  3716. if err != nil {
  3717. utils.ErrorLog(err.Error())
  3718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3719. return
  3720. }
  3721. c.ServeSuccessJSON(map[string]interface{}{
  3722. "total": total,
  3723. "patients": patients,
  3724. })
  3725. }
  3726. func (c *PatientApiController) PostIsOpenRemind() {
  3727. patient_id, _ := c.GetInt64("id", 1)
  3728. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  3729. adminUserInfo := c.GetAdminUserInfo()
  3730. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  3731. if err == nil {
  3732. c.ServeSuccessJSON(map[string]interface{}{
  3733. "msg": "成功",
  3734. "is_open_remind": is_open_remind,
  3735. })
  3736. } else if err != nil {
  3737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3738. }
  3739. }
  3740. func (c *PatientApiController) GetPatientScheduleOne() {
  3741. id, _ := c.GetInt64("id")
  3742. //查询该病人是否当天是排班
  3743. nowDateTime := time.Now()
  3744. nowDate := nowDateTime.Format("2006-01-02")
  3745. nowDate += " 00:00:00"
  3746. timeLayout := "2006-01-02"
  3747. loc, _ := time.LoadLocation("Local")
  3748. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  3749. nowdate := theTime.Unix()
  3750. fmt.Println("nowdate", nowdate)
  3751. adminUser := c.GetAdminUserInfo()
  3752. orgId := adminUser.CurrentOrgId
  3753. fmt.Println("orgid", orgId)
  3754. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  3755. if err != nil {
  3756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3757. return
  3758. }
  3759. c.ServeSuccessJSON(map[string]interface{}{
  3760. "scheduls": scheduls,
  3761. })
  3762. }
  3763. func (c *PatientApiController) ExportPatients() {
  3764. dataBody := make(map[string]interface{}, 0)
  3765. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  3766. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  3767. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  3768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3769. if err != nil {
  3770. utils.ErrorLog(err.Error())
  3771. return
  3772. }
  3773. utils.ErrorLog("%v", dataBody)
  3774. export_time := time.Now().Unix()
  3775. var patients []*models.Patients
  3776. var total_patients []interface{}
  3777. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  3778. tempPatients := dataBody["patients"].([]interface{})
  3779. total_patients = tempPatients
  3780. for index, patientMap := range tempPatients {
  3781. patientNameM := patientMap.(map[string]interface{})
  3782. var patient models.Patients
  3783. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  3784. utils.ErrorLog("name")
  3785. return
  3786. }
  3787. name, _ := patientNameM["name"].(string)
  3788. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3789. err_log := models.ExportErrLog{
  3790. LogType: 1,
  3791. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3792. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  3793. Status: 1,
  3794. CreateTime: time.Now().Unix(),
  3795. UpdateTime: time.Now().Unix(),
  3796. ExportTime: export_time,
  3797. }
  3798. service.CreateExportErrLog(&err_log)
  3799. continue
  3800. }
  3801. patient.Name = name
  3802. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  3803. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  3804. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  3805. err_log := models.ExportErrLog{
  3806. LogType: 1,
  3807. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3808. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  3809. Status: 1,
  3810. CreateTime: time.Now().Unix(),
  3811. UpdateTime: time.Now().Unix(),
  3812. ExportTime: export_time,
  3813. }
  3814. service.CreateExportErrLog(&err_log)
  3815. continue
  3816. } else {
  3817. patient.Gender = gender
  3818. }
  3819. }
  3820. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  3821. phone, _ := patientNameM["phone"].(string)
  3822. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  3823. if len(phone) == 0 {
  3824. err_log := models.ExportErrLog{
  3825. LogType: 1,
  3826. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3827. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  3828. Status: 1,
  3829. CreateTime: time.Now().Unix(),
  3830. UpdateTime: time.Now().Unix(),
  3831. ExportTime: export_time,
  3832. }
  3833. service.CreateExportErrLog(&err_log)
  3834. continue
  3835. } else {
  3836. err_log := models.ExportErrLog{
  3837. LogType: 1,
  3838. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3839. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  3840. Status: 1,
  3841. CreateTime: time.Now().Unix(),
  3842. UpdateTime: time.Now().Unix(),
  3843. ExportTime: export_time,
  3844. }
  3845. service.CreateExportErrLog(&err_log)
  3846. continue
  3847. }
  3848. } else {
  3849. //var tempPatient *models.Patients
  3850. //for _, item := range all_patient {
  3851. // if item.Phone == phone {
  3852. // tempPatient = item
  3853. // }
  3854. //}
  3855. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  3856. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  3857. if count >= 1 {
  3858. err_log := models.ExportErrLog{
  3859. LogType: 1,
  3860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3861. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3862. Status: 1,
  3863. CreateTime: time.Now().Unix(),
  3864. UpdateTime: time.Now().Unix(),
  3865. ExportTime: export_time,
  3866. }
  3867. service.CreateExportErrLog(&err_log)
  3868. continue
  3869. }
  3870. patient.Phone = phone
  3871. }
  3872. }
  3873. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3874. id_card_no, _ := patientNameM["id_card_no"].(string)
  3875. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3876. if len(id_card_no) == 0 {
  3877. err_log := models.ExportErrLog{
  3878. LogType: 1,
  3879. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3880. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3881. Status: 1,
  3882. CreateTime: time.Now().Unix(),
  3883. UpdateTime: time.Now().Unix(),
  3884. ExportTime: export_time,
  3885. }
  3886. service.CreateExportErrLog(&err_log)
  3887. continue
  3888. } else {
  3889. err_log := models.ExportErrLog{
  3890. LogType: 1,
  3891. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3892. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3893. Status: 1,
  3894. CreateTime: time.Now().Unix(),
  3895. UpdateTime: time.Now().Unix(),
  3896. ExportTime: export_time,
  3897. }
  3898. service.CreateExportErrLog(&err_log)
  3899. continue
  3900. }
  3901. } else {
  3902. //var tempPatient *models.Patients
  3903. //for _, item := range all_patient {
  3904. // if item.IdCardNo == id_card_no {
  3905. // tempPatient = item
  3906. // }
  3907. //}
  3908. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3909. if count >= 1 {
  3910. //if tempPatient != nil && tempPatient.ID > 0 {
  3911. err_log := models.ExportErrLog{
  3912. LogType: 1,
  3913. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3914. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3915. Status: 1,
  3916. CreateTime: time.Now().Unix(),
  3917. UpdateTime: time.Now().Unix(),
  3918. ExportTime: export_time,
  3919. }
  3920. service.CreateExportErrLog(&err_log)
  3921. continue
  3922. }
  3923. //}
  3924. patient.IdCardNo = id_card_no
  3925. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3926. if GetBirthDay(id_card_no) == nil {
  3927. patient.Birthday = 0
  3928. } else {
  3929. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3930. }
  3931. }
  3932. }
  3933. fmt.Println("111112222")
  3934. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3935. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3936. timeLayout := "2006/01/02"
  3937. loc, _ := time.LoadLocation("Local")
  3938. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3939. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3940. if len(first_treatment_date) == 0 {
  3941. err_log := models.ExportErrLog{
  3942. LogType: 1,
  3943. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3944. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3945. Status: 1,
  3946. CreateTime: time.Now().Unix(),
  3947. UpdateTime: time.Now().Unix(),
  3948. ExportTime: export_time,
  3949. }
  3950. service.CreateExportErrLog(&err_log)
  3951. continue
  3952. } else {
  3953. err_log := models.ExportErrLog{
  3954. LogType: 1,
  3955. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3956. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3957. Status: 1,
  3958. CreateTime: time.Now().Unix(),
  3959. UpdateTime: time.Now().Unix(),
  3960. ExportTime: export_time,
  3961. }
  3962. service.CreateExportErrLog(&err_log)
  3963. continue
  3964. }
  3965. } else {
  3966. if len(first_treatment_date) == 0 {
  3967. err_log := models.ExportErrLog{
  3968. LogType: 1,
  3969. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3970. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3971. Status: 1,
  3972. CreateTime: time.Now().Unix(),
  3973. UpdateTime: time.Now().Unix(),
  3974. ExportTime: export_time,
  3975. }
  3976. service.CreateExportErrLog(&err_log)
  3977. continue
  3978. } else {
  3979. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3980. err_log := models.ExportErrLog{
  3981. LogType: 1,
  3982. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3983. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3984. Status: 1,
  3985. CreateTime: time.Now().Unix(),
  3986. UpdateTime: time.Now().Unix(),
  3987. ExportTime: export_time,
  3988. }
  3989. service.CreateExportErrLog(&err_log)
  3990. continue
  3991. } else {
  3992. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3993. }
  3994. }
  3995. }
  3996. }
  3997. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3998. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3999. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4000. err_log := models.ExportErrLog{
  4001. LogType: 1,
  4002. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4003. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4004. Status: 1,
  4005. CreateTime: time.Now().Unix(),
  4006. UpdateTime: time.Now().Unix(),
  4007. ExportTime: export_time,
  4008. }
  4009. service.CreateExportErrLog(&err_log)
  4010. continue
  4011. } else if source == 3 {
  4012. err_log := models.ExportErrLog{
  4013. LogType: 1,
  4014. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4015. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4016. Status: 1,
  4017. CreateTime: time.Now().Unix(),
  4018. UpdateTime: time.Now().Unix(),
  4019. ExportTime: export_time,
  4020. }
  4021. service.CreateExportErrLog(&err_log)
  4022. continue
  4023. } else {
  4024. patient.Source = source
  4025. }
  4026. }
  4027. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4028. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4029. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4030. err_log := models.ExportErrLog{
  4031. LogType: 1,
  4032. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4033. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4034. Status: 1,
  4035. CreateTime: time.Now().Unix(),
  4036. UpdateTime: time.Now().Unix(),
  4037. ExportTime: export_time,
  4038. }
  4039. service.CreateExportErrLog(&err_log)
  4040. continue
  4041. } else if lapseto == 3 {
  4042. err_log := models.ExportErrLog{
  4043. LogType: 1,
  4044. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4045. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4046. Status: 1,
  4047. CreateTime: time.Now().Unix(),
  4048. UpdateTime: time.Now().Unix(),
  4049. ExportTime: export_time,
  4050. }
  4051. service.CreateExportErrLog(&err_log)
  4052. continue
  4053. } else {
  4054. patient.Lapseto = lapseto
  4055. }
  4056. }
  4057. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4058. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4059. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4060. err_log := models.ExportErrLog{
  4061. LogType: 1,
  4062. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4063. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4064. Status: 1,
  4065. CreateTime: time.Now().Unix(),
  4066. UpdateTime: time.Now().Unix(),
  4067. ExportTime: export_time,
  4068. }
  4069. service.CreateExportErrLog(&err_log)
  4070. continue
  4071. } else if is_infectious == 3 {
  4072. err_log := models.ExportErrLog{
  4073. LogType: 1,
  4074. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4075. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4076. Status: 1,
  4077. CreateTime: time.Now().Unix(),
  4078. UpdateTime: time.Now().Unix(),
  4079. ExportTime: export_time,
  4080. }
  4081. service.CreateExportErrLog(&err_log)
  4082. continue
  4083. } else {
  4084. patient.IsInfectious = is_infectious
  4085. }
  4086. }
  4087. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4088. var contagions []int64
  4089. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4090. if len(thisContagions) > 0 {
  4091. for _, item := range thisContagions {
  4092. if reflect.TypeOf(item).String() != "float64" {
  4093. continue
  4094. }
  4095. contagion := int64(item.(float64))
  4096. if contagion > 0 {
  4097. contagions = append(contagions, contagion)
  4098. }
  4099. }
  4100. }
  4101. patient.ContagionIds = contagions
  4102. }
  4103. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4104. diagnose, _ := patientNameM["diagnose"].(string)
  4105. patient.Diagnose = diagnose
  4106. }
  4107. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4108. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4109. var tempPatient *models.Patients
  4110. for _, item := range all_patient {
  4111. if item.DialysisNo == dialysis_no {
  4112. tempPatient = item
  4113. }
  4114. }
  4115. if tempPatient != nil && tempPatient.ID > 0 {
  4116. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4117. } else {
  4118. patient.DialysisNo = dialysis_no
  4119. }
  4120. }
  4121. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4122. height, _ := patientNameM["height"].(string)
  4123. heights, _ := strconv.ParseFloat(height, 64)
  4124. patient.Height = int64(heights)
  4125. }
  4126. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4127. home_address, _ := patientNameM["home_address"].(string)
  4128. patient.HomeAddress = home_address
  4129. }
  4130. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  4131. dry_weight, _ := patientNameM["dry_weight"].(string)
  4132. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  4133. patient.DryWeight = dry_weights
  4134. }
  4135. patient.CreatedTime = time.Now().Unix()
  4136. patient.UpdatedTime = time.Now().Unix()
  4137. patient.Status = 1
  4138. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  4139. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  4140. patient.IsExcelExport = 1
  4141. patient.PatientType = 1
  4142. patients = append(patients, &patient)
  4143. }
  4144. }
  4145. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4146. if len(patients) > 0 {
  4147. for _, item := range patients {
  4148. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  4149. }
  4150. log := models.ExportLog{
  4151. LogType: 1,
  4152. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4153. TotalNum: int64(len(total_patients)),
  4154. FailNum: int64(len(errLogs)),
  4155. SuccessNum: int64(len(patients)),
  4156. CreateTime: time.Now().Unix(),
  4157. UpdateTime: time.Now().Unix(),
  4158. ExportTime: export_time,
  4159. Status: 1,
  4160. }
  4161. service.CreateExportLog(&log)
  4162. c.ServeSuccessJSON(map[string]interface{}{
  4163. "msg": "导入成功",
  4164. "total_num": len(total_patients),
  4165. "success_num": len(patients),
  4166. "fail_num": int64(len(errLogs)),
  4167. })
  4168. } else {
  4169. log := models.ExportLog{
  4170. LogType: 1,
  4171. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4172. TotalNum: int64(len(total_patients)),
  4173. FailNum: int64(len(errLogs)),
  4174. SuccessNum: int64(len(patients)),
  4175. CreateTime: time.Now().Unix(),
  4176. UpdateTime: time.Now().Unix(),
  4177. ExportTime: export_time,
  4178. Status: 1,
  4179. }
  4180. service.CreateExportLog(&log)
  4181. c.ServeSuccessJSON(map[string]interface{}{
  4182. "msg": "导入成功",
  4183. "total_num": len(total_patients),
  4184. "success_num": len(patients),
  4185. "fail_num": int64(len(errLogs)),
  4186. })
  4187. }
  4188. }
  4189. func GetBirthDay(IDCardNo string) *time.Time {
  4190. dayStr := IDCardNo[6:14]
  4191. birthDay, err := time.Parse("20060102", dayStr)
  4192. if err != nil {
  4193. fmt.Println(err)
  4194. return nil
  4195. }
  4196. return &birthDay
  4197. }
  4198. func IsIdCard(id string) (res bool) {
  4199. id = strings.ToUpper(id)
  4200. if len(id) != 15 && len(id) != 18 {
  4201. fmt.Println("1111111")
  4202. return false
  4203. }
  4204. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  4205. if !r.MatchString(id) {
  4206. fmt.Println("222222")
  4207. return false
  4208. }
  4209. if len(id) == 15 {
  4210. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  4211. if tm2.Unix() == 0 {
  4212. fmt.Println("44444443333")
  4213. return false
  4214. }
  4215. return true
  4216. } else {
  4217. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  4218. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  4219. fmt.Println(tm2.Unix())
  4220. if tm2.Unix() == 0 {
  4221. fmt.Println("44445555555")
  4222. return false
  4223. }
  4224. //检验18位身份证的校验码是否正确。
  4225. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  4226. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  4227. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  4228. sign := 0
  4229. for k, v := range arr_int {
  4230. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  4231. sign += int_temp * v
  4232. }
  4233. n := sign % 11
  4234. val_num := arr_ch[n]
  4235. if val_num != string([]byte(id)[17:18]) {
  4236. fmt.Println("5556666666")
  4237. return false
  4238. }
  4239. return true
  4240. }
  4241. }
  4242. func (c *PatientApiController) SaveEditAdvices() {
  4243. adminInfo := c.GetAdminUserInfo()
  4244. orgid := adminInfo.CurrentOrgId
  4245. startTime := c.GetString("start_time")
  4246. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  4247. groupno, _ := c.GetInt64("groupno")
  4248. fmt.Println("组", groupno)
  4249. date, _ := c.GetInt64("date")
  4250. fmt.Println("date", date)
  4251. patient_id, _ := c.GetInt64("patient_id")
  4252. fmt.Println("paitent_id", patient_id)
  4253. advice := models.XtDoctorAdvice{
  4254. StartTime: theTime.Unix(),
  4255. }
  4256. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  4257. if err != nil {
  4258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4259. return
  4260. }
  4261. c.ServeSuccessJSON(map[string]interface{}{
  4262. "advice": advice,
  4263. })
  4264. }
  4265. func (c *PatientApiController) GetMaxDialysisNo() {
  4266. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  4267. c.ServeSuccessJSON(map[string]interface{}{
  4268. "dialysis_no": dialysisNo,
  4269. })
  4270. }
  4271. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  4272. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  4273. var tempPatient *models.Patients
  4274. for _, item := range patients {
  4275. if item.DialysisNo == dialysisNo2 {
  4276. tempPatient = item
  4277. }
  4278. }
  4279. if tempPatient == nil || tempPatient.ID == 0 {
  4280. return dialysisNo2
  4281. }
  4282. return GenerateDialysisNoTwo(patients)
  4283. }