his_api_controller.go 108KB

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