his_api_controller.go 98KB

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