his_api_controller.go 105KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "archive/zip"
  8. "bytes"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "reflect"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  32. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  33. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  34. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  35. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  36. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  37. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  38. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  39. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  40. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  41. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  42. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  43. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  44. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  45. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  46. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  47. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  48. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  49. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  50. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  51. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  52. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  53. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  54. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  55. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  56. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  57. beego.Router("/api/hisprescription/get", &DialysisApiController{}, "Get:GetLastOrNextHisPrescription")
  58. beego.Router("/api/callhisprescription/get", &DialysisApiController{}, "Get:GetCallHisPrescription")
  59. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  60. }
  61. func (c *HisApiController) Sscard() {
  62. r := CardInit()
  63. if r == 0 {
  64. GetBaseInfo()
  65. }
  66. c.ServeSuccessJSON(map[string]interface{}{
  67. "list": "11",
  68. })
  69. }
  70. func GetBaseInfo() error {
  71. handle := syscall.MustLoadDLL("SSCard.dll")
  72. ReadCardBas := handle.MustFindProc("ReadCardBas")
  73. 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. HifobPay float64 `json:"hifob_pay"`
  1172. MdtrtID string `json:"mdtrt_id"`
  1173. MedType string `json:"med_type"`
  1174. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1175. MedinsSetlID string `json:"medins_setl_id"`
  1176. Naty string `json:"naty"`
  1177. OthPay float64 `json:"oth_pay"`
  1178. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1179. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1180. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1181. PsnCashPay float64 `json:"psn_cash_pay"`
  1182. PsnCertType string `json:"psn_cert_type"`
  1183. PsnName string `json:"psn_name"`
  1184. PsnNo string `json:"psn_no"`
  1185. PsnPartAmt float64 `json:"psn_part_amt"`
  1186. PsnType string `json:"psn_type"`
  1187. SetlID string `json:"setl_id"`
  1188. SetlTime string `json:"setl_time"`
  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. HifobPay float64 `json:"hifob_pay"`
  1253. Gend string `json:"gend"`
  1254. Brdy string `json:"brdy"`
  1255. PsnCertType string `json:"psn_cert_type"`
  1256. PsnType string `json:"psn_type"`
  1257. EmpName string `json:"emp_name"`
  1258. Certno string `json:"certno"`
  1259. Insutype string `json:"insutype"`
  1260. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1261. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1262. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1263. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1264. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1265. ActPayDedc float64 `json:"act_pay_dedc"`
  1266. HifpPay float64 `json:"hifp_pay"`
  1267. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1268. CvlservPay float64 `json:"cvlserv_pay"`
  1269. HifesPay float64 `json:"hifes_pay"`
  1270. HifmiPay float64 `json:"hifmi_pay"`
  1271. MafPay float64 `json:"maf_pay"`
  1272. OthPay float64 `json:"oth_pay"`
  1273. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1274. PsnPay float64 `json:"psn_pay"`
  1275. AcctPay float64 `json:"acct_pay"`
  1276. CashPayamt float64 `json:"cash_payamt"`
  1277. Balc float64 `json:"balc"`
  1278. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1279. MedinsSetlId string `json:"medins_setl_id"`
  1280. RefdSetlFlag string `json:"refd_setl_flag"`
  1281. SetlTime string `json:"setl_time"`
  1282. } `json:"setlinfo"`
  1283. } `json:"output"`
  1284. RefmsgTime string `json:"refmsg_time"`
  1285. RespondTime string `json:"respond_time"`
  1286. Signtype interface{} `json:"signtype"`
  1287. WarnMsg interface{} `json:"warn_msg"`
  1288. }
  1289. type Custom struct {
  1290. DetItemFeeSumamt string
  1291. Cut string
  1292. FeedetlSn string
  1293. Price string
  1294. MedListCodg string
  1295. Type int64
  1296. AdviceId int64
  1297. ProjectId int64
  1298. ItemId int64
  1299. }
  1300. //获取个人信息----挂号-----上传就诊信息
  1301. func (c *HisApiController) GetRegisterInfo() {
  1302. id, _ := c.GetInt64("id")
  1303. record_time := c.GetString("record_time")
  1304. name := c.GetString("name")
  1305. gender, _ := c.GetInt64("gender")
  1306. age, _ := c.GetInt64("age")
  1307. birthday := c.GetString("birthday")
  1308. phone := c.GetString("phone")
  1309. medical_care, _ := c.GetInt64("medical_care")
  1310. id_card := c.GetString("id_card")
  1311. register_type, _ := c.GetInt64("register_type")
  1312. registration_fee, _ := c.GetFloat("registration_fee")
  1313. medical_expenses, _ := c.GetFloat("medical_expenses")
  1314. certificates, _ := c.GetInt64("certificates")
  1315. settlementValue, _ := c.GetInt64("settlement_value")
  1316. social_type, _ := c.GetInt64("social_type")
  1317. medical_insurance_card := c.GetString("medical_insurance_card")
  1318. timeLayout := "2006-01-02"
  1319. loc, _ := time.LoadLocation("Local")
  1320. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1321. birthUnix := birthdays.Unix()
  1322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1323. if err != nil {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. recordDateTime := theTime.Unix()
  1328. adminInfo := c.GetAdminUserInfo()
  1329. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1330. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1331. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1332. if patient == nil {
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1334. return
  1335. }
  1336. if len(patient.IdCardNo) == 0 {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1338. return
  1339. }
  1340. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1341. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1342. if config.IsOpen == 1 {
  1343. 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
  1344. resp, requestErr := http.Get(api)
  1345. if requestErr != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1347. return
  1348. }
  1349. defer resp.Body.Close()
  1350. body, ioErr := ioutil.ReadAll(resp.Body)
  1351. if ioErr != nil {
  1352. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1354. return
  1355. }
  1356. var respJSON map[string]interface{}
  1357. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1358. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1360. return
  1361. }
  1362. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1363. userJSONBytes, _ := json.Marshal(userJSON)
  1364. var res ResultTwo
  1365. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1366. utils.ErrorLog("解析失败:%v", err)
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1368. return
  1369. }
  1370. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1371. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1372. infoStr := string(Iinfos)
  1373. idetinfoStr := string(Idetinfos)
  1374. his := models.VMHisPatient{
  1375. PsnNo: res.Output.Baseinfo.PsnNo,
  1376. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1377. Certno: res.Output.Baseinfo.Certno,
  1378. PsnName: res.Output.Baseinfo.PsnName,
  1379. Gend: res.Output.Baseinfo.Gend,
  1380. Naty: res.Output.Baseinfo.Naty,
  1381. Brdy: res.Output.Baseinfo.Brdy,
  1382. Age: res.Output.Baseinfo.Age,
  1383. Iinfo: infoStr,
  1384. Idetinfo: idetinfoStr,
  1385. PatientId: patient.ID,
  1386. RecordDate: theTime.Unix(),
  1387. UserOrgId: adminInfo.CurrentOrgId,
  1388. AdminUserId: adminInfo.AdminUser.Id,
  1389. IsReturn: 1,
  1390. }
  1391. fmt.Println(his)
  1392. lastPatient, _ := service.GetLastPatient(adminInfo.CurrentOrgId)
  1393. timeStr := time.Now().Format("2006-01-02")
  1394. timeArr := strings.Split(timeStr, "-")
  1395. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
  1396. hisPatient := models.HisPatient{
  1397. Number: str,
  1398. }
  1399. err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
  1400. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1402. return
  1403. }
  1404. timestamp := time.Now().Unix()
  1405. tempTime := time.Unix(timestamp, 0)
  1406. timeFormat := tempTime.Format("20060102150405")
  1407. chrgBchno := rand.Intn(100000) + 10000
  1408. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1409. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1410. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1411. //department_id := strconv.FormatInt(department.ID, 10)
  1412. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1413. if count <= 0 {
  1414. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1415. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1416. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1417. "&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
  1418. resp, requestErr := http.Get(api)
  1419. if requestErr != nil {
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1421. return
  1422. }
  1423. defer resp.Body.Close()
  1424. body, ioErr := ioutil.ReadAll(resp.Body)
  1425. if ioErr != nil {
  1426. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1428. return
  1429. }
  1430. var respJSON map[string]interface{}
  1431. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1432. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1434. return
  1435. }
  1436. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1437. userJSONBytes, _ := json.Marshal(respJSON)
  1438. var res ResultThree
  1439. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1440. utils.ErrorLog("解析失败:%v", err)
  1441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1442. return
  1443. }
  1444. if res.Infcode == -1 {
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1446. return
  1447. }
  1448. fmt.Println("000!!!!!!")
  1449. fmt.Println(res)
  1450. fmt.Println(res.Output.Data.MdtrtID)
  1451. fmt.Println(res.Output.Data.PsnNo)
  1452. fmt.Println(res.Output.Data.IptOtpNo)
  1453. his.Number = res.Output.Data.MdtrtID
  1454. his.PsnNo = res.Output.Data.PsnNo
  1455. his.IptOtpNo = res.Output.Data.IptOtpNo
  1456. his.IdCardNo = patient.IdCardNo
  1457. his.PhoneNumber = patient.Phone
  1458. his.UserOrgId = adminInfo.CurrentOrgId
  1459. his.Status = 1
  1460. his.Ctime = time.Now().Unix()
  1461. his.Mtime = time.Now().Unix()
  1462. err := service.CreateHisPatientTwo(&his)
  1463. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  1464. if err == nil {
  1465. api := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1466. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1467. "&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 +
  1468. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1469. resp, requestErr := http.Get(api)
  1470. if requestErr != nil {
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1472. return
  1473. }
  1474. body, ioErr := ioutil.ReadAll(resp.Body)
  1475. if ioErr != nil {
  1476. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1478. return
  1479. }
  1480. var respJSON map[string]interface{}
  1481. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1482. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1484. return
  1485. }
  1486. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1487. userJSONBytes, _ := json.Marshal(respJSON)
  1488. fmt.Println(respJSON)
  1489. fmt.Println(userJSONBytes)
  1490. var res ResultSix
  1491. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1492. utils.ErrorLog("解析失败:%v", err)
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1494. return
  1495. }
  1496. if res.Infcode == -1 {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1498. return
  1499. }
  1500. c.ServeSuccessJSON(map[string]interface{}{
  1501. "his_info": his,
  1502. })
  1503. } else {
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1505. return
  1506. }
  1507. }
  1508. } else {
  1509. timeStr := time.Now().Format("2006-01-02")
  1510. timeArr := strings.Split(timeStr, "-")
  1511. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1512. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1513. var hisPatient models.XtHisPatient
  1514. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1515. hisPatient = models.XtHisPatient{
  1516. Name: name,
  1517. Age: age,
  1518. Gender: gender,
  1519. Birthday: birthUnix,
  1520. Phone: phone,
  1521. MedicalTreatmentType: medical_care,
  1522. IdType: certificates,
  1523. IdCardNo: id_card,
  1524. BalanceAccountsType: settlementValue,
  1525. SocialType: social_type,
  1526. MedicalInsuranceNumber: medical_insurance_card,
  1527. RegisterType: register_type,
  1528. RegisterCost: registration_fee,
  1529. TreatmentCost: medical_expenses,
  1530. AdminUserId: adminInfo.AdminUser.Id,
  1531. UserOrgId: adminInfo.CurrentOrgId,
  1532. Status: 1,
  1533. RecordDate: recordDateTime,
  1534. IsReturn: 1,
  1535. PatientId: patient.ID,
  1536. Ctime: time.Now().Unix(),
  1537. Mtime: time.Now().Unix(),
  1538. Number: str,
  1539. }
  1540. service.CreateHisPatient(&hisPatient)
  1541. }
  1542. c.ServeSuccessJSON(map[string]interface{}{
  1543. "his_info": hisPatient,
  1544. })
  1545. }
  1546. }
  1547. //上传明细----结算
  1548. func (c *HisApiController) GetUploadInfo() {
  1549. id, _ := c.GetInt64("id")
  1550. record_time := c.GetString("record_time")
  1551. pay_way, _ := c.GetInt64("pay_way")
  1552. pay_price, _ := c.GetFloat("pay_price")
  1553. pay_card_no := c.GetString("pay_card_no")
  1554. discount_price, _ := c.GetFloat("discount_price")
  1555. preferential_price, _ := c.GetFloat("preferential_price")
  1556. reality_price, _ := c.GetFloat("reality_price")
  1557. found_price, _ := c.GetFloat("found_price")
  1558. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1559. private_price, _ := c.GetFloat("private_price")
  1560. timeLayout := "2006-01-02"
  1561. loc, _ := time.LoadLocation("Local")
  1562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1563. if err != nil {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1565. return
  1566. }
  1567. recordDateTime := theTime.Unix()
  1568. adminUser := c.GetAdminUserInfo()
  1569. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1570. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1571. timestamp := time.Now().Unix()
  1572. tempTime := time.Unix(timestamp, 0)
  1573. timeFormat := tempTime.Format("20060102150405")
  1574. chrgBchno := rand.Intn(100000) + 10000
  1575. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1576. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1577. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1578. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1579. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1580. strconv.FormatInt(his.PatientId, 10)
  1581. client := &http.Client{}
  1582. data := make(map[string]interface{})
  1583. data["psn_no"] = his.PsnNo
  1584. data["mdtrt_id"] = his.Number
  1585. data["pre"] = prescriptions
  1586. data["chrg_bchno"] = chrg_bchno
  1587. data["org_name"] = miConfig.OrgName
  1588. data["doctor"] = patientPrescription.Doctor
  1589. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  1590. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1591. data["fixmedins_code"] = miConfig.Code
  1592. data["dept_code"] = department.Number
  1593. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1594. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1595. data["secret_key"] = miConfig.SecretKey
  1596. fmt.Println(his.PsnNo)
  1597. fmt.Println(his.Number)
  1598. fmt.Println(miConfig.OrgName)
  1599. fmt.Println(chrg_bchno)
  1600. fmt.Println(patientPrescription.Doctor)
  1601. fmt.Println(miConfig.Code)
  1602. fmt.Println(department.Number)
  1603. fmt.Println(strconv.FormatInt(patientPrescription.Departments, 10))
  1604. fmt.Println(miConfig.InsuplcAdmdvs)
  1605. fmt.Println(miConfig.MdtrtareaAdmvs)
  1606. fmt.Println(miConfig.SecretKey)
  1607. var ids []int64
  1608. //var idsTwo []int64
  1609. //
  1610. for _, item := range prescriptions {
  1611. ids = append(ids, item.ID)
  1612. }
  1613. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1614. if config.IsOpen == 1 { //对接了医保,走医保流程
  1615. bytesData, _ := json.Marshal(data)
  1616. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1617. resp, _ := client.Do(req)
  1618. defer resp.Body.Close()
  1619. body, ioErr := ioutil.ReadAll(resp.Body)
  1620. if ioErr != nil {
  1621. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1623. return
  1624. }
  1625. var respJSON map[string]interface{}
  1626. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1627. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1629. return
  1630. }
  1631. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1632. userJSONBytes, _ := json.Marshal(respJSON)
  1633. var res ResultFour
  1634. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1635. utils.ErrorLog("解析失败:%v", err)
  1636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1637. return
  1638. }
  1639. if res.Infcode == 0 {
  1640. order := &models.HisOrder{
  1641. UserOrgId: adminUser.CurrentOrgId,
  1642. HisPatientId: his.ID,
  1643. PatientId: his.PatientId,
  1644. SettleAccountsDate: recordDateTime,
  1645. Ctime: time.Now().Unix(),
  1646. Mtime: time.Now().Unix(),
  1647. Status: 1,
  1648. Number: chrg_bchno,
  1649. Infcode: res.Infcode,
  1650. WarnMsg: res.WarnMsg,
  1651. Cainfo: res.Cainfo,
  1652. ErrMsg: res.ErrMsg,
  1653. RespondTime: res.RefmsgTime,
  1654. InfRefmsgid: res.InfRefmsgid,
  1655. OrderStatus: 1,
  1656. PayWay: pay_way,
  1657. PayPrice: pay_price,
  1658. PayCardNo: pay_card_no,
  1659. DiscountPrice: discount_price,
  1660. PreferentialPrice: preferential_price,
  1661. RealityPrice: reality_price,
  1662. FoundPrice: found_price,
  1663. MedicalInsurancePrice: medical_insurance_price,
  1664. PrivatePrice: private_price,
  1665. IsMedicineInsurance: 1,
  1666. }
  1667. err = service.CreateOrder(order)
  1668. if err != nil {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1670. return
  1671. }
  1672. for _, item := range res.Output.Result {
  1673. temp := strings.Split(item.FeedetlSn, "-")
  1674. var advice_id int64 = 0
  1675. var project_id int64 = 0
  1676. var types int64 = 0
  1677. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1678. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1679. if temp[1] == "1" {
  1680. advice_id = id
  1681. project_id = 0
  1682. } else if temp[1] == "2" {
  1683. advice_id = 0
  1684. project_id = id
  1685. }
  1686. info := &models.HisOrderInfo{
  1687. OrderNumber: order.Number,
  1688. FeedetlSn: item.FeedetlSn,
  1689. UploadDate: time.Now().Unix(),
  1690. AdviceId: advice_id,
  1691. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1692. Cnt: item.Cnt,
  1693. Pric: float64(item.Pric),
  1694. PatientId: his.PatientId,
  1695. PricUplmtAmt: item.PricUplmtAmt,
  1696. SelfpayProp: item.SelfpayProp,
  1697. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1698. OverlmtAmt: item.OverlmtAmt,
  1699. PreselfpayAmt: item.PreselfpayAmt,
  1700. BasMednFlag: item.BasMednFlag,
  1701. MedChrgitmType: item.MedChrgitmType,
  1702. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1703. Status: 1,
  1704. Memo: item.Memo,
  1705. Mtime: time.Now().Unix(),
  1706. InscpScpAmt: item.InscpScpAmt,
  1707. DrtReimFlag: item.DrtReimFlag,
  1708. Ctime: time.Now().Unix(),
  1709. ListSpItemFlag: item.ListSpItemFlag,
  1710. ChldMedcFlag: item.ChldMedcFlag,
  1711. LmtUsedFlag: item.LmtUsedFlag,
  1712. ChrgitmLv: item.ChrgitmLv,
  1713. UserOrgId: adminUser.CurrentOrgId,
  1714. HisPatientId: his.ID,
  1715. OrderId: order.ID,
  1716. ProjectId: project_id,
  1717. Type: types,
  1718. }
  1719. service.CreateOrderInfo(info)
  1720. }
  1721. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1722. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1723. var total float64
  1724. for _, item := range prescriptions {
  1725. if item.Type == 1 { //药品
  1726. for _, subItem := range item.HisDoctorAdviceInfo {
  1727. total = total + (subItem.Price * subItem.PrescribingNumber)
  1728. }
  1729. }
  1730. if item.Type == 2 { //项目
  1731. for _, subItem := range item.HisPrescriptionProject {
  1732. total = total + (subItem.Price * float64(subItem.Count))
  1733. }
  1734. }
  1735. }
  1736. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1737. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1738. allTotal := fmt.Sprintf("%.2f", total)
  1739. if res.Infcode == 0 {
  1740. var rf []*ResultFive
  1741. json.Unmarshal([]byte(his.Iinfo), &rf)
  1742. psn_no := his.PsnNo
  1743. mdtrt_id := his.Number
  1744. chrg_bchno := chrg_bchno
  1745. cert_no := his.Certno
  1746. insutype := rf[0].Insutype
  1747. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1748. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1749. "&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
  1750. resp, requestErr := http.Get(api)
  1751. if requestErr != nil {
  1752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1753. return
  1754. }
  1755. defer resp.Body.Close()
  1756. body, ioErr := ioutil.ReadAll(resp.Body)
  1757. if ioErr != nil {
  1758. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1760. return
  1761. }
  1762. var respJSON map[string]interface{}
  1763. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1764. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1766. return
  1767. }
  1768. fmt.Println(respJSON)
  1769. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1770. userJSONBytes, _ := json.Marshal(respJSON)
  1771. var res ResultSeven
  1772. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1773. utils.ErrorLog("解析失败:%v", err)
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1775. return
  1776. }
  1777. if res.Infcode == -1 {
  1778. errlog := &models.HisOrderError{
  1779. UserOrgId: adminUser.CurrentOrgId,
  1780. Ctime: time.Now().Unix(),
  1781. Mtime: time.Now().Unix(),
  1782. Number: chrg_bchno,
  1783. ErrMsg: res.ErrMsg,
  1784. Status: 1,
  1785. PatientId: id,
  1786. RecordTime: recordDateTime,
  1787. Stage: 7,
  1788. }
  1789. service.CreateErrMsgLog(errlog)
  1790. } else {
  1791. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1792. order.OrderStatus = 2
  1793. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1794. order.SetlId = res.Output.Setlinfo.SetlID
  1795. order.PsnNo = res.Output.Setlinfo.PsnNo
  1796. order.PsnName = res.Output.Setlinfo.PsnName
  1797. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1798. order.Certno = res.Output.Setlinfo.Certno
  1799. order.Gend = res.Output.Setlinfo.Gend
  1800. order.Naty = res.Output.Setlinfo.Naty
  1801. order.Age = res.Output.Setlinfo.Age
  1802. order.Insutype = res.Output.Setlinfo.Insutype
  1803. order.PsnType = res.Output.Setlinfo.PsnType
  1804. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1805. order.SetlTime = res.Output.Setlinfo.SetlTime
  1806. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1807. order.MedType = res.Output.Setlinfo.MedType
  1808. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1809. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1810. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1811. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1812. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1813. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1814. order.HifpPay = res.Output.Setlinfo.HifpPay
  1815. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1816. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1817. order.HifesPay = res.Output.Setlinfo.HifesPay
  1818. order.HifobPay = res.Output.Setlinfo.HifobPay
  1819. order.MafPay = res.Output.Setlinfo.MafPay
  1820. order.OthPay = res.Output.Setlinfo.OthPay
  1821. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1822. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1823. order.AcctPay = res.Output.Setlinfo.AcctPay
  1824. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1825. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1826. order.Balc = res.Output.Setlinfo.Balc
  1827. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1828. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1829. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1830. order.ClrWay = res.Output.Setlinfo.ClrWay
  1831. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1832. detailStr := string(setlDetail)
  1833. order.SetlDetail = detailStr
  1834. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1835. err = service.UpDateOrder(order)
  1836. if err == nil {
  1837. c.ServeSuccessJSON(map[string]interface{}{
  1838. "msg": "结算成功",
  1839. })
  1840. }
  1841. }
  1842. } else {
  1843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1844. return
  1845. }
  1846. } else {
  1847. }
  1848. } else {
  1849. var total float64
  1850. for _, item := range prescriptions {
  1851. if item.Type == 1 { //药品
  1852. for _, subItem := range item.HisDoctorAdviceInfo {
  1853. total = total + (subItem.Price * subItem.PrescribingNumber)
  1854. }
  1855. }
  1856. if item.Type == 2 { //项目
  1857. for _, subItem := range item.HisPrescriptionProject {
  1858. total = total + (subItem.Price * float64(subItem.Count))
  1859. }
  1860. }
  1861. for _, subItem := range item.HisAdditionalCharge {
  1862. total = total + (subItem.Price * float64(subItem.Count))
  1863. }
  1864. }
  1865. allTotal := fmt.Sprintf("%.2f", total)
  1866. totals, _ := strconv.ParseFloat(allTotal, 64)
  1867. order := &models.HisOrder{
  1868. UserOrgId: adminUser.CurrentOrgId,
  1869. HisPatientId: his.ID,
  1870. PatientId: id,
  1871. SettleAccountsDate: recordDateTime,
  1872. Ctime: time.Now().Unix(),
  1873. Mtime: time.Now().Unix(),
  1874. Status: 1,
  1875. OrderStatus: 2,
  1876. Number: chrg_bchno,
  1877. MedfeeSumamt: totals,
  1878. PayWay: pay_way,
  1879. PayPrice: pay_price,
  1880. PayCardNo: pay_card_no,
  1881. DiscountPrice: discount_price,
  1882. PreferentialPrice: preferential_price,
  1883. RealityPrice: reality_price,
  1884. FoundPrice: found_price,
  1885. MedicalInsurancePrice: medical_insurance_price,
  1886. PrivatePrice: private_price,
  1887. }
  1888. err = service.CreateOrder(order)
  1889. if err != nil {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1891. return
  1892. }
  1893. var customs []*Custom
  1894. for _, item := range prescriptions {
  1895. if item.Type == 1 { //药品
  1896. for _, subItem := range item.HisDoctorAdviceInfo {
  1897. cus := &Custom{
  1898. AdviceId: subItem.ID,
  1899. ProjectId: 0,
  1900. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1901. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1902. FeedetlSn: subItem.FeedetlSn,
  1903. Price: fmt.Sprintf("%.2f", subItem.Price),
  1904. MedListCodg: subItem.MedListCodg,
  1905. Type: 1,
  1906. }
  1907. customs = append(customs, cus)
  1908. }
  1909. }
  1910. if item.Type == 2 { //项目
  1911. for _, subItem := range item.HisPrescriptionProject {
  1912. cus := &Custom{
  1913. AdviceId: 0,
  1914. ProjectId: subItem.ID,
  1915. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1916. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1917. FeedetlSn: subItem.FeedetlSn,
  1918. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1919. MedListCodg: subItem.MedListCodg,
  1920. Type: 2,
  1921. }
  1922. customs = append(customs, cus)
  1923. }
  1924. }
  1925. for _, item := range item.HisAdditionalCharge {
  1926. cus := &Custom{
  1927. ItemId: item.ID,
  1928. AdviceId: 0,
  1929. ProjectId: 0,
  1930. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1931. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1932. FeedetlSn: item.FeedetlSn,
  1933. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1934. MedListCodg: item.XtHisAddtionConfig.Code,
  1935. Type: 3,
  1936. }
  1937. customs = append(customs, cus)
  1938. }
  1939. }
  1940. for _, item := range customs {
  1941. var advice_id int64 = 0
  1942. var project_id int64 = 0
  1943. var item_id int64 = 0
  1944. var types int64 = 0
  1945. if item.Type == 1 {
  1946. advice_id = item.AdviceId
  1947. project_id = 0
  1948. item_id = 0
  1949. } else if item.Type == 2 {
  1950. advice_id = 0
  1951. item_id = 0
  1952. project_id = item.ProjectId
  1953. } else if item.Type == 3 {
  1954. advice_id = 0
  1955. item_id = item.ItemId
  1956. project_id = 0
  1957. }
  1958. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1959. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1960. pric, _ := strconv.ParseFloat(item.Price, 32)
  1961. info := &models.HisOrderInfo{
  1962. OrderNumber: order.Number,
  1963. UploadDate: time.Now().Unix(),
  1964. AdviceId: advice_id,
  1965. DetItemFeeSumamt: detItemFeeSumamt,
  1966. Cnt: cut,
  1967. Pric: pric,
  1968. PatientId: id,
  1969. Status: 1,
  1970. Mtime: time.Now().Unix(),
  1971. Ctime: time.Now().Unix(),
  1972. UserOrgId: adminUser.CurrentOrgId,
  1973. HisPatientId: his.ID,
  1974. OrderId: order.ID,
  1975. ProjectId: project_id,
  1976. Type: types,
  1977. ItemId: item_id,
  1978. }
  1979. service.CreateOrderInfo(info)
  1980. }
  1981. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1982. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1983. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1984. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1985. if err == nil {
  1986. c.ServeSuccessJSON(map[string]interface{}{
  1987. "msg": "结算成功",
  1988. })
  1989. }
  1990. }
  1991. }
  1992. //退款
  1993. func (c *HisApiController) Refund() {
  1994. order_id, _ := c.GetInt64("order_id")
  1995. number := c.GetString("number")
  1996. record_time := c.GetString("record_time")
  1997. patient_id, _ := c.GetInt64("patient_id")
  1998. timeLayout := "2006-01-02"
  1999. loc, _ := time.LoadLocation("Local")
  2000. adminUser := c.GetAdminUserInfo()
  2001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2002. fmt.Println(err)
  2003. if err != nil {
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. recordDateTime := theTime.Unix()
  2008. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2009. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2010. order, _ := service.GetHisOrderByID(order_id)
  2011. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2012. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2013. if config.IsOpen == 1 { //对接了医保,走医保流程
  2014. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  2015. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2016. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2017. resp, requestErr := http.Get(api)
  2018. if requestErr != nil {
  2019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2020. return
  2021. }
  2022. body, ioErr := ioutil.ReadAll(resp.Body)
  2023. if ioErr != nil {
  2024. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2026. return
  2027. }
  2028. var respJSON map[string]interface{}
  2029. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2030. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2032. return
  2033. }
  2034. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2035. userJSONBytes, _ := json.Marshal(respJSON)
  2036. fmt.Println(respJSON)
  2037. fmt.Println(userJSONBytes)
  2038. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2039. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2040. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2041. resp2, requestErr2 := http.Get(api2)
  2042. if requestErr2 != nil {
  2043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2044. return
  2045. }
  2046. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2047. if ioErr2 != nil {
  2048. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2050. return
  2051. }
  2052. var respJSON2 map[string]interface{}
  2053. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2054. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2056. return
  2057. }
  2058. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2059. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2060. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2061. resp3, requestErr3 := http.Get(api3)
  2062. if requestErr3 != nil {
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2064. return
  2065. }
  2066. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2067. if ioErr3 != nil {
  2068. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2070. return
  2071. }
  2072. var respJSON3 map[string]interface{}
  2073. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2074. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2076. return
  2077. }
  2078. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2079. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2080. if err == nil {
  2081. c.ServeSuccessJSON(map[string]interface{}{
  2082. "msg": "退费成功",
  2083. })
  2084. } else {
  2085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2086. return
  2087. }
  2088. } else {
  2089. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2090. if err == nil {
  2091. c.ServeSuccessJSON(map[string]interface{}{
  2092. "msg": "退费成功",
  2093. })
  2094. } else {
  2095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2096. return
  2097. }
  2098. }
  2099. }
  2100. //对账
  2101. func (c *HisApiController) GetCheckAccount() {
  2102. start_time := c.GetString("start_time")
  2103. end_time := c.GetString("end_time")
  2104. insutype := c.GetString("insutype")
  2105. clr_type := c.GetString("clr_type")
  2106. adminUser := c.GetAdminUserInfo()
  2107. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2108. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2109. timeLayout := "2006-01-02"
  2110. loc, _ := time.LoadLocation("Local")
  2111. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2112. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2113. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2114. decimal.DivisionPrecision = 2
  2115. var medfee_sumamt float64
  2116. var acct_pay float64
  2117. var fund_pay_sumamt float64
  2118. fixmedins_setl_cnt := int64(len(orders))
  2119. for _, item := range orders {
  2120. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2121. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  2122. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2123. }
  2124. var user_name string
  2125. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2126. if role.ID == 0 {
  2127. user_name = "xxx"
  2128. } else {
  2129. user_name = role.UserName
  2130. }
  2131. if config.IsOpen == 1 {
  2132. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2133. "insutype=" + insutype +
  2134. "&clr_type=" + clr_type +
  2135. "&setl_optins=" + miConfig.OrgName +
  2136. "&stmt_begndate=" + start_time +
  2137. "&stm_enddate=" + end_time +
  2138. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2139. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2140. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2141. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2142. "&fixmedins_code=" + miConfig.Code +
  2143. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2144. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2145. "&secret_key=" + miConfig.SecretKey +
  2146. "&org_name=" + miConfig.OrgName +
  2147. "&doctor=" + user_name
  2148. fmt.Println(api)
  2149. resp, requestErr := http.Get(api)
  2150. if requestErr != nil {
  2151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2152. return
  2153. }
  2154. body, ioErr := ioutil.ReadAll(resp.Body)
  2155. fmt.Println(body)
  2156. if ioErr != nil {
  2157. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2159. return
  2160. }
  2161. var respJSON map[string]interface{}
  2162. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2163. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2165. return
  2166. }
  2167. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2168. userJSONBytes, _ := json.Marshal(respJSON)
  2169. var res ResultEight
  2170. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2171. utils.ErrorLog("解析失败:%v", err)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2173. return
  2174. }
  2175. if res.Infcode == 0 {
  2176. c.ServeSuccessJSON(map[string]interface{}{
  2177. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2178. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2179. })
  2180. } else {
  2181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2182. }
  2183. }
  2184. }
  2185. //对账明细
  2186. func (c *HisApiController) GetCheckDetailAccount() {
  2187. start_time := c.GetString("start_time")
  2188. end_time := c.GetString("end_time")
  2189. adminUser := c.GetAdminUserInfo()
  2190. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2191. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2192. timeLayout := "2006-01-02"
  2193. loc, _ := time.LoadLocation("Local")
  2194. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2195. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2196. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2197. Mkdir(miConfig.OrgName)
  2198. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2199. file_name := file + ".txt"
  2200. zip_name := file + ".zip"
  2201. zip_path := miConfig.OrgName + "/" + zip_name
  2202. file_path := miConfig.OrgName + "/" + file_name
  2203. decimal.DivisionPrecision = 2
  2204. var medfee_sumamt float64
  2205. var psn_cash_pay float64
  2206. var fund_pay_sumamt float64
  2207. fixmedins_setl_cnt := int64(len(orders))
  2208. for _, item := range orders {
  2209. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2210. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  2211. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2212. }
  2213. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2214. defer f.Close()
  2215. if err != nil {
  2216. fmt.Println(err.Error())
  2217. } else {
  2218. for _, item := range orders {
  2219. var refd_setl_flag string
  2220. if item.OrderStatus == 2 {
  2221. refd_setl_flag = "0"
  2222. }
  2223. if item.OrderStatus == 3 {
  2224. refd_setl_flag = "1"
  2225. }
  2226. var str string
  2227. str = item.SetlId + " " +
  2228. item.MdtrtId + " " +
  2229. item.PsnNo + " " +
  2230. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2231. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2232. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2233. _, err = f.Write([]byte(str))
  2234. }
  2235. }
  2236. Zip(file_path, zip_path)
  2237. fmt.Println(ReadFile(zip_path))
  2238. fmt.Println(string(ReadFile(zip_path)))
  2239. if config.IsOpen == 1 {
  2240. var user_name string
  2241. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2242. if role.ID == 0 {
  2243. user_name = "xxx"
  2244. } else {
  2245. user_name = role.UserName
  2246. }
  2247. baseParams := models.BaseParams{
  2248. SecretKey: miConfig.SecretKey,
  2249. FixmedinsCode: miConfig.Code,
  2250. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2251. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2252. OrgName: miConfig.OrgName,
  2253. Doctor: user_name,
  2254. }
  2255. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2256. var dat map[string]interface{}
  2257. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2258. fmt.Println(dat)
  2259. } else {
  2260. fmt.Println(err)
  2261. }
  2262. userJSONBytes, _ := json.Marshal(dat)
  2263. var res ResultNine
  2264. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2265. utils.ErrorLog("解析失败:%v", err)
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2267. return
  2268. }
  2269. if res.Infcode == 0 {
  2270. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2271. "file_qury_no=" + res.Output.FileQuryNo +
  2272. "&setl_optins=" + miConfig.OrgName +
  2273. "&stmt_begndate=" + start_time +
  2274. "&stm_enddate=" + end_time +
  2275. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2276. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2277. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2278. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2279. "&fixmedins_code=" + miConfig.Code +
  2280. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2281. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2282. "&secret_key=" + miConfig.SecretKey +
  2283. "&org_name=" + miConfig.OrgName +
  2284. "&doctor=" + user_name
  2285. resp, requestErr := http.Get(api)
  2286. if requestErr != nil {
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2288. return
  2289. }
  2290. body, ioErr := ioutil.ReadAll(resp.Body)
  2291. if ioErr != nil {
  2292. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. return
  2295. }
  2296. var respJSON map[string]interface{}
  2297. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2298. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2300. return
  2301. }
  2302. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2303. userJSONBytes, _ := json.Marshal(respJSON)
  2304. var res ResultTen
  2305. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2306. utils.ErrorLog("解析失败:%v", err)
  2307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2308. return
  2309. }
  2310. if res.Infcode == 0 {
  2311. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2312. c.ServeSuccessJSON(map[string]interface{}{
  2313. "msg": "明细对账成功",
  2314. })
  2315. }
  2316. } else {
  2317. }
  2318. }
  2319. }
  2320. func (c *HisApiController) GetSettleAccounts() {
  2321. //id, _ := c.GetInt64("id")
  2322. //record_time := c.GetString("record_time")
  2323. order_id, _ := c.GetInt64("order_id")
  2324. //timeLayout := "2006-01-02"
  2325. //loc, _ := time.LoadLocation("Local")
  2326. //
  2327. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2328. //if err != nil {
  2329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2330. // return
  2331. //}
  2332. //recordDateTime := theTime.Unix()
  2333. adminUser := c.GetAdminUserInfo()
  2334. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2335. order, _ := service.GetHisOrderByID(order_id)
  2336. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2337. var bedCostTotal float64 = 0 //床位总费
  2338. var bedCostSelfTotal float64 = 0 //床位自费
  2339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2340. var operationCostTotal float64 = 0 //手术费
  2341. var operationCostSelfTotal float64 = 0 //手术费
  2342. var operationCostPartSelfTotal float64 = 0 //手术费
  2343. var otherCostTotal float64 = 0 //其他费用
  2344. var otherCostSelfTotal float64 = 0 //其他费用
  2345. var otherCostPartSelfTotal float64 = 0 //其他费用
  2346. var materialCostTotal float64 = 0 //材料费
  2347. var materialCostSelfTotal float64 = 0 //材料费
  2348. var materialCostPartSelfTotal float64 = 0 //材料费
  2349. var westernMedicineCostTotal float64 = 0 //西药费
  2350. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2351. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2352. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2353. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2354. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2355. var checkCostTotal float64 = 0 //检查费
  2356. var checkCostSelfTotal float64 = 0 //检查费
  2357. var checkCostPartSelfTotal float64 = 0 //检查费
  2358. var laboratoryCostTotal float64 = 0 //化验费
  2359. var laboratoryCostSelfTotal float64 = 0 //化验费
  2360. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2361. var treatCostTotal float64 = 0 //治疗费用
  2362. var treatCostSelfTotal float64 = 0 //治疗费用
  2363. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2364. decimal.DivisionPrecision = 2
  2365. for _, item := range orderInfos {
  2366. if item.MedChrgitmType == "01" { //床位费
  2367. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2368. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2369. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2370. }
  2371. if item.MedChrgitmType == "03" { //检查费
  2372. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2373. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2374. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2375. }
  2376. if item.MedChrgitmType == "04" { //化验费
  2377. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2378. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2379. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2380. }
  2381. if item.MedChrgitmType == "05" { //治疗费
  2382. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2383. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2384. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2385. }
  2386. if item.MedChrgitmType == "06" { //手术费
  2387. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2388. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2389. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2390. }
  2391. if item.MedChrgitmType == "08" { //材料费
  2392. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2393. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2394. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2395. }
  2396. if item.MedChrgitmType == "09" { //西药费
  2397. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2398. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2399. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2400. }
  2401. if item.MedChrgitmType == "11" { //中成费
  2402. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2403. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2404. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2405. }
  2406. if item.MedChrgitmType == "14" { //其他费
  2407. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2408. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2409. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2410. }
  2411. }
  2412. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2413. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2414. var user_name string
  2415. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2416. if role.ID == 0 {
  2417. user_name = "xxx"
  2418. } else {
  2419. user_name = role.UserName
  2420. }
  2421. baseParams := models.BaseParams{
  2422. SecretKey: miConfig.SecretKey,
  2423. FixmedinsCode: miConfig.Code,
  2424. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2425. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2426. OrgName: miConfig.OrgName,
  2427. Doctor: user_name,
  2428. }
  2429. businessParams := models.BusinessParams{
  2430. PsnNo: order.PsnNo,
  2431. MdtrtId: order.MdtrtId,
  2432. SetlId: order.SetlId,
  2433. }
  2434. if config.IsOpen == 1 {
  2435. result := service.Gdyb5203(baseParams, businessParams)
  2436. var dat map[string]interface{}
  2437. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2438. fmt.Println(dat)
  2439. } else {
  2440. fmt.Println(err)
  2441. }
  2442. userJSONBytes, _ := json.Marshal(dat)
  2443. var res ResultEleven
  2444. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2445. utils.ErrorLog("解析失败:%v", err)
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2447. return
  2448. }
  2449. if res.Infcode == 0 {
  2450. c.ServeSuccessJSON(map[string]interface{}{
  2451. "info": res.Output.Setlinfo,
  2452. "bedCostTotal": bedCostTotal,
  2453. "bedCostSelfTotal": bedCostSelfTotal,
  2454. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2455. "operationCostTotal": operationCostTotal,
  2456. "operationCostSelfTotal": operationCostSelfTotal,
  2457. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2458. "otherCostTotal": otherCostTotal,
  2459. "otherCostSelfTotal": otherCostSelfTotal,
  2460. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2461. "materialCostTotal": materialCostTotal,
  2462. "materialCostSelfTotal": materialCostSelfTotal,
  2463. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2464. "westernMedicineCostTotal": westernMedicineCostTotal,
  2465. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2466. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2467. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2468. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2469. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2470. "checkCostTotal": checkCostTotal,
  2471. "checkCostSelfTotal": checkCostSelfTotal,
  2472. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2473. "laboratoryCostTotal": laboratoryCostTotal,
  2474. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2475. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2476. "treatCostTotal": treatCostTotal,
  2477. "treatCostSelfTotal": treatCostSelfTotal,
  2478. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2479. })
  2480. }
  2481. }
  2482. }
  2483. func (this *HisApiController) AdditionalCharge() {
  2484. dataBody := make(map[string]interface{}, 0)
  2485. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2486. fmt.Println(err)
  2487. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2488. patient_id := int64(dataBody["patient_id"].(float64))
  2489. medicineData, _ := dataBody["medicineData"].([]interface{})
  2490. adminUserInfo := this.GetAdminUserInfo()
  2491. orgId := adminUserInfo.CurrentOrgId
  2492. admin_user_id := adminUserInfo.AdminUser.Id
  2493. timeStr := time.Now().Format("2006-01-02")
  2494. timeLayout := "2006-01-02 15:04:05"
  2495. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2496. timenow := timeStringToTime.Unix()
  2497. var additionalCharges []*models.HisAdditionalCharge
  2498. for _, item := range medicineData {
  2499. var randNum int
  2500. randNum = rand.Intn(10000) + 1000
  2501. timestamp := time.Now().Unix()
  2502. tempTime := time.Unix(timestamp, 0)
  2503. timeFormat := tempTime.Format("20060102150405")
  2504. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2505. items := item.(map[string]interface{})
  2506. money := items["price"].(string)
  2507. item_id_str := items["item_id"].(string)
  2508. name := items["name"].(string)
  2509. id_str := items["id"].(string)
  2510. moneys, _ := strconv.ParseInt(money, 10, 64)
  2511. monStr := strconv.FormatInt(moneys, 10)
  2512. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2513. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2514. id, _ := strconv.ParseInt(id_str, 10, 64)
  2515. additionalCharge := &models.HisAdditionalCharge{
  2516. ID: id,
  2517. HisPatientId: his_patient_id,
  2518. UserOrgId: orgId,
  2519. PatientId: patient_id,
  2520. RecordDate: timenow,
  2521. Price: monneyStr,
  2522. Status: 1,
  2523. ItemName: name,
  2524. ItemId: item_id,
  2525. AdminUserId: admin_user_id,
  2526. CreatedTime: time.Now().Unix(),
  2527. OrderStatus: 0,
  2528. PrescriptionNumber: "",
  2529. BatchNumber: "",
  2530. FeedetlSn: p_number,
  2531. }
  2532. service.CreateAdditionalCharge(additionalCharge)
  2533. additionalCharges = append(additionalCharges, additionalCharge)
  2534. }
  2535. this.ServeSuccessJSON(map[string]interface{}{
  2536. "msg": "添加成功",
  2537. "additional_charges": additionalCharges,
  2538. })
  2539. }
  2540. func (this *HisApiController) DeleteAddition() {
  2541. id, _ := this.GetInt64("id")
  2542. //TODO 需要判断是否已经结算
  2543. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2544. if err == nil {
  2545. this.ServeSuccessJSON(map[string]interface{}{
  2546. "msg": "删除成功",
  2547. })
  2548. return
  2549. } else {
  2550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2551. return
  2552. }
  2553. }
  2554. func (this *HisApiController) GetAdminUsers() {
  2555. adminUser := this.GetAdminUserInfo()
  2556. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2557. this.ServeSuccessJSON(map[string]interface{}{
  2558. "doctors": doctors,
  2559. })
  2560. }
  2561. func (this *DialysisApiController) GetLastOrNextHisPrescription() {
  2562. change_type, _ := this.GetInt64("type", 0)
  2563. record_date := this.GetString("record_time")
  2564. patient_id, _ := this.GetInt64("patient_id", 0)
  2565. timeLayout := "2006-01-02"
  2566. loc, _ := time.LoadLocation("Local")
  2567. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2568. record_time := theAdviceRecordTime.Unix()
  2569. adminUserInfo := this.GetAdminUserInfo()
  2570. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  2571. if err == nil {
  2572. if len(prescriptions) == 0 {
  2573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2574. return
  2575. } else {
  2576. this.ServeSuccessJSON(map[string]interface{}{
  2577. "prescriptions": prescriptions,
  2578. })
  2579. return
  2580. }
  2581. } else {
  2582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2583. return
  2584. }
  2585. }
  2586. func (this *DialysisApiController) GetCallHisPrescription() {
  2587. patient_id, _ := this.GetInt64("patient_id", 0)
  2588. timeLayout := "2006-01-02"
  2589. loc, _ := time.LoadLocation("Local")
  2590. start_time := this.GetString("start_time")
  2591. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2592. end_time := this.GetString("end_time")
  2593. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2594. adminUserInfo := this.GetAdminUserInfo()
  2595. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id)
  2596. if err == nil {
  2597. this.ServeSuccessJSON(map[string]interface{}{
  2598. "prescriptions": prescriptions,
  2599. })
  2600. return
  2601. } else {
  2602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2603. return
  2604. }
  2605. }
  2606. func PathExists(path string) (bool, error) {
  2607. _, err := os.Stat(path)
  2608. if err == nil {
  2609. return true, nil
  2610. }
  2611. if os.IsNotExist(err) {
  2612. return false, nil
  2613. }
  2614. return false, err
  2615. }
  2616. //创建文件夹
  2617. func Mkdir(dir string) {
  2618. // 创建文件夹
  2619. exist, err := PathExists(dir)
  2620. if err != nil {
  2621. fmt.Println(err.Error())
  2622. } else {
  2623. if exist {
  2624. fmt.Println(dir + "文件夹已存在!")
  2625. } else {
  2626. // 文件夹名称,权限
  2627. err := os.Mkdir(dir, os.ModePerm)
  2628. if err != nil {
  2629. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2630. } else {
  2631. fmt.Println(dir + "文件夹创建成功!")
  2632. }
  2633. }
  2634. }
  2635. }
  2636. //压缩文件
  2637. func Zip(srcFile string, destZip string) error {
  2638. zipfile, err := os.Create(destZip)
  2639. if err != nil {
  2640. return err
  2641. }
  2642. defer zipfile.Close()
  2643. archive := zip.NewWriter(zipfile)
  2644. defer archive.Close()
  2645. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2646. if err != nil {
  2647. return err
  2648. }
  2649. header, err := zip.FileInfoHeader(info)
  2650. if err != nil {
  2651. return err
  2652. }
  2653. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2654. // header.Name = path
  2655. if info.IsDir() {
  2656. header.Name += "/"
  2657. } else {
  2658. header.Method = zip.Deflate
  2659. }
  2660. writer, err := archive.CreateHeader(header)
  2661. if err != nil {
  2662. return err
  2663. }
  2664. if !info.IsDir() {
  2665. file, err := os.Open(path)
  2666. if err != nil {
  2667. return err
  2668. }
  2669. defer file.Close()
  2670. _, err = io.Copy(writer, file)
  2671. }
  2672. return err
  2673. })
  2674. return err
  2675. }
  2676. func ReadFile(filePath string) []byte {
  2677. f, err := os.Open(filePath)
  2678. if err != nil {
  2679. fmt.Println("read file fail", err)
  2680. return nil
  2681. }
  2682. defer f.Close()
  2683. fd, err := ioutil.ReadAll(f)
  2684. if err != nil {
  2685. fmt.Println("read to fd fail", err)
  2686. return nil
  2687. }
  2688. return fd
  2689. }