his_api_controller.go 91KB

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