his_api_controller.go 108KB

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