his_api_controller.go 146KB

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