his_api_controller.go 178KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  70. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  71. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  72. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  73. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  74. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  75. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  76. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  77. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  78. }
  79. func (c *HisApiController) GetHisUnChargePatientList() {
  80. record_date := c.GetString("record_date")
  81. timeLayout := "2006-01-02"
  82. loc, _ := time.LoadLocation("Local")
  83. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  84. if err != nil {
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. recordDateTime := theTime.Unix()
  89. adminInfo := c.GetAdminUserInfo()
  90. var tempPatients []*service.NewTempPatients
  91. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  92. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  93. var patients []*service.NewTempPatients
  94. var patients_two []*service.NewTempPatients
  95. for _, item := range tempPatients {
  96. //过滤掉没挂号的和没开处方的
  97. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  98. patients = append(patients, item)
  99. }
  100. //过滤掉没挂号的
  101. if len(item.HisPatient) > 0 {
  102. patients_two = append(patients_two, item)
  103. }
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "list": patients,
  107. "list_two": patients_two,
  108. })
  109. }
  110. func (c *HisApiController) GetPrivateExpensesOrder() {
  111. //id, _ := c.GetInt64("id")
  112. //record_time := c.GetString("record_time")
  113. order_id, _ := c.GetInt64("order_id")
  114. admin_user_id, _ := c.GetInt64("admin_user_id")
  115. //timeLayout := "2006-01-02"
  116. //loc, _ := time.LoadLocation("Local")
  117. //
  118. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  119. //if err != nil {
  120. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. // return
  122. //}
  123. //recordDateTime := theTime.Unix()
  124. adminUser := c.GetAdminUserInfo()
  125. order, _ := service.GetHisOrderByID(order_id)
  126. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  127. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  128. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  129. //var config []*models.HisXtDiagnoseConfig
  130. var name string
  131. for _, item := range diagnosis_ids {
  132. id, _ := strconv.ParseInt(item, 10, 64)
  133. diagnosisConfig, _ := service.FindDiagnoseById(id)
  134. if len(name) == 0 {
  135. name = diagnosisConfig.ClassName
  136. } else {
  137. name = name + "," + diagnosisConfig.ClassName
  138. }
  139. }
  140. decimal.DivisionPrecision = 2
  141. for _, item := range orderInfos {
  142. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  143. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  144. item.MedChrgitmType = "09"
  145. }
  146. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  147. if item.HisPrescriptionProject.Type == 2 {
  148. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  149. case 1:
  150. item.MedChrgitmType = "14"
  151. break
  152. case 2:
  153. item.MedChrgitmType = "05"
  154. break
  155. case 3:
  156. item.MedChrgitmType = "04"
  157. break
  158. case 4:
  159. item.MedChrgitmType = "14"
  160. break
  161. case 5:
  162. item.MedChrgitmType = "08"
  163. break
  164. case 6:
  165. item.MedChrgitmType = "14"
  166. break
  167. case 7:
  168. item.MedChrgitmType = "14"
  169. break
  170. case 8:
  171. item.MedChrgitmType = "03"
  172. break
  173. case 9:
  174. item.MedChrgitmType = "14"
  175. break
  176. }
  177. } else if item.HisPrescriptionProject.Type == 3 {
  178. item.MedChrgitmType = "08"
  179. }
  180. }
  181. }
  182. order.PsnCashPay = order.MedfeeSumamt
  183. //var user_name string
  184. //role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  185. //if role.ID == 0 {
  186. // user_name = "管理员"
  187. //} else {
  188. // user_name = role.UserName
  189. //}
  190. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  191. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  192. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  193. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  194. c.ServeSuccessJSON(map[string]interface{}{
  195. "org_name": org.OrgName,
  196. "name": patient.Name,
  197. "order_infos": orderInfos,
  198. "number": order.MdtrtId,
  199. "date": order.SettleAccountsDate,
  200. "charge_admin": charge_admin,
  201. "printor_admin": printor_admin,
  202. "info": order,
  203. })
  204. }
  205. func (c *HisApiController) RefudDetail() {
  206. order_id, _ := c.GetInt64("order_id")
  207. order, _ := service.GetHisOrderByID(order_id)
  208. adminUser := c.GetAdminUserInfo()
  209. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "msg": "撤销成功",
  212. })
  213. }
  214. func (c *HisApiController) Sscard() {
  215. //r := CardInit()
  216. //if r == 0 {
  217. // GetBaseInfo()
  218. //}
  219. //c.ServeSuccessJSON(map[string]interface{}{
  220. // "list": "11",
  221. //})
  222. }
  223. func GetBaseInfo() error {
  224. //handle := syscall.MustLoadDLL("SSCard.dll")
  225. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  226. //
  227. //str := make([]byte, 256)
  228. //str1 := make([]byte, 256)
  229. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  230. //if ferr != nil {
  231. // fmt.Println("ReadCardBas 报错", ferr.Error())
  232. // return ferr
  233. //}
  234. //
  235. //fmt.Println(string(str))
  236. //
  237. //fmt.Println(r)
  238. return nil
  239. }
  240. func CardInit() int {
  241. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  242. //add := DllTestDef.MustFindProc("Init")
  243. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  244. //if err != nil {
  245. // fmt.Println("SSCard的运算结果为:", ret)
  246. //}
  247. //result := int(ret)
  248. return 0
  249. }
  250. func IntPtr(n int) uintptr {
  251. return uintptr(n)
  252. }
  253. func StrPtr(s string) uintptr {
  254. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  255. }
  256. func (c *HisApiController) GetHisPatientList() {
  257. //types, _ := c.GetInt64("type", 0)
  258. record_date := c.GetString("record_date")
  259. sch_type, _ := c.GetInt64("sch_type")
  260. timeLayout := "2006-01-02"
  261. loc, _ := time.LoadLocation("Local")
  262. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  263. if err != nil {
  264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  265. return
  266. }
  267. recordDateTime := theTime.Unix()
  268. adminInfo := c.GetAdminUserInfo()
  269. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  270. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  271. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  272. //获取当前用户的信息
  273. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  274. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  275. //获取所有科室信息
  276. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "list": patients,
  279. "list_two": patients_two,
  280. "info": adminUserInfo,
  281. "doctors": doctors,
  282. "department": department,
  283. })
  284. }
  285. func (c *HisApiController) GetHisPatientInfo() {
  286. patient_id, _ := c.GetInt64("patient_id")
  287. his_patient_id, _ := c.GetInt64("his_patient_id")
  288. record_date := c.GetString("record_date")
  289. number := c.GetString("number")
  290. //start_time := c.GetString("start_time")
  291. //end_time := c.GetString("end_time")
  292. p_type, _ := c.GetInt64("p_type")
  293. timeLayout := "2006-01-02"
  294. loc, _ := time.LoadLocation("Local")
  295. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  296. if err != nil {
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  298. return
  299. }
  300. recordDateTime := theTime.Unix()
  301. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  302. //if err != nil {
  303. //
  304. //}
  305. //startRecordDateTime := startTime.Unix()
  306. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  307. //if err != nil {
  308. //
  309. //}
  310. //endRecordDateTime := endTime.Unix()
  311. admin := c.GetAdminUserInfo()
  312. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  313. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  314. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  315. var prescriptions []*models.HisPrescription
  316. var last_prescriptions []*models.HisPrescription
  317. var sch_prescriptions []*models.HisPrescriptionInfoTemplate
  318. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  319. if p_type == 1 { //住院
  320. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  321. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  322. } else { //门诊
  323. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  324. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  325. }
  326. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  327. if sch.ID > 0 {
  328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  329. sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  330. }
  331. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  332. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  333. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  334. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  335. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  336. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  337. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  338. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  339. //获取所有科室信息
  340. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  341. c.ServeSuccessJSON(map[string]interface{}{
  342. "his_info": his_patient_info,
  343. "xt_info": xt_patient_info,
  344. "prescription": prescriptions,
  345. "case_history": case_history,
  346. "info": patientPrescriptionInfo,
  347. //"month_prescriptions": monthPrescriptions,
  348. "order": order,
  349. "doctors": doctors,
  350. "department": department,
  351. "sch_prescriptions": sch_prescriptions,
  352. "last_prescriptions": last_prescriptions,
  353. "schedule": sch,
  354. "count": count,
  355. "drugStockConfig": drugStockConfig,
  356. "last_info": lastPatientPrescriptionInfo,
  357. })
  358. return
  359. }
  360. func (c *HisApiController) GetHisPrescriptionConfig() {
  361. adminInfo := c.GetAdminUserInfo()
  362. //获取医嘱模版
  363. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  364. //获取所有基础药
  365. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  366. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  367. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  368. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  369. //获取所有科室信息
  370. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  371. //获取诊断信息
  372. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  373. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  374. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  375. c.ServeSuccessJSON(map[string]interface{}{
  376. "drugs": drugs,
  377. "advices_template": advices,
  378. "drugways": drugways,
  379. "efs": efs,
  380. "doctors": doctors,
  381. "department": department,
  382. "sick": sick,
  383. "additions": additions,
  384. "diagnose": diagnose,
  385. })
  386. }
  387. func (c *HisApiController) CreateHisPrescription() {
  388. record_date := c.GetString("record_date")
  389. patient_id, _ := c.GetInt64("patient_id")
  390. reg_type, _ := c.GetInt64("reg_type")
  391. diagnose := c.GetString("diagnose")
  392. sick_type, _ := c.GetInt64("sick_type")
  393. sick_history := c.GetString("sick_history")
  394. doctor_id, _ := c.GetInt64("doctor", 0)
  395. department, _ := c.GetInt64("department", 0)
  396. his_patient_id, _ := c.GetInt64("his_patient_id")
  397. p_type, _ := c.GetInt64("p_type")
  398. dataBody := make(map[string]interface{}, 0)
  399. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  400. if err != nil {
  401. utils.ErrorLog(err.Error())
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  403. return
  404. }
  405. timeLayout := "2006-01-02"
  406. loc, _ := time.LoadLocation("Local")
  407. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  408. if err != nil {
  409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  410. return
  411. }
  412. adminInfo := c.GetAdminUserInfo()
  413. recordDateTime := theTime.Unix()
  414. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  415. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  416. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  417. if len(lists) == 1 {
  418. his_patient_id = lists[0].ID
  419. }
  420. }
  421. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  422. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  423. if drugStockConfig.IsOpen == 1 {
  424. //校验库存总量
  425. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  426. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  427. if len(prescriptions) > 0 {
  428. for _, item := range prescriptions {
  429. items := item.(map[string]interface{})
  430. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  431. advices := items["advices"].([]interface{})
  432. if len(advices) > 0 {
  433. for _, advice := range advices {
  434. var drug_id int64
  435. var prescribing_number float64
  436. var prescribingNumberUnit string
  437. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  438. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  439. }
  440. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  441. //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
  442. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  443. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  444. }
  445. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  446. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  447. }
  448. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
  449. if drug.ID == 0 {
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. if prescribingNumberUnit == drug.MinUnit {
  454. if prescribing_number > drug.Total {
  455. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  456. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  457. return
  458. }
  459. } else {
  460. if prescribingNumberUnit == drug.MaxUnit {
  461. num := prescribing_number * float64(drug.MinNumber)
  462. if num > drug.Total {
  463. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  464. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  465. return
  466. }
  467. }
  468. }
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. if stockConfig.IsOpen == 1 {
  477. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  478. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  479. if len(prescriptions) > 0 {
  480. for _, item := range prescriptions {
  481. items := item.(map[string]interface{})
  482. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  483. projects := items["project"].([]interface{})
  484. if len(projects) > 0 {
  485. for _, project := range projects {
  486. var project_id int64
  487. var project_type int64
  488. var totals float64
  489. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  490. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  491. }
  492. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  493. project_type = int64(project.(map[string]interface{})["type"].(float64))
  494. }
  495. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  496. total, _ := project.(map[string]interface{})["total"].(string)
  497. totals, _ = strconv.ParseFloat(total, 64)
  498. }
  499. if project_type == 3 {
  500. good, _ := service.FindGoodInfoByIdTwo(project_id)
  501. if good.ID == 0 {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. if totals > good.Total {
  506. c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
  507. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  508. return
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. }
  518. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  519. var hpInfo models.HisPrescriptionInfo
  520. if info.ID == 0 {
  521. var randNum int
  522. randNum = rand.Intn(10000) + 1000
  523. timestamp := time.Now().Unix()
  524. tempTime := time.Unix(timestamp, 0)
  525. timeFormat := tempTime.Format("20060102150405")
  526. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  527. hpInfo = models.HisPrescriptionInfo{
  528. HisPatientId: his_patient_id,
  529. UserOrgId: adminInfo.CurrentOrgId,
  530. RecordDate: theTime.Unix(),
  531. PatientId: patient_id,
  532. Status: 1,
  533. Ctime: time.Now().Unix(),
  534. Mtime: time.Now().Unix(),
  535. Creator: adminInfo.AdminUser.Id,
  536. Modifier: adminInfo.AdminUser.Id,
  537. Diagnosis: diagnose,
  538. SickHistory: sick_history,
  539. Departments: department,
  540. RegisterType: reg_type,
  541. PrescriptionNumber: p_number,
  542. PrescriptionStatus: 1,
  543. Doctor: role.UserName,
  544. DoctorId: doctor_id,
  545. SickType: sick_type,
  546. PType: p_type,
  547. }
  548. service.SavePatientPrescriptionInfo(hpInfo)
  549. } else {
  550. hpInfo = models.HisPrescriptionInfo{
  551. ID: info.ID,
  552. UserOrgId: adminInfo.CurrentOrgId,
  553. RecordDate: info.RecordDate,
  554. PatientId: info.PatientId,
  555. Status: 1,
  556. Ctime: info.Ctime,
  557. Mtime: time.Now().Unix(),
  558. Creator: info.Creator,
  559. Modifier: adminInfo.AdminUser.Id,
  560. Diagnosis: diagnose,
  561. SickHistory: sick_history,
  562. Departments: department,
  563. RegisterType: reg_type,
  564. PrescriptionNumber: info.PrescriptionNumber,
  565. Doctor: role.UserName,
  566. PrescriptionStatus: info.PrescriptionStatus,
  567. DoctorId: doctor_id,
  568. SickType: sick_type,
  569. PType: info.PType,
  570. HisPatientId: info.HisPatientId,
  571. }
  572. service.SavePatientPrescriptionInfo(hpInfo)
  573. }
  574. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  575. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  576. var tempPrescription *models.HisPrescription
  577. if len(prescriptions) > 0 {
  578. for _, item := range prescriptions {
  579. items := item.(map[string]interface{})
  580. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  581. utils.ErrorLog("id")
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. id := int64(items["id"].(float64))
  586. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  587. tempPrescription = &new_prescription
  588. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  589. utils.ErrorLog("type")
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  591. return
  592. }
  593. types := int64(items["type"].(float64))
  594. if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
  595. utils.ErrorLog("order_status")
  596. }
  597. order_status := int64(items["order_status"].(float64))
  598. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  599. utils.ErrorLog("med_type")
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  601. return
  602. }
  603. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  604. if med_type == "0" {
  605. med_type = "14"
  606. }
  607. if order_status == 0 {
  608. order_status = 1
  609. }
  610. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  611. utils.ErrorLog("pre_time")
  612. }
  613. preTime, _ := items["pre_time"].(string)
  614. timeLayout := "2006-01-02"
  615. loc, _ := time.LoadLocation("Local")
  616. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  617. if err != nil {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. pTime := theTime2.Unix()
  622. ctime := time.Now().Unix()
  623. if tempPrescription.ID == 0 {
  624. prescription := &models.HisPrescription{
  625. ID: 0,
  626. PatientId: patient_id,
  627. UserOrgId: adminInfo.CurrentOrgId,
  628. RecordDate: recordDateTime,
  629. Ctime: ctime,
  630. Mtime: ctime,
  631. Type: types,
  632. Modifier: adminInfo.AdminUser.Id,
  633. Creator: adminInfo.AdminUser.Id,
  634. Status: 1,
  635. Doctor: role.UserName,
  636. HisPatientId: his_patient_id,
  637. OrderStatus: order_status,
  638. BatchNumber: "",
  639. PrescriptionNumber: hpInfo.PrescriptionNumber,
  640. PreTime: pTime,
  641. PType: p_type,
  642. MedType: med_type,
  643. }
  644. tempPrescription = prescription
  645. service.SaveHisPrescription(tempPrescription)
  646. } else {
  647. tempPrescription.ID = id
  648. tempPrescription.Type = types
  649. tempPrescription.Modifier = adminInfo.AdminUser.Id
  650. tempPrescription.Mtime = time.Now().Unix()
  651. tempPrescription.Doctor = role.UserName
  652. tempPrescription.OrderStatus = order_status
  653. tempPrescription.PreTime = pTime
  654. tempPrescription.MedType = med_type
  655. service.SaveHisPrescription(tempPrescription)
  656. }
  657. //service.SaveHisPrescription(prescription)
  658. //更改患者挂号状态
  659. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  660. fmt.Println("更改失败", err2)
  661. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  662. advices := items["advices"].([]interface{})
  663. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  664. groupNo := int64(0)
  665. ctime := time.Now().Unix()
  666. mtime := ctime
  667. if len(advices) > 0 {
  668. for _, advice := range advices {
  669. var s models.HisDoctorAdviceInfo
  670. s.PrescriptionId = tempPrescription.ID
  671. s.AdviceType = 2
  672. s.AdviceDoctor = doctor_id
  673. s.StopState = 2
  674. s.ExecutionState = 2
  675. s.AdviceDate = recordDateTime
  676. s.Status = 1
  677. s.UserOrgId = adminInfo.CurrentOrgId
  678. s.RecordDate = recordDateTime
  679. s.StartTime = tempPrescription.PreTime
  680. s.Groupno = groupNo
  681. s.CreatedTime = ctime
  682. s.UpdatedTime = mtime
  683. s.PatientId = patient_id
  684. s.HisPatientId = his_patient_id
  685. s.StartTime = pTime
  686. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  687. if errcode > 0 {
  688. c.ServeFailJSONWithSGJErrorCode(errcode)
  689. return
  690. }
  691. s.StartTime = pTime
  692. service.CreateHisDoctorAdvice(&s)
  693. var randNum int
  694. randNum = rand.Intn(10000) + 1000
  695. timestamp := time.Now().Unix()
  696. tempTime := time.Unix(timestamp, 0)
  697. timeFormat := tempTime.Format("20060102150405")
  698. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  699. service.CreateHisDoctorAdvice(&s)
  700. }
  701. }
  702. }
  703. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  704. projects := items["project"].([]interface{})
  705. if len(projects) > 0 {
  706. for _, project := range projects {
  707. var p models.HisPrescriptionProject
  708. p.PrescriptionId = tempPrescription.ID
  709. p.Ctime = time.Now().Unix()
  710. p.Mtime = time.Now().Unix()
  711. p.PatientId = patient_id
  712. p.RecordDate = recordDateTime
  713. p.Doctor = doctor_id
  714. p.UserOrgId = adminInfo.CurrentOrgId
  715. p.HisPatientId = his_patient_id
  716. p.Status = 1
  717. p.StartTime = pTime
  718. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  719. if errcode > 0 {
  720. c.ServeFailJSONWithSGJErrorCode(errcode)
  721. return
  722. }
  723. service.CreateHisProjectTwo(&p)
  724. var randNum int
  725. randNum = rand.Intn(10000) + 1000
  726. timestamp := time.Now().Unix()
  727. tempTime := time.Unix(timestamp, 0)
  728. timeFormat := tempTime.Format("20060102150405")
  729. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  730. service.SaveHisProjectTwo(&p)
  731. if p.Type == 3 { //处理透前准备耗材数量数据
  732. consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  733. if consumables.ID > 0 {
  734. consumables.Count = p.Count
  735. service.UpdateConsumables(&consumables)
  736. }
  737. }
  738. }
  739. }
  740. }
  741. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  742. addition := items["addition"].([]interface{})
  743. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  744. ctime := time.Now().Unix()
  745. mtime := ctime
  746. if len(addition) > 0 {
  747. for _, item := range addition {
  748. var s models.HisAdditionalCharge
  749. s.PrescriptionId = tempPrescription.ID
  750. s.Status = 1
  751. s.UserOrgId = adminInfo.CurrentOrgId
  752. s.RecordDate = recordDateTime
  753. s.CreatedTime = ctime
  754. s.UpdatedTime = mtime
  755. s.PatientId = patient_id
  756. s.HisPatientId = his_patient_id
  757. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  758. if errcode > 0 {
  759. c.ServeFailJSONWithSGJErrorCode(errcode)
  760. return
  761. }
  762. service.CreateAdditionalCharge(&s)
  763. var randNum int
  764. randNum = rand.Intn(10000) + 1000
  765. timestamp := time.Now().Unix()
  766. tempTime := time.Unix(timestamp, 0)
  767. timeFormat := tempTime.Format("20060102150405")
  768. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  769. service.CreateAdditionalCharge(&s)
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. if err == nil {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "msg": "保存成功",
  779. })
  780. return
  781. } else {
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  783. return
  784. }
  785. }
  786. func (c *HisApiController) EditHisPrescription() {
  787. record_date := c.GetString("record_date")
  788. patient_id, _ := c.GetInt64("patient_id")
  789. reg_type, _ := c.GetInt64("reg_type")
  790. //diagnose, _ := c.GetInt64("diagnose", 0)
  791. diagnose := c.GetString("diagnose")
  792. sick_type, _ := c.GetInt64("sick_type")
  793. sick_history := c.GetString("sick_history")
  794. doctor_id, _ := c.GetInt64("doctor", 0)
  795. department, _ := c.GetInt64("department", 0)
  796. his_patient_id, _ := c.GetInt64("his_patient_id")
  797. p_type, _ := c.GetInt64("p_type")
  798. dataBody := make(map[string]interface{}, 0)
  799. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  800. if err != nil {
  801. utils.ErrorLog(err.Error())
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  803. return
  804. }
  805. timeLayout := "2006-01-02"
  806. loc, _ := time.LoadLocation("Local")
  807. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  808. if err != nil {
  809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  810. return
  811. }
  812. adminInfo := c.GetAdminUserInfo()
  813. recordDateTime := theTime.Unix()
  814. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  815. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
  816. var hpInfo models.HisPrescriptionInfo
  817. if info.ID == 0 {
  818. var randNum int
  819. randNum = rand.Intn(10000) + 1000
  820. timestamp := time.Now().Unix()
  821. tempTime := time.Unix(timestamp, 0)
  822. timeFormat := tempTime.Format("20060102150405")
  823. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  824. hpInfo = models.HisPrescriptionInfo{
  825. UserOrgId: adminInfo.CurrentOrgId,
  826. RecordDate: theTime.Unix(),
  827. PatientId: patient_id,
  828. Status: 1,
  829. Ctime: time.Now().Unix(),
  830. Mtime: time.Now().Unix(),
  831. Creator: adminInfo.AdminUser.Id,
  832. Modifier: adminInfo.AdminUser.Id,
  833. Diagnosis: diagnose,
  834. SickHistory: sick_history,
  835. Departments: department,
  836. RegisterType: reg_type,
  837. PrescriptionNumber: p_number,
  838. PrescriptionStatus: 1,
  839. Doctor: role.UserName,
  840. DoctorId: doctor_id,
  841. SickType: sick_type,
  842. PType: p_type,
  843. }
  844. service.SavePatientPrescriptionInfo(hpInfo)
  845. } else {
  846. hpInfo = models.HisPrescriptionInfo{
  847. ID: info.ID,
  848. UserOrgId: adminInfo.CurrentOrgId,
  849. RecordDate: info.RecordDate,
  850. PatientId: info.PatientId,
  851. Status: 1,
  852. Ctime: info.Ctime,
  853. Mtime: time.Now().Unix(),
  854. Creator: info.Creator,
  855. Modifier: adminInfo.AdminUser.Id,
  856. Diagnosis: diagnose,
  857. SickHistory: sick_history,
  858. Departments: department,
  859. RegisterType: reg_type,
  860. PrescriptionNumber: info.PrescriptionNumber,
  861. Doctor: role.UserName,
  862. PrescriptionStatus: info.PrescriptionStatus,
  863. DoctorId: doctor_id,
  864. SickType: sick_type,
  865. PType: info.PType,
  866. }
  867. service.SavePatientPrescriptionInfo(hpInfo)
  868. }
  869. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  870. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  871. if len(prescriptions) > 0 {
  872. for _, item := range prescriptions {
  873. items := item.(map[string]interface{})
  874. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  875. utils.ErrorLog("id")
  876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  877. return
  878. }
  879. id := int64(items["id"].(float64))
  880. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  881. utils.ErrorLog("type")
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  883. return
  884. }
  885. types := int64(items["type"].(float64))
  886. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  887. utils.ErrorLog("med_type")
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  889. return
  890. }
  891. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  892. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  893. ctime := time.Now().Unix()
  894. prescription := &models.HisPrescription{
  895. ID: id,
  896. PatientId: patient_id,
  897. UserOrgId: adminInfo.CurrentOrgId,
  898. RecordDate: recordDateTime,
  899. Ctime: ctime,
  900. Mtime: ctime,
  901. Type: types,
  902. Modifier: adminInfo.AdminUser.Id,
  903. Creator: adminInfo.AdminUser.Id,
  904. Status: 1,
  905. Doctor: role.UserName,
  906. HisPatientId: his_patient_id,
  907. OrderStatus: 1,
  908. BatchNumber: "",
  909. PrescriptionNumber: hpInfo.PrescriptionNumber,
  910. PType: hpInfo.PType,
  911. MedType: med_type,
  912. }
  913. if historyPrescription.ID > 0 {
  914. prescription.PreTime = historyPrescription.PreTime
  915. }
  916. service.SaveHisPrescription(prescription)
  917. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  918. advices := items["advices"].([]interface{})
  919. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  920. groupNo := int64(0)
  921. ctime := time.Now().Unix()
  922. mtime := ctime
  923. if len(advices) > 0 {
  924. for _, advice := range advices {
  925. var s models.HisDoctorAdviceInfo
  926. s.PrescriptionId = prescription.ID
  927. s.AdviceType = 2
  928. s.AdviceDoctor = adminInfo.AdminUser.Id
  929. s.StopState = 2
  930. s.ExecutionState = 2
  931. s.AdviceDate = recordDateTime
  932. s.Status = 1
  933. s.UserOrgId = adminInfo.CurrentOrgId
  934. s.RecordDate = recordDateTime
  935. s.StartTime = prescription.PreTime
  936. s.Groupno = groupNo
  937. s.CreatedTime = ctime
  938. s.UpdatedTime = mtime
  939. s.PatientId = patient_id
  940. s.HisPatientId = his_patient_id
  941. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  942. if errcode > 0 {
  943. c.ServeFailJSONWithSGJErrorCode(errcode)
  944. return
  945. }
  946. service.CreateHisDoctorAdvice(&s)
  947. }
  948. }
  949. }
  950. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  951. projects := items["project"].([]interface{})
  952. if len(projects) > 0 {
  953. for _, project := range projects {
  954. var p models.HisPrescriptionProject
  955. p.PrescriptionId = prescription.ID
  956. p.Ctime = time.Now().Unix()
  957. p.Mtime = time.Now().Unix()
  958. p.PatientId = patient_id
  959. p.RecordDate = recordDateTime
  960. p.UserOrgId = adminInfo.CurrentOrgId
  961. p.HisPatientId = his_patient_id
  962. p.Status = 1
  963. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  964. if errcode > 0 {
  965. c.ServeFailJSONWithSGJErrorCode(errcode)
  966. return
  967. }
  968. service.CreateHisProjectTwo(&p)
  969. }
  970. }
  971. }
  972. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  973. addition := items["addition"].([]interface{})
  974. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  975. ctime := time.Now().Unix()
  976. mtime := ctime
  977. if len(addition) > 0 {
  978. for _, item := range addition {
  979. var s models.HisAdditionalCharge
  980. s.PrescriptionId = prescription.ID
  981. s.Status = 1
  982. s.UserOrgId = adminInfo.CurrentOrgId
  983. s.RecordDate = recordDateTime
  984. s.CreatedTime = ctime
  985. s.UpdatedTime = mtime
  986. s.PatientId = patient_id
  987. s.HisPatientId = his_patient_id
  988. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  989. if errcode > 0 {
  990. c.ServeFailJSONWithSGJErrorCode(errcode)
  991. return
  992. }
  993. service.CreateAdditionalCharge(&s)
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. if err == nil {
  1001. c.ServeSuccessJSON(map[string]interface{}{
  1002. "msg": "保存成功",
  1003. })
  1004. return
  1005. } else {
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1007. return
  1008. }
  1009. }
  1010. func (c *HisApiController) DeletePrescription() {
  1011. prescription_id, _ := c.GetInt64("id")
  1012. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1013. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1014. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1015. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1016. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1017. if err == nil {
  1018. if len(projects) > 0 {
  1019. for _, item := range projects {
  1020. if stockConfig.IsOpen == 1 {
  1021. if item.Type == 3 {
  1022. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1023. f_count, _ := strconv.ParseFloat(strconv.FormatInt(item.Count, 10), 64)
  1024. good.Total = good.Total + f_count
  1025. service.UpdateGoodInfo(&good)
  1026. }
  1027. }
  1028. if item.Type == 3 { //处理透前准备耗材数量数据
  1029. consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
  1030. if consumables.ID > 0 {
  1031. consumables.Count = 0
  1032. service.UpdateConsumables(&consumables)
  1033. }
  1034. }
  1035. }
  1036. }
  1037. if drugStockConfig.IsOpen == 1 {
  1038. if len(advices) > 0 {
  1039. for _, item := range advices {
  1040. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1041. if item.PrescribingNumberUnit == drug.MinUnit {
  1042. drug.Total = drug.Total + item.PrescribingNumber
  1043. service.UpdateBaseDrugLib(&drug)
  1044. } else {
  1045. if item.PrescribingNumberUnit == drug.MaxUnit {
  1046. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  1047. drug.Total = drug.Total + item.PrescribingNumber
  1048. service.UpdateBaseDrugLib(&drug)
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. c.ServeSuccessJSON(map[string]interface{}{
  1055. "msg": "删除成功",
  1056. })
  1057. return
  1058. } else {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1060. return
  1061. }
  1062. }
  1063. func (c *HisApiController) DeleteDoctorAdvice() {
  1064. id, _ := c.GetInt64("id")
  1065. advice, _ := service.GetHisDoctorAdvicesById(id)
  1066. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1067. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  1068. if err == nil {
  1069. if drugStockConfig.IsOpen == 1 {
  1070. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  1071. if advice.PrescribingNumberUnit == drug.MinUnit {
  1072. drug.Total = drug.Total + advice.PrescribingNumber
  1073. service.UpdateBaseDrugLib(&drug)
  1074. } else {
  1075. if advice.PrescribingNumberUnit == drug.MaxUnit {
  1076. advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
  1077. drug.Total = drug.Total + advice.PrescribingNumber
  1078. service.UpdateBaseDrugLib(&drug)
  1079. }
  1080. }
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "删除成功",
  1084. })
  1085. return
  1086. } else {
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1088. return
  1089. }
  1090. }
  1091. func (c *HisApiController) DeleteProject() {
  1092. id, _ := c.GetInt64("id")
  1093. adminInfo := c.GetAdminUserInfo()
  1094. project, _ := service.GetHisProjectByID(id)
  1095. var consumable models.DialysisBeforePrepare
  1096. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1097. if project.ID > 0 && project.Type == 3 {
  1098. consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
  1099. }
  1100. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  1101. if err == nil {
  1102. if stockConfig.IsOpen == 1 {
  1103. if project.Type == 3 {
  1104. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1105. f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
  1106. good.Total = good.Total + f_count
  1107. service.UpdateGoodInfo(&good)
  1108. }
  1109. }
  1110. if consumable.ID > 0 {
  1111. consumable.Count = 0
  1112. service.UpdateConsumables(&consumable)
  1113. }
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "msg": "删除成功",
  1116. })
  1117. return
  1118. } else {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1120. return
  1121. }
  1122. }
  1123. func (c *HisApiController) CreateHisAdditionalCharge() {
  1124. his_patient_id, _ := c.GetInt64("his_patient_id")
  1125. patient_id, _ := c.GetInt64("patient_id")
  1126. record_date := c.GetString("record_date")
  1127. timeLayout := "2006-01-02"
  1128. loc, _ := time.LoadLocation("Local")
  1129. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1130. if err != nil {
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1132. return
  1133. }
  1134. adminInfo := c.GetAdminUserInfo()
  1135. recordDateTime := theTime.Unix()
  1136. dataBody := make(map[string]interface{}, 0)
  1137. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1138. if err != nil {
  1139. utils.ErrorLog(err.Error())
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1141. return
  1142. }
  1143. var additions []*models.HisAdditionalCharge
  1144. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  1145. additions, _ := dataBody["addition"].([]interface{})
  1146. if len(additions) > 0 {
  1147. for _, item := range additions {
  1148. items := item.(map[string]interface{})
  1149. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  1150. utils.ErrorLog("item_id")
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. item_id := int64(items["item_id"].(float64))
  1155. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  1156. utils.ErrorLog("item_name")
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. item_name := items["item_name"].(string)
  1161. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1162. utils.ErrorLog("price")
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1167. ctime := time.Now().Unix()
  1168. additional := &models.HisAdditionalCharge{
  1169. PatientId: patient_id,
  1170. HisPatientId: his_patient_id,
  1171. UserOrgId: adminInfo.CurrentOrgId,
  1172. RecordDate: recordDateTime,
  1173. CreatedTime: ctime,
  1174. UpdatedTime: ctime,
  1175. Modifier: adminInfo.AdminUser.Id,
  1176. Creator: adminInfo.AdminUser.Id,
  1177. Price: price,
  1178. ItemName: item_name,
  1179. ItemId: item_id,
  1180. Status: 1,
  1181. }
  1182. additions = append(additions, additional)
  1183. }
  1184. }
  1185. }
  1186. for _, item := range additions {
  1187. service.CreateAddtionalCharge(item)
  1188. }
  1189. c.ServeSuccessJSON(map[string]interface{}{
  1190. "msg": "创建成功",
  1191. })
  1192. }
  1193. func (c *HisApiController) CreateHisPatientCaseHistory() {
  1194. blood_fat := c.GetString("blood_fat")
  1195. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  1196. blood_sugar := c.GetString("blood_sugar")
  1197. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  1198. fmt.Println(bloodsugarfloat)
  1199. chief_conplaint := c.GetString("chief_conplaint")
  1200. dbp := c.GetString("dbp")
  1201. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  1202. delivery_way, _ := c.GetInt64("delivery_way")
  1203. diagnostic := c.GetString("diagnostic")
  1204. family_history := c.GetString("family_history")
  1205. height := c.GetString("height")
  1206. history_of_present_illness := c.GetString("history_of_present_illness")
  1207. is_infect, _ := c.GetInt64("is_infect")
  1208. fmt.Println("is", is_infect)
  1209. past_history := c.GetString("past_history")
  1210. patient_id, _ := c.GetInt64("patient_id")
  1211. his_patient_id, _ := c.GetInt64("his_patient_id")
  1212. fmt.Println("patient_id", patient_id)
  1213. personal_history := c.GetString("personal_history")
  1214. pulse := c.GetString("pulse")
  1215. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  1216. sbp := c.GetString("sbp")
  1217. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  1218. heightfloat, _ := strconv.ParseFloat(height, 64)
  1219. sicktype := c.GetString("sick_type")
  1220. fmt.Println("sicketype", sicktype)
  1221. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  1222. symptom := c.GetString("symptom")
  1223. sick_date := c.GetString("sick_date")
  1224. temperatures := c.GetString("temperature")
  1225. fmt.Println("temperatures", temperatures)
  1226. temperature, _ := strconv.ParseFloat(temperatures, 64)
  1227. record_date := c.GetString("record_date")
  1228. breathing := c.GetString("breathing")
  1229. doctor_advice := c.GetString("doctor_advice")
  1230. remark := c.GetString("remark")
  1231. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  1232. sick, _ := c.GetInt64("sick")
  1233. diagnose, _ := c.GetInt64("diagnose")
  1234. id, _ := c.GetInt64("id")
  1235. timeLayout := "2006-01-02"
  1236. loc, _ := time.LoadLocation("Local")
  1237. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1238. allergic_history := c.GetString("allergic_history")
  1239. if err != nil {
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1241. return
  1242. }
  1243. recordDateTime := theTime.Unix()
  1244. fmt.Println("recordDataTime", recordDateTime)
  1245. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  1246. if err != nil {
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1248. return
  1249. }
  1250. sickTimes := sickTime.Unix()
  1251. ctime := time.Now().Unix()
  1252. caseHistory := models.HisPatientCaseHistory{
  1253. HisPatientId: his_patient_id,
  1254. PatientId: patient_id,
  1255. Temperature: temperature,
  1256. BloodSugar: bloodsugarfloat,
  1257. Pulse: pulsefloat,
  1258. Sbp: sbpfloat,
  1259. Dbp: dbpfloat,
  1260. Height: heightfloat,
  1261. BloodFat: bloodfatfloat,
  1262. SickType: sick_type,
  1263. Symptom: symptom,
  1264. SickDate: sickTimes,
  1265. IsInfect: is_infect,
  1266. HistoryOfPresentIllness: history_of_present_illness,
  1267. PastHistory: past_history,
  1268. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  1269. ChiefConplaint: chief_conplaint,
  1270. PersonalHistory: personal_history,
  1271. FamilyHistory: family_history,
  1272. Diagnostic: diagnostic,
  1273. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1274. Status: 1,
  1275. Ctime: ctime,
  1276. Mtime: ctime,
  1277. RecordDate: recordDateTime,
  1278. DeliveryWay: delivery_way,
  1279. Breathing: breathingfloat,
  1280. DoctorAdvice: doctor_advice,
  1281. Remark: remark,
  1282. Sick: sick,
  1283. Diagnose: diagnose,
  1284. AllergicHistory: allergic_history,
  1285. }
  1286. //查询该患者是否有病历
  1287. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  1288. if errcodes == gorm.ErrRecordNotFound {
  1289. err = service.SaveHisPatientCaseHistory(&caseHistory)
  1290. if err != nil {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1292. return
  1293. }
  1294. c.ServeSuccessJSON(map[string]interface{}{
  1295. "caseHistory": caseHistory,
  1296. })
  1297. return
  1298. } else if errcodes == nil {
  1299. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  1300. if err != nil {
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1302. return
  1303. }
  1304. c.ServeSuccessJSON(map[string]interface{}{
  1305. "caseHistory": caseHistory,
  1306. })
  1307. }
  1308. //查询该患者是否有病历
  1309. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  1310. //if errcode == gorm.ErrRecordNotFound {
  1311. // err = service.SaveHisPatientCaseHistory(caseHistory)
  1312. // if err != nil {
  1313. // c.ServeSuccessJSON(map[string]interface{}{
  1314. // "msg": "保存成功",
  1315. // })
  1316. // }
  1317. //} else if errcode == nil {
  1318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1319. // return
  1320. //}
  1321. }
  1322. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  1323. patient_id, _ := c.GetInt64("patient_id", 0)
  1324. adminUser := c.GetAdminUserInfo()
  1325. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  1326. c.ServeSuccessJSON(map[string]interface{}{
  1327. "list": caseHistorys,
  1328. })
  1329. }
  1330. func (c *HisApiController) GetHisPatientCaseHistory() {
  1331. record_date, _ := c.GetInt64("record_date", 0)
  1332. patient_id, _ := c.GetInt64("patient_id", 0)
  1333. admin := c.GetAdminUserInfo()
  1334. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  1335. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  1336. c.ServeSuccessJSON(map[string]interface{}{
  1337. "info": info,
  1338. "case_history": case_history,
  1339. })
  1340. }
  1341. func (c *HisApiController) CreateCaseHistoryTemplate() {
  1342. template_name := c.GetString("template_name")
  1343. template_remark := c.GetString("template_remark")
  1344. doctor := c.GetAdminUserInfo().AdminUser.Id
  1345. diagnostic := c.GetString("diagnostic")
  1346. chief_conplaint := c.GetString("chief_conplain")
  1347. history_of_present_illness := c.GetString("history_of_present_illness")
  1348. past_history := c.GetString("past_history")
  1349. personal_history := c.GetString("personal_history")
  1350. family_history := c.GetString("family_history")
  1351. user_name := c.GetString("user_name")
  1352. doctor_advice := c.GetString("doctor_advice")
  1353. remark := c.GetString("remark")
  1354. //record_date := c.GetString("record_date")
  1355. //fmt.Println("record_date--------",record_date)
  1356. //timeLayout := "2006-01-02"
  1357. //loc, _ := time.LoadLocation("Local")
  1358. //
  1359. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1360. //if err != nil {
  1361. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. // return
  1363. //}
  1364. //recordDateTime := theTime.Unix()
  1365. ctime := time.Now().Unix()
  1366. template := models.HisCaseHistoryTemplate{
  1367. HistoryOfPresentIllness: history_of_present_illness,
  1368. PastHistory: past_history,
  1369. ChiefConplaint: chief_conplaint,
  1370. PersonalHistory: personal_history,
  1371. FamilyHistory: family_history,
  1372. Diagnostic: diagnostic,
  1373. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1374. Status: 1,
  1375. Ctime: ctime,
  1376. Mtime: ctime,
  1377. RecordDate: time.Now().Unix(),
  1378. TemplateName: template_name,
  1379. TemplateRemark: template_remark,
  1380. Creator: doctor,
  1381. Modifier: doctor,
  1382. UserName: user_name,
  1383. DoctorAdvice: doctor_advice,
  1384. Remark: remark,
  1385. }
  1386. err := service.SaveHisPatientCaseHistoryTemplate(template)
  1387. if err == nil {
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "msg": "保存成功",
  1390. })
  1391. } else {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1393. return
  1394. }
  1395. }
  1396. func (c *HisApiController) GetCaseHistoryTemplate() {
  1397. timeLayout := "2006-01-02"
  1398. loc, _ := time.LoadLocation("Local")
  1399. keyword := c.GetString("keyword")
  1400. start_time := c.GetString("start_time")
  1401. end_time := c.GetString("end_time")
  1402. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1403. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1404. admin := c.GetAdminUserInfo()
  1405. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  1406. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  1407. c.ServeSuccessJSON(map[string]interface{}{
  1408. "template": template,
  1409. //"history": history,
  1410. })
  1411. }
  1412. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1413. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1414. utils.ErrorLog("drug_name")
  1415. return enums.ErrorCodeParamWrong
  1416. }
  1417. adviceName, _ := json["drug_name"].(string)
  1418. if len(adviceName) == 0 {
  1419. utils.ErrorLog("len(advice_name) == 0")
  1420. return enums.ErrorCodeParamWrong
  1421. }
  1422. advice.AdviceName = adviceName
  1423. adviceDesc, _ := json["advice_desc"].(string)
  1424. advice.AdviceDesc = adviceDesc
  1425. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1426. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1427. advice.DrugSpec = drugSpec
  1428. }
  1429. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1430. remark, _ := json["remark"].(string)
  1431. advice.Remark = remark
  1432. }
  1433. if json["id"] == nil {
  1434. advice.DrugId = 0
  1435. } else {
  1436. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1437. drug_id := int64(json["id"].(float64))
  1438. advice.DrugId = drug_id
  1439. }
  1440. }
  1441. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1442. advice_id := int64(json["advice_id"].(float64))
  1443. advice.ID = advice_id
  1444. if advice.ID > 0 {
  1445. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1446. if err == nil {
  1447. if hisAdvice.ID > 0 {
  1448. advice.ExecutionTime = hisAdvice.ExecutionTime
  1449. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1450. advice.ExecutionState = hisAdvice.ExecutionState
  1451. advice.CheckTime = hisAdvice.CheckTime
  1452. advice.Checker = hisAdvice.Checker
  1453. advice.CheckState = hisAdvice.CheckState
  1454. advice.StartTime = hisAdvice.StartTime
  1455. advice.FeedetlSn = hisAdvice.FeedetlSn
  1456. }
  1457. }
  1458. }
  1459. }
  1460. //
  1461. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1462. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1463. // advice.ExecutionTime = execution_time
  1464. //}
  1465. //
  1466. //
  1467. //
  1468. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1469. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1470. // advice.ExecutionStaff = execution_staff
  1471. //}
  1472. //
  1473. //
  1474. //
  1475. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1476. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1477. // advice.ExecutionState = execution_state
  1478. //}
  1479. //
  1480. //
  1481. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1482. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1483. // advice.CheckTime = check_time
  1484. //}
  1485. //
  1486. //
  1487. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1488. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1489. // advice.CheckState = check_state
  1490. //}
  1491. //
  1492. //
  1493. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1494. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1495. // advice.Checker = checker
  1496. //}
  1497. //
  1498. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1499. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1500. // advice.StartTime = start_time
  1501. //}
  1502. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1503. drugSpecUnit, _ := json["min_unit"].(string)
  1504. advice.DrugSpecUnit = drugSpecUnit
  1505. }
  1506. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1507. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1508. advice.SingleDose = singleDose
  1509. }
  1510. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1511. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1512. advice.SingleDoseUnit = singleDoseUnit
  1513. }
  1514. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1515. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1516. advice.PrescribingNumber = prescribingNumber
  1517. }
  1518. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1519. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1520. advice.PrescribingNumberUnit = prescribingNumberUnit
  1521. }
  1522. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1523. deliveryWay, _ := json["delivery_way"].(string)
  1524. advice.DeliveryWay = deliveryWay
  1525. }
  1526. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1527. executionFrequency, _ := json["execution_frequency"].(string)
  1528. advice.ExecutionFrequency = executionFrequency
  1529. }
  1530. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1531. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1532. advice.Price = price
  1533. }
  1534. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1535. med_list_codg, _ := json["medical_insurance_number"].(string)
  1536. advice.MedListCodg = med_list_codg
  1537. }
  1538. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1539. day := int64(json["day"].(float64))
  1540. advice.Day = day
  1541. }
  1542. return 0
  1543. }
  1544. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1545. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1546. id := int64(json["id"].(float64))
  1547. project.ID = id
  1548. historyProject, _ := service.GetHisProjectByID(id)
  1549. project.FeedetlSn = historyProject.FeedetlSn
  1550. }
  1551. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1552. project_id := int64(json["project_id"].(float64))
  1553. project.ProjectId = project_id
  1554. }
  1555. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1556. // price := int64(json["price"].(float64))
  1557. // formatInt_price := strconv.FormatInt(price, 10)
  1558. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1559. // project.Price = float_price
  1560. // }
  1561. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1562. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1563. project.Price = price
  1564. }
  1565. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1566. total, _ := json["total"].(string)
  1567. totals, _ := strconv.ParseInt(total, 10, 64)
  1568. project.Count = totals
  1569. }
  1570. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1571. medical_code, _ := json["medical_code"].(string)
  1572. project.MedListCodg = medical_code
  1573. }
  1574. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1575. single_dose, _ := json["single_dose"].(string)
  1576. project.SingleDose = single_dose
  1577. }
  1578. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1579. delivery_way, _ := json["delivery_way"].(string)
  1580. project.DeliveryWay = delivery_way
  1581. }
  1582. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1583. execution_frequency, _ := json["execution_frequency"].(string)
  1584. project.ExecutionFrequency = execution_frequency
  1585. }
  1586. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1587. remark, _ := json["remark"].(string)
  1588. project.Remark = remark
  1589. }
  1590. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1591. day, _ := json["number_days"].(string)
  1592. project.Day = day
  1593. }
  1594. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1595. unit, _ := json["unit"].(string)
  1596. project.Unit = unit
  1597. }
  1598. return 0
  1599. }
  1600. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1601. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1602. id := int64(json["id"].(float64))
  1603. historyAddtions, _ := service.GetHisAdditionByID(id)
  1604. additionalCharge.ID = id
  1605. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  1606. }
  1607. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1608. item_id := int64(json["item_id"].(float64))
  1609. additionalCharge.ItemId = item_id
  1610. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1611. if config.ID > 0 {
  1612. if len(config.Code) > 0 {
  1613. additionalCharge.MedListCodg = config.Code
  1614. }
  1615. }
  1616. }
  1617. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1618. // price := int64(json["price"].(float64))
  1619. // formatInt_price := strconv.FormatInt(price, 10)
  1620. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1621. // additionalCharge.Price = float_price
  1622. // }
  1623. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1624. // price := int64(json["price"].(float64))
  1625. // formatInt_price := strconv.FormatInt(price, 10)
  1626. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1627. // additionalCharge.Price = float_price
  1628. //}
  1629. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1630. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1631. additionalCharge.Price = price
  1632. }
  1633. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1634. count, _ := json["count"].(string)
  1635. counts, _ := strconv.ParseInt(count, 10, 64)
  1636. additionalCharge.Count = counts
  1637. }
  1638. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1639. item_name, _ := json["item_name"].(string)
  1640. additionalCharge.ItemName = item_name
  1641. }
  1642. return 0
  1643. }
  1644. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1645. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1646. utils.ErrorLog("drug_name")
  1647. return enums.ErrorCodeParamWrong
  1648. }
  1649. adviceName, _ := json["drug_name"].(string)
  1650. if len(adviceName) == 0 {
  1651. utils.ErrorLog("len(advice_name) == 0")
  1652. return enums.ErrorCodeParamWrong
  1653. }
  1654. advice.AdviceName = adviceName
  1655. adviceDesc, _ := json["advice_desc"].(string)
  1656. advice.AdviceDesc = adviceDesc
  1657. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1658. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1659. advice.DrugSpec = drugSpec
  1660. }
  1661. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1662. remark, _ := json["remark"].(string)
  1663. advice.Remark = remark
  1664. }
  1665. if json["id"] == nil {
  1666. advice.DrugId = 0
  1667. } else {
  1668. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1669. drug_id := int64(json["id"].(float64))
  1670. advice.DrugId = drug_id
  1671. }
  1672. }
  1673. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  1674. groupno := int64(json["groupno"].(float64))
  1675. advice.Groupno = groupno
  1676. }
  1677. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1678. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1679. advice.PrescribingNumber = prescribingNumber
  1680. }
  1681. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1682. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1683. advice.PrescribingNumberUnit = prescribingNumberUnit
  1684. }
  1685. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1686. advice_id := int64(json["advice_id"].(float64))
  1687. advice.ID = advice_id
  1688. if advice.ID > 0 {
  1689. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1690. if err == nil {
  1691. if hisAdvice.ID > 0 {
  1692. advice.ExecutionTime = hisAdvice.ExecutionTime
  1693. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1694. advice.ExecutionState = hisAdvice.ExecutionState
  1695. advice.CheckTime = hisAdvice.CheckTime
  1696. advice.Checker = hisAdvice.Checker
  1697. advice.CheckState = hisAdvice.CheckState
  1698. advice.StartTime = hisAdvice.StartTime
  1699. //advice.Groupno = hisAdvice.Groupno
  1700. }
  1701. }
  1702. }
  1703. }
  1704. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  1705. if drugStockConfig.IsOpen == 1 {
  1706. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  1707. if advice.ID == 0 { //医嘱不存在
  1708. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  1709. drug.Total = drug.Total - advice.PrescribingNumber
  1710. service.UpdateBaseDrugLib(&drug)
  1711. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  1712. num := advice.PrescribingNumber * float64(drug.MinNumber)
  1713. drug.Total = drug.Total - num
  1714. service.UpdateBaseDrugLib(&drug)
  1715. }
  1716. } else if advice.ID > 0 { //医嘱存在
  1717. hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  1718. var num float64
  1719. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  1720. if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  1721. if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  1722. num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  1723. drug.Total = drug.Total + num
  1724. service.UpdateBaseDrugLib(&drug)
  1725. } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  1726. num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  1727. drug.Total = drug.Total - num
  1728. service.UpdateBaseDrugLib(&drug)
  1729. }
  1730. } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  1731. num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1732. if num2 > advice.PrescribingNumber {
  1733. num = num2 - advice.PrescribingNumber
  1734. drug.Total = drug.Total + num
  1735. service.UpdateBaseDrugLib(&drug)
  1736. } else if num2 < advice.PrescribingNumber {
  1737. num = advice.PrescribingNumber - num2
  1738. drug.Total = drug.Total - num
  1739. service.UpdateBaseDrugLib(&drug)
  1740. }
  1741. }
  1742. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  1743. if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  1744. num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1745. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1746. if num1 > num2 {
  1747. num = num1 - num2
  1748. drug.Total = drug.Total + num
  1749. service.UpdateBaseDrugLib(&drug)
  1750. } else if num1 < num2 {
  1751. num = num2 - num1
  1752. drug.Total = drug.Total - num
  1753. service.UpdateBaseDrugLib(&drug)
  1754. }
  1755. } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  1756. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1757. //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  1758. if hisAdvice.PrescribingNumber > num2 {
  1759. num = hisAdvice.PrescribingNumber - num2
  1760. drug.Total = drug.Total + num
  1761. service.UpdateBaseDrugLib(&drug)
  1762. } else if num2 < advice.PrescribingNumber {
  1763. num = num2 - hisAdvice.PrescribingNumber
  1764. drug.Total = drug.Total - num
  1765. service.UpdateBaseDrugLib(&drug)
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. //
  1772. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1773. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1774. // advice.ExecutionTime = execution_time
  1775. //}
  1776. //
  1777. //
  1778. //
  1779. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1780. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1781. // advice.ExecutionStaff = execution_staff
  1782. //}
  1783. //
  1784. //
  1785. //
  1786. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1787. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1788. // advice.ExecutionState = execution_state
  1789. //}
  1790. //
  1791. //
  1792. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1793. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1794. // advice.CheckTime = check_time
  1795. //}
  1796. //
  1797. //
  1798. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1799. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1800. // advice.CheckState = check_state
  1801. //}
  1802. //
  1803. //
  1804. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1805. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1806. // advice.Checker = checker
  1807. //}
  1808. //
  1809. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1810. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1811. // advice.StartTime = start_time
  1812. //}
  1813. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1814. drugSpecUnit, _ := json["min_unit"].(string)
  1815. advice.DrugSpecUnit = drugSpecUnit
  1816. }
  1817. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1818. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1819. advice.SingleDose = singleDose
  1820. }
  1821. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1822. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1823. advice.SingleDoseUnit = singleDoseUnit
  1824. }
  1825. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1826. deliveryWay, _ := json["delivery_way"].(string)
  1827. advice.DeliveryWay = deliveryWay
  1828. }
  1829. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1830. executionFrequency, _ := json["execution_frequency"].(string)
  1831. advice.ExecutionFrequency = executionFrequency
  1832. }
  1833. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1834. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1835. advice.Price = price
  1836. }
  1837. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1838. med_list_codg, _ := json["medical_insurance_number"].(string)
  1839. advice.MedListCodg = med_list_codg
  1840. }
  1841. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1842. day := int64(json["day"].(float64))
  1843. advice.Day = day
  1844. }
  1845. return 0
  1846. }
  1847. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1848. project.ExecutionStaff = 0
  1849. project.ExecutionState = 2
  1850. project.ExecutionTime = 0
  1851. project.Checker = 0
  1852. project.CheckState = 2
  1853. project.CheckTime = 0
  1854. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1855. id := int64(json["id"].(float64))
  1856. project.ID = id
  1857. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  1858. project.ExecutionStaff = temp_project.ExecutionStaff
  1859. project.ExecutionState = temp_project.ExecutionState
  1860. project.ExecutionTime = temp_project.ExecutionTime
  1861. project.Checker = temp_project.Checker
  1862. project.CheckState = temp_project.CheckState
  1863. project.CheckTime = temp_project.CheckTime
  1864. }
  1865. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1866. types := int64(json["type"].(float64))
  1867. project.Type = types
  1868. }
  1869. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1870. project_id := int64(json["project_id"].(float64))
  1871. project.ProjectId = project_id
  1872. fmt.Println(project_id)
  1873. fmt.Println(project.ProjectId)
  1874. }
  1875. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1876. // price := int64(json["price"].(float64))
  1877. // formatInt_price := strconv.FormatInt(price, 10)
  1878. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1879. // project.Price = float_price
  1880. // }
  1881. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1882. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1883. project.Price = price
  1884. }
  1885. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1886. total, _ := json["total"].(string)
  1887. totals, _ := strconv.ParseInt(total, 10, 64)
  1888. project.Count = totals
  1889. }
  1890. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1891. medical_code, _ := json["medical_code"].(string)
  1892. project.MedListCodg = medical_code
  1893. }
  1894. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1895. single_dose, _ := json["single_dose"].(string)
  1896. project.SingleDose = single_dose
  1897. }
  1898. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1899. delivery_way, _ := json["delivery_way"].(string)
  1900. project.DeliveryWay = delivery_way
  1901. }
  1902. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1903. execution_frequency, _ := json["execution_frequency"].(string)
  1904. project.ExecutionFrequency = execution_frequency
  1905. }
  1906. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1907. remark, _ := json["remark"].(string)
  1908. project.Remark = remark
  1909. }
  1910. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1911. day, _ := json["number_days"].(string)
  1912. project.Day = day
  1913. }
  1914. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1915. unit, _ := json["unit"].(string)
  1916. project.Unit = unit
  1917. }
  1918. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  1919. if project.ID == 0 {
  1920. if stockConfig.IsOpen == 1 {
  1921. if project.Type == 3 {
  1922. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1923. f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
  1924. good.Total = good.Total - f_count
  1925. service.UpdateGoodInfo(&good)
  1926. }
  1927. }
  1928. } else {
  1929. temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  1930. if stockConfig.IsOpen == 1 {
  1931. if project.Type == 3 {
  1932. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1933. if project.Count < temp_project.Count {
  1934. other_count := temp_project.Count - project.Count
  1935. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
  1936. good.Total = good.Total + other_count_two
  1937. service.UpdateGoodInfo(&good)
  1938. } else if project.Count > temp_project.Count {
  1939. other_count := project.Count - temp_project.Count
  1940. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
  1941. good.Total = good.Total - other_count_two
  1942. service.UpdateGoodInfo(&good)
  1943. }
  1944. }
  1945. }
  1946. }
  1947. return 0
  1948. }
  1949. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1950. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1951. id := int64(json["id"].(float64))
  1952. additionalCharge.ID = id
  1953. }
  1954. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1955. item_id := int64(json["item_id"].(float64))
  1956. additionalCharge.ItemId = item_id
  1957. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1958. if config.ID > 0 {
  1959. if len(config.Code) > 0 {
  1960. additionalCharge.MedListCodg = config.Code
  1961. }
  1962. }
  1963. }
  1964. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1965. // price := int64(json["price"].(float64))
  1966. // formatInt_price := strconv.FormatInt(price, 10)
  1967. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1968. // additionalCharge.Price = float_price
  1969. // }
  1970. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1971. // price := int64(json["price"].(float64))
  1972. // formatInt_price := strconv.FormatInt(price, 10)
  1973. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1974. // additionalCharge.Price = float_price
  1975. //}
  1976. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1977. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1978. additionalCharge.Price = price
  1979. }
  1980. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1981. count, _ := json["count"].(string)
  1982. counts, _ := strconv.ParseInt(count, 10, 64)
  1983. additionalCharge.Count = counts
  1984. }
  1985. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1986. item_name, _ := json["item_name"].(string)
  1987. additionalCharge.ItemName = item_name
  1988. }
  1989. return 0
  1990. }
  1991. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  1992. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1993. utils.ErrorLog("drug_name")
  1994. return enums.ErrorCodeParamWrong
  1995. }
  1996. adviceName, _ := json["drug_name"].(string)
  1997. if len(adviceName) == 0 {
  1998. utils.ErrorLog("len(advice_name) == 0")
  1999. return enums.ErrorCodeParamWrong
  2000. }
  2001. advice.AdviceName = adviceName
  2002. adviceDesc, _ := json["advice_desc"].(string)
  2003. advice.AdviceDesc = adviceDesc
  2004. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2005. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2006. advice.DrugSpec = drugSpec
  2007. }
  2008. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2009. remark, _ := json["remark"].(string)
  2010. advice.Remark = remark
  2011. }
  2012. if json["id"] == nil {
  2013. advice.DrugId = 0
  2014. } else {
  2015. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2016. drug_id := int64(json["id"].(float64))
  2017. advice.DrugId = drug_id
  2018. }
  2019. }
  2020. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2021. drugSpecUnit, _ := json["min_unit"].(string)
  2022. advice.DrugSpecUnit = drugSpecUnit
  2023. }
  2024. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2025. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2026. advice.SingleDose = singleDose
  2027. }
  2028. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2029. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2030. advice.SingleDoseUnit = singleDoseUnit
  2031. }
  2032. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2033. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2034. advice.PrescribingNumber = prescribingNumber
  2035. }
  2036. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2037. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2038. advice.PrescribingNumberUnit = prescribingNumberUnit
  2039. }
  2040. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2041. deliveryWay, _ := json["delivery_way"].(string)
  2042. advice.DeliveryWay = deliveryWay
  2043. }
  2044. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2045. executionFrequency, _ := json["execution_frequency"].(string)
  2046. advice.ExecutionFrequency = executionFrequency
  2047. }
  2048. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2049. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2050. advice.Price = price
  2051. }
  2052. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2053. med_list_codg, _ := json["medical_insurance_number"].(string)
  2054. advice.MedListCodg = med_list_codg
  2055. }
  2056. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2057. day := int64(json["day"].(float64))
  2058. advice.Day = day
  2059. }
  2060. return 0
  2061. }
  2062. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  2063. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  2064. types := int64(json["type"].(float64))
  2065. project.Type = types
  2066. }
  2067. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2068. project_id := int64(json["project_id"].(float64))
  2069. project.ProjectId = project_id
  2070. }
  2071. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2072. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2073. project.Price = price
  2074. }
  2075. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2076. total, _ := json["total"].(string)
  2077. totals, _ := strconv.ParseInt(total, 10, 64)
  2078. project.Count = totals
  2079. }
  2080. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2081. medical_code, _ := json["medical_code"].(string)
  2082. project.MedListCodg = medical_code
  2083. }
  2084. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2085. single_dose, _ := json["single_dose"].(string)
  2086. project.SingleDose = single_dose
  2087. }
  2088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2089. delivery_way, _ := json["delivery_way"].(string)
  2090. project.DeliveryWay = delivery_way
  2091. }
  2092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2093. execution_frequency, _ := json["execution_frequency"].(string)
  2094. project.ExecutionFrequency = execution_frequency
  2095. }
  2096. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2097. remark, _ := json["remark"].(string)
  2098. project.Remark = remark
  2099. }
  2100. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2101. day, _ := json["number_days"].(string)
  2102. project.Day = day
  2103. }
  2104. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2105. unit, _ := json["unit"].(string)
  2106. project.Unit = unit
  2107. }
  2108. return 0
  2109. }
  2110. func (c *HisApiController) GetHisOrderList() {
  2111. page, _ := c.GetInt64("page", -1)
  2112. limit, _ := c.GetInt64("limit", -1)
  2113. start_time := c.GetString("start_time")
  2114. end_time := c.GetString("end_time")
  2115. types, _ := c.GetInt64("type", 0)
  2116. keywords := c.GetString("keywords")
  2117. p_type, _ := c.GetInt64("p_type", 0)
  2118. timeLayout := "2006-01-02"
  2119. loc, _ := time.LoadLocation("Local")
  2120. var startTime int64
  2121. if len(start_time) > 0 {
  2122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2123. if err != nil {
  2124. fmt.Println(err)
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2126. return
  2127. }
  2128. startTime = theTime.Unix()
  2129. }
  2130. var endTime int64
  2131. if len(end_time) > 0 {
  2132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2133. if err != nil {
  2134. utils.ErrorLog(err.Error())
  2135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2136. return
  2137. }
  2138. endTime = theTime.Unix()
  2139. }
  2140. adminUser := c.GetAdminUserInfo()
  2141. org_id := adminUser.CurrentOrgId
  2142. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  2143. for _, item := range order {
  2144. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  2145. item.DoctorName = info.Doctor
  2146. item.DepartmentName = info.XtHisDepartment.Name
  2147. }
  2148. if err == nil {
  2149. c.ServeSuccessJSON(map[string]interface{}{
  2150. "order": order,
  2151. "total": total,
  2152. })
  2153. } else {
  2154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2155. return
  2156. }
  2157. }
  2158. func (c *HisApiController) GetHisOrder() {
  2159. patient_id, _ := c.GetInt64("patient_id", 0)
  2160. number := c.GetString("number")
  2161. adminInfo := c.GetAdminUserInfo()
  2162. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  2163. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  2164. if err == nil {
  2165. c.ServeSuccessJSON(map[string]interface{}{
  2166. "order": order,
  2167. "prescription": prescriptions,
  2168. })
  2169. } else {
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. }
  2174. func (c *HisApiController) GetHisPrescriptionList() {
  2175. record_date := c.GetString("record_date")
  2176. keywords := c.GetString("keywords")
  2177. page, _ := c.GetInt64("page")
  2178. limit, _ := c.GetInt64("limit")
  2179. timeLayout := "2006-01-02"
  2180. loc, _ := time.LoadLocation("Local")
  2181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2182. if err != nil {
  2183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2184. return
  2185. }
  2186. recordDateTime := theTime.Unix()
  2187. adminInfo := c.GetAdminUserInfo()
  2188. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  2189. //adminInfo := c.GetAdminUserInfo()
  2190. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  2191. //fmt.Println(prescriptionOrder)
  2192. if err == nil {
  2193. c.ServeSuccessJSON(map[string]interface{}{
  2194. "order": prescriptionOrder,
  2195. "total": total,
  2196. })
  2197. } else {
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2199. return
  2200. }
  2201. }
  2202. func (c *HisApiController) GetHisPrescriptionInfo() {
  2203. id, _ := c.GetInt64("id")
  2204. adminInfo := c.GetAdminUserInfo()
  2205. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  2206. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  2207. if err == nil {
  2208. c.ServeSuccessJSON(map[string]interface{}{
  2209. "order": prescriptionOrder,
  2210. "prescription": prescription,
  2211. })
  2212. } else {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2214. return
  2215. }
  2216. }
  2217. func (c *HisApiController) GetMedicalInsuranceConfig() {
  2218. adminUser := c.GetAdminUserInfo()
  2219. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2220. c.ServeSuccessJSON(map[string]interface{}{
  2221. "config": config,
  2222. })
  2223. }
  2224. type ResultTwo struct {
  2225. ErrMsg interface{} `json:"err_msg"`
  2226. InfRefmsgid string `json:"inf_refmsgid"`
  2227. Infcode int64 `json:"infcode"`
  2228. Output struct {
  2229. Baseinfo struct {
  2230. Age float64 `json:"age"`
  2231. Brdy string `json:"brdy"`
  2232. Certno string `json:"certno"`
  2233. Gend string `json:"gend"`
  2234. Naty string `json:"naty"`
  2235. PsnCertType string `json:"psn_cert_type"`
  2236. PsnName string `json:"psn_name"`
  2237. PsnNo string `json:"psn_no"`
  2238. } `json:"baseinfo"`
  2239. Idetinfo []interface{} `json:"idetinfo"`
  2240. Iinfo []struct {
  2241. Balc float64 `json:"balc"`
  2242. CvlservFlag string `json:"cvlserv_flag"`
  2243. EmpName string `json:"emp_name"`
  2244. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  2245. Insutype string `json:"insutype"`
  2246. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  2247. PausInsuDate interface{} `json:"paus_insu_date"`
  2248. PsnInsuDate string `json:"psn_insu_date"`
  2249. PsnInsuStas string `json:"psn_insu_stas"`
  2250. PsnType string `json:"psn_type"`
  2251. } `json:"insuinfo"`
  2252. } `json:"output"`
  2253. RefmsgTime string `json:"refmsg_time"`
  2254. RespondTime string `json:"respond_time"`
  2255. Signtype interface{} `json:"signtype"`
  2256. WarnInfo interface{} `json:"warn_info"`
  2257. }
  2258. type ResultThree struct {
  2259. Cainfo interface{} `json:"cainfo"`
  2260. ErrMsg interface{} `json:"err_msg"`
  2261. InfRefmsgid string `json:"inf_refmsgid"`
  2262. Infcode int64 `json:"infcode"`
  2263. Output struct {
  2264. Data struct {
  2265. IptOtpNo string `json:"ipt_otp_no"`
  2266. MdtrtID string `json:"mdtrt_id"`
  2267. PsnNo string `json:"psn_no"`
  2268. } `json:"data"`
  2269. } `json:"output"`
  2270. RefmsgTime string `json:"refmsg_time"`
  2271. RespondTime string `json:"respond_time"`
  2272. Signtype interface{} `json:"signtype"`
  2273. WarnMsg interface{} `json:"warn_msg"`
  2274. }
  2275. type ResultFour struct {
  2276. Cainfo string `json:"cainfo"`
  2277. ErrMsg string `json:"err_msg"`
  2278. InfRefmsgid string `json:"inf_refmsgid"`
  2279. Infcode int64 `json:"infcode"`
  2280. Output struct {
  2281. Result []struct {
  2282. BasMednFlag string `json:"bas_medn_flag"`
  2283. ChldMedcFlag string `json:"chld_medc_flag"`
  2284. ChrgitmLv string `json:"chrgitm_lv"`
  2285. Cnt float64 `json:"cnt"`
  2286. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  2287. DrtReimFlag string `json:"drt_reim_flag"`
  2288. FeedetlSn string `json:"feedetl_sn"`
  2289. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2290. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  2291. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2292. ListSpItemFlag string `json:"list_sp_item_flag"`
  2293. LmtUsedFlag string `json:"lmt_used_flag"`
  2294. MedChrgitmType string `json:"med_chrgitm_type"`
  2295. Memo string `json:"memo"`
  2296. OverlmtAmt float64 `json:"overlmt_amt"`
  2297. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2298. Pric float64 `json:"pric"`
  2299. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  2300. SelfpayProp float64 `json:"selfpay_prop"`
  2301. } `json:"result"`
  2302. } `json:"output"`
  2303. RefmsgTime string `json:"refmsg_time"`
  2304. RespondTime string `json:"respond_time"`
  2305. Signtype string `json:"signtype"`
  2306. WarnMsg string `json:"warn_msg"`
  2307. }
  2308. type ResultFive struct {
  2309. Insutype string `json:"insutype"`
  2310. }
  2311. type ResultSix struct {
  2312. Cainfo interface{} `json:"cainfo"`
  2313. ErrMsg interface{} `json:"err_msg"`
  2314. InfRefmsgid string `json:"inf_refmsgid"`
  2315. Infcode int64 `json:"infcode"`
  2316. Output struct {
  2317. } `json:"output"`
  2318. RefmsgTime string `json:"refmsg_time"`
  2319. RespondTime string `json:"respond_time"`
  2320. Signtype interface{} `json:"signtype"`
  2321. WarnMsg interface{} `json:"warn_msg"`
  2322. }
  2323. type ResultSeven struct {
  2324. Cainfo string `json:"cainfo"`
  2325. ErrMsg string `json:"err_msg"`
  2326. InfRefmsgid string `json:"inf_refmsgid"`
  2327. Infcode int64 `json:"infcode"`
  2328. Output struct {
  2329. Setldetail []interface{} `json:"setldetail"`
  2330. Setlinfo struct {
  2331. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2332. AcctPay float64 `json:"acct_pay"`
  2333. ActPayDedc float64 `json:"act_pay_dedc"`
  2334. Age float64 `json:"age"`
  2335. Balc float64 `json:"balc"`
  2336. Brdy string `json:"brdy"`
  2337. Certno string `json:"certno"`
  2338. ClrOptins string `json:"clr_optins"`
  2339. ClrType string `json:"clr_type"`
  2340. ClrWay string `json:"clr_way"`
  2341. CvlservFlag string `json:"cvlserv_flag"`
  2342. CvlservPay float64 `json:"cvlserv_pay"`
  2343. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2344. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2345. Gend string `json:"gend"`
  2346. HifesPay float64 `json:"hifes_pay"`
  2347. HifmiPay float64 `json:"hifmi_pay"`
  2348. HifobPay float64 `json:"hifob_pay"`
  2349. HifpPay float64 `json:"hifp_pay"`
  2350. HospPartAmt float64 `json:"hosp_part_amt"`
  2351. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2352. Insutype string `json:"insutype"`
  2353. MafPay float64 `json:"maf_pay"`
  2354. MdtrtCertType string `json:"mdtrt_cert_type"`
  2355. MdtrtID string `json:"mdtrt_id"`
  2356. MedType string `json:"med_type"`
  2357. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2358. MedinsSetlID string `json:"medins_setl_id"`
  2359. Naty string `json:"naty"`
  2360. OthPay float64 `json:"oth_pay"`
  2361. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2362. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2363. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2364. PsnCashPay float64 `json:"psn_cash_pay"`
  2365. PsnCertType string `json:"psn_cert_type"`
  2366. PsnName string `json:"psn_name"`
  2367. PsnNo string `json:"psn_no"`
  2368. PsnPartAmt float64 `json:"psn_part_amt"`
  2369. PsnType string `json:"psn_type"`
  2370. SetlID string `json:"setl_id"`
  2371. SetlTime string `json:"setl_time"`
  2372. } `json:"setlinfo"`
  2373. } `json:"output"`
  2374. RefmsgTime string `json:"refmsg_time"`
  2375. RespondTime string `json:"respond_time"`
  2376. Signtype interface{} `json:"signtype"`
  2377. WarnMsg interface{} `json:"warn_msg"`
  2378. }
  2379. type ResultEight struct {
  2380. Cainfo string `json:"cainfo"`
  2381. ErrMsg string `json:"err_msg"`
  2382. InfRefmsgid string `json:"inf_refmsgid"`
  2383. Infcode int64 `json:"infcode"`
  2384. Output struct {
  2385. Stmtinfo struct {
  2386. SetlOptins string `json:"setl_optins"`
  2387. StmtRslt string `json:"stmt_rslt"`
  2388. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  2389. } `json:"stmtinfo"`
  2390. } `json:"output"`
  2391. RefmsgTime string `json:"refmsg_time"`
  2392. RespondTime string `json:"respond_time"`
  2393. Signtype interface{} `json:"signtype"`
  2394. WarnMsg interface{} `json:"warn_msg"`
  2395. }
  2396. type ResultNine struct {
  2397. Cainfo string `json:"cainfo"`
  2398. ErrMsg string `json:"err_msg"`
  2399. InfRefmsgid string `json:"inf_refmsgid"`
  2400. Infcode int64 `json:"infcode"`
  2401. Output struct {
  2402. FileQuryNo string `json:"file_qury_no"`
  2403. } `json:"output"`
  2404. RefmsgTime string `json:"refmsg_time"`
  2405. RespondTime string `json:"respond_time"`
  2406. Signtype interface{} `json:"signtype"`
  2407. WarnMsg interface{} `json:"warn_msg"`
  2408. }
  2409. type ResultTen struct {
  2410. Cainfo string `json:"cainfo"`
  2411. ErrMsg string `json:"err_msg"`
  2412. InfRefmsgid string `json:"inf_refmsgid"`
  2413. Infcode int64 `json:"infcode"`
  2414. Output struct {
  2415. DldEndtime string `json:"dld_endtime"`
  2416. FileQuryNo string `json:"file_qury_no"`
  2417. Filename string `json:"filename"`
  2418. } `json:"output"`
  2419. RefmsgTime string `json:"refmsg_time"`
  2420. RespondTime string `json:"respond_time"`
  2421. Signtype interface{} `json:"signtype"`
  2422. WarnMsg interface{} `json:"warn_msg"`
  2423. }
  2424. type ResultEleven struct {
  2425. Cainfo string `json:"cainfo"`
  2426. ErrMsg string `json:"err_msg"`
  2427. InfRefmsgid string `json:"inf_refmsgid"`
  2428. Infcode int64 `json:"infcode"`
  2429. Output struct {
  2430. Setlinfo struct {
  2431. FixmedinsName string `json:"fixmedins_name"`
  2432. FixmedinsCode string `json:"fixmedins_code"`
  2433. PsnNo string `json:"psn_no"`
  2434. PsnName string `json:"psn_name"`
  2435. HifobPay float64 `json:"hifob_pay"`
  2436. Gend string `json:"gend"`
  2437. Brdy string `json:"brdy"`
  2438. PsnCertType string `json:"psn_cert_type"`
  2439. PsnType string `json:"psn_type"`
  2440. EmpName string `json:"emp_name"`
  2441. Certno string `json:"certno"`
  2442. Insutype string `json:"insutype"`
  2443. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2444. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2445. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2446. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2447. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2448. ActPayDedc float64 `json:"act_pay_dedc"`
  2449. HifpPay float64 `json:"hifp_pay"`
  2450. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2451. CvlservPay float64 `json:"cvlserv_pay"`
  2452. HifesPay float64 `json:"hifes_pay"`
  2453. HifmiPay float64 `json:"hifmi_pay"`
  2454. MafPay float64 `json:"maf_pay"`
  2455. OthPay float64 `json:"oth_pay"`
  2456. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2457. PsnPay float64 `json:"psn_pay"`
  2458. AcctPay float64 `json:"acct_pay"`
  2459. CashPayamt float64 `json:"cash_payamt"`
  2460. Balc float64 `json:"balc"`
  2461. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2462. MedinsSetlId string `json:"medins_setl_id"`
  2463. RefdSetlFlag string `json:"refd_setl_flag"`
  2464. SetlTime string `json:"setl_time"`
  2465. MedType string `json:"med_type"`
  2466. } `json:"setlinfo"`
  2467. } `json:"output"`
  2468. RefmsgTime string `json:"refmsg_time"`
  2469. RespondTime string `json:"respond_time"`
  2470. Signtype interface{} `json:"signtype"`
  2471. WarnMsg interface{} `json:"warn_msg"`
  2472. }
  2473. type Custom struct {
  2474. DetItemFeeSumamt string
  2475. Cut string
  2476. FeedetlSn string
  2477. Price string
  2478. MedListCodg string
  2479. Type int64
  2480. AdviceId int64
  2481. ProjectId int64
  2482. ItemId int64
  2483. }
  2484. //获取个人信息----挂号-----上传就诊信息
  2485. func (c *HisApiController) GetRegisterInfo() {
  2486. id, _ := c.GetInt64("id")
  2487. record_time := c.GetString("record_time")
  2488. settlementValue, _ := c.GetInt64("settlement_value")
  2489. medical_insurance_card := c.GetString("medical_insurance_card")
  2490. name := c.GetString("name")
  2491. id_card_type, _ := c.GetInt64("id_card_type")
  2492. certificates, _ := c.GetInt64("certificates")
  2493. medical_care, _ := c.GetInt64("medical_care")
  2494. birthday := c.GetString("birthday")
  2495. age, _ := c.GetInt64("age")
  2496. id_card := c.GetString("id_card")
  2497. register_type, _ := c.GetInt64("register")
  2498. doctor, _ := c.GetInt64("doctor")
  2499. department, _ := c.GetInt64("department")
  2500. gender, _ := c.GetInt64("sex")
  2501. phone := c.GetString("phone")
  2502. registration_fee, _ := c.GetFloat("registration_fee")
  2503. medical_expenses, _ := c.GetFloat("medical_expenses")
  2504. social_type, _ := c.GetInt64("social_type")
  2505. //diagnosis_id, _ := c.GetInt64("diagnosis")
  2506. diagnosis_ids := c.GetString("diagnosis")
  2507. sick_type, _ := c.GetInt64("sick_type")
  2508. reg_type := c.GetString("p_type")
  2509. timeLayout := "2006-01-02"
  2510. loc, _ := time.LoadLocation("Local")
  2511. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  2512. birthUnix := birthdays.Unix()
  2513. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2514. if err != nil {
  2515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2516. return
  2517. }
  2518. recordDateTime := theTime.Unix()
  2519. adminInfo := c.GetAdminUserInfo()
  2520. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  2521. if tempPatient.ID == 0 {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  2523. return
  2524. }
  2525. var patient service.Patients
  2526. if id == 0 {
  2527. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  2528. } else {
  2529. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2530. }
  2531. if patient.ID == 0 {
  2532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2533. return
  2534. }
  2535. if len(patient.IdCardNo) == 0 {
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2537. return
  2538. }
  2539. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2540. if len(his) >= 1 {
  2541. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  2542. if len(his) >= 1 && order.ID == 0 {
  2543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  2544. return
  2545. }
  2546. }
  2547. timeStr := time.Now().Format("2006-01-02 15:04:05")
  2548. fmt.Println(timeStr)
  2549. timeArr := strings.Split(timeStr, " ")
  2550. fmt.Println(timeArr)
  2551. timeArrTwo := strings.Split(timeArr[0], "-")
  2552. timeArrThree := strings.Split(timeArr[1], ":")
  2553. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  2554. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2555. if len(lists) == 0 {
  2556. var hisPatient models.XtHisPatient
  2557. hisPatient = models.XtHisPatient{
  2558. Name: name,
  2559. Age: age,
  2560. Gender: gender,
  2561. Birthday: birthUnix,
  2562. Phone: phone,
  2563. MedicalTreatmentType: medical_care,
  2564. IdType: certificates,
  2565. IdCardNo: id_card,
  2566. BalanceAccountsType: settlementValue,
  2567. SocialType: social_type,
  2568. MedicalInsuranceNumber: medical_insurance_card,
  2569. RegisterType: register_type,
  2570. RegisterCost: registration_fee,
  2571. TreatmentCost: medical_expenses,
  2572. AdminUserId: adminInfo.AdminUser.Id,
  2573. UserOrgId: adminInfo.CurrentOrgId,
  2574. Status: 1,
  2575. RecordDate: recordDateTime,
  2576. IsReturn: 1,
  2577. PatientId: patient.ID,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: time.Now().Unix(),
  2580. Number: str,
  2581. IdCardType: id_card_type,
  2582. Departments: department,
  2583. Doctor: doctor,
  2584. PType: reg_type,
  2585. Diagnosis: diagnosis_ids,
  2586. SickType: sick_type,
  2587. }
  2588. service.CreateHisPatient(&hisPatient)
  2589. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2590. c.ServeSuccessJSON(map[string]interface{}{
  2591. "his_info": hisPatient,
  2592. })
  2593. } else {
  2594. //chrgBchno := rand.Intn(1000000) + 10000
  2595. var hisPatient models.XtHisPatient
  2596. hisPatient = models.XtHisPatient{
  2597. Name: name,
  2598. Age: age,
  2599. Gender: gender,
  2600. Birthday: birthUnix,
  2601. Phone: phone,
  2602. MedicalTreatmentType: medical_care,
  2603. IdType: certificates,
  2604. IdCardNo: id_card,
  2605. BalanceAccountsType: settlementValue,
  2606. SocialType: social_type,
  2607. MedicalInsuranceNumber: medical_insurance_card,
  2608. RegisterType: register_type,
  2609. RegisterCost: registration_fee,
  2610. TreatmentCost: medical_expenses,
  2611. AdminUserId: adminInfo.AdminUser.Id,
  2612. UserOrgId: adminInfo.CurrentOrgId,
  2613. Status: 1,
  2614. RecordDate: recordDateTime,
  2615. IsReturn: 1,
  2616. PatientId: patient.ID,
  2617. Ctime: time.Now().Unix(),
  2618. Mtime: time.Now().Unix(),
  2619. Number: str,
  2620. IdCardType: id_card_type,
  2621. Departments: department,
  2622. Doctor: doctor,
  2623. PType: reg_type,
  2624. Diagnosis: diagnosis_ids,
  2625. SickType: sick_type,
  2626. }
  2627. service.CreateHisPatient(&hisPatient)
  2628. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2629. c.ServeSuccessJSON(map[string]interface{}{
  2630. "his_info": hisPatient,
  2631. })
  2632. }
  2633. }
  2634. //上传明细----结算
  2635. func (c *HisApiController) GetUploadInfo() {
  2636. id, _ := c.GetInt64("id")
  2637. record_time := c.GetString("record_time")
  2638. his_patient_id, _ := c.GetInt64("his_patient_id")
  2639. pay_way, _ := c.GetInt64("pay_way")
  2640. pay_price, _ := c.GetFloat("pay_price")
  2641. pay_card_no := c.GetString("pay_card_no")
  2642. discount_price, _ := c.GetFloat("discount_price")
  2643. preferential_price, _ := c.GetFloat("preferential_price")
  2644. reality_price, _ := c.GetFloat("reality_price")
  2645. found_price, _ := c.GetFloat("found_price")
  2646. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2647. private_price, _ := c.GetFloat("private_price")
  2648. timeLayout := "2006-01-02"
  2649. loc, _ := time.LoadLocation("Local")
  2650. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2651. fapiao_code := c.GetString("fapiao_code")
  2652. fapiao_number := c.GetString("fapiao_number")
  2653. diagnosis_id := c.GetString("diagnosis")
  2654. sick_type, _ := c.GetInt64("sick_type")
  2655. reg_type, _ := c.GetInt64("p_type")
  2656. order_id, _ := c.GetInt64("order_id")
  2657. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  2658. tempOrder, _ := service.GetHisOrderByID(order_id)
  2659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2660. if err != nil {
  2661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2662. return
  2663. }
  2664. recordDateTime := theTime.Unix()
  2665. adminUser := c.GetAdminUserInfo()
  2666. var prescriptions []*models.HisPrescription
  2667. var start_time int64
  2668. var end_time int64
  2669. ids_str := c.GetString("ids")
  2670. ids_arr := strings.Split(ids_str, ",")
  2671. if tempOrder.ID == 0 {
  2672. if settle_accounts_type == 1 { //日结
  2673. fmt.Println(reg_type)
  2674. if reg_type == 11 {
  2675. fmt.Println(reg_type)
  2676. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2677. } else {
  2678. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  2679. }
  2680. } else { //月结
  2681. start_time_str := c.GetString("start_time")
  2682. end_time_str := c.GetString("end_time")
  2683. timeLayout := "2006-01-02"
  2684. loc, _ := time.LoadLocation("Local")
  2685. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2686. if err != nil {
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. recordStartTime := theStartTime.Unix()
  2691. start_time = recordStartTime
  2692. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2693. if err != nil {
  2694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2695. return
  2696. }
  2697. recordEndTime := theEndTime.Unix()
  2698. end_time = recordEndTime
  2699. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  2700. }
  2701. timestamp := time.Now().Unix()
  2702. tempTime := time.Unix(timestamp, 0)
  2703. timeFormat := tempTime.Format("20060102150405")
  2704. chrgBchno := rand.Intn(100000) + 10000
  2705. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2706. strconv.FormatInt(his.PatientId, 10)
  2707. var ids []int64
  2708. fmt.Println(prescriptions)
  2709. for _, item := range prescriptions {
  2710. ids = append(ids, item.ID)
  2711. }
  2712. var total float64
  2713. fmt.Println(prescriptions)
  2714. for _, item := range prescriptions {
  2715. fmt.Println(item)
  2716. if item.Type == 1 { //药品
  2717. for _, subItem := range item.HisDoctorAdviceInfo {
  2718. total = total + (subItem.Price * subItem.PrescribingNumber)
  2719. }
  2720. }
  2721. if item.Type == 2 { //项目
  2722. for _, subItem := range item.HisPrescriptionProject {
  2723. total = total + (subItem.Price * float64(subItem.Count))
  2724. }
  2725. }
  2726. for _, subItem := range item.HisAdditionalCharge {
  2727. total = total + (subItem.Price * float64(subItem.Count))
  2728. }
  2729. }
  2730. allTotal := fmt.Sprintf("%.2f", total)
  2731. totals, _ := strconv.ParseFloat(allTotal, 64)
  2732. order := &models.HisOrder{
  2733. UserOrgId: adminUser.CurrentOrgId,
  2734. HisPatientId: his.ID,
  2735. PatientId: id,
  2736. SettleAccountsDate: recordDateTime,
  2737. Ctime: time.Now().Unix(),
  2738. Mtime: time.Now().Unix(),
  2739. Status: 1,
  2740. OrderStatus: 2,
  2741. MdtrtId: his.Number,
  2742. Number: chrg_bchno,
  2743. MedfeeSumamt: totals,
  2744. PayWay: pay_way,
  2745. PayPrice: pay_price,
  2746. MedType: strconv.Itoa(int(reg_type)),
  2747. PayCardNo: pay_card_no,
  2748. DiscountPrice: discount_price,
  2749. PreferentialPrice: preferential_price,
  2750. RealityPrice: reality_price,
  2751. FoundPrice: found_price,
  2752. MedicalInsurancePrice: medical_insurance_price,
  2753. PrivatePrice: private_price,
  2754. SettleEndTime: end_time,
  2755. SettleStartTime: start_time,
  2756. SettleType: settle_accounts_type,
  2757. FaPiaoCode: fapiao_code,
  2758. FaPiaoNumber: fapiao_number,
  2759. Diagnosis: diagnosis_id,
  2760. PType: 2,
  2761. }
  2762. err = service.CreateOrder(order)
  2763. if err != nil {
  2764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2765. return
  2766. }
  2767. var customs []*Custom
  2768. for _, item := range prescriptions {
  2769. if item.Type == 1 { //药品
  2770. for _, subItem := range item.HisDoctorAdviceInfo {
  2771. cus := &Custom{
  2772. AdviceId: subItem.ID,
  2773. ProjectId: 0,
  2774. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2775. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2776. FeedetlSn: subItem.FeedetlSn,
  2777. Price: fmt.Sprintf("%.2f", subItem.Price),
  2778. MedListCodg: subItem.MedListCodg,
  2779. Type: 1,
  2780. }
  2781. customs = append(customs, cus)
  2782. }
  2783. }
  2784. if item.Type == 2 { //项目
  2785. for _, subItem := range item.HisPrescriptionProject {
  2786. cus := &Custom{
  2787. AdviceId: 0,
  2788. ProjectId: subItem.ID,
  2789. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2790. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2791. FeedetlSn: subItem.FeedetlSn,
  2792. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2793. MedListCodg: subItem.MedListCodg,
  2794. Type: 2,
  2795. }
  2796. customs = append(customs, cus)
  2797. }
  2798. }
  2799. for _, item := range item.HisAdditionalCharge {
  2800. cus := &Custom{
  2801. ItemId: item.ID,
  2802. AdviceId: 0,
  2803. ProjectId: 0,
  2804. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2805. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2806. FeedetlSn: item.FeedetlSn,
  2807. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2808. MedListCodg: item.XtHisAddtionConfig.Code,
  2809. Type: 3,
  2810. }
  2811. customs = append(customs, cus)
  2812. }
  2813. }
  2814. for _, item := range customs {
  2815. var advice_id int64 = 0
  2816. var project_id int64 = 0
  2817. var item_id int64 = 0
  2818. var types int64 = 0
  2819. if item.Type == 1 {
  2820. advice_id = item.AdviceId
  2821. project_id = 0
  2822. item_id = 0
  2823. } else if item.Type == 2 {
  2824. advice_id = 0
  2825. item_id = 0
  2826. project_id = item.ProjectId
  2827. } else if item.Type == 3 {
  2828. advice_id = 0
  2829. item_id = item.ItemId
  2830. project_id = 0
  2831. }
  2832. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2833. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2834. pric, _ := strconv.ParseFloat(item.Price, 32)
  2835. info := &models.HisOrderInfo{
  2836. OrderNumber: order.Number,
  2837. UploadDate: time.Now().Unix(),
  2838. AdviceId: advice_id,
  2839. DetItemFeeSumamt: detItemFeeSumamt,
  2840. Cnt: cut,
  2841. Pric: pric,
  2842. PatientId: id,
  2843. Status: 1,
  2844. Mtime: time.Now().Unix(),
  2845. Ctime: time.Now().Unix(),
  2846. UserOrgId: adminUser.CurrentOrgId,
  2847. HisPatientId: his.ID,
  2848. OrderId: order.ID,
  2849. ProjectId: project_id,
  2850. Type: types,
  2851. ItemId: item_id,
  2852. }
  2853. service.CreateOrderInfo(info)
  2854. }
  2855. his.Diagnosis = diagnosis_id
  2856. his.SickType = sick_type
  2857. his.RegisterType = reg_type
  2858. his.MedicalTreatmentType = reg_type
  2859. service.UpdataHisPateint(&his)
  2860. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2861. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  2862. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2863. if err == nil {
  2864. c.ServeSuccessJSON(map[string]interface{}{
  2865. "msg": "结算成功",
  2866. })
  2867. }
  2868. } else {
  2869. if tempOrder.IsPre > 0 {
  2870. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2871. totals, _ := strconv.ParseFloat(allTotal, 64)
  2872. tempOrder.OrderStatus = 2
  2873. tempOrder.PayWay = pay_way
  2874. tempOrder.PayPrice = pay_price
  2875. tempOrder.PayCardNo = pay_card_no
  2876. tempOrder.DiscountPrice = discount_price
  2877. tempOrder.PreferentialPrice = preferential_price
  2878. tempOrder.RealityPrice = reality_price
  2879. tempOrder.FoundPrice = found_price
  2880. tempOrder.MedicalInsurancePrice = medical_insurance_price
  2881. tempOrder.PrivatePrice = private_price
  2882. tempOrder.FaPiaoCode = fapiao_code
  2883. tempOrder.FaPiaoNumber = fapiao_number
  2884. tempOrder.PType = 2
  2885. tempOrder.MedfeeSumamt = totals
  2886. tempOrder.Diagnosis = diagnosis_id
  2887. err = service.SaveHisOrder(&tempOrder)
  2888. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  2889. if err != nil {
  2890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2891. return
  2892. }
  2893. if err == nil {
  2894. c.ServeSuccessJSON(map[string]interface{}{
  2895. "msg": "结算成功",
  2896. })
  2897. }
  2898. }
  2899. }
  2900. }
  2901. //退款
  2902. func (c *HisApiController) Refund() {
  2903. order_id, _ := c.GetInt64("order_id")
  2904. order, _ := service.GetHisOrderByID(order_id)
  2905. adminUser := c.GetAdminUserInfo()
  2906. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  2907. if err == nil {
  2908. c.ServeSuccessJSON(map[string]interface{}{
  2909. "msg": "退费成功",
  2910. })
  2911. } else {
  2912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2913. return
  2914. }
  2915. }
  2916. func (c *HisApiController) RefundNumber() {
  2917. his_patient_id, _ := c.GetInt64("id")
  2918. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  2919. info.Status = 0
  2920. err := service.SaveHisPatient(info)
  2921. if err == nil {
  2922. c.ServeSuccessJSON(map[string]interface{}{
  2923. "msg": "退号成功",
  2924. })
  2925. } else {
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2927. return
  2928. }
  2929. }
  2930. func (this *HisApiController) AdditionalCharge() {
  2931. dataBody := make(map[string]interface{}, 0)
  2932. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2933. fmt.Println(err)
  2934. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2935. patient_id := int64(dataBody["patient_id"].(float64))
  2936. medicineData, _ := dataBody["medicineData"].([]interface{})
  2937. adminUserInfo := this.GetAdminUserInfo()
  2938. orgId := adminUserInfo.CurrentOrgId
  2939. admin_user_id := adminUserInfo.AdminUser.Id
  2940. timeStr := time.Now().Format("2006-01-02")
  2941. timeLayout := "2006-01-02 15:04:05"
  2942. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2943. timenow := timeStringToTime.Unix()
  2944. var additionalCharges []*models.HisAdditionalCharge
  2945. for _, item := range medicineData {
  2946. var randNum int
  2947. randNum = rand.Intn(10000) + 1000
  2948. timestamp := time.Now().Unix()
  2949. tempTime := time.Unix(timestamp, 0)
  2950. timeFormat := tempTime.Format("20060102150405")
  2951. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2952. items := item.(map[string]interface{})
  2953. money := items["price"].(string)
  2954. item_id_str := items["item_id"].(string)
  2955. name := items["name"].(string)
  2956. id_str := items["id"].(string)
  2957. moneys, _ := strconv.ParseInt(money, 10, 64)
  2958. monStr := strconv.FormatInt(moneys, 10)
  2959. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2960. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2961. id, _ := strconv.ParseInt(id_str, 10, 64)
  2962. additionalCharge := &models.HisAdditionalCharge{
  2963. ID: id,
  2964. HisPatientId: his_patient_id,
  2965. UserOrgId: orgId,
  2966. PatientId: patient_id,
  2967. RecordDate: timenow,
  2968. Price: monneyStr,
  2969. Status: 1,
  2970. ItemName: name,
  2971. ItemId: item_id,
  2972. AdminUserId: admin_user_id,
  2973. CreatedTime: time.Now().Unix(),
  2974. OrderStatus: 0,
  2975. PrescriptionNumber: "",
  2976. BatchNumber: "",
  2977. FeedetlSn: p_number,
  2978. }
  2979. service.CreateAdditionalCharge(additionalCharge)
  2980. additionalCharges = append(additionalCharges, additionalCharge)
  2981. }
  2982. this.ServeSuccessJSON(map[string]interface{}{
  2983. "msg": "添加成功",
  2984. "additional_charges": additionalCharges,
  2985. })
  2986. }
  2987. func (this *HisApiController) DeleteAddition() {
  2988. id, _ := this.GetInt64("id")
  2989. //TODO 需要判断是否已经结算
  2990. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2991. if err == nil {
  2992. this.ServeSuccessJSON(map[string]interface{}{
  2993. "msg": "删除成功",
  2994. })
  2995. return
  2996. } else {
  2997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2998. return
  2999. }
  3000. }
  3001. func (this *HisApiController) GetAdminUsers() {
  3002. adminUser := this.GetAdminUserInfo()
  3003. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  3004. this.ServeSuccessJSON(map[string]interface{}{
  3005. "doctors": doctors,
  3006. })
  3007. }
  3008. func (this *HisApiController) GetLastOrNextHisPrescription() {
  3009. change_type, _ := this.GetInt64("type", 0)
  3010. record_date := this.GetString("record_time")
  3011. patient_id, _ := this.GetInt64("patient_id", 0)
  3012. p_type, _ := this.GetInt64("p_type", 0)
  3013. timeLayout := "2006-01-02"
  3014. loc, _ := time.LoadLocation("Local")
  3015. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3016. record_time := theAdviceRecordTime.Unix()
  3017. adminUserInfo := this.GetAdminUserInfo()
  3018. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  3019. if err == nil {
  3020. if len(prescriptions) == 0 {
  3021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3022. return
  3023. } else {
  3024. this.ServeSuccessJSON(map[string]interface{}{
  3025. "prescriptions": prescriptions,
  3026. })
  3027. return
  3028. }
  3029. } else {
  3030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3031. return
  3032. }
  3033. }
  3034. func (this *HisApiController) GetCallHisPrescription() {
  3035. patient_id, _ := this.GetInt64("patient_id", 0)
  3036. timeLayout := "2006-01-02"
  3037. loc, _ := time.LoadLocation("Local")
  3038. start_time := this.GetString("start_time")
  3039. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3040. end_time := this.GetString("end_time")
  3041. p_type, _ := this.GetInt64("p_type")
  3042. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3043. adminUserInfo := this.GetAdminUserInfo()
  3044. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  3045. if err == nil {
  3046. this.ServeSuccessJSON(map[string]interface{}{
  3047. "prescriptions": prescriptions,
  3048. })
  3049. return
  3050. } else {
  3051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3052. return
  3053. }
  3054. }
  3055. func (this *HisApiController) GetHisDayPrescription() {
  3056. timeLayout := "2006-01-02"
  3057. loc, _ := time.LoadLocation("Local")
  3058. start_time := this.GetString("start_time")
  3059. patient_id, _ := this.GetInt64("patient_id", 0)
  3060. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3061. end_time := this.GetString("end_time")
  3062. p_type, _ := this.GetInt64("p_type")
  3063. order_status, _ := this.GetInt64("type")
  3064. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3065. adminUserInfo := this.GetAdminUserInfo()
  3066. var dayHisPrescription []*models.HisPrescription
  3067. var err error
  3068. if order_status == 1 || order_status == 0 {
  3069. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  3070. } else if order_status == 2 {
  3071. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  3072. }
  3073. if err == nil {
  3074. this.ServeSuccessJSON(map[string]interface{}{
  3075. "day_prescription": dayHisPrescription,
  3076. })
  3077. return
  3078. } else {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3080. return
  3081. }
  3082. }
  3083. func (c *HisApiController) GetHisChargePatientList() {
  3084. record_date := c.GetString("record_date")
  3085. order_status, _ := c.GetInt64("type")
  3086. timeLayout := "2006-01-02"
  3087. loc, _ := time.LoadLocation("Local")
  3088. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3089. if err != nil {
  3090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3091. return
  3092. }
  3093. recordDateTime := theTime.Unix()
  3094. adminInfo := c.GetAdminUserInfo()
  3095. var tempPatients []*service.NewTempPatients
  3096. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3097. if order_status != 2 {
  3098. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3099. } else {
  3100. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  3101. }
  3102. var patients []*service.NewTempPatients
  3103. var patients_two []*service.NewTempPatients
  3104. for _, item := range tempPatients {
  3105. //过滤掉没挂号的和没开处方的
  3106. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  3107. patients = append(patients, item)
  3108. }
  3109. //过滤掉没挂号的
  3110. if len(item.HisPatient) > 0 {
  3111. patients_two = append(patients_two, item)
  3112. }
  3113. }
  3114. c.ServeSuccessJSON(map[string]interface{}{
  3115. "list": patients,
  3116. "list_two": patients_two,
  3117. })
  3118. }
  3119. func (c *HisApiController) GetHisUnRegisterPatientList() {
  3120. record_date := c.GetString("record_date")
  3121. timeLayout := "2006-01-02"
  3122. loc, _ := time.LoadLocation("Local")
  3123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3124. if err != nil {
  3125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3126. return
  3127. }
  3128. recordDateTime := theTime.Unix()
  3129. adminUser := c.GetAdminUserInfo()
  3130. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  3131. var patients []*service.Patients
  3132. for _, item := range tempPatients {
  3133. if item.HisPatient.ID == 0 {
  3134. patients = append(patients, item)
  3135. }
  3136. }
  3137. c.ServeSuccessJSON(map[string]interface{}{
  3138. "list": patients,
  3139. //"list_two": patients_two,
  3140. })
  3141. }
  3142. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  3143. newArr = make([]*service.Patients, 0)
  3144. for i := 0; i < len(patient); i++ {
  3145. repeat := false
  3146. for j := i + 1; j < len(patient); j++ {
  3147. if patient[i].ID == patient[j].ID {
  3148. repeat = true
  3149. break
  3150. }
  3151. }
  3152. if !repeat {
  3153. newArr = append(newArr, patient[i])
  3154. }
  3155. }
  3156. return
  3157. }
  3158. func (c *HisApiController) GetHisChargePatientInfo() {
  3159. patient_id, _ := c.GetInt64("patient_id")
  3160. his_patient_id, _ := c.GetInt64("his_patient_id")
  3161. record_date := c.GetString("record_date")
  3162. //start_time := c.GetString("start_time")
  3163. //end_time := c.GetString("end_time")
  3164. order_status, _ := c.GetInt64("type", 0)
  3165. p_type, _ := c.GetInt64("p_type", 0)
  3166. order_id, _ := c.GetInt64("order_id", 0)
  3167. timeLayout := "2006-01-02"
  3168. loc, _ := time.LoadLocation("Local")
  3169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3170. if err != nil {
  3171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3172. return
  3173. }
  3174. recordDateTime := theTime.Unix()
  3175. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3176. //if err != nil {
  3177. //
  3178. //}
  3179. //startRecordDateTime := startTime.Unix()
  3180. //
  3181. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3182. //if err != nil {
  3183. //
  3184. //}
  3185. //endRecordDateTime := endTime.Unix()
  3186. admin := c.GetAdminUserInfo()
  3187. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  3188. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  3189. var prescriptions []*models.HisPrescription
  3190. order, _ := service.GetHisOrderByID(order_id)
  3191. if order_status == 1 || order_status == 0 {
  3192. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  3193. } else if order_status == 2 {
  3194. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  3195. }
  3196. //var monthPrescriptions []*models.HisPrescription
  3197. //if order_status == 1 || order_status == 0 {
  3198. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  3199. //} else if order_status == 2 {
  3200. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  3201. //}
  3202. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  3203. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  3204. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  3205. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  3206. //获取所有科室信息
  3207. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  3208. c.ServeSuccessJSON(map[string]interface{}{
  3209. "his_info": his_patient_info,
  3210. "xt_info": xt_patient_info,
  3211. "prescription": prescriptions,
  3212. "case_history": case_history,
  3213. "info": patientPrescriptionInfo,
  3214. "last_info": lastPatientPrescriptionInfo,
  3215. //"month_prescriptions": monthPrescriptions,
  3216. "order": order,
  3217. "doctors": doctors,
  3218. "department": department,
  3219. })
  3220. return
  3221. }
  3222. func (c *HisApiController) GetAllOrderDetail() {
  3223. order_id, _ := c.GetInt64("id", 0)
  3224. order, _ := service.GetHisOrderByID(order_id)
  3225. if order.ID == 0 {
  3226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3227. return
  3228. }
  3229. org_id := c.GetAdminUserInfo().CurrentOrgId
  3230. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  3231. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  3232. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  3233. c.ServeSuccessJSON(map[string]interface{}{
  3234. "order": order,
  3235. "order_info": order_info,
  3236. "patient": patient,
  3237. "admin_info": adminInfo,
  3238. })
  3239. return
  3240. }
  3241. func (c *HisApiController) GetAllOrderDetailCollect() {
  3242. order_id, _ := c.GetInt64("id", 0)
  3243. order, _ := service.GetHisOrderByID(order_id)
  3244. if order.ID == 0 {
  3245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3246. return
  3247. }
  3248. org_id := c.GetAdminUserInfo().CurrentOrgId
  3249. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  3250. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  3251. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  3252. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  3253. if his.BalanceAccountsType != 2 {
  3254. c.ServeSuccessJSON(map[string]interface{}{
  3255. "order": order,
  3256. "order_info": order_info,
  3257. "patient": patient,
  3258. "admin_info": adminInfo,
  3259. })
  3260. } else {
  3261. for _, item := range order_info {
  3262. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  3263. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  3264. item.MedChrgitmType = "09"
  3265. }
  3266. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  3267. if item.HisPrescriptionProject.Type == 2 {
  3268. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  3269. case 1:
  3270. item.MedChrgitmType = "14"
  3271. break
  3272. case 2:
  3273. item.MedChrgitmType = "05"
  3274. break
  3275. case 3:
  3276. item.MedChrgitmType = "04"
  3277. break
  3278. case 4:
  3279. item.MedChrgitmType = "14"
  3280. break
  3281. case 5:
  3282. item.MedChrgitmType = "08"
  3283. break
  3284. case 6:
  3285. item.MedChrgitmType = "14"
  3286. break
  3287. case 7:
  3288. item.MedChrgitmType = "14"
  3289. break
  3290. case 8:
  3291. item.MedChrgitmType = "03"
  3292. break
  3293. case 9:
  3294. item.MedChrgitmType = "14"
  3295. break
  3296. }
  3297. } else if item.HisPrescriptionProject.Type == 3 {
  3298. item.MedChrgitmType = "08"
  3299. }
  3300. }
  3301. }
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "order": order,
  3304. "order_info": order_info,
  3305. "patient": patient,
  3306. "admin_info": adminInfo,
  3307. })
  3308. }
  3309. return
  3310. }
  3311. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  3312. page, _ := c.GetInt64("page")
  3313. limit, _ := c.GetInt64("limit")
  3314. keywords := c.GetString("keywords")
  3315. start_time := c.GetString("start_time")
  3316. end_time := c.GetString("end_time")
  3317. //clr_type := c.GetString("clr_type")
  3318. insutype := c.GetString("insutype")
  3319. timeLayout := "2006-01-02"
  3320. loc, _ := time.LoadLocation("Local")
  3321. var theStartTIme int64
  3322. if len(start_time) > 0 {
  3323. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3324. theStartTIme = theTime.Unix()
  3325. }
  3326. var theEndtTIme int64
  3327. if len(end_time) > 0 {
  3328. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3329. theEndtTIme = theTime.Unix()
  3330. }
  3331. if page <= 0 {
  3332. page = 1
  3333. }
  3334. if limit <= 0 {
  3335. limit = 10
  3336. }
  3337. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  3338. c.ServeSuccessJSON(map[string]interface{}{
  3339. "total": total,
  3340. "list": list,
  3341. })
  3342. return
  3343. }
  3344. func (c *HisApiController) GetPutOnRecordList() {
  3345. page, _ := c.GetInt64("page")
  3346. limit, _ := c.GetInt64("limit")
  3347. keywords := c.GetString("keywords")
  3348. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  3349. if page <= 0 {
  3350. page = 1
  3351. }
  3352. if limit <= 0 {
  3353. limit = 10
  3354. }
  3355. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  3356. c.ServeSuccessJSON(map[string]interface{}{
  3357. "total": total,
  3358. "list": list,
  3359. })
  3360. return
  3361. }
  3362. func (c *HisApiController) GetCompareData() {
  3363. start_time := c.GetString("start_time")
  3364. end_time := c.GetString("end_time")
  3365. insutype := c.GetString("insutype")
  3366. timeLayout := "2006-01-02"
  3367. loc, _ := time.LoadLocation("Local")
  3368. var theStartTIme int64
  3369. if len(start_time) > 0 {
  3370. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3371. if err != nil {
  3372. theStartTIme = 0
  3373. }
  3374. theStartTIme = theTime.Unix()
  3375. }
  3376. var theEndtTIme int64
  3377. if len(end_time) > 0 {
  3378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3379. if err != nil {
  3380. theEndtTIme = 0
  3381. }
  3382. theEndtTIme = theTime.Unix()
  3383. }
  3384. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  3385. if err == nil {
  3386. c.ServeSuccessJSON(map[string]interface{}{
  3387. "list": formData,
  3388. })
  3389. } else {
  3390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. }
  3393. }
  3394. func (c *HisApiController) GetFaPiaoData() {
  3395. order_id, _ := c.GetInt64("order_id")
  3396. patient_id, _ := c.GetInt64("patient_id")
  3397. number := c.GetString("number")
  3398. adminUser := c.GetAdminUserInfo()
  3399. order, _ := service.GetHisOrderByID(order_id)
  3400. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3401. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3402. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3403. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  3404. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  3405. var bedCostTotal float64 = 0 //床位总费
  3406. var bedCostSelfTotal float64 = 0 //床位自费
  3407. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3408. var operationCostTotal float64 = 0 //手术费
  3409. var operationCostSelfTotal float64 = 0 //手术费
  3410. var operationCostPartSelfTotal float64 = 0 //手术费
  3411. var otherCostTotal float64 = 0 //其他费用
  3412. var otherCostSelfTotal float64 = 0 //其他费用
  3413. var otherCostPartSelfTotal float64 = 0 //其他费用
  3414. var materialCostTotal float64 = 0 //材料费
  3415. var materialCostSelfTotal float64 = 0 //材料费
  3416. var materialCostPartSelfTotal float64 = 0 //材料费
  3417. var westernMedicineCostTotal float64 = 0 //西药费
  3418. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3419. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3420. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3421. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3422. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3423. var checkCostTotal float64 = 0 //检查费
  3424. var checkCostSelfTotal float64 = 0 //检查费
  3425. var checkCostPartSelfTotal float64 = 0 //检查费
  3426. var laboratoryCostTotal float64 = 0 //化验费
  3427. var laboratoryCostSelfTotal float64 = 0 //化验费
  3428. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3429. var treatCostTotal float64 = 0 //治疗费用
  3430. var treatCostSelfTotal float64 = 0 //治疗费用
  3431. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3432. decimal.DivisionPrecision = 2
  3433. if his.BalanceAccountsType == 2 {
  3434. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  3435. for _, item := range orderInfos_two {
  3436. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  3437. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  3438. item.MedChrgitmType = "09"
  3439. }
  3440. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  3441. if item.HisPrescriptionProject.Type == 2 {
  3442. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  3443. case 1:
  3444. item.MedChrgitmType = "14"
  3445. break
  3446. case 2:
  3447. item.MedChrgitmType = "05"
  3448. break
  3449. case 3:
  3450. item.MedChrgitmType = "04"
  3451. break
  3452. case 4:
  3453. item.MedChrgitmType = "14"
  3454. break
  3455. case 5:
  3456. item.MedChrgitmType = "08"
  3457. break
  3458. case 6:
  3459. item.MedChrgitmType = "14"
  3460. break
  3461. case 7:
  3462. item.MedChrgitmType = "14"
  3463. break
  3464. case 8:
  3465. item.MedChrgitmType = "03"
  3466. break
  3467. case 9:
  3468. item.MedChrgitmType = "14"
  3469. break
  3470. }
  3471. } else if item.HisPrescriptionProject.Type == 3 {
  3472. item.MedChrgitmType = "08"
  3473. }
  3474. }
  3475. }
  3476. for _, item := range orderInfos_two {
  3477. if item.MedChrgitmType == "01" { //床位费
  3478. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3479. bedCostSelfTotal = bedCostTotal
  3480. }
  3481. if item.MedChrgitmType == "03" { //检查费
  3482. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3483. checkCostSelfTotal = checkCostTotal
  3484. }
  3485. if item.MedChrgitmType == "04" { //化验费
  3486. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3487. laboratoryCostSelfTotal = laboratoryCostTotal
  3488. }
  3489. if item.MedChrgitmType == "05" { //治疗费
  3490. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3491. treatCostSelfTotal = treatCostTotal
  3492. }
  3493. if item.MedChrgitmType == "06" { //手术费
  3494. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3495. operationCostSelfTotal = treatCostTotal
  3496. }
  3497. if item.MedChrgitmType == "08" { //材料费
  3498. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3499. materialCostSelfTotal = materialCostTotal
  3500. }
  3501. if item.MedChrgitmType == "09" { //西药费
  3502. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3503. westernMedicineCostSelfTotal = westernMedicineCostTotal
  3504. }
  3505. if item.MedChrgitmType == "11" { //中成费
  3506. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3507. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  3508. }
  3509. if item.MedChrgitmType == "14" { //其他费
  3510. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3511. otherCostSelfTotal = otherCostTotal
  3512. }
  3513. }
  3514. } else {
  3515. for _, item := range orderInfos {
  3516. if item.MedChrgitmType == "01" { //床位费
  3517. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3518. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3519. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3520. }
  3521. if item.MedChrgitmType == "03" { //检查费
  3522. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3523. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3524. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3525. }
  3526. if item.MedChrgitmType == "04" { //化验费
  3527. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3528. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3529. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3530. }
  3531. if item.MedChrgitmType == "05" { //治疗费
  3532. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3533. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3534. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3535. }
  3536. if item.MedChrgitmType == "06" { //手术费
  3537. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3538. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3539. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3540. }
  3541. if item.MedChrgitmType == "08" { //材料费
  3542. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3543. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3544. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3545. }
  3546. if item.MedChrgitmType == "09" { //西药费
  3547. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3548. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3549. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3550. }
  3551. if item.MedChrgitmType == "11" { //中成费
  3552. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3553. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3554. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3555. }
  3556. if item.MedChrgitmType == "14" { //其他费
  3557. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3558. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3559. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3560. }
  3561. }
  3562. }
  3563. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3564. c.ServeSuccessJSON(map[string]interface{}{
  3565. "order_number": order.Number, //业务流水号
  3566. "id_card_no": his.IdCardNo, //社会保障号
  3567. "department_name": department.Name, //科室
  3568. "number": his.Number, //门诊号
  3569. "date": order.SettleEndTime, //结算日期
  3570. "name": order.PsnName, //姓名
  3571. "gender": order.Gend, //性别
  3572. "psn_cash_money": order.PsnCashPay, //个人支付
  3573. "pay_way": "门诊", //结算方式
  3574. "medfee_sumamt": order.MedfeeSumamt, //总费用
  3575. "admin_user_name": admin.UserName, //收款员
  3576. "bedCostTotal": bedCostTotal,
  3577. "bedCostSelfTotal": bedCostSelfTotal,
  3578. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3579. "operationCostTotal": operationCostTotal,
  3580. "operationCostSelfTotal": operationCostSelfTotal,
  3581. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3582. "otherCostTotal": otherCostTotal,
  3583. "otherCostSelfTotal": otherCostSelfTotal,
  3584. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3585. "materialCostTotal": materialCostTotal,
  3586. "materialCostSelfTotal": materialCostSelfTotal,
  3587. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3588. "westernMedicineCostTotal": westernMedicineCostTotal,
  3589. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3590. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3591. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3592. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3593. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3594. "checkCostTotal": checkCostTotal,
  3595. "checkCostSelfTotal": checkCostSelfTotal,
  3596. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3597. "laboratoryCostTotal": laboratoryCostTotal,
  3598. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3599. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3600. "treatCostTotal": treatCostTotal,
  3601. "treatCostSelfTotal": treatCostSelfTotal,
  3602. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3603. })
  3604. }
  3605. func (this *HisApiController) GetIncomeStatisticsData() {
  3606. start_time := this.GetString("start_time")
  3607. end_time := this.GetString("end_time")
  3608. key_words := this.GetString("key_words")
  3609. limit, _ := this.GetInt64("limit")
  3610. page, _ := this.GetInt64("page")
  3611. if page <= 0 {
  3612. page = 1
  3613. }
  3614. if limit <= 0 {
  3615. limit = 10
  3616. }
  3617. statistics_type, _ := this.GetInt64("statistics_type")
  3618. admin := this.GetAdminUserInfo()
  3619. timeLayout := "2006-01-02"
  3620. loc, _ := time.LoadLocation("Local")
  3621. var theStartTIme int64
  3622. if len(start_time) > 0 {
  3623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3624. if err != nil {
  3625. theStartTIme = 0
  3626. }
  3627. theStartTIme = theTime.Unix()
  3628. }
  3629. var theEndtTIme int64
  3630. if len(end_time) > 0 {
  3631. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3632. if err != nil {
  3633. theEndtTIme = 0
  3634. }
  3635. theEndtTIme = theTime.Unix()
  3636. }
  3637. if statistics_type == 1 {
  3638. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3639. this.ServeSuccessJSON(map[string]interface{}{
  3640. "list": list,
  3641. "total": total,
  3642. })
  3643. } else {
  3644. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3645. this.ServeSuccessJSON(map[string]interface{}{
  3646. "list": list,
  3647. "total": total,
  3648. })
  3649. }
  3650. }
  3651. func (c *HisApiController) PostProjectInformation() {
  3652. adminUser := c.GetAdminUserInfo()
  3653. orgId := adminUser.CurrentOrgId
  3654. dataBody := make(map[string]interface{}, 0)
  3655. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3656. if err != nil {
  3657. utils.ErrorLog(err.Error())
  3658. return
  3659. }
  3660. utils.ErrorLog("%v", dataBody)
  3661. var projectList []*models.HisProject
  3662. var total_goods []interface{}
  3663. tempProjects := dataBody["projects"].([]interface{})
  3664. total_goods = tempProjects
  3665. for index, projectMap := range tempProjects {
  3666. projectM := projectMap.(map[string]interface{})
  3667. var project models.HisProject
  3668. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  3669. utils.ErrorLog("project_name")
  3670. return
  3671. }
  3672. project_name, _ := projectM["project_name"].(string)
  3673. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  3674. err_log := models.ExportErrLog{
  3675. LogType: 6,
  3676. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3677. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  3678. Status: 1,
  3679. CreateTime: time.Now().Unix(),
  3680. UpdateTime: time.Now().Unix(),
  3681. ExportTime: time.Now().Unix(),
  3682. }
  3683. service.CreateExportErrLog(&err_log)
  3684. continue
  3685. }
  3686. project.ProjectName = project_name
  3687. prices := projectM["price"].(string)
  3688. price, _ := strconv.ParseFloat(prices, 64)
  3689. if price <= 0 { //名字为空则生成一条导入错误日志
  3690. err_log := models.ExportErrLog{
  3691. LogType: 6,
  3692. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3693. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  3694. Status: 1,
  3695. CreateTime: time.Now().Unix(),
  3696. UpdateTime: time.Now().Unix(),
  3697. ExportTime: time.Now().Unix(),
  3698. }
  3699. service.CreateExportErrLog(&err_log)
  3700. continue
  3701. }
  3702. project.Price = price
  3703. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  3704. utils.ErrorLog("unit_id")
  3705. return
  3706. }
  3707. unit := projectM["unit"].(string)
  3708. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  3709. err_log := models.ExportErrLog{
  3710. LogType: 6,
  3711. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3712. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  3713. Status: 1,
  3714. CreateTime: time.Now().Unix(),
  3715. UpdateTime: time.Now().Unix(),
  3716. ExportTime: time.Now().Unix(),
  3717. }
  3718. service.CreateExportErrLog(&err_log)
  3719. continue
  3720. }
  3721. project.Unit = unit
  3722. cost_classify := projectM["cost_classify"].(string)
  3723. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  3724. err_log := models.ExportErrLog{
  3725. LogType: 6,
  3726. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3727. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3728. Status: 1,
  3729. CreateTime: time.Now().Unix(),
  3730. UpdateTime: time.Now().Unix(),
  3731. ExportTime: time.Now().Unix(),
  3732. }
  3733. service.CreateExportErrLog(&err_log)
  3734. continue
  3735. }
  3736. var costClassify = "费用类别"
  3737. var cost_classify_id int64
  3738. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  3739. if len(cost_classify) != 0 {
  3740. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  3741. if errcode == gorm.ErrRecordNotFound {
  3742. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  3743. dataconfig := models.DictDataconfig{
  3744. ParentId: costClassifyConfig.ID,
  3745. Module: "system",
  3746. OrgId: orgId,
  3747. Name: cost_classify,
  3748. FieldName: "",
  3749. Value: costConfig.Value + 1,
  3750. CreatedTime: "",
  3751. UpdatedTime: "",
  3752. CreateUserId: adminUser.AdminUser.Id,
  3753. Status: 1,
  3754. Remark: "",
  3755. DeleteIdSystem: 0,
  3756. Title: "",
  3757. Content: "",
  3758. Order: 0,
  3759. Code: "",
  3760. }
  3761. service.CreatedDicConfig(&dataconfig)
  3762. }
  3763. }
  3764. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  3765. for _, it := range costClassList {
  3766. if cost_classify == it.Name {
  3767. cost_classify_id = int64(it.Value)
  3768. }
  3769. }
  3770. project.CostClassify = cost_classify_id
  3771. executive_section := projectM["executive_section"].(string)
  3772. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  3773. err_log := models.ExportErrLog{
  3774. LogType: 6,
  3775. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3776. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  3777. Status: 1,
  3778. CreateTime: time.Now().Unix(),
  3779. UpdateTime: time.Now().Unix(),
  3780. ExportTime: time.Now().Unix(),
  3781. }
  3782. service.CreateExportErrLog(&err_log)
  3783. continue
  3784. }
  3785. if len(executive_section) != 0 {
  3786. //查找科室是否有内容
  3787. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  3788. if errcodedepart == gorm.ErrRecordNotFound {
  3789. department := models.XtHisDepartment{
  3790. Name: executive_section,
  3791. Status: 1,
  3792. UserOrgId: adminUser.CurrentOrgId,
  3793. CreatedTime: time.Now().Unix(),
  3794. }
  3795. service.CreateDePartment(&department)
  3796. }
  3797. }
  3798. var executive_section_id int64
  3799. departMentList, _ := service.GetAllDepartMent(orgId)
  3800. for _, it := range departMentList {
  3801. if executive_section == it.Name {
  3802. executive_section_id = it.ID
  3803. }
  3804. }
  3805. project.ExecutiveSection = executive_section_id
  3806. medical_coverage := projectM["medical_coverage"].(string)
  3807. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  3808. err_log := models.ExportErrLog{
  3809. LogType: 6,
  3810. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3811. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3812. Status: 1,
  3813. CreateTime: time.Now().Unix(),
  3814. UpdateTime: time.Now().Unix(),
  3815. ExportTime: time.Now().Unix(),
  3816. }
  3817. service.CreateExportErrLog(&err_log)
  3818. continue
  3819. }
  3820. var medicalCoverage = "医保等级"
  3821. var medical_coverage_id int64
  3822. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  3823. if len(medical_coverage) != 0 {
  3824. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  3825. if errormedicalcoverage == gorm.ErrRecordNotFound {
  3826. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  3827. dataconfig := models.DictDataconfig{
  3828. ParentId: medicalCoverageConfig.ID,
  3829. Module: "system",
  3830. OrgId: orgId,
  3831. Name: medical_coverage,
  3832. FieldName: "",
  3833. Value: medicalCoverageConfig.Value + 1,
  3834. CreatedTime: "",
  3835. UpdatedTime: "",
  3836. CreateUserId: adminUser.AdminUser.Id,
  3837. Status: 1,
  3838. Remark: "",
  3839. DeleteIdSystem: 0,
  3840. Title: "",
  3841. Content: "",
  3842. Order: 0,
  3843. Code: "",
  3844. }
  3845. service.CreatedDicConfig(&dataconfig)
  3846. }
  3847. }
  3848. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  3849. for _, it := range medicalCoverageList {
  3850. if medical_coverage == it.Name {
  3851. medical_coverage_id = int64(it.Value)
  3852. }
  3853. }
  3854. project.MedicalCoverage = medical_coverage_id
  3855. pinyin := projectM["pinyin"].(string)
  3856. project.Pinyin = pinyin
  3857. wubi := projectM["wubi"].(string)
  3858. project.Wubi = wubi
  3859. statistical_classification := projectM["statistical_classification"].(string)
  3860. var statisticalClassification = "统计分类"
  3861. var statistical_classification_id int64
  3862. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  3863. if len(statistical_classification) != 0 {
  3864. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  3865. if classificationerrcodes == gorm.ErrRecordNotFound {
  3866. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  3867. dataconfig := models.DictDataconfig{
  3868. ParentId: classiFication.ID,
  3869. Module: "system",
  3870. OrgId: orgId,
  3871. Name: statistical_classification,
  3872. FieldName: "",
  3873. Value: classiFicationConfig.Value + 1,
  3874. CreatedTime: "",
  3875. UpdatedTime: "",
  3876. CreateUserId: adminUser.AdminUser.Id,
  3877. Status: 1,
  3878. Remark: "",
  3879. DeleteIdSystem: 0,
  3880. Title: "",
  3881. Content: "",
  3882. Order: 0,
  3883. Code: "",
  3884. }
  3885. service.CreatedDicConfig(&dataconfig)
  3886. }
  3887. }
  3888. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  3889. for _, it := range classiFicationList {
  3890. if statistical_classification == it.Name {
  3891. statistical_classification_id = int64(it.Value)
  3892. }
  3893. }
  3894. project.StatisticalClassification = statistical_classification_id
  3895. disease_directory := int64(projectM["disease_directory"].(float64))
  3896. project.DiseaseDirectory = disease_directory
  3897. is_record := int64(projectM["is_record"].(float64))
  3898. project.IsRecord = is_record
  3899. medical_code := projectM["medical_code"].(string)
  3900. project.MedicalCode = medical_code
  3901. tube_color := projectM["tube_color"].(string)
  3902. var tubeColor = "试管颜色"
  3903. var tube_color_id int64
  3904. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  3905. if len(tube_color) != 0 {
  3906. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  3907. if errcodetube == gorm.ErrRecordNotFound {
  3908. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  3909. dataconfig := models.DictDataconfig{
  3910. ParentId: tubeColorConfig.ID,
  3911. Module: "system",
  3912. OrgId: orgId,
  3913. Name: tube_color,
  3914. FieldName: "",
  3915. Value: tubeConfig.Value + 1,
  3916. CreatedTime: "",
  3917. UpdatedTime: "",
  3918. CreateUserId: adminUser.AdminUser.Id,
  3919. Status: 1,
  3920. Remark: "",
  3921. DeleteIdSystem: 0,
  3922. Title: "",
  3923. Content: "",
  3924. Order: 0,
  3925. Code: "",
  3926. }
  3927. service.CreatedDicConfig(&dataconfig)
  3928. }
  3929. }
  3930. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  3931. for _, it := range tubeColorList {
  3932. if tube_color == it.Name {
  3933. tube_color_id = int64(it.Value)
  3934. }
  3935. }
  3936. project.TubeColor = tube_color_id
  3937. single_dose := projectM["single_dose"].(string)
  3938. project.SingleDose = single_dose
  3939. execution_frequency := projectM["execution_frequency"].(string)
  3940. project.ExecutionFrequency = execution_frequency
  3941. delivery_way := projectM["delivery_way"].(string)
  3942. project.DeliveryWay = delivery_way
  3943. number_days := projectM["number_days"].(string)
  3944. project.NumberDays = number_days
  3945. total := projectM["total"].(string)
  3946. project.Total = total
  3947. medical_status := int64(projectM["medical_status"].(float64))
  3948. project.MedicalStatus = medical_status
  3949. category := int64(projectM["category"].(float64))
  3950. project.Category = category
  3951. specail_project := int64(projectM["specail_project"].(float64))
  3952. project.SpecailProject = specail_project
  3953. social_security_directory_code := projectM["social_security_directory_code"].(string)
  3954. project.SocialSecurityDirectoryCode = social_security_directory_code
  3955. remark := projectM["remark"].(string)
  3956. project.Remark = remark
  3957. record_date := projectM["record_date"].(string)
  3958. timeLayout := "2006-01-02"
  3959. loc, _ := time.LoadLocation("Local")
  3960. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3961. project.RecordDate = theTime.Unix()
  3962. projectList = append(projectList, &project)
  3963. }
  3964. export_time := time.Now().Unix()
  3965. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3966. if len(projectList) > 0 {
  3967. for _, item := range projectList {
  3968. project := models.HisProject{
  3969. ProjectName: item.ProjectName,
  3970. Price: item.Price,
  3971. Unit: item.Unit,
  3972. CostClassify: item.CostClassify,
  3973. ExecutiveSection: item.ExecutiveSection,
  3974. MedicalCoverage: item.MedicalCoverage,
  3975. UserOrgId: orgId,
  3976. Status: 1,
  3977. CreatedTime: time.Now().Unix(),
  3978. Pinyin: item.Pinyin,
  3979. Wubi: item.Wubi,
  3980. StatisticalClassification: item.StatisticalClassification,
  3981. DiseaseDirectory: item.DiseaseDirectory,
  3982. IsRecord: item.IsRecord,
  3983. MedicalCode: item.MedicalCode,
  3984. TubeColor: item.TubeColor,
  3985. SingleDose: item.SingleDose,
  3986. DeliveryWay: item.DeliveryWay,
  3987. NumberDays: item.NumberDays,
  3988. Total: item.Total,
  3989. Category: item.Category,
  3990. MedicalStatus: item.MedicalStatus,
  3991. SpecailProject: item.SpecailProject,
  3992. RecordDate: item.RecordDate,
  3993. Remark: item.Remark,
  3994. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3995. ExecutionFrequency: item.ExecutionFrequency,
  3996. }
  3997. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  3998. if errcodeproject == gorm.ErrRecordNotFound {
  3999. service.CreateProjectInfomation(&project)
  4000. } else if errcodeproject == nil {
  4001. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  4002. }
  4003. log := models.ExportLog{
  4004. LogType: 6,
  4005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4006. TotalNum: int64(len(total_goods)),
  4007. FailNum: int64(len(errLogs)),
  4008. SuccessNum: int64(len(projectList)),
  4009. CreateTime: time.Now().Unix(),
  4010. UpdateTime: time.Now().Unix(),
  4011. ExportTime: export_time,
  4012. Status: 1,
  4013. }
  4014. service.CreateExportLog(&log)
  4015. c.ServeSuccessJSON(map[string]interface{}{
  4016. "msg": "导入成功",
  4017. "total_num": len(total_goods),
  4018. "success_num": len(projectList),
  4019. "fail_num": int64(len(errLogs)),
  4020. })
  4021. }
  4022. } else {
  4023. log := models.ExportLog{
  4024. LogType: 6,
  4025. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4026. TotalNum: int64(len(total_goods)),
  4027. FailNum: int64(len(errLogs)),
  4028. SuccessNum: int64(len(projectList)),
  4029. CreateTime: time.Now().Unix(),
  4030. UpdateTime: time.Now().Unix(),
  4031. ExportTime: export_time,
  4032. Status: 1,
  4033. }
  4034. service.CreateExportLog(&log)
  4035. c.ServeSuccessJSON(map[string]interface{}{
  4036. "msg": "导入成功",
  4037. "total_num": len(total_goods),
  4038. "success_num": len(projectList),
  4039. "fail_num": int64(len(errLogs)),
  4040. })
  4041. }
  4042. }
  4043. //func (this *HisApiController) EditProjectInformation(){
  4044. //
  4045. // id, _ := this.GetInt64("id")
  4046. // project_team := this.GetString("project_team")
  4047. // price := this.GetString("price")
  4048. // price_float, _ := strconv.ParseFloat(price, 64)
  4049. // pinyin := this.GetString("pinyin")
  4050. // wubi := this.GetString("wubi")
  4051. // tube_color, _ := this.GetInt64("tube_color")
  4052. // team_type, _ := this.GetInt64("team_type")
  4053. // remark := this.GetString("remark")
  4054. // ids := this.GetString("ids")
  4055. // item_id := this.GetString("item_id")
  4056. // projectTeam := models.XtHisProjectTeam{
  4057. // ProjectTeam: project_team,
  4058. // Price: price_float,
  4059. // Pinyin: pinyin,
  4060. // Wubi: wubi,
  4061. // TubeColor: tube_color,
  4062. // TeamType: team_type,
  4063. // Remark: remark,
  4064. // ProjectId: ids,
  4065. // ItemId: item_id,
  4066. // }
  4067. //
  4068. //
  4069. // dataBody := make(map[string]interface{}, 0)
  4070. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4071. // if err != nil {
  4072. // utils.ErrorLog(err.Error())
  4073. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4074. // return
  4075. // }
  4076. //
  4077. // err = service.UpdatedProjectTeam(id, &projectTeam)
  4078. //
  4079. //
  4080. // if err != nil {
  4081. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4082. // return
  4083. // }
  4084. //
  4085. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  4086. // infos, _ := dataBody["info"].([]interface{})
  4087. // if len(infos) > 0 {
  4088. // var ids []string
  4089. //
  4090. // for _, item := range infos {
  4091. // items := item.(map[string]interface{})
  4092. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4093. // utils.ErrorLog("id")
  4094. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4095. // return
  4096. // }
  4097. // id := int64(items["id"].(float64))
  4098. //
  4099. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4100. // utils.ErrorLog("type")
  4101. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4102. // return
  4103. // }
  4104. // types := int64(items["type"].(float64))
  4105. //
  4106. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4107. // utils.ErrorLog("number")
  4108. // }
  4109. //
  4110. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  4111. //
  4112. // projectList := models.XtHisProjectList{
  4113. // Number: number,
  4114. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4115. // ProjectId: id,
  4116. // Status: 1,
  4117. // CreatedTime: time.Now().Unix(),
  4118. // UpdatedTime: time.Now().Unix(),
  4119. // TeamId: projectTeam.ID,
  4120. // Type: types,
  4121. // }
  4122. // list := projectList
  4123. //
  4124. // service.CreateProjectList(&list)
  4125. //
  4126. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  4127. //
  4128. // }
  4129. // ids_str := strings.Join(ids, ",")
  4130. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  4131. // service.SaveProjectTeam(&projectTeam)
  4132. // this.ServeSuccessJSON(map[string]interface{}{
  4133. // "projectTeam": projectTeam,
  4134. // })
  4135. // }
  4136. // }
  4137. //}
  4138. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  4139. name := c.GetString("name")
  4140. mode_id, _ := c.GetInt64("mode", 0)
  4141. types, _ := c.GetInt64("type", 0)
  4142. patient_id, _ := c.GetInt64("patient_id", 0)
  4143. types = 1
  4144. adminInfo := c.GetAdminUserInfo()
  4145. template := &models.HisPrescriptionTemplate{
  4146. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4147. PatientId: patient_id,
  4148. Type: types,
  4149. Status: 1,
  4150. Ctime: time.Now().Unix(),
  4151. Mtime: time.Now().Unix(),
  4152. Name: name,
  4153. Mode: mode_id,
  4154. }
  4155. dataBody := make(map[string]interface{}, 0)
  4156. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4157. if err != nil {
  4158. utils.ErrorLog(err.Error())
  4159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4160. return
  4161. }
  4162. err = service.CreateHisPrescriptionTemplate(template)
  4163. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4164. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4165. if len(prescriptions) > 0 {
  4166. for _, item := range prescriptions {
  4167. items := item.(map[string]interface{})
  4168. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4169. utils.ErrorLog("type")
  4170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4171. return
  4172. }
  4173. types := int64(items["type"].(float64))
  4174. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4175. utils.ErrorLog("med_type")
  4176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4177. return
  4178. }
  4179. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4180. ctime := time.Now().Unix()
  4181. prescription := &models.HisPrescriptionInfoTemplate{
  4182. PatientId: patient_id,
  4183. UserOrgId: adminInfo.CurrentOrgId,
  4184. Ctime: ctime,
  4185. Mtime: ctime,
  4186. Type: types,
  4187. Modifier: adminInfo.AdminUser.Id,
  4188. Creator: adminInfo.AdminUser.Id,
  4189. Status: 1,
  4190. PTemplateId: template.ID,
  4191. MedType: med_type,
  4192. }
  4193. service.CreateHisPrescriptionInfoTemplate(prescription)
  4194. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4195. advices := items["advices"].([]interface{})
  4196. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4197. groupNo := int64(0)
  4198. ctime := time.Now().Unix()
  4199. mtime := ctime
  4200. if len(advices) > 0 {
  4201. for _, advice := range advices {
  4202. var s models.HisPrescriptionAdviceTemplate
  4203. s.PrescriptionId = prescription.ID
  4204. s.AdviceType = 2
  4205. s.StopState = 2
  4206. s.ExecutionState = 2
  4207. s.Status = 1
  4208. s.UserOrgId = adminInfo.CurrentOrgId
  4209. s.Groupno = groupNo
  4210. s.CreatedTime = ctime
  4211. s.UpdatedTime = mtime
  4212. s.PatientId = patient_id
  4213. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  4214. if errcode > 0 {
  4215. c.ServeFailJSONWithSGJErrorCode(errcode)
  4216. return
  4217. }
  4218. service.CreateHisPrescriptionAdviceTemplate(&s)
  4219. }
  4220. }
  4221. }
  4222. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4223. projects := items["project"].([]interface{})
  4224. if len(projects) > 0 {
  4225. for _, project := range projects {
  4226. var p models.HisPrescriptionProjectTemplate
  4227. p.PrescriptionId = prescription.ID
  4228. p.Ctime = time.Now().Unix()
  4229. p.Mtime = time.Now().Unix()
  4230. p.PatientId = patient_id
  4231. p.UserOrgId = adminInfo.CurrentOrgId
  4232. p.Status = 1
  4233. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  4234. if errcode > 0 {
  4235. c.ServeFailJSONWithSGJErrorCode(errcode)
  4236. return
  4237. }
  4238. service.CreateHisPrescriptionProjectTemplate(&p)
  4239. }
  4240. }
  4241. }
  4242. }
  4243. c.ServeSuccessJSON(map[string]interface{}{
  4244. "msg": "创建成功",
  4245. })
  4246. }
  4247. }
  4248. }
  4249. func (c *HisApiController) PreSettle() {
  4250. id, _ := c.GetInt64("id")
  4251. record_time := c.GetString("record_time")
  4252. his_patient_id, _ := c.GetInt64("his_patient_id")
  4253. timeLayout := "2006-01-02"
  4254. loc, _ := time.LoadLocation("Local")
  4255. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4256. diagnosis_id := c.GetString("diagnosis")
  4257. sick_type, _ := c.GetInt64("sick_type")
  4258. reg_type, _ := c.GetInt64("p_type")
  4259. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4261. if err != nil {
  4262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4263. return
  4264. }
  4265. recordDateTime := theTime.Unix()
  4266. adminUser := c.GetAdminUserInfo()
  4267. var prescriptions []*models.HisPrescription
  4268. var start_time int64
  4269. var end_time int64
  4270. ids_str := c.GetString("ids")
  4271. ids_arr := strings.Split(ids_str, ",")
  4272. fmt.Println(reg_type)
  4273. if settle_accounts_type == 1 { //日结
  4274. if reg_type == 11 {
  4275. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4276. } else {
  4277. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4278. }
  4279. fmt.Println(prescriptions)
  4280. } else { //月结
  4281. start_time_str := c.GetString("start_time")
  4282. end_time_str := c.GetString("end_time")
  4283. timeLayout := "2006-01-02"
  4284. loc, _ := time.LoadLocation("Local")
  4285. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4286. if err != nil {
  4287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4288. return
  4289. }
  4290. recordStartTime := theStartTime.Unix()
  4291. start_time = recordStartTime
  4292. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4293. if err != nil {
  4294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4295. return
  4296. }
  4297. recordEndTime := theEndTime.Unix()
  4298. end_time = recordEndTime
  4299. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4300. }
  4301. if reg_type == 1111 || reg_type == 1112 {
  4302. reg_type = 11
  4303. }
  4304. timestamp := time.Now().Unix()
  4305. tempTime := time.Unix(timestamp, 0)
  4306. timeFormat := tempTime.Format("20060102150405")
  4307. chrgBchno := rand.Intn(100000) + 10000
  4308. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4309. strconv.FormatInt(his.PatientId, 10)
  4310. var ids []int64
  4311. for _, item := range prescriptions {
  4312. ids = append(ids, item.ID)
  4313. }
  4314. fmt.Println(ids)
  4315. var total float64
  4316. for _, item := range prescriptions {
  4317. fmt.Println(item)
  4318. if item.Type == 1 { //药品
  4319. for _, subItem := range item.HisDoctorAdviceInfo {
  4320. total = total + (subItem.Price * subItem.PrescribingNumber)
  4321. }
  4322. }
  4323. if item.Type == 2 { //项目
  4324. for _, subItem := range item.HisPrescriptionProject {
  4325. total = total + (subItem.Price * float64(subItem.Count))
  4326. }
  4327. }
  4328. for _, subItem := range item.HisAdditionalCharge {
  4329. total = total + (subItem.Price * float64(subItem.Count))
  4330. }
  4331. }
  4332. allTotal := fmt.Sprintf("%.2f", total)
  4333. totals, _ := strconv.ParseFloat(allTotal, 64)
  4334. order := &models.HisOrder{
  4335. UserOrgId: adminUser.CurrentOrgId,
  4336. HisPatientId: his.ID,
  4337. PatientId: id,
  4338. SettleAccountsDate: recordDateTime,
  4339. Ctime: time.Now().Unix(),
  4340. Mtime: time.Now().Unix(),
  4341. Status: 1,
  4342. OrderStatus: 1,
  4343. MdtrtId: his.Number,
  4344. Number: chrg_bchno,
  4345. MedfeeSumamt: totals,
  4346. SettleEndTime: end_time,
  4347. SettleStartTime: start_time,
  4348. SettleType: settle_accounts_type,
  4349. PType: 2,
  4350. IsPre: 1,
  4351. MedType: strconv.Itoa(int(reg_type)),
  4352. Diagnosis: diagnosis_id,
  4353. }
  4354. err = service.CreateOrder(order)
  4355. if err != nil {
  4356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4357. return
  4358. }
  4359. var customs []*Custom
  4360. for _, item := range prescriptions {
  4361. fmt.Println(item.Type)
  4362. if item.Type == 1 { //药品
  4363. for _, subItem := range item.HisDoctorAdviceInfo {
  4364. cus := &Custom{
  4365. AdviceId: subItem.ID,
  4366. ProjectId: 0,
  4367. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  4368. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  4369. FeedetlSn: subItem.FeedetlSn,
  4370. Price: fmt.Sprintf("%.2f", subItem.Price),
  4371. MedListCodg: subItem.MedListCodg,
  4372. Type: 1,
  4373. }
  4374. customs = append(customs, cus)
  4375. }
  4376. }
  4377. if item.Type == 2 { //项目
  4378. for _, subItem := range item.HisPrescriptionProject {
  4379. cus := &Custom{
  4380. AdviceId: 0,
  4381. ProjectId: subItem.ID,
  4382. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  4383. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  4384. FeedetlSn: subItem.FeedetlSn,
  4385. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  4386. MedListCodg: subItem.MedListCodg,
  4387. Type: 2,
  4388. }
  4389. customs = append(customs, cus)
  4390. }
  4391. }
  4392. for _, item := range item.HisAdditionalCharge {
  4393. cus := &Custom{
  4394. ItemId: item.ID,
  4395. AdviceId: 0,
  4396. ProjectId: 0,
  4397. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  4398. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  4399. FeedetlSn: item.FeedetlSn,
  4400. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  4401. MedListCodg: item.XtHisAddtionConfig.Code,
  4402. Type: 3,
  4403. }
  4404. customs = append(customs, cus)
  4405. }
  4406. }
  4407. fmt.Println(customs)
  4408. for _, item := range customs {
  4409. var advice_id int64 = 0
  4410. var project_id int64 = 0
  4411. var item_id int64 = 0
  4412. var types int64 = 0
  4413. if item.Type == 1 {
  4414. advice_id = item.AdviceId
  4415. project_id = 0
  4416. item_id = 0
  4417. } else if item.Type == 2 {
  4418. advice_id = 0
  4419. item_id = 0
  4420. project_id = item.ProjectId
  4421. } else if item.Type == 3 {
  4422. advice_id = 0
  4423. item_id = item.ItemId
  4424. project_id = 0
  4425. }
  4426. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4427. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4428. pric, _ := strconv.ParseFloat(item.Price, 32)
  4429. info := &models.HisOrderInfo{
  4430. OrderNumber: order.Number,
  4431. UploadDate: time.Now().Unix(),
  4432. AdviceId: advice_id,
  4433. DetItemFeeSumamt: detItemFeeSumamt,
  4434. Cnt: cut,
  4435. Pric: pric,
  4436. PatientId: id,
  4437. Status: 1,
  4438. Mtime: time.Now().Unix(),
  4439. Ctime: time.Now().Unix(),
  4440. UserOrgId: adminUser.CurrentOrgId,
  4441. HisPatientId: his.ID,
  4442. OrderId: order.ID,
  4443. ProjectId: project_id,
  4444. Type: types,
  4445. ItemId: item_id,
  4446. }
  4447. service.CreateOrderInfo(info)
  4448. }
  4449. his.SickType = sick_type
  4450. service.UpdataHisPateint(&his)
  4451. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4452. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4453. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4454. if err == nil {
  4455. c.ServeSuccessJSON(map[string]interface{}{
  4456. "msg": "结算成功",
  4457. })
  4458. }
  4459. }
  4460. func (c *HisApiController) GetPrivateExpensesInfo() {
  4461. order_id, _ := c.GetInt64("id", 0)
  4462. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  4463. order, _ := service.GetHisOrderByID(order_id)
  4464. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  4465. if order.ID == 0 {
  4466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4467. return
  4468. }
  4469. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4470. org_id := c.GetAdminUserInfo().CurrentOrgId
  4471. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4472. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4473. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4474. c.ServeSuccessJSON(map[string]interface{}{
  4475. "order": order,
  4476. "order_info": order_info,
  4477. "patient": patient,
  4478. "admin_info": adminInfo,
  4479. "his": his,
  4480. "current_admin": role,
  4481. })
  4482. }
  4483. func (this *HisApiController) ChangeMedType() {
  4484. med_type := this.GetString("med_type")
  4485. id, _ := this.GetInt64("id")
  4486. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  4487. prescription.MedType = med_type
  4488. err := service.SaveHisPrescription(&prescription)
  4489. if err == nil {
  4490. this.ServeSuccessJSON(map[string]interface{}{
  4491. "msg": "修改成功",
  4492. })
  4493. } else {
  4494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4495. return
  4496. }
  4497. }
  4498. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  4499. patient_id, _ := c.GetInt64("patient_id")
  4500. his_patient_id, _ := c.GetInt64("his_patient_id")
  4501. record_date := c.GetString("record_date")
  4502. start_time := c.GetString("start_time")
  4503. end_time := c.GetString("end_time")
  4504. order_status, _ := c.GetInt64("type", 0)
  4505. p_type, _ := c.GetInt64("p_type", 0)
  4506. order_id, _ := c.GetInt64("order_id", 0)
  4507. timeLayout := "2006-01-02"
  4508. loc, _ := time.LoadLocation("Local")
  4509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4510. if err != nil {
  4511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4512. return
  4513. }
  4514. recordDateTime := theTime.Unix()
  4515. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4516. if err != nil {
  4517. }
  4518. startRecordDateTime := startTime.Unix()
  4519. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4520. if err != nil {
  4521. }
  4522. endRecordDateTime := endTime.Unix()
  4523. admin := c.GetAdminUserInfo()
  4524. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4525. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4526. order, _ := service.GetHisOrderByID(order_id)
  4527. var monthPrescriptions []*models.HisPrescription
  4528. if order_status == 1 || order_status == 0 {
  4529. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4530. } else if order_status == 2 {
  4531. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4532. }
  4533. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4534. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4535. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4536. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4537. //获取所有科室信息
  4538. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4539. c.ServeSuccessJSON(map[string]interface{}{
  4540. "his_info": his_patient_info,
  4541. "xt_info": xt_patient_info,
  4542. "case_history": case_history,
  4543. "info": patientPrescriptionInfo,
  4544. "last_info": lastPatientPrescriptionInfo,
  4545. "month_prescriptions": monthPrescriptions,
  4546. "order": order,
  4547. "doctors": doctors,
  4548. "department": department,
  4549. })
  4550. return
  4551. }
  4552. func (c *HisApiController) GetHisMonthPatientInfo() {
  4553. patient_id, _ := c.GetInt64("patient_id")
  4554. his_patient_id, _ := c.GetInt64("his_patient_id")
  4555. record_date := c.GetString("record_date")
  4556. number := c.GetString("number")
  4557. start_time := c.GetString("start_time")
  4558. end_time := c.GetString("end_time")
  4559. p_type, _ := c.GetInt64("p_type")
  4560. timeLayout := "2006-01-02"
  4561. loc, _ := time.LoadLocation("Local")
  4562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4563. if err != nil {
  4564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4565. return
  4566. }
  4567. recordDateTime := theTime.Unix()
  4568. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4569. if err != nil {
  4570. }
  4571. startRecordDateTime := startTime.Unix()
  4572. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4573. if err != nil {
  4574. }
  4575. endRecordDateTime := endTime.Unix()
  4576. admin := c.GetAdminUserInfo()
  4577. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  4578. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4579. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  4580. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4581. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4582. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4583. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4584. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  4585. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  4587. //获取所有科室信息
  4588. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4589. c.ServeSuccessJSON(map[string]interface{}{
  4590. "his_info": his_patient_info,
  4591. "xt_info": xt_patient_info,
  4592. "case_history": case_history,
  4593. "info": patientPrescriptionInfo,
  4594. "month_prescriptions": monthPrescriptions,
  4595. "order": order,
  4596. "doctors": doctors,
  4597. "department": department,
  4598. "count": count,
  4599. "drugStockConfig": drugStockConfig,
  4600. "last_info": lastPatientPrescriptionInfo,
  4601. })
  4602. return
  4603. }