his_api_controller.go 173KB

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