his_api_controller.go 90KB

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