his_api_controller.go 79KB

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