his_api_controller.go 105KB

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