his_api_controller.go 164KB

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