his_api_controller.go 104KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967
  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. formatInt_price := strconv.FormatInt(price, 10)
  869. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  870. project.Price = float_price
  871. }
  872. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  873. total, _ := json["total"].(string)
  874. totals, _ := strconv.ParseInt(total, 10, 64)
  875. project.Count = totals
  876. }
  877. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  878. medical_code, _ := json["medical_code"].(string)
  879. project.MedListCodg = medical_code
  880. }
  881. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  882. single_dose, _ := json["single_dose"].(string)
  883. project.SingleDose = single_dose
  884. }
  885. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  886. delivery_way, _ := json["delivery_way"].(string)
  887. project.DeliveryWay = delivery_way
  888. }
  889. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  890. execution_frequency, _ := json["execution_frequency"].(string)
  891. project.ExecutionFrequency = execution_frequency
  892. }
  893. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  894. remark, _ := json["remark"].(string)
  895. project.Remark = remark
  896. }
  897. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  898. day, _ := json["number_days"].(string)
  899. project.Day = day
  900. }
  901. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  902. unit, _ := json["unit"].(string)
  903. project.Unit = unit
  904. }
  905. return 0
  906. }
  907. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}) int {
  908. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  909. id := int64(json["id"].(float64))
  910. additionalCharge.ID = id
  911. }
  912. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  913. item_id := int64(json["item_id"].(float64))
  914. additionalCharge.ItemId = item_id
  915. }
  916. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  917. price := int64(json["price"].(float64))
  918. formatInt_price := strconv.FormatInt(price, 10)
  919. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  920. additionalCharge.Price = float_price
  921. }
  922. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  923. count, _ := json["count"].(string)
  924. counts, _ := strconv.ParseInt(count, 10, 64)
  925. additionalCharge.Count = counts
  926. }
  927. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  928. item_name, _ := json["item_name"].(string)
  929. additionalCharge.ItemName = item_name
  930. }
  931. return 0
  932. }
  933. func (c *HisApiController) GetHisOrderList() {
  934. page, _ := c.GetInt64("page", -1)
  935. limit, _ := c.GetInt64("limit", -1)
  936. start_time := c.GetString("start_time")
  937. end_time := c.GetString("end_time")
  938. types, _ := c.GetInt64("type", 0)
  939. keywords := c.GetString("keywords")
  940. timeLayout := "2006-01-02"
  941. loc, _ := time.LoadLocation("Local")
  942. var startTime int64
  943. if len(start_time) > 0 {
  944. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  945. if err != nil {
  946. fmt.Println(err)
  947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. startTime = theTime.Unix()
  951. }
  952. var endTime int64
  953. if len(end_time) > 0 {
  954. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  955. if err != nil {
  956. utils.ErrorLog(err.Error())
  957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  958. return
  959. }
  960. endTime = theTime.Unix()
  961. }
  962. adminUser := c.GetAdminUserInfo()
  963. org_id := adminUser.CurrentOrgId
  964. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
  965. if err == nil {
  966. c.ServeSuccessJSON(map[string]interface{}{
  967. "order": order,
  968. "total": total,
  969. })
  970. } else {
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  972. return
  973. }
  974. }
  975. func (c *HisApiController) GetHisOrder() {
  976. patient_id, _ := c.GetInt64("patient_id", 0)
  977. number := c.GetString("number")
  978. adminInfo := c.GetAdminUserInfo()
  979. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  980. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  981. if err == nil {
  982. c.ServeSuccessJSON(map[string]interface{}{
  983. "order": order,
  984. "prescription": prescriptions,
  985. })
  986. } else {
  987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  988. return
  989. }
  990. }
  991. func (c *HisApiController) GetHisPrescriptionList() {
  992. record_date := c.GetString("record_date")
  993. keywords := c.GetString("keywords")
  994. page, _ := c.GetInt64("page")
  995. limit, _ := c.GetInt64("limit")
  996. timeLayout := "2006-01-02"
  997. loc, _ := time.LoadLocation("Local")
  998. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  999. if err != nil {
  1000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1001. return
  1002. }
  1003. recordDateTime := theTime.Unix()
  1004. adminInfo := c.GetAdminUserInfo()
  1005. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  1006. //adminInfo := c.GetAdminUserInfo()
  1007. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  1008. //fmt.Println(prescriptionOrder)
  1009. if err == nil {
  1010. c.ServeSuccessJSON(map[string]interface{}{
  1011. "order": prescriptionOrder,
  1012. "total": total,
  1013. })
  1014. } else {
  1015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1016. return
  1017. }
  1018. }
  1019. func (c *HisApiController) GetHisPrescriptionInfo() {
  1020. id, _ := c.GetInt64("id")
  1021. adminInfo := c.GetAdminUserInfo()
  1022. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  1023. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  1024. if err == nil {
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "order": prescriptionOrder,
  1027. "prescription": prescription,
  1028. })
  1029. } else {
  1030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1031. return
  1032. }
  1033. }
  1034. func (c *HisApiController) GetMedicalInsuranceConfig() {
  1035. adminUser := c.GetAdminUserInfo()
  1036. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1037. c.ServeSuccessJSON(map[string]interface{}{
  1038. "config": config,
  1039. })
  1040. }
  1041. type ResultTwo struct {
  1042. ErrMsg interface{} `json:"err_msg"`
  1043. InfRefmsgid string `json:"inf_refmsgid"`
  1044. Infcode int64 `json:"infcode"`
  1045. Output struct {
  1046. Baseinfo struct {
  1047. Age float64 `json:"age"`
  1048. Brdy string `json:"brdy"`
  1049. Certno string `json:"certno"`
  1050. Gend string `json:"gend"`
  1051. Naty string `json:"naty"`
  1052. PsnCertType string `json:"psn_cert_type"`
  1053. PsnName string `json:"psn_name"`
  1054. PsnNo string `json:"psn_no"`
  1055. } `json:"baseinfo"`
  1056. Idetinfo []interface{} `json:"idetinfo"`
  1057. Iinfo []struct {
  1058. Balc int64 `json:"balc"`
  1059. CvlservFlag string `json:"cvlserv_flag"`
  1060. EmpName string `json:"emp_name"`
  1061. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1062. Insutype string `json:"insutype"`
  1063. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1064. PausInsuDate interface{} `json:"paus_insu_date"`
  1065. PsnInsuDate string `json:"psn_insu_date"`
  1066. PsnInsuStas string `json:"psn_insu_stas"`
  1067. PsnType string `json:"psn_type"`
  1068. } `json:"insuinfo"`
  1069. } `json:"output"`
  1070. RefmsgTime string `json:"refmsg_time"`
  1071. RespondTime string `json:"respond_time"`
  1072. Signtype interface{} `json:"signtype"`
  1073. WarnInfo interface{} `json:"warn_info"`
  1074. }
  1075. type ResultThree struct {
  1076. Cainfo interface{} `json:"cainfo"`
  1077. ErrMsg interface{} `json:"err_msg"`
  1078. InfRefmsgid string `json:"inf_refmsgid"`
  1079. Infcode int64 `json:"infcode"`
  1080. Output struct {
  1081. Data struct {
  1082. IptOtpNo string `json:"ipt_otp_no"`
  1083. MdtrtID string `json:"mdtrt_id"`
  1084. PsnNo string `json:"psn_no"`
  1085. } `json:"data"`
  1086. } `json:"output"`
  1087. RefmsgTime string `json:"refmsg_time"`
  1088. RespondTime string `json:"respond_time"`
  1089. Signtype interface{} `json:"signtype"`
  1090. WarnMsg interface{} `json:"warn_msg"`
  1091. }
  1092. type ResultFour struct {
  1093. Cainfo string `json:"cainfo"`
  1094. ErrMsg string `json:"err_msg"`
  1095. InfRefmsgid string `json:"inf_refmsgid"`
  1096. Infcode int64 `json:"infcode"`
  1097. Output struct {
  1098. Result []struct {
  1099. BasMednFlag string `json:"bas_medn_flag"`
  1100. ChldMedcFlag string `json:"chld_medc_flag"`
  1101. ChrgitmLv string `json:"chrgitm_lv"`
  1102. Cnt float64 `json:"cnt"`
  1103. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1104. DrtReimFlag string `json:"drt_reim_flag"`
  1105. FeedetlSn string `json:"feedetl_sn"`
  1106. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1107. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1108. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1109. ListSpItemFlag string `json:"list_sp_item_flag"`
  1110. LmtUsedFlag string `json:"lmt_used_flag"`
  1111. MedChrgitmType string `json:"med_chrgitm_type"`
  1112. Memo string `json:"memo"`
  1113. OverlmtAmt float64 `json:"overlmt_amt"`
  1114. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1115. Pric float64 `json:"pric"`
  1116. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1117. SelfpayProp float64 `json:"selfpay_prop"`
  1118. } `json:"result"`
  1119. } `json:"output"`
  1120. RefmsgTime string `json:"refmsg_time"`
  1121. RespondTime string `json:"respond_time"`
  1122. Signtype string `json:"signtype"`
  1123. WarnMsg string `json:"warn_msg"`
  1124. }
  1125. type ResultFive struct {
  1126. Insutype string `json:"insutype"`
  1127. }
  1128. type ResultSix struct {
  1129. Cainfo interface{} `json:"cainfo"`
  1130. ErrMsg interface{} `json:"err_msg"`
  1131. InfRefmsgid string `json:"inf_refmsgid"`
  1132. Infcode int64 `json:"infcode"`
  1133. Output struct {
  1134. } `json:"output"`
  1135. RefmsgTime string `json:"refmsg_time"`
  1136. RespondTime string `json:"respond_time"`
  1137. Signtype interface{} `json:"signtype"`
  1138. WarnMsg interface{} `json:"warn_msg"`
  1139. }
  1140. type ResultSeven struct {
  1141. Cainfo string `json:"cainfo"`
  1142. ErrMsg string `json:"err_msg"`
  1143. InfRefmsgid string `json:"inf_refmsgid"`
  1144. Infcode int64 `json:"infcode"`
  1145. Output struct {
  1146. Setldetail []interface{} `json:"setldetail"`
  1147. Setlinfo struct {
  1148. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1149. AcctPay float64 `json:"acct_pay"`
  1150. ActPayDedc float64 `json:"act_pay_dedc"`
  1151. Age float64 `json:"age"`
  1152. Balc float64 `json:"balc"`
  1153. Brdy string `json:"brdy"`
  1154. Certno string `json:"certno"`
  1155. ClrOptins string `json:"clr_optins"`
  1156. ClrType string `json:"clr_type"`
  1157. ClrWay string `json:"clr_way"`
  1158. CvlservFlag string `json:"cvlserv_flag"`
  1159. CvlservPay float64 `json:"cvlserv_pay"`
  1160. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1161. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1162. Gend string `json:"gend"`
  1163. HifesPay float64 `json:"hifes_pay"`
  1164. HifmiPay float64 `json:"hifmi_pay"`
  1165. HifpPay float64 `json:"hifp_pay"`
  1166. HospPartAmt float64 `json:"hosp_part_amt"`
  1167. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1168. Insutype string `json:"insutype"`
  1169. MafPay float64 `json:"maf_pay"`
  1170. MdtrtCertType string `json:"mdtrt_cert_type"`
  1171. MdtrtID string `json:"mdtrt_id"`
  1172. MedType string `json:"med_type"`
  1173. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1174. MedinsSetlID string `json:"medins_setl_id"`
  1175. Naty string `json:"naty"`
  1176. OthPay float64 `json:"oth_pay"`
  1177. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1178. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1179. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1180. PsnCashPay float64 `json:"psn_cash_pay"`
  1181. PsnCertType string `json:"psn_cert_type"`
  1182. PsnName string `json:"psn_name"`
  1183. PsnNo string `json:"psn_no"`
  1184. PsnPartAmt float64 `json:"psn_part_amt"`
  1185. PsnType string `json:"psn_type"`
  1186. SetlID string `json:"setl_id"`
  1187. SetlTime string `json:"setl_time"`
  1188. HifobPay float64 `json:"hifob_pay"`
  1189. } `json:"setlinfo"`
  1190. } `json:"output"`
  1191. RefmsgTime string `json:"refmsg_time"`
  1192. RespondTime string `json:"respond_time"`
  1193. Signtype interface{} `json:"signtype"`
  1194. WarnMsg interface{} `json:"warn_msg"`
  1195. }
  1196. type ResultEight struct {
  1197. Cainfo string `json:"cainfo"`
  1198. ErrMsg string `json:"err_msg"`
  1199. InfRefmsgid string `json:"inf_refmsgid"`
  1200. Infcode int64 `json:"infcode"`
  1201. Output struct {
  1202. Stmtinfo struct {
  1203. SetlOptins string `json:"setl_optins"`
  1204. StmtRslt string `json:"stmt_rslt"`
  1205. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1206. } `json:"stmtinfo"`
  1207. } `json:"output"`
  1208. RefmsgTime string `json:"refmsg_time"`
  1209. RespondTime string `json:"respond_time"`
  1210. Signtype interface{} `json:"signtype"`
  1211. WarnMsg interface{} `json:"warn_msg"`
  1212. }
  1213. type ResultNine struct {
  1214. Cainfo string `json:"cainfo"`
  1215. ErrMsg string `json:"err_msg"`
  1216. InfRefmsgid string `json:"inf_refmsgid"`
  1217. Infcode int64 `json:"infcode"`
  1218. Output struct {
  1219. FileQuryNo string `json:"file_qury_no"`
  1220. } `json:"output"`
  1221. RefmsgTime string `json:"refmsg_time"`
  1222. RespondTime string `json:"respond_time"`
  1223. Signtype interface{} `json:"signtype"`
  1224. WarnMsg interface{} `json:"warn_msg"`
  1225. }
  1226. type ResultTen struct {
  1227. Cainfo string `json:"cainfo"`
  1228. ErrMsg string `json:"err_msg"`
  1229. InfRefmsgid string `json:"inf_refmsgid"`
  1230. Infcode int64 `json:"infcode"`
  1231. Output struct {
  1232. DldEndtime string `json:"dld_endtime"`
  1233. FileQuryNo string `json:"file_qury_no"`
  1234. Filename string `json:"filename"`
  1235. } `json:"output"`
  1236. RefmsgTime string `json:"refmsg_time"`
  1237. RespondTime string `json:"respond_time"`
  1238. Signtype interface{} `json:"signtype"`
  1239. WarnMsg interface{} `json:"warn_msg"`
  1240. }
  1241. type ResultEleven struct {
  1242. Cainfo string `json:"cainfo"`
  1243. ErrMsg string `json:"err_msg"`
  1244. InfRefmsgid string `json:"inf_refmsgid"`
  1245. Infcode int64 `json:"infcode"`
  1246. Output struct {
  1247. Setlinfo struct {
  1248. FixmedinsName string `json:"fixmedins_name"`
  1249. FixmedinsCode string `json:"fixmedins_code"`
  1250. PsnNo string `json:"psn_no"`
  1251. PsnName string `json:"psn_name"`
  1252. Gend string `json:"gend"`
  1253. Brdy string `json:"brdy"`
  1254. PsnCertType string `json:"psn_cert_type"`
  1255. PsnType string `json:"psn_type"`
  1256. EmpName string `json:"emp_name"`
  1257. Certno string `json:"certno"`
  1258. Insutype string `json:"insutype"`
  1259. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1260. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1261. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1262. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1263. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1264. ActPayDedc float64 `json:"act_pay_dedc"`
  1265. HifpPay float64 `json:"hifp_pay"`
  1266. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1267. CvlservPay float64 `json:"cvlserv_pay"`
  1268. HifesPay float64 `json:"hifes_pay"`
  1269. HifmiPay float64 `json:"hifmi_pay"`
  1270. MafPay float64 `json:"maf_pay"`
  1271. OthPay float64 `json:"oth_pay"`
  1272. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1273. PsnPay float64 `json:"psn_pay"`
  1274. AcctPay float64 `json:"acct_pay"`
  1275. CashPayamt float64 `json:"cash_payamt"`
  1276. Balc float64 `json:"balc"`
  1277. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1278. MedinsSetlId string `json:"medins_setl_id"`
  1279. RefdSetlFlag string `json:"refd_setl_flag"`
  1280. SetlTime string `json:"setl_time"`
  1281. } `json:"setlinfo"`
  1282. } `json:"output"`
  1283. RefmsgTime string `json:"refmsg_time"`
  1284. RespondTime string `json:"respond_time"`
  1285. Signtype interface{} `json:"signtype"`
  1286. WarnMsg interface{} `json:"warn_msg"`
  1287. }
  1288. type Custom struct {
  1289. DetItemFeeSumamt string
  1290. Cut string
  1291. FeedetlSn string
  1292. Price string
  1293. MedListCodg string
  1294. Type int64
  1295. AdviceId int64
  1296. ProjectId int64
  1297. ItemId int64
  1298. }
  1299. //获取个人信息----挂号-----上传就诊信息
  1300. func (c *HisApiController) GetRegisterInfo() {
  1301. id, _ := c.GetInt64("id")
  1302. record_time := c.GetString("record_time")
  1303. name := c.GetString("name")
  1304. gender, _ := c.GetInt64("gender")
  1305. age, _ := c.GetInt64("age")
  1306. birthday := c.GetString("birthday")
  1307. phone := c.GetString("phone")
  1308. medical_care, _ := c.GetInt64("medical_care")
  1309. id_card := c.GetString("id_card")
  1310. register_type, _ := c.GetInt64("register_type")
  1311. registration_fee, _ := c.GetFloat("registration_fee")
  1312. medical_expenses, _ := c.GetFloat("medical_expenses")
  1313. certificates, _ := c.GetInt64("certificates")
  1314. settlementValue, _ := c.GetInt64("settlement_value")
  1315. social_type, _ := c.GetInt64("social_type")
  1316. medical_insurance_card := c.GetString("medical_insurance_card")
  1317. timeLayout := "2006-01-02"
  1318. loc, _ := time.LoadLocation("Local")
  1319. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1320. birthUnix := birthdays.Unix()
  1321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1322. if err != nil {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. recordDateTime := theTime.Unix()
  1327. adminInfo := c.GetAdminUserInfo()
  1328. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1329. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1330. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1331. if patient == nil {
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1333. return
  1334. }
  1335. if len(patient.IdCardNo) == 0 {
  1336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1337. return
  1338. }
  1339. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1340. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1341. if config.IsOpen == 1 {
  1342. 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
  1343. resp, requestErr := http.Get(api)
  1344. if requestErr != nil {
  1345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1346. return
  1347. }
  1348. defer resp.Body.Close()
  1349. body, ioErr := ioutil.ReadAll(resp.Body)
  1350. if ioErr != nil {
  1351. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1353. return
  1354. }
  1355. var respJSON map[string]interface{}
  1356. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1357. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1359. return
  1360. }
  1361. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1362. userJSONBytes, _ := json.Marshal(userJSON)
  1363. var res ResultTwo
  1364. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1365. utils.ErrorLog("解析失败:%v", err)
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1367. return
  1368. }
  1369. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1370. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1371. infoStr := string(Iinfos)
  1372. idetinfoStr := string(Idetinfos)
  1373. his := models.VMHisPatient{
  1374. PsnNo: res.Output.Baseinfo.PsnNo,
  1375. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1376. Certno: res.Output.Baseinfo.Certno,
  1377. PsnName: res.Output.Baseinfo.PsnName,
  1378. Gend: res.Output.Baseinfo.Gend,
  1379. Naty: res.Output.Baseinfo.Naty,
  1380. Brdy: res.Output.Baseinfo.Brdy,
  1381. Age: res.Output.Baseinfo.Age,
  1382. Iinfo: infoStr,
  1383. Idetinfo: idetinfoStr,
  1384. PatientId: patient.ID,
  1385. RecordDate: theTime.Unix(),
  1386. UserOrgId: adminInfo.CurrentOrgId,
  1387. AdminUserId: adminInfo.AdminUser.Id,
  1388. IsReturn: 1,
  1389. }
  1390. fmt.Println(his)
  1391. lastPatient, _ := service.GetLastPatient(adminInfo.CurrentOrgId)
  1392. timeStr := time.Now().Format("2006-01-02")
  1393. timeArr := strings.Split(timeStr, "-")
  1394. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
  1395. hisPatient := models.HisPatient{
  1396. Number: str,
  1397. }
  1398. err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
  1399. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1401. return
  1402. }
  1403. timestamp := time.Now().Unix()
  1404. tempTime := time.Unix(timestamp, 0)
  1405. timeFormat := tempTime.Format("20060102150405")
  1406. chrgBchno := rand.Intn(100000) + 10000
  1407. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1408. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1409. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1410. //department_id := strconv.FormatInt(department.ID, 10)
  1411. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1412. if count <= 0 {
  1413. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1414. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1415. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1416. "&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
  1417. resp, requestErr := http.Get(api)
  1418. if requestErr != nil {
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1420. return
  1421. }
  1422. defer resp.Body.Close()
  1423. body, ioErr := ioutil.ReadAll(resp.Body)
  1424. if ioErr != nil {
  1425. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1427. return
  1428. }
  1429. var respJSON map[string]interface{}
  1430. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1431. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1433. return
  1434. }
  1435. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1436. userJSONBytes, _ := json.Marshal(respJSON)
  1437. var res ResultThree
  1438. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1439. utils.ErrorLog("解析失败:%v", err)
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1441. return
  1442. }
  1443. if res.Infcode == -1 {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1445. return
  1446. }
  1447. fmt.Println("000!!!!!!")
  1448. fmt.Println(res)
  1449. fmt.Println(res.Output.Data.MdtrtID)
  1450. fmt.Println(res.Output.Data.PsnNo)
  1451. fmt.Println(res.Output.Data.IptOtpNo)
  1452. his.Number = res.Output.Data.MdtrtID
  1453. his.PsnNo = res.Output.Data.PsnNo
  1454. his.IptOtpNo = res.Output.Data.IptOtpNo
  1455. his.IdCardNo = patient.IdCardNo
  1456. his.PhoneNumber = patient.Phone
  1457. his.UserOrgId = adminInfo.CurrentOrgId
  1458. his.Status = 1
  1459. his.Ctime = time.Now().Unix()
  1460. his.Mtime = time.Now().Unix()
  1461. err := service.CreateHisPatientTwo(&his)
  1462. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  1463. if err == nil {
  1464. api := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1465. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1466. "&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 +
  1467. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1468. resp, requestErr := http.Get(api)
  1469. if requestErr != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1471. return
  1472. }
  1473. body, ioErr := ioutil.ReadAll(resp.Body)
  1474. if ioErr != nil {
  1475. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1477. return
  1478. }
  1479. var respJSON map[string]interface{}
  1480. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1481. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1483. return
  1484. }
  1485. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1486. userJSONBytes, _ := json.Marshal(respJSON)
  1487. fmt.Println(respJSON)
  1488. fmt.Println(userJSONBytes)
  1489. var res ResultSix
  1490. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1491. utils.ErrorLog("解析失败:%v", err)
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1493. return
  1494. }
  1495. if res.Infcode == -1 {
  1496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1497. return
  1498. }
  1499. c.ServeSuccessJSON(map[string]interface{}{
  1500. "his_info": his,
  1501. })
  1502. } else {
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1504. return
  1505. }
  1506. }
  1507. } else {
  1508. timeStr := time.Now().Format("2006-01-02")
  1509. timeArr := strings.Split(timeStr, "-")
  1510. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1511. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1512. var hisPatient models.XtHisPatient
  1513. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1514. hisPatient = models.XtHisPatient{
  1515. Name: name,
  1516. Age: age,
  1517. Gender: gender,
  1518. Birthday: birthUnix,
  1519. Phone: phone,
  1520. MedicalTreatmentType: medical_care,
  1521. IdType: certificates,
  1522. IdCardNo: id_card,
  1523. BalanceAccountsType: settlementValue,
  1524. SocialType: social_type,
  1525. MedicalInsuranceNumber: medical_insurance_card,
  1526. RegisterType: register_type,
  1527. RegisterCost: registration_fee,
  1528. TreatmentCost: medical_expenses,
  1529. AdminUserId: adminInfo.AdminUser.Id,
  1530. UserOrgId: adminInfo.CurrentOrgId,
  1531. Status: 1,
  1532. RecordDate: recordDateTime,
  1533. IsReturn: 1,
  1534. PatientId: patient.ID,
  1535. Ctime: time.Now().Unix(),
  1536. Mtime: time.Now().Unix(),
  1537. Number: str,
  1538. }
  1539. service.CreateHisPatient(&hisPatient)
  1540. }
  1541. c.ServeSuccessJSON(map[string]interface{}{
  1542. "his_info": hisPatient,
  1543. })
  1544. }
  1545. }
  1546. //上传明细----结算
  1547. func (c *HisApiController) GetUploadInfo() {
  1548. id, _ := c.GetInt64("id")
  1549. record_time := c.GetString("record_time")
  1550. pay_way, _ := c.GetInt64("pay_way")
  1551. pay_price, _ := c.GetFloat("pay_price")
  1552. pay_card_no := c.GetString("pay_card_no")
  1553. discount_price, _ := c.GetFloat("discount_price")
  1554. preferential_price, _ := c.GetFloat("preferential_price")
  1555. reality_price, _ := c.GetFloat("reality_price")
  1556. found_price, _ := c.GetFloat("found_price")
  1557. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1558. private_price, _ := c.GetFloat("private_price")
  1559. timeLayout := "2006-01-02"
  1560. loc, _ := time.LoadLocation("Local")
  1561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1562. if err != nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. recordDateTime := theTime.Unix()
  1567. adminUser := c.GetAdminUserInfo()
  1568. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1569. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1570. timestamp := time.Now().Unix()
  1571. tempTime := time.Unix(timestamp, 0)
  1572. timeFormat := tempTime.Format("20060102150405")
  1573. chrgBchno := rand.Intn(100000) + 10000
  1574. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1575. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1576. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1577. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1578. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1579. strconv.FormatInt(his.PatientId, 10)
  1580. client := &http.Client{}
  1581. data := make(map[string]interface{})
  1582. data["psn_no"] = his.PsnNo
  1583. data["mdtrt_id"] = his.Number
  1584. data["pre"] = prescriptions
  1585. data["chrg_bchno"] = chrg_bchno
  1586. data["org_name"] = miConfig.OrgName
  1587. data["doctor"] = patientPrescription.Doctor
  1588. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  1589. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1590. data["fixmedins_code"] = miConfig.Code
  1591. data["dept_code"] = department.Number
  1592. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1593. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1594. data["secret_key"] = miConfig.SecretKey
  1595. fmt.Println(his.PsnNo)
  1596. fmt.Println(his.Number)
  1597. fmt.Println(miConfig.OrgName)
  1598. fmt.Println(chrg_bchno)
  1599. fmt.Println(patientPrescription.Doctor)
  1600. fmt.Println(miConfig.Code)
  1601. fmt.Println(department.Number)
  1602. fmt.Println(strconv.FormatInt(patientPrescription.Departments, 10))
  1603. fmt.Println(miConfig.InsuplcAdmdvs)
  1604. fmt.Println(miConfig.MdtrtareaAdmvs)
  1605. fmt.Println(miConfig.SecretKey)
  1606. var ids []int64
  1607. //var idsTwo []int64
  1608. //
  1609. for _, item := range prescriptions {
  1610. ids = append(ids, item.ID)
  1611. }
  1612. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1613. if config.IsOpen == 1 { //对接了医保,走医保流程
  1614. bytesData, _ := json.Marshal(data)
  1615. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1616. resp, _ := client.Do(req)
  1617. defer resp.Body.Close()
  1618. body, ioErr := ioutil.ReadAll(resp.Body)
  1619. if ioErr != nil {
  1620. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1622. return
  1623. }
  1624. var respJSON map[string]interface{}
  1625. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1626. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1628. return
  1629. }
  1630. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1631. userJSONBytes, _ := json.Marshal(respJSON)
  1632. var res ResultFour
  1633. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1634. utils.ErrorLog("解析失败:%v", err)
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1636. return
  1637. }
  1638. if res.Infcode == 0 {
  1639. order := &models.HisOrder{
  1640. UserOrgId: adminUser.CurrentOrgId,
  1641. HisPatientId: his.ID,
  1642. PatientId: his.PatientId,
  1643. SettleAccountsDate: recordDateTime,
  1644. Ctime: time.Now().Unix(),
  1645. Mtime: time.Now().Unix(),
  1646. Status: 1,
  1647. Number: chrg_bchno,
  1648. Infcode: res.Infcode,
  1649. WarnMsg: res.WarnMsg,
  1650. Cainfo: res.Cainfo,
  1651. ErrMsg: res.ErrMsg,
  1652. RespondTime: res.RefmsgTime,
  1653. InfRefmsgid: res.InfRefmsgid,
  1654. OrderStatus: 1,
  1655. PayWay: pay_way,
  1656. PayPrice: pay_price,
  1657. PayCardNo: pay_card_no,
  1658. DiscountPrice: discount_price,
  1659. PreferentialPrice: preferential_price,
  1660. RealityPrice: reality_price,
  1661. FoundPrice: found_price,
  1662. MedicalInsurancePrice: medical_insurance_price,
  1663. PrivatePrice: private_price,
  1664. IsMedicineInsurance: 1,
  1665. }
  1666. err = service.CreateOrder(order)
  1667. if err != nil {
  1668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1669. return
  1670. }
  1671. for _, item := range res.Output.Result {
  1672. temp := strings.Split(item.FeedetlSn, "-")
  1673. var advice_id int64 = 0
  1674. var project_id int64 = 0
  1675. var types int64 = 0
  1676. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1677. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1678. if temp[1] == "1" {
  1679. advice_id = id
  1680. project_id = 0
  1681. } else if temp[1] == "2" {
  1682. advice_id = 0
  1683. project_id = id
  1684. }
  1685. info := &models.HisOrderInfo{
  1686. OrderNumber: order.Number,
  1687. FeedetlSn: item.FeedetlSn,
  1688. UploadDate: time.Now().Unix(),
  1689. AdviceId: advice_id,
  1690. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1691. Cnt: item.Cnt,
  1692. Pric: float64(item.Pric),
  1693. PatientId: his.PatientId,
  1694. PricUplmtAmt: item.PricUplmtAmt,
  1695. SelfpayProp: item.SelfpayProp,
  1696. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1697. OverlmtAmt: item.OverlmtAmt,
  1698. PreselfpayAmt: item.PreselfpayAmt,
  1699. BasMednFlag: item.BasMednFlag,
  1700. MedChrgitmType: item.MedChrgitmType,
  1701. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1702. Status: 1,
  1703. Memo: item.Memo,
  1704. Mtime: time.Now().Unix(),
  1705. InscpScpAmt: item.InscpScpAmt,
  1706. DrtReimFlag: item.DrtReimFlag,
  1707. Ctime: time.Now().Unix(),
  1708. ListSpItemFlag: item.ListSpItemFlag,
  1709. ChldMedcFlag: item.ChldMedcFlag,
  1710. LmtUsedFlag: item.LmtUsedFlag,
  1711. ChrgitmLv: item.ChrgitmLv,
  1712. UserOrgId: adminUser.CurrentOrgId,
  1713. HisPatientId: his.ID,
  1714. OrderId: order.ID,
  1715. ProjectId: project_id,
  1716. Type: types,
  1717. }
  1718. service.CreateOrderInfo(info)
  1719. }
  1720. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1721. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1722. var total float64
  1723. for _, item := range prescriptions {
  1724. if item.Type == 1 { //药品
  1725. for _, subItem := range item.HisDoctorAdviceInfo {
  1726. total = total + (subItem.Price * subItem.PrescribingNumber)
  1727. }
  1728. }
  1729. if item.Type == 2 { //项目
  1730. for _, subItem := range item.HisPrescriptionProject {
  1731. total = total + (subItem.Price * float64(subItem.Count))
  1732. }
  1733. }
  1734. }
  1735. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1736. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1737. allTotal := fmt.Sprintf("%.2f", total)
  1738. if res.Infcode == 0 {
  1739. var rf []*ResultFive
  1740. json.Unmarshal([]byte(his.Iinfo), &rf)
  1741. psn_no := his.PsnNo
  1742. mdtrt_id := his.Number
  1743. chrg_bchno := chrg_bchno
  1744. cert_no := his.Certno
  1745. insutype := rf[0].Insutype
  1746. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1747. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1748. "&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
  1749. resp, requestErr := http.Get(api)
  1750. if requestErr != nil {
  1751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1752. return
  1753. }
  1754. defer resp.Body.Close()
  1755. body, ioErr := ioutil.ReadAll(resp.Body)
  1756. if ioErr != nil {
  1757. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1759. return
  1760. }
  1761. var respJSON map[string]interface{}
  1762. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1763. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1765. return
  1766. }
  1767. fmt.Println(respJSON)
  1768. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1769. userJSONBytes, _ := json.Marshal(respJSON)
  1770. var res ResultSeven
  1771. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1772. utils.ErrorLog("解析失败:%v", err)
  1773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1774. return
  1775. }
  1776. if res.Infcode == -1 {
  1777. errlog := &models.HisOrderError{
  1778. UserOrgId: adminUser.CurrentOrgId,
  1779. Ctime: time.Now().Unix(),
  1780. Mtime: time.Now().Unix(),
  1781. Number: chrg_bchno,
  1782. ErrMsg: res.ErrMsg,
  1783. Status: 1,
  1784. PatientId: id,
  1785. RecordTime: recordDateTime,
  1786. Stage: 7,
  1787. }
  1788. service.CreateErrMsgLog(errlog)
  1789. } else {
  1790. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1791. order.OrderStatus = 2
  1792. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1793. order.SetlId = res.Output.Setlinfo.SetlID
  1794. order.PsnNo = res.Output.Setlinfo.PsnNo
  1795. order.PsnName = res.Output.Setlinfo.PsnName
  1796. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1797. order.Certno = res.Output.Setlinfo.Certno
  1798. order.Gend = res.Output.Setlinfo.Gend
  1799. order.Naty = res.Output.Setlinfo.Naty
  1800. order.Age = res.Output.Setlinfo.Age
  1801. order.Insutype = res.Output.Setlinfo.Insutype
  1802. order.PsnType = res.Output.Setlinfo.PsnType
  1803. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1804. order.SetlTime = res.Output.Setlinfo.SetlTime
  1805. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1806. order.MedType = res.Output.Setlinfo.MedType
  1807. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1808. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1809. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1810. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1811. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1812. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1813. order.HifpPay = res.Output.Setlinfo.HifpPay
  1814. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1815. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1816. order.HifesPay = res.Output.Setlinfo.HifesPay
  1817. order.HifobPay = res.Output.Setlinfo.HifobPay
  1818. order.MafPay = res.Output.Setlinfo.MafPay
  1819. order.OthPay = res.Output.Setlinfo.OthPay
  1820. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1821. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1822. order.AcctPay = res.Output.Setlinfo.AcctPay
  1823. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1824. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1825. order.Balc = res.Output.Setlinfo.Balc
  1826. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1827. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1828. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1829. order.ClrWay = res.Output.Setlinfo.ClrWay
  1830. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1831. detailStr := string(setlDetail)
  1832. order.SetlDetail = detailStr
  1833. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1834. err = service.UpDateOrder(order)
  1835. if err == nil {
  1836. c.ServeSuccessJSON(map[string]interface{}{
  1837. "msg": "结算成功",
  1838. })
  1839. }
  1840. }
  1841. } else {
  1842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1843. return
  1844. }
  1845. } else {
  1846. }
  1847. } else {
  1848. var total float64
  1849. for _, item := range prescriptions {
  1850. if item.Type == 1 { //药品
  1851. for _, subItem := range item.HisDoctorAdviceInfo {
  1852. total = total + (subItem.Price * subItem.PrescribingNumber)
  1853. }
  1854. }
  1855. if item.Type == 2 { //项目
  1856. for _, subItem := range item.HisPrescriptionProject {
  1857. total = total + (subItem.Price * float64(subItem.Count))
  1858. }
  1859. }
  1860. for _, subItem := range item.HisAdditionalCharge {
  1861. total = total + (subItem.Price * float64(subItem.Count))
  1862. }
  1863. }
  1864. allTotal := fmt.Sprintf("%.2f", total)
  1865. totals, _ := strconv.ParseFloat(allTotal, 64)
  1866. order := &models.HisOrder{
  1867. UserOrgId: adminUser.CurrentOrgId,
  1868. HisPatientId: his.ID,
  1869. PatientId: id,
  1870. SettleAccountsDate: recordDateTime,
  1871. Ctime: time.Now().Unix(),
  1872. Mtime: time.Now().Unix(),
  1873. Status: 1,
  1874. OrderStatus: 2,
  1875. Number: chrg_bchno,
  1876. MedfeeSumamt: totals,
  1877. PayWay: pay_way,
  1878. PayPrice: pay_price,
  1879. PayCardNo: pay_card_no,
  1880. DiscountPrice: discount_price,
  1881. PreferentialPrice: preferential_price,
  1882. RealityPrice: reality_price,
  1883. FoundPrice: found_price,
  1884. MedicalInsurancePrice: medical_insurance_price,
  1885. PrivatePrice: private_price,
  1886. }
  1887. err = service.CreateOrder(order)
  1888. if err != nil {
  1889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1890. return
  1891. }
  1892. var customs []*Custom
  1893. for _, item := range prescriptions {
  1894. if item.Type == 1 { //药品
  1895. for _, subItem := range item.HisDoctorAdviceInfo {
  1896. cus := &Custom{
  1897. AdviceId: subItem.ID,
  1898. ProjectId: 0,
  1899. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1900. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1901. FeedetlSn: subItem.FeedetlSn,
  1902. Price: fmt.Sprintf("%.2f", subItem.Price),
  1903. MedListCodg: subItem.MedListCodg,
  1904. Type: 1,
  1905. }
  1906. customs = append(customs, cus)
  1907. }
  1908. }
  1909. if item.Type == 2 { //项目
  1910. for _, subItem := range item.HisPrescriptionProject {
  1911. cus := &Custom{
  1912. AdviceId: 0,
  1913. ProjectId: subItem.ID,
  1914. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1915. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1916. FeedetlSn: subItem.FeedetlSn,
  1917. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1918. MedListCodg: subItem.MedListCodg,
  1919. Type: 2,
  1920. }
  1921. customs = append(customs, cus)
  1922. }
  1923. }
  1924. for _, item := range item.HisAdditionalCharge {
  1925. cus := &Custom{
  1926. ItemId: item.ID,
  1927. AdviceId: 0,
  1928. ProjectId: 0,
  1929. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1930. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1931. FeedetlSn: item.FeedetlSn,
  1932. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1933. MedListCodg: item.XtHisAddtionConfig.Code,
  1934. Type: 3,
  1935. }
  1936. customs = append(customs, cus)
  1937. }
  1938. }
  1939. for _, item := range customs {
  1940. var advice_id int64 = 0
  1941. var project_id int64 = 0
  1942. var item_id int64 = 0
  1943. var types int64 = 0
  1944. if item.Type == 1 {
  1945. advice_id = item.AdviceId
  1946. project_id = 0
  1947. item_id = 0
  1948. } else if item.Type == 2 {
  1949. advice_id = 0
  1950. item_id = 0
  1951. project_id = item.ProjectId
  1952. } else if item.Type == 3 {
  1953. advice_id = 0
  1954. item_id = item.ItemId
  1955. project_id = 0
  1956. }
  1957. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1958. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1959. pric, _ := strconv.ParseFloat(item.Price, 32)
  1960. info := &models.HisOrderInfo{
  1961. OrderNumber: order.Number,
  1962. UploadDate: time.Now().Unix(),
  1963. AdviceId: advice_id,
  1964. DetItemFeeSumamt: detItemFeeSumamt,
  1965. Cnt: cut,
  1966. Pric: pric,
  1967. PatientId: id,
  1968. Status: 1,
  1969. Mtime: time.Now().Unix(),
  1970. Ctime: time.Now().Unix(),
  1971. UserOrgId: adminUser.CurrentOrgId,
  1972. HisPatientId: his.ID,
  1973. OrderId: order.ID,
  1974. ProjectId: project_id,
  1975. Type: types,
  1976. ItemId: item_id,
  1977. }
  1978. service.CreateOrderInfo(info)
  1979. }
  1980. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1981. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1982. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1983. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1984. if err == nil {
  1985. c.ServeSuccessJSON(map[string]interface{}{
  1986. "msg": "结算成功",
  1987. })
  1988. }
  1989. }
  1990. }
  1991. //退款
  1992. func (c *HisApiController) Refund() {
  1993. order_id, _ := c.GetInt64("order_id")
  1994. number := c.GetString("number")
  1995. record_time := c.GetString("record_time")
  1996. patient_id, _ := c.GetInt64("patient_id")
  1997. timeLayout := "2006-01-02"
  1998. loc, _ := time.LoadLocation("Local")
  1999. adminUser := c.GetAdminUserInfo()
  2000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2001. fmt.Println(err)
  2002. if err != nil {
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2004. return
  2005. }
  2006. recordDateTime := theTime.Unix()
  2007. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2008. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2009. order, _ := service.GetHisOrderByID(order_id)
  2010. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2011. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2012. if config.IsOpen == 1 { //对接了医保,走医保流程
  2013. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  2014. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2015. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2016. resp, requestErr := http.Get(api)
  2017. if requestErr != nil {
  2018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2019. return
  2020. }
  2021. body, ioErr := ioutil.ReadAll(resp.Body)
  2022. if ioErr != nil {
  2023. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2025. return
  2026. }
  2027. var respJSON map[string]interface{}
  2028. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2029. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2031. return
  2032. }
  2033. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2034. userJSONBytes, _ := json.Marshal(respJSON)
  2035. fmt.Println(respJSON)
  2036. fmt.Println(userJSONBytes)
  2037. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2038. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2039. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2040. resp2, requestErr2 := http.Get(api2)
  2041. if requestErr2 != nil {
  2042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2043. return
  2044. }
  2045. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2046. if ioErr2 != nil {
  2047. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2049. return
  2050. }
  2051. var respJSON2 map[string]interface{}
  2052. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2053. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2055. return
  2056. }
  2057. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2058. if err == nil {
  2059. c.ServeSuccessJSON(map[string]interface{}{
  2060. "msg": "退费成功",
  2061. })
  2062. } else {
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2064. return
  2065. }
  2066. } else {
  2067. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2068. if err == nil {
  2069. c.ServeSuccessJSON(map[string]interface{}{
  2070. "msg": "退费成功",
  2071. })
  2072. } else {
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2074. return
  2075. }
  2076. }
  2077. }
  2078. //对账
  2079. func (c *HisApiController) GetCheckAccount() {
  2080. start_time := c.GetString("start_time")
  2081. end_time := c.GetString("end_time")
  2082. insutype := c.GetString("insutype")
  2083. clr_type := c.GetString("clr_type")
  2084. adminUser := c.GetAdminUserInfo()
  2085. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2086. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2087. timeLayout := "2006-01-02"
  2088. loc, _ := time.LoadLocation("Local")
  2089. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2090. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2091. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2092. decimal.DivisionPrecision = 2
  2093. var medfee_sumamt float64
  2094. var acct_pay float64
  2095. var fund_pay_sumamt float64
  2096. fixmedins_setl_cnt := int64(len(orders))
  2097. for _, item := range orders {
  2098. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2099. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  2100. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2101. }
  2102. var user_name string
  2103. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2104. if role.ID == 0 {
  2105. user_name = "xxx"
  2106. } else {
  2107. user_name = role.UserName
  2108. }
  2109. if config.IsOpen == 1 {
  2110. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2111. "insutype=" + insutype +
  2112. "&clr_type=" + clr_type +
  2113. "&setl_optins=" + miConfig.OrgName +
  2114. "&stmt_begndate=" + start_time +
  2115. "&stm_enddate=" + end_time +
  2116. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2117. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2118. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2119. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2120. "&fixmedins_code=" + miConfig.Code +
  2121. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2122. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2123. "&secret_key=" + miConfig.SecretKey +
  2124. "&org_name=" + miConfig.OrgName +
  2125. "&doctor=" + user_name
  2126. fmt.Println(api)
  2127. resp, requestErr := http.Get(api)
  2128. if requestErr != nil {
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2130. return
  2131. }
  2132. body, ioErr := ioutil.ReadAll(resp.Body)
  2133. fmt.Println(body)
  2134. if ioErr != nil {
  2135. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2137. return
  2138. }
  2139. var respJSON map[string]interface{}
  2140. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2141. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2143. return
  2144. }
  2145. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2146. userJSONBytes, _ := json.Marshal(respJSON)
  2147. var res ResultEight
  2148. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2149. utils.ErrorLog("解析失败:%v", err)
  2150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2151. return
  2152. }
  2153. if res.Infcode == 0 {
  2154. c.ServeSuccessJSON(map[string]interface{}{
  2155. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2156. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2157. })
  2158. } else {
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2160. }
  2161. }
  2162. }
  2163. //对账明细
  2164. func (c *HisApiController) GetCheckDetailAccount() {
  2165. start_time := c.GetString("start_time")
  2166. end_time := c.GetString("end_time")
  2167. adminUser := c.GetAdminUserInfo()
  2168. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2169. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2170. timeLayout := "2006-01-02"
  2171. loc, _ := time.LoadLocation("Local")
  2172. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2173. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2174. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2175. Mkdir(miConfig.OrgName)
  2176. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2177. file_name := file + ".txt"
  2178. zip_name := file + ".zip"
  2179. zip_path := miConfig.OrgName + "/" + zip_name
  2180. file_path := miConfig.OrgName + "/" + file_name
  2181. decimal.DivisionPrecision = 2
  2182. var medfee_sumamt float64
  2183. var psn_cash_pay float64
  2184. var fund_pay_sumamt float64
  2185. fixmedins_setl_cnt := int64(len(orders))
  2186. for _, item := range orders {
  2187. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2188. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  2189. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2190. }
  2191. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2192. defer f.Close()
  2193. if err != nil {
  2194. fmt.Println(err.Error())
  2195. } else {
  2196. for _, item := range orders {
  2197. var refd_setl_flag string
  2198. if item.OrderStatus == 2 {
  2199. refd_setl_flag = "0"
  2200. }
  2201. if item.OrderStatus == 3 {
  2202. refd_setl_flag = "1"
  2203. }
  2204. var str string
  2205. str = item.SetlId + " " +
  2206. item.MdtrtId + " " +
  2207. item.PsnNo + " " +
  2208. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2209. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2210. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2211. _, err = f.Write([]byte(str))
  2212. }
  2213. }
  2214. Zip(file_path, zip_path)
  2215. fmt.Println(ReadFile(zip_path))
  2216. fmt.Println(string(ReadFile(zip_path)))
  2217. if config.IsOpen == 1 {
  2218. var user_name string
  2219. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2220. if role.ID == 0 {
  2221. user_name = "xxx"
  2222. } else {
  2223. user_name = role.UserName
  2224. }
  2225. baseParams := models.BaseParams{
  2226. SecretKey: miConfig.SecretKey,
  2227. FixmedinsCode: miConfig.Code,
  2228. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2229. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2230. OrgName: miConfig.OrgName,
  2231. Doctor: user_name,
  2232. }
  2233. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2234. var dat map[string]interface{}
  2235. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2236. fmt.Println(dat)
  2237. } else {
  2238. fmt.Println(err)
  2239. }
  2240. userJSONBytes, _ := json.Marshal(dat)
  2241. var res ResultNine
  2242. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2243. utils.ErrorLog("解析失败:%v", err)
  2244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. if res.Infcode == 0 {
  2248. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2249. "file_qury_no=" + res.Output.FileQuryNo +
  2250. "&setl_optins=" + miConfig.OrgName +
  2251. "&stmt_begndate=" + start_time +
  2252. "&stm_enddate=" + end_time +
  2253. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2254. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2255. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2256. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2257. "&fixmedins_code=" + miConfig.Code +
  2258. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2259. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2260. "&secret_key=" + miConfig.SecretKey +
  2261. "&org_name=" + miConfig.OrgName +
  2262. "&doctor=" + user_name
  2263. resp, requestErr := http.Get(api)
  2264. if requestErr != nil {
  2265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2266. return
  2267. }
  2268. body, ioErr := ioutil.ReadAll(resp.Body)
  2269. if ioErr != nil {
  2270. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2272. return
  2273. }
  2274. var respJSON map[string]interface{}
  2275. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2276. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2278. return
  2279. }
  2280. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2281. userJSONBytes, _ := json.Marshal(respJSON)
  2282. var res ResultTen
  2283. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2284. utils.ErrorLog("解析失败:%v", err)
  2285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2286. return
  2287. }
  2288. if res.Infcode == 0 {
  2289. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2290. c.ServeSuccessJSON(map[string]interface{}{
  2291. "msg": "明细对账成功",
  2292. })
  2293. }
  2294. } else {
  2295. }
  2296. }
  2297. }
  2298. func (c *HisApiController) GetSettleAccounts() {
  2299. //id, _ := c.GetInt64("id")
  2300. //record_time := c.GetString("record_time")
  2301. order_id, _ := c.GetInt64("order_id")
  2302. //timeLayout := "2006-01-02"
  2303. //loc, _ := time.LoadLocation("Local")
  2304. //
  2305. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2306. //if err != nil {
  2307. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2308. // return
  2309. //}
  2310. //recordDateTime := theTime.Unix()
  2311. adminUser := c.GetAdminUserInfo()
  2312. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2313. order, _ := service.GetHisOrderByID(order_id)
  2314. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2315. var bedCostTotal float64 = 0 //床位总费
  2316. var bedCostSelfTotal float64 = 0 //床位自费
  2317. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2318. var operationCostTotal float64 = 0 //手术费
  2319. var operationCostSelfTotal float64 = 0 //手术费
  2320. var operationCostPartSelfTotal float64 = 0 //手术费
  2321. var otherCostTotal float64 = 0 //其他费用
  2322. var otherCostSelfTotal float64 = 0 //其他费用
  2323. var otherCostPartSelfTotal float64 = 0 //其他费用
  2324. var materialCostTotal float64 = 0 //材料费
  2325. var materialCostSelfTotal float64 = 0 //材料费
  2326. var materialCostPartSelfTotal float64 = 0 //材料费
  2327. var westernMedicineCostTotal float64 = 0 //西药费
  2328. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2329. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2330. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2331. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2332. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2333. var checkCostTotal float64 = 0 //检查费
  2334. var checkCostSelfTotal float64 = 0 //检查费
  2335. var checkCostPartSelfTotal float64 = 0 //检查费
  2336. var laboratoryCostTotal float64 = 0 //化验费
  2337. var laboratoryCostSelfTotal float64 = 0 //化验费
  2338. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2339. var treatCostTotal float64 = 0 //治疗费用
  2340. var treatCostSelfTotal float64 = 0 //治疗费用
  2341. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2342. decimal.DivisionPrecision = 2
  2343. for _, item := range orderInfos {
  2344. if item.MedChrgitmType == "01" { //床位费
  2345. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2346. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2347. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2348. }
  2349. if item.MedChrgitmType == "03" { //检查费
  2350. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2351. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2352. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2353. }
  2354. if item.MedChrgitmType == "04" { //化验费
  2355. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2356. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2357. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2358. }
  2359. if item.MedChrgitmType == "05" { //治疗费
  2360. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2361. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2362. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2363. }
  2364. if item.MedChrgitmType == "06" { //手术费
  2365. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2366. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2367. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2368. }
  2369. if item.MedChrgitmType == "08" { //材料费
  2370. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2371. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2372. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2373. }
  2374. if item.MedChrgitmType == "09" { //西药费
  2375. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2376. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2377. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2378. }
  2379. if item.MedChrgitmType == "11" { //中成费
  2380. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2381. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2382. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2383. }
  2384. if item.MedChrgitmType == "14" { //其他费
  2385. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2386. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2387. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2388. }
  2389. }
  2390. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2391. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2392. var user_name string
  2393. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2394. if role.ID == 0 {
  2395. user_name = "xxx"
  2396. } else {
  2397. user_name = role.UserName
  2398. }
  2399. baseParams := models.BaseParams{
  2400. SecretKey: miConfig.SecretKey,
  2401. FixmedinsCode: miConfig.Code,
  2402. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2403. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2404. OrgName: miConfig.OrgName,
  2405. Doctor: user_name,
  2406. }
  2407. businessParams := models.BusinessParams{
  2408. PsnNo: order.PsnNo,
  2409. MdtrtId: order.MdtrtId,
  2410. SetlId: order.SetlId,
  2411. }
  2412. if config.IsOpen == 1 {
  2413. result := service.Gdyb5203(baseParams, businessParams)
  2414. var dat map[string]interface{}
  2415. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2416. fmt.Println(dat)
  2417. } else {
  2418. fmt.Println(err)
  2419. }
  2420. userJSONBytes, _ := json.Marshal(dat)
  2421. var res ResultEleven
  2422. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2423. utils.ErrorLog("解析失败:%v", err)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. if res.Infcode == 0 {
  2428. c.ServeSuccessJSON(map[string]interface{}{
  2429. "info": res.Output.Setlinfo,
  2430. "bedCostTotal": bedCostTotal,
  2431. "bedCostSelfTotal": bedCostSelfTotal,
  2432. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2433. "operationCostTotal": operationCostTotal,
  2434. "operationCostSelfTotal": operationCostSelfTotal,
  2435. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2436. "otherCostTotal": otherCostTotal,
  2437. "otherCostSelfTotal": otherCostSelfTotal,
  2438. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2439. "materialCostTotal": materialCostTotal,
  2440. "materialCostSelfTotal": materialCostSelfTotal,
  2441. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2442. "westernMedicineCostTotal": westernMedicineCostTotal,
  2443. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2444. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2445. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2446. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2447. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2448. "checkCostTotal": checkCostTotal,
  2449. "checkCostSelfTotal": checkCostSelfTotal,
  2450. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2451. "laboratoryCostTotal": laboratoryCostTotal,
  2452. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2453. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2454. "treatCostTotal": treatCostTotal,
  2455. "treatCostSelfTotal": treatCostSelfTotal,
  2456. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2457. })
  2458. }
  2459. }
  2460. }
  2461. func (this *HisApiController) AdditionalCharge() {
  2462. dataBody := make(map[string]interface{}, 0)
  2463. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2464. fmt.Println(err)
  2465. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2466. patient_id := int64(dataBody["patient_id"].(float64))
  2467. medicineData, _ := dataBody["medicineData"].([]interface{})
  2468. adminUserInfo := this.GetAdminUserInfo()
  2469. orgId := adminUserInfo.CurrentOrgId
  2470. admin_user_id := adminUserInfo.AdminUser.Id
  2471. timeStr := time.Now().Format("2006-01-02")
  2472. timeLayout := "2006-01-02 15:04:05"
  2473. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2474. timenow := timeStringToTime.Unix()
  2475. var additionalCharges []*models.HisAdditionalCharge
  2476. for _, item := range medicineData {
  2477. var randNum int
  2478. randNum = rand.Intn(10000) + 1000
  2479. timestamp := time.Now().Unix()
  2480. tempTime := time.Unix(timestamp, 0)
  2481. timeFormat := tempTime.Format("20060102150405")
  2482. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2483. items := item.(map[string]interface{})
  2484. money := items["price"].(string)
  2485. item_id_str := items["item_id"].(string)
  2486. name := items["name"].(string)
  2487. id_str := items["id"].(string)
  2488. moneys, _ := strconv.ParseInt(money, 10, 64)
  2489. monStr := strconv.FormatInt(moneys, 10)
  2490. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2491. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2492. id, _ := strconv.ParseInt(id_str, 10, 64)
  2493. additionalCharge := &models.HisAdditionalCharge{
  2494. ID: id,
  2495. HisPatientId: his_patient_id,
  2496. UserOrgId: orgId,
  2497. PatientId: patient_id,
  2498. RecordDate: timenow,
  2499. Price: monneyStr,
  2500. Status: 1,
  2501. ItemName: name,
  2502. ItemId: item_id,
  2503. AdminUserId: admin_user_id,
  2504. CreatedTime: time.Now().Unix(),
  2505. OrderStatus: 0,
  2506. PrescriptionNumber: "",
  2507. BatchNumber: "",
  2508. FeedetlSn: p_number,
  2509. }
  2510. service.CreateAdditionalCharge(additionalCharge)
  2511. additionalCharges = append(additionalCharges, additionalCharge)
  2512. }
  2513. this.ServeSuccessJSON(map[string]interface{}{
  2514. "msg": "添加成功",
  2515. "additional_charges": additionalCharges,
  2516. })
  2517. }
  2518. func (this *HisApiController) DeleteAddition() {
  2519. id, _ := this.GetInt64("id")
  2520. //TODO 需要判断是否已经结算
  2521. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2522. if err == nil {
  2523. this.ServeSuccessJSON(map[string]interface{}{
  2524. "msg": "删除成功",
  2525. })
  2526. return
  2527. } else {
  2528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2529. return
  2530. }
  2531. }
  2532. func (this *HisApiController) GetAdminUsers() {
  2533. adminUser := this.GetAdminUserInfo()
  2534. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2535. this.ServeSuccessJSON(map[string]interface{}{
  2536. "doctors": doctors,
  2537. })
  2538. }
  2539. func (this *DialysisApiController) GetLastOrNextHisPrescription() {
  2540. change_type, _ := this.GetInt64("type", 0)
  2541. record_date := this.GetString("record_time")
  2542. patient_id, _ := this.GetInt64("patient_id", 0)
  2543. timeLayout := "2006-01-02"
  2544. loc, _ := time.LoadLocation("Local")
  2545. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2546. record_time := theAdviceRecordTime.Unix()
  2547. adminUserInfo := this.GetAdminUserInfo()
  2548. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  2549. if err == nil {
  2550. if len(prescriptions) == 0 {
  2551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2552. return
  2553. } else {
  2554. this.ServeSuccessJSON(map[string]interface{}{
  2555. "prescriptions": prescriptions,
  2556. })
  2557. return
  2558. }
  2559. } else {
  2560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2561. return
  2562. }
  2563. }
  2564. func (this *DialysisApiController) GetCallHisPrescription() {
  2565. patient_id, _ := this.GetInt64("patient_id", 0)
  2566. timeLayout := "2006-01-02"
  2567. loc, _ := time.LoadLocation("Local")
  2568. start_time := this.GetString("start_time")
  2569. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2570. end_time := this.GetString("end_time")
  2571. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2572. adminUserInfo := this.GetAdminUserInfo()
  2573. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id)
  2574. if err == nil {
  2575. this.ServeSuccessJSON(map[string]interface{}{
  2576. "prescriptions": prescriptions,
  2577. })
  2578. return
  2579. } else {
  2580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2581. return
  2582. }
  2583. }
  2584. func PathExists(path string) (bool, error) {
  2585. _, err := os.Stat(path)
  2586. if err == nil {
  2587. return true, nil
  2588. }
  2589. if os.IsNotExist(err) {
  2590. return false, nil
  2591. }
  2592. return false, err
  2593. }
  2594. //创建文件夹
  2595. func Mkdir(dir string) {
  2596. // 创建文件夹
  2597. exist, err := PathExists(dir)
  2598. if err != nil {
  2599. fmt.Println(err.Error())
  2600. } else {
  2601. if exist {
  2602. fmt.Println(dir + "文件夹已存在!")
  2603. } else {
  2604. // 文件夹名称,权限
  2605. err := os.Mkdir(dir, os.ModePerm)
  2606. if err != nil {
  2607. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2608. } else {
  2609. fmt.Println(dir + "文件夹创建成功!")
  2610. }
  2611. }
  2612. }
  2613. }
  2614. //压缩文件
  2615. func Zip(srcFile string, destZip string) error {
  2616. zipfile, err := os.Create(destZip)
  2617. if err != nil {
  2618. return err
  2619. }
  2620. defer zipfile.Close()
  2621. archive := zip.NewWriter(zipfile)
  2622. defer archive.Close()
  2623. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2624. if err != nil {
  2625. return err
  2626. }
  2627. header, err := zip.FileInfoHeader(info)
  2628. if err != nil {
  2629. return err
  2630. }
  2631. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2632. // header.Name = path
  2633. if info.IsDir() {
  2634. header.Name += "/"
  2635. } else {
  2636. header.Method = zip.Deflate
  2637. }
  2638. writer, err := archive.CreateHeader(header)
  2639. if err != nil {
  2640. return err
  2641. }
  2642. if !info.IsDir() {
  2643. file, err := os.Open(path)
  2644. if err != nil {
  2645. return err
  2646. }
  2647. defer file.Close()
  2648. _, err = io.Copy(writer, file)
  2649. }
  2650. return err
  2651. })
  2652. return err
  2653. }
  2654. func ReadFile(filePath string) []byte {
  2655. f, err := os.Open(filePath)
  2656. if err != nil {
  2657. fmt.Println("read file fail", err)
  2658. return nil
  2659. }
  2660. defer f.Close()
  2661. fd, err := ioutil.ReadAll(f)
  2662. if err != nil {
  2663. fmt.Println("read to fd fail", err)
  2664. return nil
  2665. }
  2666. return fd
  2667. }