his_api_controller.go 74KB

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