his_api_controller.go 160KB

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