his_api_controller.go 95KB

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