his_api_controller.go 151KB

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