his_api_controller.go 123KB

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