his_api_controller.go 94KB

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