common_service.go 185KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  8. )
  9. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  10. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  11. return inspection, err
  12. }
  13. func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
  14. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
  15. return inspection, err
  16. }
  17. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  18. reference := models.XtInspectionReference{}
  19. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  20. return reference, err
  21. }
  22. func GetItemid(id int64) (models.XtInspectionReference, error) {
  23. reference := models.XtInspectionReference{}
  24. err = XTReadDB().Model(&reference).Where("id = ? and status = 1", id).Find(&reference).Error
  25. return reference, err
  26. }
  27. func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
  28. standard := models.XtQualityControlStandard{}
  29. err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
  30. if err == gorm.ErrRecordNotFound {
  31. return nil, err
  32. }
  33. if err != nil {
  34. return nil, err
  35. }
  36. return &standard, nil
  37. }
  38. func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
  39. err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
  40. return standard, err
  41. }
  42. func SaveInspection(standard *models.XtQualityControlStandard) error {
  43. err := XTWriteDB().Create(&standard).Error
  44. return err
  45. }
  46. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  47. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  48. if orgid > 0 {
  49. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  50. }
  51. table := XTReadDB().Table("xt_inspection_reference as s")
  52. fmt.Println(table)
  53. offset := (page - 1) * limit
  54. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").Count(&total).
  55. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  56. return standard, total, err
  57. }
  58. func GetDefaultBloodPressure(orgid int64) (standard []*models.XtQualityControlStandard, err error) {
  59. err = XTReadDB().Model(&standard).Where("user_org_id = ? and status = 1 and is_status = 0", orgid).Find(&standard).Error
  60. return standard, err
  61. }
  62. func GetConfigurationListTwo(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  63. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  64. if orgid > 0 {
  65. db = db.Where("x.user_org_id = ? and x.is_status =1", orgid)
  66. }
  67. table := XTReadDB().Table("xt_inspection_reference as s")
  68. fmt.Println(table)
  69. offset := (page - 1) * limit
  70. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").
  71. Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor and s.project_id = x.inspection_major").Where("s.org_id = ? and s.status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Scan(&standard).Error
  72. return standard, total, err
  73. }
  74. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  75. standard := models.XtQualityControlStandard{}
  76. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  77. return standard, err
  78. }
  79. func GetIdByItemId(itemid int64, orgid int64) (models.XtInspectionReference, error) {
  80. reference := models.XtInspectionReference{}
  81. err := XTReadDB().Model(&reference).Where("item_id = ? and org_id = ?", itemid, orgid).Find(&reference).Error
  82. return reference, err
  83. }
  84. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  85. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  86. return standard, err
  87. }
  88. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  89. err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "range_value": st.RangeValue, "range_type": st.RangeType, "updated_time": time.Now().Unix()}).Error
  90. return err
  91. }
  92. func DeleteConfiguration(id int64) (err error) {
  93. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  94. return err
  95. }
  96. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  97. diseases := models.XtInspectionReference{}
  98. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  99. if err == gorm.ErrRecordNotFound {
  100. return nil, err
  101. }
  102. if err != nil {
  103. return nil, err
  104. }
  105. return &diseases, nil
  106. }
  107. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  108. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  109. return reference, err
  110. }
  111. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  112. configuration := models.XtCheckConfiguration{}
  113. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  114. if err == gorm.ErrRecordNotFound {
  115. return nil, err
  116. }
  117. if err != nil {
  118. return nil, err
  119. }
  120. return &configuration, nil
  121. }
  122. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  123. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  124. return configuration, err
  125. }
  126. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  127. err := XTWriteDB().Create(&configuration).Error
  128. return err
  129. }
  130. func GetAllChekcListTwo(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  131. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  132. table := XTReadDB().Table("xt_inspection_reference as r")
  133. fmt.Println(table)
  134. if orgid > 0 {
  135. db = db.Where("x.user_org_id = ?", orgid)
  136. }
  137. offset := (page - 1) * limit
  138. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  139. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  140. return check, total, err
  141. }
  142. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  143. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  144. table := XTReadDB().Table("xt_inspection_reference as r")
  145. fmt.Println(table)
  146. if orgid > 0 {
  147. db = db.Where("x.user_org_id = ?", orgid)
  148. }
  149. offset := (page - 1) * limit
  150. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  151. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Where("r.org_id = ? and r.status = 1", orgid).Offset(offset).Limit(limit).Scan(&check).Error
  152. return check, total, err
  153. }
  154. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  155. configuration := models.XtCheckConfiguration{}
  156. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  157. return configuration, err
  158. }
  159. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  160. err := XTWriteDB().Model(&con).Where("id=?", id).Updates(map[string]interface{}{"inspection_major": con.InspectionMajor, "inspection_frequency": con.InspectionFrequency, "sort": con.Sort, "updated_time": time.Now().Unix()}).Error
  161. return err
  162. }
  163. func DeleteCheck(id int64) error {
  164. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  165. return err
  166. }
  167. //
  168. //func GetDialysiTotal(startime int64, endtime int64, orgid int64,lapsetotype int64,sourcetype int64) (order []*models.DialysisOrder, total int64, err error) {
  169. // err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  170. // return order, total, err
  171. //}
  172. func GetDialysiTotal(startime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (models.PatientPrescriptionCountStruct, error) {
  173. counts := models.PatientPrescriptionCountStruct{}
  174. db := XTReadDB().Table("xt_dialysis_order as x").Select("count(x.id) as count").Joins("Join xt_dialysis_prescription as prescription On x.dialysis_date = prescription.record_date AND x.patient_id = prescription.patient_id AND prescription.status = 1 AND prescription.mode_id > 0").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? AND x.status = 1", startime, endtime, orgid)
  175. if lapsetotype > 0 {
  176. err = db.Where("x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  177. }
  178. if lapsetotype == 0 {
  179. err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  180. }
  181. if sourcetype > 0 {
  182. err = db.Where("x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  183. }
  184. if sourcetype == 0 {
  185. err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  186. }
  187. return counts, err
  188. }
  189. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  190. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  191. if starttime > 0 {
  192. db = db.Where("o.dialysis_date >=?", starttime)
  193. }
  194. if endtime > 0 {
  195. db = db.Where("o.dialysis_date<=?", endtime)
  196. }
  197. if orgid > 0 {
  198. db = db.Where("o.user_org_id = ?", orgid)
  199. }
  200. if lapsetotype > 0 {
  201. db = db.Where("p.lapseto = ?", lapsetotype)
  202. }
  203. if sourcetype > 0 {
  204. db = db.Where("p.source = ?", sourcetype)
  205. }
  206. err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND s.mode_id > 0 ", starttime, endtime).Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
  207. return counts, err
  208. }
  209. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  210. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  211. table := readDb.Table("xt_dialysis_order as s")
  212. fmt.Println(table)
  213. err = db.Select("x.patient_id,x.lapseto_type").Joins("left join xt_dialysis_order as s on s.patient_id = x.patient_id").Where("x.lapseto_time >=? and x.lapseto_time <= ? and x.lapseto_type = 2 and s.user_org_id = ?", starttime, endtime, orgid).Group("x.patient_id").Count(&total).Scan(&counts).Error
  214. return counts, total, err
  215. }
  216. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  217. db := XTReadDB().Table("xt_patients as x")
  218. if sourcetype == 0 {
  219. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  220. }
  221. if sourcetype > 0 {
  222. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  223. }
  224. return patients, err
  225. }
  226. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  227. db := XTReadDB().Table("xt_patients as x")
  228. if sourcetype == 0 {
  229. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  230. }
  231. if sourcetype > 0 {
  232. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  233. }
  234. return patients, err
  235. }
  236. func GetPatientTotalCount(orgID int64, lapsetotype int64, sourcetype int64) (total int64) {
  237. db := readDb.Table("xt_patients as x")
  238. //if lapsetotype > 0 {
  239. // db = db.Where("x.lapseto = ?", lapsetotype)
  240. //}
  241. //if sourcetype > 0 {
  242. // db = db.Where("x.source = ?", sourcetype)
  243. //}
  244. db.Where("x.user_org_id=? and x.status=1", orgID).Count(&total)
  245. return
  246. }
  247. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  248. err = XTReadDB().Model(&dialysisorder).Group("patient_id").Where("user_org_id = ? and dialysis_date >= ? and dialysis_date <=? and status =1", orgid, starttime, endtime).Count(&total).Find(&dialysisorder).Error
  249. return dialysisorder, total, err
  250. }
  251. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  252. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  253. table := XTReadDB().Table("xt_patients as x")
  254. fmt.Println("table", table)
  255. err = db.Select("s.dialysis_date,s.prescription_id").Joins("left join xt_patients as x on x.id = s.patient_id").Where("s.dialysis_date>=? and s.dialysis_date<=? and s.user_org_id = ? and s.status = 1 and x.gender = 1", starttime, endtime, orgid).Group("s.patient_id").Count(&total).Scan(&dialysisorder).Error
  256. return dialysisorder, total, err
  257. }
  258. func GetManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  259. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  260. if lapsetotype > 0 {
  261. db = db.Where("x.lapseto = ?", lapsetotype)
  262. }
  263. if sourcetype > 0 {
  264. db = db.Where("x.source = ?", sourcetype)
  265. }
  266. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 1", orgid).Count(&total).Find(&patients).Error
  267. return patients, total, err
  268. }
  269. func GetWoManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  270. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  271. if lapsetotype > 0 {
  272. db = db.Where("x.lapseto = ?", lapsetotype)
  273. }
  274. if sourcetype > 0 {
  275. db = db.Where("x.source = ?", sourcetype)
  276. }
  277. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 2", orgid).Count(&total).Find(&patients).Error
  278. return patients, total, err
  279. }
  280. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  281. // err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_dialysis_order as o on o.patient_id = x.patient_id").Joins("join xt_patients as s on s.id = x.patient_id").Where("o.user_org_id = ? and o.status =1 and o.dialysis_date>=? and o.dialysis_date <=? and x.status =1 and s.is_infectious = 2", orgid, starttime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  282. // return counts, err
  283. //}
  284. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientContagionsCountStruct, err error) {
  285. if lapsetotype == 0 {
  286. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  287. }
  288. if sourcetype == 0 {
  289. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  290. }
  291. if lapsetotype > 0 {
  292. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.lapseto = ?", orgid, startime, endtime, lapsetotype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  293. }
  294. if sourcetype > 0 {
  295. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.source = ?", orgid, startime, endtime, sourcetype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  296. }
  297. return counts, err
  298. }
  299. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  300. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  301. return patients, total, err
  302. }
  303. func GetTotalAgeCount(orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientAgeCountStruct, err error) {
  304. if lapsetotype == 0 || sourcetype == 0 {
  305. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  306. SELECT
  307. CASE
  308. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  309. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  310. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  311. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  312. ELSE '150'
  313. END
  314. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  315. )a GROUP BY nnd`, orgid).Scan(&counts)
  316. }
  317. if lapsetotype > 0 {
  318. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  319. SELECT
  320. CASE
  321. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  322. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  323. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  324. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  325. ELSE '150'
  326. END
  327. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.lapseto = ?
  328. )a GROUP BY nnd`, orgid, lapsetotype).Scan(&counts)
  329. }
  330. if sourcetype > 0 {
  331. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  332. SELECT
  333. CASE
  334. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  335. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  336. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  337. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  338. ELSE '150'
  339. END
  340. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.source = ?
  341. )a GROUP BY nnd`, orgid, sourcetype).Scan(&counts)
  342. }
  343. return
  344. }
  345. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  346. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  347. SELECT
  348. CASE
  349. when (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')>0) and (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')<20) THEN '20'
  350. END
  351. AS nnd FROM xt_patients as s left join xt_dialysis_order as o on o.patient_id = s.id where s.user_org_id=? and s.status=1 and o.dialysis_date>= ? and o.dialysis_date<=?
  352. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  353. return
  354. }
  355. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  356. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  357. return patients, err
  358. }
  359. func GetDialysisAgeData(orgID int64, lapsetotype int64, sourcetype int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  360. if lapsetotype == 0 || sourcetype == 0 {
  361. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  362. SELECT
  363. CASE
  364. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  365. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  366. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  367. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  368. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0)a GROUP BY nnd`, orgID).Scan(&counts)
  369. }
  370. if lapsetotype > 0 {
  371. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  372. SELECT
  373. CASE
  374. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  375. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  376. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  377. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  378. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.lapseto = ?)a GROUP BY nnd`, orgID, lapsetotype).Scan(&counts)
  379. }
  380. if sourcetype > 0 {
  381. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  382. SELECT
  383. CASE
  384. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  385. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  386. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  387. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  388. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.source = ?)a GROUP BY nnd`, orgID, sourcetype).Scan(&counts)
  389. }
  390. return
  391. }
  392. func GetCurentOrgPatients(orgid int64) (patients []*models.BloodXtPatients, err error) {
  393. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  394. return patients, err
  395. }
  396. func TotalDialysisCount(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  397. db := XTReadDB().Table("xt_dialysis_order as o")
  398. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", startime, endtime, orgid).Group("o.patient_id").Scan(&order).Error
  399. return order, err
  400. }
  401. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  402. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  403. if orgid > 0 {
  404. db = db.Where("o.user_org_id = ?", orgid)
  405. }
  406. if startime > 0 {
  407. db = db.Where("o.dialysis_date>=?", startime)
  408. }
  409. if endtime > 0 {
  410. db = db.Where("o.dialysis_date<=?", endtime)
  411. }
  412. offset := (page - 1) * limit
  413. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("join xt_patients as p on p.id = o.patient_id").Where("s.status = 1").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  414. return order, total, err
  415. }
  416. func GetDialysisScheduleList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrderSchedule, err error) {
  417. db := XTReadDB().Table("xt_schedule as o").Where("o.status = 1")
  418. if orgid > 0 {
  419. db = db.Where("o.user_org_id = ?", orgid)
  420. }
  421. if startime > 0 {
  422. db = db.Where("o.schedule_date>=?", startime)
  423. }
  424. if endtime > 0 {
  425. db = db.Where("o.schedule_date<=?", endtime)
  426. }
  427. err = db.Group("o.patient_id,o.mode_id").Select("o.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_patients as p on p.id = o.patient_id").Where("o.status = 1").Scan(&order).Error
  428. return order, err
  429. }
  430. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrder, err error) {
  431. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  432. if orgid > 0 {
  433. db = db.Where("o.user_org_id = ?", orgid)
  434. }
  435. if startime > 0 {
  436. db = db.Where("o.dialysis_date>=?", startime)
  437. }
  438. if endtime > 0 {
  439. db = db.Where("o.dialysis_date<=?", endtime)
  440. }
  441. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,s.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("join xt_patients as p on p.id = o.patient_id").Where("s.status = 1 ").Scan(&order).Error
  442. return order, err
  443. }
  444. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  445. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  446. db = db.Where("o.user_org_id = ?", orgid)
  447. if startime > 0 {
  448. db = db.Where("o.dialysis_date>=?", startime)
  449. }
  450. if endtime > 0 {
  451. db = db.Where("o.dialysis_date<=?", endtime)
  452. }
  453. offset := (page - 1) * limit
  454. err = db.Group("s.patient_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0 AND s.status =1").Joins("join xt_patients as p on p.id = o.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  455. return order, total, err
  456. }
  457. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  458. standard := models.XtQualityControlStandard{}
  459. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1 and is_status = 1", orgid).Last(&standard).Error
  460. return standard, err
  461. }
  462. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  463. configuration := models.XtCheckConfiguration{}
  464. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  465. return configuration, err
  466. }
  467. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  468. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  469. table := XTReadDB().Table("xt_patients as s")
  470. fmt.Println(table)
  471. if id > 0 {
  472. db = db.Where("p.patient_id = ?", id)
  473. }
  474. if orgid > 0 {
  475. db = db.Where("p.user_org_id = ?", orgid)
  476. }
  477. if startime > 0 {
  478. db = db.Where("p.record_date >= ?", startime)
  479. }
  480. if endtime > 0 {
  481. db = db.Where("p.record_date <=?", endtime)
  482. }
  483. offset := (page - 1) * limit
  484. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  485. return prescription, total, err
  486. }
  487. func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  488. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  489. table := XTReadDB().Table("xt_patients as s")
  490. fmt.Println(table)
  491. //if len(keywords) > 0 {
  492. // likeKey := "%" + keywords + "%"
  493. // db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  494. //}
  495. if patient_id > 0 {
  496. db = db.Where("s.id = ?", patient_id)
  497. }
  498. if orgid > 0 {
  499. db = db.Where("p.user_org_id = ?", orgid)
  500. }
  501. if startime > 0 {
  502. db = db.Where("p.record_date >= ?", startime)
  503. }
  504. if endtime > 0 {
  505. db = db.Where("p.record_date <=?", endtime)
  506. }
  507. offset := (page - 1) * limit
  508. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  509. return prescription, total, err
  510. }
  511. func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
  512. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  513. sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
  514. if orgID > 0 {
  515. db = db.Where("o.user_org_id = ?", orgID)
  516. }
  517. if startime > 0 {
  518. db = db.Where("o.dialysis_date >=?", startime)
  519. }
  520. if endtime > 0 {
  521. db = db.Where("o.dialysis_date<=?", endtime)
  522. }
  523. if lapseto == 0 {
  524. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  525. }
  526. if lapseto > 0 {
  527. db = db.Where("p.lapseto = ?", lapseto)
  528. }
  529. err = db.Group("o.dialysis_date").Select(sql).Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status =1").Scan(&blood).Error
  530. return blood, total, err
  531. }
  532. func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (ttd []*models.TreatTotalStruct, err error) {
  533. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1 ")
  534. p := XTReadDB().Table("xt_patients as p")
  535. fmt.Println(p)
  536. if orgid > 0 {
  537. db = db.Where("o.user_org_id = ?", orgid)
  538. }
  539. if startime > 0 {
  540. db = db.Where("o.dialysis_date>=?", startime)
  541. }
  542. if endtime > 0 {
  543. db = db.Where("o.dialysis_date<=?", endtime)
  544. }
  545. //if lapseto == 0 {
  546. // db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  547. //}
  548. if lapseto > 0 {
  549. db = db.Where("p.lapseto = ?", lapseto)
  550. }
  551. err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.mode_id > 0").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  552. return ttd, err
  553. }
  554. func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, err error) {
  555. db := readDb
  556. sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
  557. datesql := " o.dialysis_date as date"
  558. group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
  559. db = db.Table(" xt_dialysis_order AS o").Joins("join xt_dialysis_prescription as s on o.patient_id = s.patient_id AND o.dialysis_date = s.record_date AND s.mode_id > 0")
  560. if orgID > 0 {
  561. db = db.Where("o.user_org_id = ?", orgID)
  562. }
  563. if modeID > 0 {
  564. db = db.Where("s.mode_id=?", modeID)
  565. }
  566. if startime > 0 {
  567. db = db.Where("o.dialysis_date>=?", startime)
  568. }
  569. if endtime > 0 {
  570. db = db.Where("o.dialysis_date<=?", endtime)
  571. }
  572. db = db.Where("o.status=1")
  573. err = db.Select("s.mode_id, count(s.mode_id) as number").Order("s.mode_id asc").Find(&ttd).Error
  574. if err != nil {
  575. return
  576. }
  577. var ds []*DialysisTotalDataStruct
  578. err = db.Select(datesql).Group(group).Find(&ds).Error
  579. if err != nil {
  580. return
  581. }
  582. dates := make([]string, 0)
  583. if len(ds) > 0 {
  584. for _, d := range ds {
  585. dates = append(dates, d.Date)
  586. }
  587. db = db.Where("o.dialysis_date IN (?)", dates)
  588. }
  589. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, s.mode_id").Find(&dtd).Error
  590. return
  591. }
  592. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  593. var count int
  594. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  595. table := XTReadDB().Table("xt_inspection_reference as s")
  596. if orgid > 0 {
  597. db = db.Where("x.user_org_id = ?", orgid)
  598. }
  599. fmt.Println(table)
  600. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,s.project_name").Joins("left join xt_inspection_reference as s on s.project_id = x.inspection_major").Count(&count).Order("x.sort asc").Scan(&configuration).Error
  601. return configuration, err
  602. }
  603. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64, patientid int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  604. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  605. table := XTReadDB().Table("xt_inspection_reference as r")
  606. fmt.Println(table)
  607. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  608. fmt.Println(d)
  609. if orgid > 0 {
  610. db = db.Where("x.org_id = ?", orgid)
  611. }
  612. if startime > 0 {
  613. db = db.Where("x.inspect_date >=?", startime)
  614. }
  615. if endtime > 0 {
  616. db = db.Where("x.inspect_date <=?", endtime)
  617. }
  618. if patientid > 0 {
  619. db = db.Where("x.patient_id = ?", patientid)
  620. }
  621. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  622. return
  623. }
  624. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  625. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  626. table := XTReadDB().Table("xt_inspection_reference as r")
  627. fmt.Println(table)
  628. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  629. fmt.Println(d)
  630. if id > 0 {
  631. db = db.Where("x.patient_id=?", id)
  632. }
  633. if orgid > 0 {
  634. db = db.Where("x.org_id = ?", orgid)
  635. }
  636. if startime > 0 {
  637. db = db.Where("x.inspect_date >=?", startime)
  638. }
  639. if endtime > 0 {
  640. db = db.Where("x.inspect_date <=?", endtime)
  641. }
  642. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  643. return
  644. }
  645. func GetSearchPatientInfo(orgid int64, keywords int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  646. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  647. table := XTReadDB().Table("xt_inspection_reference as r")
  648. fmt.Println(table)
  649. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  650. fmt.Println(d)
  651. p := XTReadDB().Table("xt_patients as p")
  652. fmt.Println(p)
  653. //if len(keywords) > 0 {
  654. // likeKey := "%" + keywords + "%"
  655. // db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  656. //}
  657. if keywords > 0 {
  658. db = db.Where("x.patient_id = ?", keywords)
  659. }
  660. if orgid > 0 {
  661. db = db.Where("x.org_id = ?", orgid)
  662. }
  663. if startime > 0 {
  664. db = db.Where("x.inspect_date >=?", startime)
  665. }
  666. if endtime > 0 {
  667. db = db.Where("x.inspect_date <=?", endtime)
  668. }
  669. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as p on p.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  670. return
  671. }
  672. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  673. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  674. table := XTReadDB().Table("xt_inspection_reference ar r")
  675. fmt.Println(table)
  676. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  677. return checkconfiguration, err
  678. }
  679. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  680. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  681. table := XTReadDB().Table("xt_inspection_reference ar r")
  682. fmt.Println(table)
  683. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  684. return checkconfiguration, err
  685. }
  686. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  687. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  688. table := XTReadDB().Table("xt_patients as s")
  689. fmt.Println("table", table)
  690. if orgid > 0 {
  691. db = db.Where("x.org_id = ?", orgid)
  692. }
  693. if startime > 0 {
  694. db = db.Where("x.inspect_date >= ?", startime)
  695. }
  696. if endtime > 0 {
  697. db = db.Where("x.inspect_date <=?", endtime)
  698. }
  699. offset := (page - 1) * limit
  700. err = db.Group("x.patient_id").Select("x.id,x.patient_id,x.project_id,x.project_name,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  701. return inspection, total, err
  702. }
  703. func GetPatientListInfo(orgid int64, startime int64, endtime int64, limit int64, page int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  704. patients, _, err := GetPatientListData(orgid, startime, endtime, limit, page)
  705. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  706. table := XTReadDB().Table("xt_inspection_reference as r")
  707. fmt.Println(table)
  708. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  709. pa := XTReadDB().Table("xt_patients as s")
  710. fmt.Println(pa)
  711. fmt.Println(d)
  712. if orgid > 0 {
  713. db = db.Where("x.org_id = ?", orgid)
  714. }
  715. if startime > 0 {
  716. db = db.Where("x.inspect_date >=?", startime)
  717. }
  718. if endtime > 0 {
  719. db = db.Where("x.inspect_date <=?", endtime)
  720. }
  721. //if len(ds) > 0 {
  722. // for _, d := range ds {
  723. // dates = append(dates, d.Date)
  724. // }
  725. //
  726. // db = db.Where("o.dialysis_date IN (?)", dates)
  727. //
  728. ////}
  729. selectContent := "CASE"
  730. dates := make([]string, 0)
  731. for _, item := range patients {
  732. selectContent = selectContent + " WHEN x.patient_id =" + strconv.FormatInt(item.PatientId, 10) + " THEN " + "'" + item.Name + "'"
  733. dates = append(dates, strconv.FormatInt(item.PatientId, 10))
  734. }
  735. db = db.Where("x.patient_id in(?)", dates)
  736. err = db.Select(selectContent + "ELSE '未知' END AS name,count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  737. //err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  738. return
  739. }
  740. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  741. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  742. if id > 0 {
  743. db = db.Where("s.id = ?", id)
  744. }
  745. if orgid > 0 {
  746. db = db.Where("x.org_id = ?", orgid)
  747. }
  748. if startime > 0 {
  749. db = db.Where("x.inspect_date >=?", startime)
  750. }
  751. if endtime > 0 {
  752. db = db.Where("x.inspect_date <=?", endtime)
  753. }
  754. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  755. return
  756. }
  757. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  758. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  759. table := XTReadDB().Table("xt_inspection_reference as r")
  760. fmt.Println(table)
  761. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  762. pa := XTReadDB().Table("xt_patients as s")
  763. fmt.Println(pa)
  764. fmt.Println(d)
  765. if len(keywords) > 0 {
  766. likeKey := "%" + keywords + "%"
  767. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  768. }
  769. if orgid > 0 {
  770. db = db.Where("x.org_id = ?", orgid)
  771. }
  772. if startime > 0 {
  773. db = db.Where("x.inspect_date >=?", startime)
  774. }
  775. if endtime > 0 {
  776. db = db.Where("x.inspect_date <=?", endtime)
  777. }
  778. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  779. return
  780. }
  781. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  782. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  783. if orgid > 0 {
  784. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  785. }
  786. table := XTReadDB().Table("xt_inspection_reference as s")
  787. fmt.Println(table)
  788. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name,x.range_value,x.range_type,x.is_status").
  789. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  790. return standard, err
  791. }
  792. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  793. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  794. if orgid >= 0 {
  795. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  796. }
  797. table := XTReadDB().Table("xt_inspection_reference as s")
  798. fmt.Println(table)
  799. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
  800. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  801. return standard, err
  802. }
  803. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  804. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  805. table := XTReadDB().Table("xt_inspection_reference as r")
  806. fmt.Println(table)
  807. if orgid > 0 {
  808. db = db.Where("x.org_id = ?", orgid)
  809. }
  810. if startime > 0 {
  811. db = db.Where("x.inspect_date >=?", startime)
  812. }
  813. if endtime > 0 {
  814. db = db.Where("x.inspect_date <=?", endtime)
  815. }
  816. err = db.Group("x.item_id").Select(" count(x.item_id ) AS count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  817. return inspection, err
  818. }
  819. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  820. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  821. table := XTReadDB().Table("xt_inspection_reference as r")
  822. fmt.Println(table)
  823. if orgid > 0 {
  824. db = db.Where("x.org_id = ?", orgid)
  825. }
  826. if startime > 0 {
  827. db = db.Where("x.inspect_date >=?", startime)
  828. }
  829. if endtime > 0 {
  830. db = db.Where("x.inspect_date <=?", endtime)
  831. }
  832. err = db.Group("x.item_id").Select("count(x.item_id) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Where("x.inspect_value+0 >= r.range_min+0 and x.inspect_value+0 <= r.range_max+0").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  833. return inspection, err
  834. }
  835. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  836. fmt.Println(lapseto)
  837. fmt.Println(origin)
  838. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  839. if orgid > 0 {
  840. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and r.range_type = 1 and q.user_org_id = ? and q.is_status = 1", orgid, orgid)
  841. }
  842. if startime > 0 {
  843. db = db.Where("x.inspect_date >=?", startime)
  844. }
  845. if endtime > 0 {
  846. db = db.Where("x.inspect_date <=?", endtime)
  847. }
  848. if lapseto > 0 && origin > 0 {
  849. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  850. }
  851. if lapseto > 0 && origin == 0 {
  852. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  853. }
  854. if lapseto == 0 && origin > 0 {
  855. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  856. }
  857. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=q.min_range+0 and x.inspect_value +0 <= q.large_range+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  858. return inspection, err
  859. }
  860. func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  861. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  862. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  863. fmt.Println(q)
  864. if orgid > 0 {
  865. db = db.Where("x.org_id = ? and r.range_type = 2 and q.user_org_id = ? and q.is_status = 1 and x.inspect_value <>''", orgid, orgid)
  866. }
  867. if startime > 0 {
  868. db = db.Where("x.inspect_date >=?", startime)
  869. }
  870. if endtime > 0 {
  871. db = db.Where("x.inspect_date <=?", endtime)
  872. }
  873. if lapseto > 0 && origin > 0 {
  874. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  875. }
  876. if lapseto > 0 && origin == 0 {
  877. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  878. }
  879. if lapseto == 0 && origin > 0 {
  880. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  881. }
  882. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when q.range_value = x.inspect_value and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  883. return inspection, err
  884. }
  885. func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  886. if lapseto == 0 {
  887. d := XTReadDB().Table("xt_patients as s")
  888. fmt.Println("d", d)
  889. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  890. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  891. "SELECT " +
  892. "CASE " +
  893. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  894. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  895. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  896. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  897. " ELSE '其他'" +
  898. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and x.inspect_value <> 0"
  899. countParams := make([]interface{}, 0)
  900. countParams = append(countParams, firststart)
  901. countParams = append(countParams, firstend)
  902. countParams = append(countParams, sencondstart)
  903. countParams = append(countParams, sencondend)
  904. countParams = append(countParams, threestart)
  905. countParams = append(countParams, threeend)
  906. countParams = append(countParams, fourstart)
  907. countParams = append(countParams, fourend)
  908. if orgid > 0 {
  909. db = db.Where("x.org_id=?", orgid)
  910. countSQL += " AND x.org_id=?"
  911. countParams = append(countParams, orgid)
  912. }
  913. if modetype > 0 {
  914. db = db.Where("x.item_id = ?", modetype)
  915. countSQL += " AND x.item_id=?"
  916. countParams = append(countParams, modetype)
  917. }
  918. if startime > 0 {
  919. db = db.Where("x.inspect_date >= ?", startime)
  920. countSQL += " AND x.inspect_date >=?"
  921. countParams = append(countParams, startime)
  922. }
  923. if endtime > 0 {
  924. db = db.Where("x.inspect_date <= ?", endtime)
  925. countSQL += " AND x.inspect_date <=?"
  926. countParams = append(countParams, endtime)
  927. }
  928. countSQL += ")a GROUP BY nnd"
  929. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  930. }
  931. if lapseto == 1 {
  932. d := XTReadDB().Table("xt_patients as s")
  933. fmt.Println("d", d)
  934. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  935. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  936. "SELECT " +
  937. "CASE " +
  938. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  939. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  940. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  941. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  942. "ELSE '其他'" +
  943. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  944. countParams := make([]interface{}, 0)
  945. countParams = append(countParams, firststart)
  946. countParams = append(countParams, firstend)
  947. countParams = append(countParams, sencondstart)
  948. countParams = append(countParams, sencondend)
  949. countParams = append(countParams, threestart)
  950. countParams = append(countParams, threeend)
  951. countParams = append(countParams, fourstart)
  952. countParams = append(countParams, fourend)
  953. if orgid > 0 {
  954. db = db.Where("x.org_id=?", orgid)
  955. countSQL += " AND x.org_id=?"
  956. countParams = append(countParams, orgid)
  957. }
  958. if modetype > 0 {
  959. db = db.Where("x.item_id = ?", modetype)
  960. countSQL += " AND x.item_id=?"
  961. countParams = append(countParams, modetype)
  962. }
  963. if startime > 0 {
  964. db = db.Where("x.inspect_date >= ?", startime)
  965. countSQL += " AND x.inspect_date >=?"
  966. countParams = append(countParams, startime)
  967. }
  968. if endtime > 0 {
  969. db = db.Where("x.inspect_date <= ?", endtime)
  970. countSQL += " AND x.inspect_date <=?"
  971. countParams = append(countParams, endtime)
  972. }
  973. countSQL += ")a GROUP BY nnd"
  974. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  975. }
  976. if lapseto == 2 {
  977. d := XTReadDB().Table("xt_patients as s")
  978. fmt.Println("d", d)
  979. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  980. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  981. "SELECT " +
  982. "CASE " +
  983. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  984. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  985. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  986. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  987. " ELSE '其他'" +
  988. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  989. countParams := make([]interface{}, 0)
  990. countParams = append(countParams, firststart)
  991. countParams = append(countParams, firstend)
  992. countParams = append(countParams, sencondstart)
  993. countParams = append(countParams, sencondend)
  994. countParams = append(countParams, threestart)
  995. countParams = append(countParams, threeend)
  996. countParams = append(countParams, fourstart)
  997. countParams = append(countParams, fourend)
  998. if orgid > 0 {
  999. db = db.Where("x.org_id=?", orgid)
  1000. countSQL += " AND x.org_id=?"
  1001. countParams = append(countParams, orgid)
  1002. }
  1003. if modetype > 0 {
  1004. db = db.Where("x.item_id = ?", modetype)
  1005. countSQL += " AND x.item_id=?"
  1006. countParams = append(countParams, modetype)
  1007. }
  1008. if startime > 0 {
  1009. db = db.Where("x.inspect_date >= ?", startime)
  1010. countSQL += " AND x.inspect_date >=?"
  1011. countParams = append(countParams, startime)
  1012. }
  1013. if endtime > 0 {
  1014. db = db.Where("x.inspect_date <= ?", endtime)
  1015. countSQL += " AND x.inspect_date <=?"
  1016. countParams = append(countParams, endtime)
  1017. }
  1018. countSQL += ")a GROUP BY nnd"
  1019. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1020. }
  1021. return
  1022. }
  1023. func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1024. if lapseto == 0 {
  1025. d := XTReadDB().Table("xt_patients as s")
  1026. fmt.Println("d", d)
  1027. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1028. table := XTReadDB().Table("xt_inspection_reference as r")
  1029. q := XTReadDB().Table("xt_quality_control_standard as r")
  1030. fmt.Println("q", q)
  1031. fmt.Println(table)
  1032. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1033. "SELECT " +
  1034. "CASE " +
  1035. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1036. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1037. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1038. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1039. " ELSE '其他'" +
  1040. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1041. countParams := make([]interface{}, 0)
  1042. countParams = append(countParams, firststart)
  1043. countParams = append(countParams, firstend)
  1044. countParams = append(countParams, sencondstart)
  1045. countParams = append(countParams, sencondend)
  1046. countParams = append(countParams, threestart)
  1047. countParams = append(countParams, threeend)
  1048. countParams = append(countParams, fourstart)
  1049. countParams = append(countParams, fourend)
  1050. if orgid > 0 {
  1051. db = db.Where("x.org_id=?", orgid)
  1052. countSQL += " AND x.org_id=?"
  1053. countParams = append(countParams, orgid)
  1054. }
  1055. if orgid > 0 {
  1056. db = db.Where("r.user_org_id=?", orgid)
  1057. countSQL += " AND r.user_org_id=?"
  1058. countParams = append(countParams, orgid)
  1059. }
  1060. if modetype > 0 {
  1061. db = db.Where("x.item_id = ?", modetype)
  1062. countSQL += " AND x.item_id=?"
  1063. countParams = append(countParams, modetype)
  1064. }
  1065. if startime > 0 {
  1066. db = db.Where("x.inspect_date >= ? ", startime)
  1067. countSQL += " AND x.inspect_date >=?"
  1068. countParams = append(countParams, startime)
  1069. }
  1070. if endtime > 0 {
  1071. db = db.Where("x.inspect_date <= ?", endtime)
  1072. countSQL += " AND x.inspect_date <=?"
  1073. countParams = append(countParams, endtime)
  1074. }
  1075. countSQL += ")a GROUP BY nnd"
  1076. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1077. }
  1078. if lapseto == 1 {
  1079. d := XTReadDB().Table("xt_patients as s")
  1080. fmt.Println("d", d)
  1081. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1082. table := XTReadDB().Table("xt_inspection_reference as r")
  1083. q := XTReadDB().Table("xt_quality_control_standard as r")
  1084. fmt.Println("q", q)
  1085. fmt.Println(table)
  1086. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1087. "SELECT " +
  1088. "CASE " +
  1089. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1090. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1091. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1092. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1093. " ELSE '其他'" +
  1094. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1095. countParams := make([]interface{}, 0)
  1096. countParams = append(countParams, firststart)
  1097. countParams = append(countParams, firstend)
  1098. countParams = append(countParams, sencondstart)
  1099. countParams = append(countParams, sencondend)
  1100. countParams = append(countParams, threestart)
  1101. countParams = append(countParams, threeend)
  1102. countParams = append(countParams, fourstart)
  1103. countParams = append(countParams, fourend)
  1104. if orgid > 0 {
  1105. db = db.Where("x.org_id=?", orgid)
  1106. countSQL += " AND x.org_id=?"
  1107. countParams = append(countParams, orgid)
  1108. }
  1109. if orgid > 0 {
  1110. db = db.Where("r.user_org_id=?", orgid)
  1111. countSQL += " AND r.user_org_id=?"
  1112. countParams = append(countParams, orgid)
  1113. }
  1114. if modetype > 0 {
  1115. db = db.Where("x.item_id = ?", modetype)
  1116. countSQL += " AND x.item_id=?"
  1117. countParams = append(countParams, modetype)
  1118. }
  1119. if startime > 0 {
  1120. db = db.Where("x.inspect_date >= ? ", startime)
  1121. countSQL += " AND x.inspect_date >=?"
  1122. countParams = append(countParams, startime)
  1123. }
  1124. if endtime > 0 {
  1125. db = db.Where("x.inspect_date <= ?", endtime)
  1126. countSQL += " AND x.inspect_date <=?"
  1127. countParams = append(countParams, endtime)
  1128. }
  1129. countSQL += ")a GROUP BY nnd"
  1130. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1131. }
  1132. return
  1133. }
  1134. func GetProjectStandListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1135. if lapseto == 0 {
  1136. d := XTReadDB().Table("xt_patients as s")
  1137. fmt.Println("d", d)
  1138. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1139. table := XTReadDB().Table("xt_inspection_reference as r")
  1140. q := XTReadDB().Table("xt_quality_control_standard as r")
  1141. fmt.Println("q", q)
  1142. fmt.Println(table)
  1143. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1144. "SELECT " +
  1145. "CASE " +
  1146. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1147. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1148. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1149. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1150. " ELSE '其他'" +
  1151. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1152. countParams := make([]interface{}, 0)
  1153. countParams = append(countParams, firststart)
  1154. countParams = append(countParams, firstend)
  1155. countParams = append(countParams, sencondstart)
  1156. countParams = append(countParams, sencondend)
  1157. countParams = append(countParams, threestart)
  1158. countParams = append(countParams, threeend)
  1159. countParams = append(countParams, fourstart)
  1160. countParams = append(countParams, fourend)
  1161. if orgid > 0 {
  1162. db = db.Where("x.org_id=?", orgid)
  1163. countSQL += " AND x.org_id=?"
  1164. countParams = append(countParams, orgid)
  1165. }
  1166. if orgid > 0 {
  1167. db = db.Where("r.user_org_id=?", orgid)
  1168. countSQL += " AND r.user_org_id=?"
  1169. countParams = append(countParams, orgid)
  1170. }
  1171. if modetype > 0 {
  1172. db = db.Where("x.item_id = ?", modetype)
  1173. countSQL += " AND x.item_id=?"
  1174. countParams = append(countParams, modetype)
  1175. }
  1176. if startime > 0 {
  1177. db = db.Where("x.inspect_date >= ? ", startime)
  1178. countSQL += " AND x.inspect_date >=?"
  1179. countParams = append(countParams, startime)
  1180. }
  1181. if endtime > 0 {
  1182. db = db.Where("x.inspect_date <= ?", endtime)
  1183. countSQL += " AND x.inspect_date <=?"
  1184. countParams = append(countParams, endtime)
  1185. }
  1186. countSQL += ")a GROUP BY nnd"
  1187. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1188. }
  1189. if lapseto == 1 {
  1190. d := XTReadDB().Table("xt_patients as s")
  1191. fmt.Println("d", d)
  1192. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1193. table := XTReadDB().Table("xt_inspection_reference as r")
  1194. q := XTReadDB().Table("xt_quality_control_standard as r")
  1195. fmt.Println("q", q)
  1196. fmt.Println(table)
  1197. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1198. "SELECT " +
  1199. "CASE " +
  1200. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1201. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1202. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1203. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1204. " ELSE '其他'" +
  1205. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1206. countParams := make([]interface{}, 0)
  1207. countParams = append(countParams, firststart)
  1208. countParams = append(countParams, firstend)
  1209. countParams = append(countParams, sencondstart)
  1210. countParams = append(countParams, sencondend)
  1211. countParams = append(countParams, threestart)
  1212. countParams = append(countParams, threeend)
  1213. countParams = append(countParams, fourstart)
  1214. countParams = append(countParams, fourend)
  1215. if orgid > 0 {
  1216. db = db.Where("x.org_id=?", orgid)
  1217. countSQL += " AND x.org_id=?"
  1218. countParams = append(countParams, orgid)
  1219. }
  1220. if orgid > 0 {
  1221. db = db.Where("r.user_org_id=?", orgid)
  1222. countSQL += " AND r.user_org_id=?"
  1223. countParams = append(countParams, orgid)
  1224. }
  1225. if modetype > 0 {
  1226. db = db.Where("x.item_id = ?", modetype)
  1227. countSQL += " AND x.item_id=?"
  1228. countParams = append(countParams, modetype)
  1229. }
  1230. if startime > 0 {
  1231. db = db.Where("x.inspect_date >= ? ", startime)
  1232. countSQL += " AND x.inspect_date >=?"
  1233. countParams = append(countParams, startime)
  1234. }
  1235. if endtime > 0 {
  1236. db = db.Where("x.inspect_date <= ?", endtime)
  1237. countSQL += " AND x.inspect_date <=?"
  1238. countParams = append(countParams, endtime)
  1239. }
  1240. countSQL += ")a GROUP BY nnd"
  1241. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1242. }
  1243. return
  1244. }
  1245. func GetMonthProjectList(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1246. if lapseto == 0 {
  1247. d := XTReadDB().Table("xt_patients as s")
  1248. fmt.Println("d", d)
  1249. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1")
  1250. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1251. "SELECT " +
  1252. "CASE " +
  1253. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1254. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1255. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1256. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1257. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1258. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1259. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1260. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1261. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1262. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1263. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1264. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1265. " ELSE '其他'" +
  1266. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1267. countParams := make([]interface{}, 0)
  1268. countParams = append(countParams, januaryStartStrUnix)
  1269. countParams = append(countParams, januaryEndStrUnix)
  1270. countParams = append(countParams, febStartStrStrUnix)
  1271. countParams = append(countParams, febEndStrUnix)
  1272. countParams = append(countParams, marchStartStrUnix)
  1273. countParams = append(countParams, marchEndStrUnix)
  1274. countParams = append(countParams, aprStartStrUnix)
  1275. countParams = append(countParams, aprEndStrsUnix)
  1276. countParams = append(countParams, mayStartStrUnix)
  1277. countParams = append(countParams, mayEndStrsUnix)
  1278. countParams = append(countParams, junStartStrUnix)
  1279. countParams = append(countParams, junEndStrsUnix)
  1280. countParams = append(countParams, julStartStrUnix)
  1281. countParams = append(countParams, julEndStrsUnix)
  1282. countParams = append(countParams, augStartStrUnix)
  1283. countParams = append(countParams, augEndStrsUnix)
  1284. countParams = append(countParams, sepStartStrUnix)
  1285. countParams = append(countParams, sepEndStrsUnix)
  1286. countParams = append(countParams, octStartStrUnix)
  1287. countParams = append(countParams, octEndStrsUnix)
  1288. countParams = append(countParams, novStartStrUnix)
  1289. countParams = append(countParams, novEndStrsUnix)
  1290. countParams = append(countParams, decStartStrUnix)
  1291. countParams = append(countParams, decEndStrsUnix)
  1292. if orgid > 0 {
  1293. db = db.Where("x.org_id=?", orgid)
  1294. countSQL += " AND x.org_id=?"
  1295. countParams = append(countParams, orgid)
  1296. }
  1297. if modetype > 0 {
  1298. db = db.Where("x.item_id = ?", modetype)
  1299. countSQL += " AND x.item_id=?"
  1300. countParams = append(countParams, modetype)
  1301. }
  1302. if januaryStartStrUnix > 0 {
  1303. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1304. countSQL += " AND x.inspect_date >=?"
  1305. countParams = append(countParams, januaryStartStrUnix)
  1306. }
  1307. if decEndStrsUnix > 0 {
  1308. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1309. countSQL += " AND x.inspect_date <=?"
  1310. countParams = append(countParams, decEndStrsUnix)
  1311. }
  1312. countSQL += ")a GROUP BY nnd"
  1313. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1314. }
  1315. if lapseto == 1 {
  1316. d := XTReadDB().Table("xt_patients as s")
  1317. fmt.Println("d", d)
  1318. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1 ")
  1319. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1320. "SELECT " +
  1321. "CASE " +
  1322. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1323. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1324. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1325. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1326. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1327. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1328. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1329. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1330. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1331. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1332. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1333. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1334. " ELSE '其他'" +
  1335. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1336. countParams := make([]interface{}, 0)
  1337. countParams = append(countParams, januaryStartStrUnix)
  1338. countParams = append(countParams, januaryEndStrUnix)
  1339. countParams = append(countParams, febStartStrStrUnix)
  1340. countParams = append(countParams, febEndStrUnix)
  1341. countParams = append(countParams, marchStartStrUnix)
  1342. countParams = append(countParams, marchEndStrUnix)
  1343. countParams = append(countParams, aprStartStrUnix)
  1344. countParams = append(countParams, aprEndStrsUnix)
  1345. countParams = append(countParams, mayStartStrUnix)
  1346. countParams = append(countParams, mayEndStrsUnix)
  1347. countParams = append(countParams, junStartStrUnix)
  1348. countParams = append(countParams, junEndStrsUnix)
  1349. countParams = append(countParams, julStartStrUnix)
  1350. countParams = append(countParams, julEndStrsUnix)
  1351. countParams = append(countParams, augStartStrUnix)
  1352. countParams = append(countParams, augEndStrsUnix)
  1353. countParams = append(countParams, sepStartStrUnix)
  1354. countParams = append(countParams, sepEndStrsUnix)
  1355. countParams = append(countParams, octStartStrUnix)
  1356. countParams = append(countParams, octEndStrsUnix)
  1357. countParams = append(countParams, novStartStrUnix)
  1358. countParams = append(countParams, novEndStrsUnix)
  1359. countParams = append(countParams, decStartStrUnix)
  1360. countParams = append(countParams, decEndStrsUnix)
  1361. if orgid > 0 {
  1362. db = db.Where("x.org_id=?", orgid)
  1363. countSQL += " AND x.org_id=?"
  1364. countParams = append(countParams, orgid)
  1365. }
  1366. if modetype > 0 {
  1367. db = db.Where("x.item_id = ?", modetype)
  1368. countSQL += " AND x.item_id=?"
  1369. countParams = append(countParams, modetype)
  1370. }
  1371. if januaryStartStrUnix > 0 {
  1372. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1373. countSQL += " AND x.inspect_date >=?"
  1374. countParams = append(countParams, januaryStartStrUnix)
  1375. }
  1376. if decEndStrsUnix > 0 {
  1377. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1378. countSQL += " AND x.inspect_date <=?"
  1379. countParams = append(countParams, decEndStrsUnix)
  1380. }
  1381. countSQL += ")a GROUP BY nnd"
  1382. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1383. }
  1384. if lapseto == 2 {
  1385. d := XTReadDB().Table("xt_patients as s")
  1386. fmt.Println("d", d)
  1387. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_value <> 0 and x.inspect_type = 1")
  1388. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1389. "SELECT " +
  1390. "CASE " +
  1391. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1392. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1393. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1394. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1395. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1396. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1397. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1398. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1399. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1400. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1401. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1402. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1403. " ELSE '其他'" +
  1404. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1405. countParams := make([]interface{}, 0)
  1406. countParams = append(countParams, januaryStartStrUnix)
  1407. countParams = append(countParams, januaryEndStrUnix)
  1408. countParams = append(countParams, febStartStrStrUnix)
  1409. countParams = append(countParams, febEndStrUnix)
  1410. countParams = append(countParams, marchStartStrUnix)
  1411. countParams = append(countParams, marchEndStrUnix)
  1412. countParams = append(countParams, aprStartStrUnix)
  1413. countParams = append(countParams, aprEndStrsUnix)
  1414. countParams = append(countParams, mayStartStrUnix)
  1415. countParams = append(countParams, mayEndStrsUnix)
  1416. countParams = append(countParams, junStartStrUnix)
  1417. countParams = append(countParams, junEndStrsUnix)
  1418. countParams = append(countParams, julStartStrUnix)
  1419. countParams = append(countParams, julEndStrsUnix)
  1420. countParams = append(countParams, augStartStrUnix)
  1421. countParams = append(countParams, augEndStrsUnix)
  1422. countParams = append(countParams, sepStartStrUnix)
  1423. countParams = append(countParams, sepEndStrsUnix)
  1424. countParams = append(countParams, octStartStrUnix)
  1425. countParams = append(countParams, octEndStrsUnix)
  1426. countParams = append(countParams, novStartStrUnix)
  1427. countParams = append(countParams, novEndStrsUnix)
  1428. countParams = append(countParams, decStartStrUnix)
  1429. countParams = append(countParams, decEndStrsUnix)
  1430. if orgid > 0 {
  1431. db = db.Where("x.org_id=?", orgid)
  1432. countSQL += " AND x.org_id=?"
  1433. countParams = append(countParams, orgid)
  1434. }
  1435. if modetype > 0 {
  1436. db = db.Where("x.item_id = ?", modetype)
  1437. countSQL += " AND x.item_id=?"
  1438. countParams = append(countParams, modetype)
  1439. }
  1440. if januaryStartStrUnix > 0 {
  1441. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1442. countSQL += " AND x.inspect_date >=?"
  1443. countParams = append(countParams, januaryStartStrUnix)
  1444. }
  1445. if decEndStrsUnix > 0 {
  1446. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1447. countSQL += " AND x.inspect_date <=?"
  1448. countParams = append(countParams, decEndStrsUnix)
  1449. }
  1450. countSQL += ")a GROUP BY nnd"
  1451. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1452. }
  1453. return
  1454. }
  1455. func GetMonthProjectListOne(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1456. if lapseto == 0 {
  1457. d := XTReadDB().Table("xt_patients as s")
  1458. fmt.Println("d", d)
  1459. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1460. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1461. "SELECT " +
  1462. "CASE " +
  1463. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1464. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1465. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1466. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1467. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1468. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1469. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1470. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1471. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1472. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1473. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1474. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1475. " ELSE '其他'" +
  1476. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1477. countParams := make([]interface{}, 0)
  1478. countParams = append(countParams, januaryStartStrUnix)
  1479. countParams = append(countParams, januaryEndStrUnix)
  1480. countParams = append(countParams, febStartStrStrUnix)
  1481. countParams = append(countParams, febEndStrUnix)
  1482. countParams = append(countParams, marchStartStrUnix)
  1483. countParams = append(countParams, marchEndStrUnix)
  1484. countParams = append(countParams, aprStartStrUnix)
  1485. countParams = append(countParams, aprEndStrsUnix)
  1486. countParams = append(countParams, mayStartStrUnix)
  1487. countParams = append(countParams, mayEndStrsUnix)
  1488. countParams = append(countParams, junStartStrUnix)
  1489. countParams = append(countParams, junEndStrsUnix)
  1490. countParams = append(countParams, julStartStrUnix)
  1491. countParams = append(countParams, julEndStrsUnix)
  1492. countParams = append(countParams, augStartStrUnix)
  1493. countParams = append(countParams, augEndStrsUnix)
  1494. countParams = append(countParams, sepStartStrUnix)
  1495. countParams = append(countParams, sepEndStrsUnix)
  1496. countParams = append(countParams, octStartStrUnix)
  1497. countParams = append(countParams, octEndStrsUnix)
  1498. countParams = append(countParams, novStartStrUnix)
  1499. countParams = append(countParams, novEndStrsUnix)
  1500. countParams = append(countParams, decStartStrUnix)
  1501. countParams = append(countParams, decEndStrsUnix)
  1502. if orgid > 0 {
  1503. db = db.Where("x.org_id=?", orgid)
  1504. countSQL += " AND x.org_id=?"
  1505. countParams = append(countParams, orgid)
  1506. }
  1507. if modetype > 0 {
  1508. db = db.Where("x.item_id = ?", modetype)
  1509. countSQL += " AND x.item_id=?"
  1510. countParams = append(countParams, modetype)
  1511. }
  1512. if januaryStartStrUnix > 0 {
  1513. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1514. countSQL += " AND x.inspect_date >=?"
  1515. countParams = append(countParams, januaryStartStrUnix)
  1516. }
  1517. if decEndStrsUnix > 0 {
  1518. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1519. countSQL += " AND x.inspect_date <=?"
  1520. countParams = append(countParams, decEndStrsUnix)
  1521. }
  1522. countSQL += ")a GROUP BY nnd"
  1523. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1524. }
  1525. if lapseto == 1 {
  1526. d := XTReadDB().Table("xt_patients as s")
  1527. fmt.Println("d", d)
  1528. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and and x.inspect_type = 2")
  1529. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1530. "SELECT " +
  1531. "CASE " +
  1532. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1533. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1534. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1535. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1536. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1537. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1538. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1539. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1540. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1541. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1542. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1543. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1544. " ELSE '其他'" +
  1545. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1546. countParams := make([]interface{}, 0)
  1547. countParams = append(countParams, januaryStartStrUnix)
  1548. countParams = append(countParams, januaryEndStrUnix)
  1549. countParams = append(countParams, febStartStrStrUnix)
  1550. countParams = append(countParams, febEndStrUnix)
  1551. countParams = append(countParams, marchStartStrUnix)
  1552. countParams = append(countParams, marchEndStrUnix)
  1553. countParams = append(countParams, aprStartStrUnix)
  1554. countParams = append(countParams, aprEndStrsUnix)
  1555. countParams = append(countParams, mayStartStrUnix)
  1556. countParams = append(countParams, mayEndStrsUnix)
  1557. countParams = append(countParams, junStartStrUnix)
  1558. countParams = append(countParams, junEndStrsUnix)
  1559. countParams = append(countParams, julStartStrUnix)
  1560. countParams = append(countParams, julEndStrsUnix)
  1561. countParams = append(countParams, augStartStrUnix)
  1562. countParams = append(countParams, augEndStrsUnix)
  1563. countParams = append(countParams, sepStartStrUnix)
  1564. countParams = append(countParams, sepEndStrsUnix)
  1565. countParams = append(countParams, octStartStrUnix)
  1566. countParams = append(countParams, octEndStrsUnix)
  1567. countParams = append(countParams, novStartStrUnix)
  1568. countParams = append(countParams, novEndStrsUnix)
  1569. countParams = append(countParams, decStartStrUnix)
  1570. countParams = append(countParams, decEndStrsUnix)
  1571. if orgid > 0 {
  1572. db = db.Where("x.org_id=?", orgid)
  1573. countSQL += " AND x.org_id=?"
  1574. countParams = append(countParams, orgid)
  1575. }
  1576. if modetype > 0 {
  1577. db = db.Where("x.item_id = ?", modetype)
  1578. countSQL += " AND x.item_id=?"
  1579. countParams = append(countParams, modetype)
  1580. }
  1581. if januaryStartStrUnix > 0 {
  1582. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1583. countSQL += " AND x.inspect_date >=?"
  1584. countParams = append(countParams, januaryStartStrUnix)
  1585. }
  1586. if decEndStrsUnix > 0 {
  1587. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1588. countSQL += " AND x.inspect_date <=?"
  1589. countParams = append(countParams, decEndStrsUnix)
  1590. }
  1591. countSQL += ")a GROUP BY nnd"
  1592. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1593. }
  1594. if lapseto == 2 {
  1595. d := XTReadDB().Table("xt_patients as s")
  1596. fmt.Println("d", d)
  1597. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1598. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1599. "SELECT " +
  1600. "CASE " +
  1601. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1602. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1603. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1604. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1605. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1606. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1607. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1608. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1609. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1610. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1611. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1612. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1613. " ELSE '其他'" +
  1614. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1615. countParams := make([]interface{}, 0)
  1616. countParams = append(countParams, januaryStartStrUnix)
  1617. countParams = append(countParams, januaryEndStrUnix)
  1618. countParams = append(countParams, febStartStrStrUnix)
  1619. countParams = append(countParams, febEndStrUnix)
  1620. countParams = append(countParams, marchStartStrUnix)
  1621. countParams = append(countParams, marchEndStrUnix)
  1622. countParams = append(countParams, aprStartStrUnix)
  1623. countParams = append(countParams, aprEndStrsUnix)
  1624. countParams = append(countParams, mayStartStrUnix)
  1625. countParams = append(countParams, mayEndStrsUnix)
  1626. countParams = append(countParams, junStartStrUnix)
  1627. countParams = append(countParams, junEndStrsUnix)
  1628. countParams = append(countParams, julStartStrUnix)
  1629. countParams = append(countParams, julEndStrsUnix)
  1630. countParams = append(countParams, augStartStrUnix)
  1631. countParams = append(countParams, augEndStrsUnix)
  1632. countParams = append(countParams, sepStartStrUnix)
  1633. countParams = append(countParams, sepEndStrsUnix)
  1634. countParams = append(countParams, octStartStrUnix)
  1635. countParams = append(countParams, octEndStrsUnix)
  1636. countParams = append(countParams, novStartStrUnix)
  1637. countParams = append(countParams, novEndStrsUnix)
  1638. countParams = append(countParams, decStartStrUnix)
  1639. countParams = append(countParams, decEndStrsUnix)
  1640. if orgid > 0 {
  1641. db = db.Where("x.org_id=?", orgid)
  1642. countSQL += " AND x.org_id=?"
  1643. countParams = append(countParams, orgid)
  1644. }
  1645. if modetype > 0 {
  1646. db = db.Where("x.item_id = ?", modetype)
  1647. countSQL += " AND x.item_id=?"
  1648. countParams = append(countParams, modetype)
  1649. }
  1650. if januaryStartStrUnix > 0 {
  1651. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1652. countSQL += " AND x.inspect_date >=?"
  1653. countParams = append(countParams, januaryStartStrUnix)
  1654. }
  1655. if decEndStrsUnix > 0 {
  1656. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1657. countSQL += " AND x.inspect_date <=?"
  1658. countParams = append(countParams, decEndStrsUnix)
  1659. }
  1660. countSQL += ")a GROUP BY nnd"
  1661. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1662. }
  1663. return
  1664. }
  1665. func GetProjectListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  1666. if lapseto == 0 {
  1667. d := XTReadDB().Table("xt_patients as s")
  1668. fmt.Println("d", d)
  1669. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1670. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1671. "SELECT " +
  1672. "CASE " +
  1673. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1674. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1675. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1676. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1677. " ELSE '其他'" +
  1678. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1679. countParams := make([]interface{}, 0)
  1680. countParams = append(countParams, firststart)
  1681. countParams = append(countParams, firstend)
  1682. countParams = append(countParams, sencondstart)
  1683. countParams = append(countParams, sencondend)
  1684. countParams = append(countParams, threestart)
  1685. countParams = append(countParams, threeend)
  1686. countParams = append(countParams, fourstart)
  1687. countParams = append(countParams, fourend)
  1688. if orgid > 0 {
  1689. db = db.Where("x.org_id=?", orgid)
  1690. countSQL += " AND x.org_id=?"
  1691. countParams = append(countParams, orgid)
  1692. }
  1693. if modetype > 0 {
  1694. db = db.Where("x.item_id = ?", modetype)
  1695. countSQL += " AND x.item_id=?"
  1696. countParams = append(countParams, modetype)
  1697. }
  1698. if startime > 0 {
  1699. db = db.Where("x.inspect_date >= ?", startime)
  1700. countSQL += " AND x.inspect_date >=?"
  1701. countParams = append(countParams, startime)
  1702. }
  1703. if endtime > 0 {
  1704. db = db.Where("x.inspect_date <= ?", endtime)
  1705. countSQL += " AND x.inspect_date <=?"
  1706. countParams = append(countParams, endtime)
  1707. }
  1708. countSQL += ")a GROUP BY nnd"
  1709. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1710. }
  1711. if lapseto == 1 {
  1712. d := XTReadDB().Table("xt_patients as s")
  1713. fmt.Println("d", d)
  1714. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1715. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1716. "SELECT " +
  1717. "CASE " +
  1718. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1719. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1720. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1721. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1722. " ELSE '其他'" +
  1723. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1724. countParams := make([]interface{}, 0)
  1725. countParams = append(countParams, firststart)
  1726. countParams = append(countParams, firstend)
  1727. countParams = append(countParams, sencondstart)
  1728. countParams = append(countParams, sencondend)
  1729. countParams = append(countParams, threestart)
  1730. countParams = append(countParams, threeend)
  1731. countParams = append(countParams, fourstart)
  1732. countParams = append(countParams, fourend)
  1733. if orgid > 0 {
  1734. db = db.Where("x.org_id=?", orgid)
  1735. countSQL += " AND x.org_id=?"
  1736. countParams = append(countParams, orgid)
  1737. }
  1738. if modetype > 0 {
  1739. db = db.Where("x.item_id = ?", modetype)
  1740. countSQL += " AND x.item_id=?"
  1741. countParams = append(countParams, modetype)
  1742. }
  1743. if startime > 0 {
  1744. db = db.Where("x.inspect_date >= ?", startime)
  1745. countSQL += " AND x.inspect_date >=?"
  1746. countParams = append(countParams, startime)
  1747. }
  1748. if endtime > 0 {
  1749. db = db.Where("x.inspect_date <= ?", endtime)
  1750. countSQL += " AND x.inspect_date <=?"
  1751. countParams = append(countParams, endtime)
  1752. }
  1753. countSQL += ")a GROUP BY nnd"
  1754. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1755. }
  1756. if lapseto == 2 {
  1757. d := XTReadDB().Table("xt_patients as s")
  1758. fmt.Println("d", d)
  1759. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1760. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1761. "SELECT " +
  1762. "CASE " +
  1763. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1764. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1765. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1766. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1767. " ELSE '其他'" +
  1768. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1769. countParams := make([]interface{}, 0)
  1770. countParams = append(countParams, firststart)
  1771. countParams = append(countParams, firstend)
  1772. countParams = append(countParams, sencondstart)
  1773. countParams = append(countParams, sencondend)
  1774. countParams = append(countParams, threestart)
  1775. countParams = append(countParams, threeend)
  1776. countParams = append(countParams, fourstart)
  1777. countParams = append(countParams, fourend)
  1778. if orgid > 0 {
  1779. db = db.Where("x.org_id=?", orgid)
  1780. countSQL += " AND x.org_id=?"
  1781. countParams = append(countParams, orgid)
  1782. }
  1783. if modetype > 0 {
  1784. db = db.Where("x.item_id = ?", modetype)
  1785. countSQL += " AND x.item_id=?"
  1786. countParams = append(countParams, modetype)
  1787. }
  1788. if startime > 0 {
  1789. db = db.Where("x.inspect_date >= ?", startime)
  1790. countSQL += " AND x.inspect_date >=?"
  1791. countParams = append(countParams, startime)
  1792. }
  1793. if endtime > 0 {
  1794. db = db.Where("x.inspect_date <= ?", endtime)
  1795. countSQL += " AND x.inspect_date <=?"
  1796. countParams = append(countParams, endtime)
  1797. }
  1798. countSQL += ")a GROUP BY nnd"
  1799. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1800. }
  1801. return
  1802. }
  1803. func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  1804. if lapseto == 0 {
  1805. d := XTReadDB().Table("xt_patients as s")
  1806. fmt.Println("d", d)
  1807. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1808. table := XTReadDB().Table("xt_quality_control_standard as r")
  1809. fmt.Println(table)
  1810. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1811. "SELECT " +
  1812. "CASE " +
  1813. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1814. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1815. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1816. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1817. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1818. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1819. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1820. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1821. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1822. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1823. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1824. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1825. " ELSE '其他'" +
  1826. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1827. countParams := make([]interface{}, 0)
  1828. countParams = append(countParams, januaryStartStrUnix)
  1829. countParams = append(countParams, januaryEndStrUnix)
  1830. countParams = append(countParams, febStartStrStrUnix)
  1831. countParams = append(countParams, febEndStrUnix)
  1832. countParams = append(countParams, marchStartStrUnix)
  1833. countParams = append(countParams, marchEndStrUnix)
  1834. countParams = append(countParams, aprStartStrUnix)
  1835. countParams = append(countParams, aprEndStrsUnix)
  1836. countParams = append(countParams, mayStartStrUnix)
  1837. countParams = append(countParams, mayEndStrsUnix)
  1838. countParams = append(countParams, junStartStrUnix)
  1839. countParams = append(countParams, junEndStrsUnix)
  1840. countParams = append(countParams, julStartStrUnix)
  1841. countParams = append(countParams, julEndStrsUnix)
  1842. countParams = append(countParams, augStartStrUnix)
  1843. countParams = append(countParams, augEndStrsUnix)
  1844. countParams = append(countParams, sepStartStrUnix)
  1845. countParams = append(countParams, sepEndStrsUnix)
  1846. countParams = append(countParams, octStartStrUnix)
  1847. countParams = append(countParams, octEndStrsUnix)
  1848. countParams = append(countParams, novStartStrUnix)
  1849. countParams = append(countParams, novEndStrsUnix)
  1850. countParams = append(countParams, decStartStrUnix)
  1851. countParams = append(countParams, decEndStrsUnix)
  1852. if orgid > 0 {
  1853. db = db.Where("x.org_id=?", orgid)
  1854. countSQL += " AND x.org_id=?"
  1855. countParams = append(countParams, orgid)
  1856. }
  1857. if orgid > 0 {
  1858. db = db.Where("r.user_org_id=?", orgid)
  1859. countSQL += " AND r.user_org_id=?"
  1860. countParams = append(countParams, orgid)
  1861. }
  1862. if modetype > 0 {
  1863. db = db.Where("x.item_id = ?", modetype)
  1864. countSQL += " AND x.item_id=?"
  1865. countParams = append(countParams, modetype)
  1866. }
  1867. if januaryStartStrUnix > 0 {
  1868. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1869. countSQL += " AND x.inspect_date >=?"
  1870. countParams = append(countParams, januaryStartStrUnix)
  1871. }
  1872. if decEndStrsUnix > 0 {
  1873. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1874. countSQL += " AND x.inspect_date <=?"
  1875. countParams = append(countParams, decEndStrsUnix)
  1876. }
  1877. countSQL += ")a GROUP BY nnd"
  1878. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1879. }
  1880. if lapseto == 1 {
  1881. d := XTReadDB().Table("xt_patients as s")
  1882. fmt.Println("d", d)
  1883. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1884. table := XTReadDB().Table("xt_quality_control_standard as r")
  1885. fmt.Println(table)
  1886. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1887. "SELECT " +
  1888. "CASE " +
  1889. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1890. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1891. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1892. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1893. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1894. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1895. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1896. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1897. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1898. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1899. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1900. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1901. " ELSE '其他'" +
  1902. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1903. countParams := make([]interface{}, 0)
  1904. countParams = append(countParams, januaryStartStrUnix)
  1905. countParams = append(countParams, januaryEndStrUnix)
  1906. countParams = append(countParams, febStartStrStrUnix)
  1907. countParams = append(countParams, febEndStrUnix)
  1908. countParams = append(countParams, marchStartStrUnix)
  1909. countParams = append(countParams, marchEndStrUnix)
  1910. countParams = append(countParams, aprStartStrUnix)
  1911. countParams = append(countParams, aprEndStrsUnix)
  1912. countParams = append(countParams, mayStartStrUnix)
  1913. countParams = append(countParams, mayEndStrsUnix)
  1914. countParams = append(countParams, junStartStrUnix)
  1915. countParams = append(countParams, junEndStrsUnix)
  1916. countParams = append(countParams, julStartStrUnix)
  1917. countParams = append(countParams, julEndStrsUnix)
  1918. countParams = append(countParams, augStartStrUnix)
  1919. countParams = append(countParams, augEndStrsUnix)
  1920. countParams = append(countParams, sepStartStrUnix)
  1921. countParams = append(countParams, sepEndStrsUnix)
  1922. countParams = append(countParams, octStartStrUnix)
  1923. countParams = append(countParams, octEndStrsUnix)
  1924. countParams = append(countParams, novStartStrUnix)
  1925. countParams = append(countParams, novEndStrsUnix)
  1926. countParams = append(countParams, decStartStrUnix)
  1927. countParams = append(countParams, decEndStrsUnix)
  1928. if orgid > 0 {
  1929. db = db.Where("x.org_id=?", orgid)
  1930. countSQL += " AND x.org_id=?"
  1931. countParams = append(countParams, orgid)
  1932. }
  1933. if orgid > 0 {
  1934. db = db.Where("r.user_org_id=?", orgid)
  1935. countSQL += " AND r.user_org_id=?"
  1936. countParams = append(countParams, orgid)
  1937. }
  1938. if modetype > 0 {
  1939. db = db.Where("x.item_id = ?", modetype)
  1940. countSQL += " AND x.item_id=?"
  1941. countParams = append(countParams, modetype)
  1942. }
  1943. if januaryStartStrUnix > 0 {
  1944. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1945. countSQL += " AND x.inspect_date >=?"
  1946. countParams = append(countParams, januaryStartStrUnix)
  1947. }
  1948. if decEndStrsUnix > 0 {
  1949. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1950. countSQL += " AND x.inspect_date <=?"
  1951. countParams = append(countParams, decEndStrsUnix)
  1952. }
  1953. countSQL += ")a GROUP BY nnd"
  1954. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1955. }
  1956. if lapseto == 2 {
  1957. d := XTReadDB().Table("xt_patients as s")
  1958. fmt.Println("d", d)
  1959. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1960. table := XTReadDB().Table("xt_quality_control_standard as r")
  1961. fmt.Println(table)
  1962. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1963. "SELECT " +
  1964. "CASE " +
  1965. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1966. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1967. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1968. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1969. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1970. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1971. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1972. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1973. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1974. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1975. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1976. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1977. " ELSE '其他'" +
  1978. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1979. countParams := make([]interface{}, 0)
  1980. countParams = append(countParams, januaryStartStrUnix)
  1981. countParams = append(countParams, januaryEndStrUnix)
  1982. countParams = append(countParams, febStartStrStrUnix)
  1983. countParams = append(countParams, febEndStrUnix)
  1984. countParams = append(countParams, marchStartStrUnix)
  1985. countParams = append(countParams, marchEndStrUnix)
  1986. countParams = append(countParams, aprStartStrUnix)
  1987. countParams = append(countParams, aprEndStrsUnix)
  1988. countParams = append(countParams, mayStartStrUnix)
  1989. countParams = append(countParams, mayEndStrsUnix)
  1990. countParams = append(countParams, junStartStrUnix)
  1991. countParams = append(countParams, junEndStrsUnix)
  1992. countParams = append(countParams, julStartStrUnix)
  1993. countParams = append(countParams, julEndStrsUnix)
  1994. countParams = append(countParams, augStartStrUnix)
  1995. countParams = append(countParams, augEndStrsUnix)
  1996. countParams = append(countParams, sepStartStrUnix)
  1997. countParams = append(countParams, sepEndStrsUnix)
  1998. countParams = append(countParams, octStartStrUnix)
  1999. countParams = append(countParams, octEndStrsUnix)
  2000. countParams = append(countParams, novStartStrUnix)
  2001. countParams = append(countParams, novEndStrsUnix)
  2002. countParams = append(countParams, decStartStrUnix)
  2003. countParams = append(countParams, decEndStrsUnix)
  2004. if orgid > 0 {
  2005. db = db.Where("x.org_id=?", orgid)
  2006. countSQL += " AND x.org_id=?"
  2007. countParams = append(countParams, orgid)
  2008. }
  2009. if orgid > 0 {
  2010. db = db.Where("r.user_org_id=?", orgid)
  2011. countSQL += " AND r.user_org_id=?"
  2012. countParams = append(countParams, orgid)
  2013. }
  2014. if modetype > 0 {
  2015. db = db.Where("x.item_id = ?", modetype)
  2016. countSQL += " AND x.item_id=?"
  2017. countParams = append(countParams, modetype)
  2018. }
  2019. if januaryStartStrUnix > 0 {
  2020. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2021. countSQL += " AND x.inspect_date >=?"
  2022. countParams = append(countParams, januaryStartStrUnix)
  2023. }
  2024. if decEndStrsUnix > 0 {
  2025. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2026. countSQL += " AND x.inspect_date <=?"
  2027. countParams = append(countParams, decEndStrsUnix)
  2028. }
  2029. countSQL += ")a GROUP BY nnd"
  2030. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2031. }
  2032. return
  2033. }
  2034. func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  2035. if lapseto == 0 {
  2036. d := XTReadDB().Table("xt_patients as s")
  2037. fmt.Println("d", d)
  2038. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2039. table := XTReadDB().Table("xt_quality_control_standard as r")
  2040. fmt.Println(table)
  2041. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2042. "SELECT " +
  2043. "CASE " +
  2044. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2045. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2046. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2047. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2048. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2049. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2050. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2051. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2052. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2053. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2054. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2055. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2056. " ELSE '其他'" +
  2057. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2058. countParams := make([]interface{}, 0)
  2059. countParams = append(countParams, januaryStartStrUnix)
  2060. countParams = append(countParams, januaryEndStrUnix)
  2061. countParams = append(countParams, febStartStrStrUnix)
  2062. countParams = append(countParams, febEndStrUnix)
  2063. countParams = append(countParams, marchStartStrUnix)
  2064. countParams = append(countParams, marchEndStrUnix)
  2065. countParams = append(countParams, aprStartStrUnix)
  2066. countParams = append(countParams, aprEndStrsUnix)
  2067. countParams = append(countParams, mayStartStrUnix)
  2068. countParams = append(countParams, mayEndStrsUnix)
  2069. countParams = append(countParams, junStartStrUnix)
  2070. countParams = append(countParams, junEndStrsUnix)
  2071. countParams = append(countParams, julStartStrUnix)
  2072. countParams = append(countParams, julEndStrsUnix)
  2073. countParams = append(countParams, augStartStrUnix)
  2074. countParams = append(countParams, augEndStrsUnix)
  2075. countParams = append(countParams, sepStartStrUnix)
  2076. countParams = append(countParams, sepEndStrsUnix)
  2077. countParams = append(countParams, octStartStrUnix)
  2078. countParams = append(countParams, octEndStrsUnix)
  2079. countParams = append(countParams, novStartStrUnix)
  2080. countParams = append(countParams, novEndStrsUnix)
  2081. countParams = append(countParams, decStartStrUnix)
  2082. countParams = append(countParams, decEndStrsUnix)
  2083. if orgid > 0 {
  2084. db = db.Where("x.org_id=?", orgid)
  2085. countSQL += " AND x.org_id=?"
  2086. countParams = append(countParams, orgid)
  2087. }
  2088. if orgid > 0 {
  2089. db = db.Where("r.user_org_id=?", orgid)
  2090. countSQL += " AND r.user_org_id=?"
  2091. countParams = append(countParams, orgid)
  2092. }
  2093. if modetype > 0 {
  2094. db = db.Where("x.item_id = ?", modetype)
  2095. countSQL += " AND x.item_id=?"
  2096. countParams = append(countParams, modetype)
  2097. }
  2098. if januaryStartStrUnix > 0 {
  2099. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2100. countSQL += " AND x.inspect_date >=?"
  2101. countParams = append(countParams, januaryStartStrUnix)
  2102. }
  2103. if decEndStrsUnix > 0 {
  2104. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2105. countSQL += " AND x.inspect_date <=?"
  2106. countParams = append(countParams, decEndStrsUnix)
  2107. }
  2108. countSQL += ")a GROUP BY nnd"
  2109. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2110. }
  2111. if lapseto == 1 {
  2112. d := XTReadDB().Table("xt_patients as s")
  2113. fmt.Println("d", d)
  2114. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2115. table := XTReadDB().Table("xt_quality_control_standard as r")
  2116. fmt.Println(table)
  2117. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2118. "SELECT " +
  2119. "CASE " +
  2120. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2121. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2122. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2123. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2124. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2125. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2126. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2127. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2128. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2129. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2130. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2131. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2132. " ELSE '其他'" +
  2133. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value = r.range_value)"
  2134. countParams := make([]interface{}, 0)
  2135. countParams = append(countParams, januaryStartStrUnix)
  2136. countParams = append(countParams, januaryEndStrUnix)
  2137. countParams = append(countParams, febStartStrStrUnix)
  2138. countParams = append(countParams, febEndStrUnix)
  2139. countParams = append(countParams, marchStartStrUnix)
  2140. countParams = append(countParams, marchEndStrUnix)
  2141. countParams = append(countParams, aprStartStrUnix)
  2142. countParams = append(countParams, aprEndStrsUnix)
  2143. countParams = append(countParams, mayStartStrUnix)
  2144. countParams = append(countParams, mayEndStrsUnix)
  2145. countParams = append(countParams, junStartStrUnix)
  2146. countParams = append(countParams, junEndStrsUnix)
  2147. countParams = append(countParams, julStartStrUnix)
  2148. countParams = append(countParams, julEndStrsUnix)
  2149. countParams = append(countParams, augStartStrUnix)
  2150. countParams = append(countParams, augEndStrsUnix)
  2151. countParams = append(countParams, sepStartStrUnix)
  2152. countParams = append(countParams, sepEndStrsUnix)
  2153. countParams = append(countParams, octStartStrUnix)
  2154. countParams = append(countParams, octEndStrsUnix)
  2155. countParams = append(countParams, novStartStrUnix)
  2156. countParams = append(countParams, novEndStrsUnix)
  2157. countParams = append(countParams, decStartStrUnix)
  2158. countParams = append(countParams, decEndStrsUnix)
  2159. if orgid > 0 {
  2160. db = db.Where("x.org_id=?", orgid)
  2161. countSQL += " AND x.org_id=?"
  2162. countParams = append(countParams, orgid)
  2163. }
  2164. if orgid > 0 {
  2165. db = db.Where("r.user_org_id=?", orgid)
  2166. countSQL += " AND r.user_org_id=?"
  2167. countParams = append(countParams, orgid)
  2168. }
  2169. if modetype > 0 {
  2170. db = db.Where("x.item_id = ?", modetype)
  2171. countSQL += " AND x.item_id=?"
  2172. countParams = append(countParams, modetype)
  2173. }
  2174. if januaryStartStrUnix > 0 {
  2175. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2176. countSQL += " AND x.inspect_date >=?"
  2177. countParams = append(countParams, januaryStartStrUnix)
  2178. }
  2179. if decEndStrsUnix > 0 {
  2180. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2181. countSQL += " AND x.inspect_date <=?"
  2182. countParams = append(countParams, decEndStrsUnix)
  2183. }
  2184. countSQL += ")a GROUP BY nnd"
  2185. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2186. }
  2187. if lapseto == 2 {
  2188. d := XTReadDB().Table("xt_patients as s")
  2189. fmt.Println("d", d)
  2190. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2191. table := XTReadDB().Table("xt_quality_control_standard as r")
  2192. fmt.Println(table)
  2193. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2194. "SELECT " +
  2195. "CASE " +
  2196. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2197. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2198. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2199. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2200. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2201. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2202. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2203. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2204. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2205. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2206. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2207. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2208. " ELSE '其他'" +
  2209. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2210. countParams := make([]interface{}, 0)
  2211. countParams = append(countParams, januaryStartStrUnix)
  2212. countParams = append(countParams, januaryEndStrUnix)
  2213. countParams = append(countParams, febStartStrStrUnix)
  2214. countParams = append(countParams, febEndStrUnix)
  2215. countParams = append(countParams, marchStartStrUnix)
  2216. countParams = append(countParams, marchEndStrUnix)
  2217. countParams = append(countParams, aprStartStrUnix)
  2218. countParams = append(countParams, aprEndStrsUnix)
  2219. countParams = append(countParams, mayStartStrUnix)
  2220. countParams = append(countParams, mayEndStrsUnix)
  2221. countParams = append(countParams, junStartStrUnix)
  2222. countParams = append(countParams, junEndStrsUnix)
  2223. countParams = append(countParams, julStartStrUnix)
  2224. countParams = append(countParams, julEndStrsUnix)
  2225. countParams = append(countParams, augStartStrUnix)
  2226. countParams = append(countParams, augEndStrsUnix)
  2227. countParams = append(countParams, sepStartStrUnix)
  2228. countParams = append(countParams, sepEndStrsUnix)
  2229. countParams = append(countParams, octStartStrUnix)
  2230. countParams = append(countParams, octEndStrsUnix)
  2231. countParams = append(countParams, novStartStrUnix)
  2232. countParams = append(countParams, novEndStrsUnix)
  2233. countParams = append(countParams, decStartStrUnix)
  2234. countParams = append(countParams, decEndStrsUnix)
  2235. if orgid > 0 {
  2236. db = db.Where("x.org_id=?", orgid)
  2237. countSQL += " AND x.org_id=?"
  2238. countParams = append(countParams, orgid)
  2239. }
  2240. if orgid > 0 {
  2241. db = db.Where("r.user_org_id=?", orgid)
  2242. countSQL += " AND r.user_org_id=?"
  2243. countParams = append(countParams, orgid)
  2244. }
  2245. if modetype > 0 {
  2246. db = db.Where("x.item_id = ?", modetype)
  2247. countSQL += " AND x.item_id=?"
  2248. countParams = append(countParams, modetype)
  2249. }
  2250. if januaryStartStrUnix > 0 {
  2251. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2252. countSQL += " AND x.inspect_date >=?"
  2253. countParams = append(countParams, januaryStartStrUnix)
  2254. }
  2255. if decEndStrsUnix > 0 {
  2256. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2257. countSQL += " AND x.inspect_date <=?"
  2258. countParams = append(countParams, decEndStrsUnix)
  2259. }
  2260. countSQL += ")a GROUP BY nnd"
  2261. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2262. }
  2263. return
  2264. }
  2265. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2266. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2267. table := readDb.Table("xt_patients as s")
  2268. fmt.Println(table)
  2269. d := readDb.Table(" xt_inspection_reference as r")
  2270. fmt.Println(d)
  2271. if orgid > 0 {
  2272. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2273. }
  2274. if lapstor == 0 {
  2275. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2276. }
  2277. if lapstor == 1 {
  2278. db = db.Where("s.lapseto = 1")
  2279. }
  2280. if lapstor == 2 {
  2281. db = db.Where("s.lapseto = 2")
  2282. }
  2283. if startime > 0 {
  2284. db = db.Where("x.inspect_date >=?", startime)
  2285. }
  2286. if endtime > 0 {
  2287. db = db.Where("x.inspect_date <=?", endtime)
  2288. }
  2289. offset := (page - 1) * limit
  2290. err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as r on x.item_id = r.inspection_minor ").Where("r.user_org_id = ? and r.status = 1 and r.is_status = 1", orgid).Group("x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2291. return inspection, total, err
  2292. }
  2293. //func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2294. //
  2295. // db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2296. // table := readDb.Table("xt_patients as s")
  2297. // fmt.Println(table)
  2298. // d := readDb.Table(" xt_inspection_reference as r")
  2299. // fmt.Println(d)
  2300. //
  2301. // if orgid > 0 {
  2302. // db = db.Where("x.org_id = ?", orgid)
  2303. // }
  2304. // if lapstor == 0 {
  2305. // table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2306. // }
  2307. // if lapstor == 1 {
  2308. // db = db.Where("s.lapseto = 1")
  2309. // }
  2310. // if lapstor == 2 {
  2311. // db = db.Where("s.lapseto = 2")
  2312. // }
  2313. // if startime > 0 {
  2314. // db = db.Where("x.inspect_date >=?", startime)
  2315. // }
  2316. // if endtime > 0 {
  2317. // db = db.Where("x.inspect_date <=?", endtime)
  2318. // }
  2319. // offset := (page - 1) * limit
  2320. // err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0 )").Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2321. //
  2322. // return inspection, total, err
  2323. //}
  2324. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2325. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2326. table := readDb.Table("xt_patients as s")
  2327. //fmt.Println(table)
  2328. d := readDb.Table(" xt_inspection_reference as r")
  2329. fmt.Println(d)
  2330. d2 := readDb.Table("xt_quality_control_standard as d")
  2331. fmt.Println("d2", d2)
  2332. if orgid > 0 {
  2333. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1", orgid)
  2334. }
  2335. if lapstor == 0 {
  2336. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2337. }
  2338. if lapstor == 1 {
  2339. table = table.Where("s.lapseto = 1")
  2340. }
  2341. if lapstor == 2 {
  2342. table = table.Where("s.lapseto = 2")
  2343. }
  2344. if startime > 0 {
  2345. db = db.Where("x.inspect_date >=?", startime)
  2346. }
  2347. if endtime > 0 {
  2348. db = db.Where("x.inspect_date <=?", endtime)
  2349. }
  2350. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.min_range<>''and d.user_org_id = ? and d.is_status =1 and NOT EXISTS(SELECT 1 FROM xt_inspection AS x2 WHERE x2.patient_id = x.patient_id AND x2.org_id = ? AND x2.item_id = x.item_id AND x2.inspect_date > x.inspect_date)", orgid, orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2351. return inspection, err
  2352. }
  2353. func GetTotalPatientsControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2354. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2355. table := readDb.Table("xt_quality_control_standard as s")
  2356. fmt.Println(table)
  2357. if orgid > 0 {
  2358. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2359. }
  2360. if startime > 0 {
  2361. db = db.Where("x.inspect_date >=?", startime)
  2362. }
  2363. if endtime > 0 {
  2364. db = db.Where("x.inspect_date <=?", endtime)
  2365. }
  2366. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("s.status = 1 and s.is_status =1").Count(&total).Scan(&inspection).Error
  2367. return inspection, total, err
  2368. }
  2369. func GetStandControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2370. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2371. table := readDb.Table("xt_quality_control_standard as s")
  2372. fmt.Println(table)
  2373. if orgid > 0 {
  2374. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1 ", orgid)
  2375. }
  2376. if startime > 0 {
  2377. db = db.Where("x.inspect_date >=?", startime)
  2378. }
  2379. if endtime > 0 {
  2380. db = db.Where("x.inspect_date <=?", endtime)
  2381. }
  2382. db = db.Where("s.status = 1 and s.is_status = 1")
  2383. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value+0 >= s.min_range + 0 and x.inspect_value+0 <= s.large_range + 0 ").Count(&total).Scan(&inspection).Error
  2384. return inspection, total, err
  2385. }
  2386. func GetStandControlOne(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2387. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2388. table := readDb.Table("xt_quality_control_standard as s")
  2389. fmt.Println(table)
  2390. if orgid > 0 {
  2391. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2 ", orgid)
  2392. }
  2393. if startime > 0 {
  2394. db = db.Where("x.inspect_date >=?", startime)
  2395. }
  2396. if endtime > 0 {
  2397. db = db.Where("x.inspect_date <=?", endtime)
  2398. }
  2399. db = db.Where("s.status = 1 and s.is_status = 1")
  2400. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value = s.range_value").Count(&total).Scan(&inspection).Error
  2401. return inspection, total, err
  2402. }
  2403. func GetInfectiousPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2404. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2405. table := readDb.Table("xt_patients as s")
  2406. fmt.Println(table)
  2407. d := readDb.Table(" xt_inspection_reference as r")
  2408. fmt.Println(d)
  2409. d2 := readDb.Table("xt_quality_control_standard as d")
  2410. fmt.Println("d2", d2)
  2411. if orgid > 0 {
  2412. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2413. }
  2414. if lapstor == 0 {
  2415. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2416. }
  2417. if lapstor == 1 {
  2418. table = table.Where("s.lapseto = 1")
  2419. }
  2420. if lapstor == 2 {
  2421. table = table.Where("s.lapseto = 2")
  2422. }
  2423. if startime > 0 {
  2424. db = db.Where("x.inspect_date >=?", startime)
  2425. }
  2426. if endtime > 0 {
  2427. db = db.Where("x.inspect_date <=?", endtime)
  2428. }
  2429. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2430. return inspection, err
  2431. }
  2432. func GetInfectiousControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2433. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2434. table := readDb.Table("xt_patients as s")
  2435. fmt.Println(table)
  2436. d := readDb.Table(" xt_inspection_reference as r")
  2437. fmt.Println(d)
  2438. d2 := readDb.Table("xt_quality_control_standard as d")
  2439. fmt.Println("d2", d2)
  2440. if orgid > 0 {
  2441. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2442. }
  2443. if lapstor == 0 {
  2444. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2445. }
  2446. if lapstor == 1 {
  2447. table = table.Where("s.lapseto = 1")
  2448. }
  2449. if lapstor == 2 {
  2450. table = table.Where("s.lapseto = 2")
  2451. }
  2452. if startime > 0 {
  2453. db = db.Where("x.inspect_date >=?", startime)
  2454. }
  2455. if endtime > 0 {
  2456. db = db.Where("x.inspect_date <=?", endtime)
  2457. }
  2458. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.range_value <>''and d.user_org_id = ? and d.is_status = 1", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2459. return inspection, err
  2460. }
  2461. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2462. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2463. table := readDb.Table("xt_patients as s")
  2464. fmt.Println(table)
  2465. d := readDb.Table(" xt_inspection_reference as r")
  2466. fmt.Println(d)
  2467. d2 := readDb.Table("xt_quality_control_standard as d")
  2468. fmt.Println("d2", d2)
  2469. if len(keywords) > 0 {
  2470. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  2471. }
  2472. if orgid > 0 {
  2473. db = db.Where("x.org_id = ?", orgid)
  2474. }
  2475. if lapstor == 0 {
  2476. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2477. }
  2478. if lapstor == 1 {
  2479. table = table.Where("s.lapseto = 1")
  2480. }
  2481. if lapstor == 2 {
  2482. table = table.Where("s.lapseto = 2")
  2483. }
  2484. if startime > 0 {
  2485. db = db.Where("x.inspect_date >=?", startime)
  2486. }
  2487. if endtime > 0 {
  2488. db = db.Where("x.inspect_date <=?", endtime)
  2489. }
  2490. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2491. return inspection, err
  2492. }
  2493. func GetPatientNames(orgid int64, patientid int64) (models.XtPatients, error) {
  2494. patients := models.XtPatients{}
  2495. err := readDb.Where("user_org_id = ? and id = ? and status = 1", orgid, patientid).Find(&patients).Error
  2496. return patients, err
  2497. }
  2498. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64, inspectdate int64) (inspection []*models.PatientInspectionCount, err error) {
  2499. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2500. table := readDb.Table("xt_patients as s")
  2501. fmt.Println(table)
  2502. d := readDb.Table(" xt_inspection_reference as r")
  2503. fmt.Println(d)
  2504. d2 := readDb.Table("xt_quality_control_standard as d")
  2505. fmt.Println("d2", d2)
  2506. if orgid > 0 {
  2507. db = db.Where("x.org_id = ?", orgid)
  2508. }
  2509. if patientid > 0 {
  2510. db = db.Where("x.patient_id = ?", patientid)
  2511. }
  2512. //if startime > 0 {
  2513. // db = db.Where("x.inspect_date >=?", startime)
  2514. //}
  2515. //if endtime > 0 {
  2516. // db = db.Where("x.inspect_date <=?", endtime)
  2517. //}
  2518. if itemid > 0 {
  2519. db = db.Where("x.item_id = ?", itemid)
  2520. }
  2521. if inspectdate > 0 {
  2522. db = db.Where("x.inspect_date = ?", inspectdate)
  2523. }
  2524. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2525. return inspection, err
  2526. }
  2527. func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  2528. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2529. table := readDb.Table("xt_patients as s")
  2530. fmt.Println(table)
  2531. d := readDb.Table(" xt_inspection_reference as r")
  2532. fmt.Println(d)
  2533. d2 := readDb.Table("xt_quality_control_standard as d")
  2534. fmt.Println("d2", d2)
  2535. if orgid > 0 {
  2536. db = db.Where("x.org_id = ? and (x.inspect_value <> '' or x.inspect_value+0 <> 0)", orgid)
  2537. }
  2538. if patientid > 0 {
  2539. db = db.Where("x.patient_id = ?", patientid)
  2540. }
  2541. if startime > 0 {
  2542. db = db.Where("x.inspect_date >=?", startime)
  2543. }
  2544. if endtime > 0 {
  2545. db = db.Where("x.inspect_date <=?", endtime)
  2546. }
  2547. if itemid > 0 {
  2548. db = db.Where("x.item_id = ?", itemid)
  2549. }
  2550. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2551. return inspection, err
  2552. }
  2553. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2554. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2555. table := readDb.Table("xt_patients as s")
  2556. fmt.Println(table)
  2557. d := readDb.Table(" xt_inspection_reference as r")
  2558. fmt.Println(d)
  2559. d2 := readDb.Table("xt_quality_control_standard as d")
  2560. fmt.Println("d2", d2)
  2561. if orgid > 0 {
  2562. db = db.Where("x.org_id = ?", orgid)
  2563. }
  2564. if patientid > 0 {
  2565. db = db.Where("x.patient_id = ?", patientid)
  2566. }
  2567. if startime > 0 {
  2568. db = db.Where("x.inspect_date >=?", startime)
  2569. }
  2570. if endtime > 0 {
  2571. db = db.Where("x.inspect_date <=?", endtime)
  2572. }
  2573. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.large_range,d.min_range,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2574. return inspection, err
  2575. }
  2576. func GetBloodPressureDetail(id int64) (models.XtQualityControlStandard, error) {
  2577. standard := models.XtQualityControlStandard{}
  2578. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  2579. return standard, err
  2580. }
  2581. func UpdateBloodPressure(st *models.XtQualityControlStandard, id int64) error {
  2582. err := XTWriteDB().Model(&st).Where("id=?", id).Update(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "updated_time": st.UpdatedTime}).Error
  2583. return err
  2584. }
  2585. func GetSystolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2586. db := XTReadDB().Table("xt_monitoring_record as x")
  2587. err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2588. return record, total, err
  2589. }
  2590. func GetSystolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2591. db := XTReadDB().Table("xt_monitoring_record as x")
  2592. if lapseto > 0 && origin > 0 {
  2593. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  2594. }
  2595. if lapseto > 0 && origin == 0 {
  2596. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  2597. }
  2598. if lapseto == 0 && origin > 0 {
  2599. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  2600. }
  2601. err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2602. return record, total, err
  2603. }
  2604. func GetStandSystolicBloodPressure(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2605. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2606. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -1 and s.inspection_major = 0 and x.systolic_blood_pressure <> 0 and x.systolic_blood_pressure +0 >= s.min_range +0 and x.systolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2607. return record, total, err
  2608. }
  2609. func GetDiastolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2610. db := XTReadDB().Table("xt_monitoring_record as x")
  2611. err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2612. return record, total, err
  2613. }
  2614. func GetDiastolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2615. db := XTReadDB().Table("xt_monitoring_record as x")
  2616. if lapseto > 0 && origin > 0 {
  2617. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  2618. }
  2619. if lapseto > 0 && origin == 0 {
  2620. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  2621. }
  2622. if lapseto == 0 && origin > 0 {
  2623. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  2624. }
  2625. err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2626. return record, total, err
  2627. }
  2628. func GetDiastolicStandPressure(orgid int64, startime int64, endtime int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2629. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2630. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -2 and s.inspection_major = 0 and x.diastolic_blood_pressure <> 0 and x.diastolic_blood_pressure +0 >= s.min_range +0 and x.diastolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2631. return record, total, err
  2632. }
  2633. func GetQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2634. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2635. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2636. "SELECT " +
  2637. "CASE " +
  2638. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2639. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2640. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2641. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2642. " ELSE '其他'" +
  2643. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2644. countParams := make([]interface{}, 0)
  2645. countParams = append(countParams, firststart)
  2646. countParams = append(countParams, firstend)
  2647. countParams = append(countParams, sencondstart)
  2648. countParams = append(countParams, sencondend)
  2649. countParams = append(countParams, threestart)
  2650. countParams = append(countParams, threeend)
  2651. countParams = append(countParams, fourstart)
  2652. countParams = append(countParams, fourend)
  2653. if orgid > 0 {
  2654. db = db.Where("x.org_id=?", orgid)
  2655. countSQL += " AND x.org_id=?"
  2656. countParams = append(countParams, orgid)
  2657. db = db.Where("x.inspect_date>=?", firststart)
  2658. countSQL += " AND x.inspect_date>=?"
  2659. countParams = append(countParams, firststart)
  2660. db = db.Where("x.inspect_date<=?", fourend)
  2661. countSQL += " AND x.inspect_date<=?"
  2662. countParams = append(countParams, fourend)
  2663. }
  2664. countSQL += ")a GROUP BY nnd"
  2665. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2666. return
  2667. }
  2668. func GetQuarterTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2669. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2670. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2671. "SELECT " +
  2672. "CASE " +
  2673. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2674. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2675. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2676. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2677. " ELSE '其他'" +
  2678. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2679. countParams := make([]interface{}, 0)
  2680. countParams = append(countParams, firststart)
  2681. countParams = append(countParams, firstend)
  2682. countParams = append(countParams, sencondstart)
  2683. countParams = append(countParams, sencondend)
  2684. countParams = append(countParams, threestart)
  2685. countParams = append(countParams, threeend)
  2686. countParams = append(countParams, fourstart)
  2687. countParams = append(countParams, fourend)
  2688. if orgid > 0 {
  2689. db = db.Where("x.org_id=?", orgid)
  2690. countSQL += " AND x.org_id=?"
  2691. countParams = append(countParams, orgid)
  2692. db = db.Where("x.inspect_date>=?", firststart)
  2693. countSQL += " AND x.inspect_date>=?"
  2694. countParams = append(countParams, firststart)
  2695. db = db.Where("x.inspect_date<=?", fourend)
  2696. countSQL += " AND x.inspect_date<=?"
  2697. countParams = append(countParams, fourend)
  2698. }
  2699. countSQL += ")a GROUP BY nnd"
  2700. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2701. return
  2702. }
  2703. func GetContagionQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2704. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2705. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2706. "SELECT " +
  2707. "CASE " +
  2708. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2709. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2710. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2711. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2712. " ELSE '其他'" +
  2713. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2714. countParams := make([]interface{}, 0)
  2715. countParams = append(countParams, firststart)
  2716. countParams = append(countParams, firstend)
  2717. countParams = append(countParams, sencondstart)
  2718. countParams = append(countParams, sencondend)
  2719. countParams = append(countParams, threestart)
  2720. countParams = append(countParams, threeend)
  2721. countParams = append(countParams, fourstart)
  2722. countParams = append(countParams, fourend)
  2723. if orgid > 0 {
  2724. db = db.Where("x.org_id=?", orgid)
  2725. countSQL += " AND x.org_id=?"
  2726. countParams = append(countParams, orgid)
  2727. db = db.Where("x.inspect_date>=?", firststart)
  2728. countSQL += " AND x.inspect_date>=?"
  2729. countParams = append(countParams, firststart)
  2730. db = db.Where("x.inspect_date<=?", fourend)
  2731. countSQL += " AND x.inspect_date<=?"
  2732. countParams = append(countParams, fourend)
  2733. }
  2734. countSQL += ")a GROUP BY nnd"
  2735. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2736. return
  2737. }
  2738. func GetContagionTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2739. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2740. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2741. "SELECT " +
  2742. "CASE " +
  2743. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2744. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2745. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2746. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2747. " ELSE '其他'" +
  2748. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2749. countParams := make([]interface{}, 0)
  2750. countParams = append(countParams, firststart)
  2751. countParams = append(countParams, firstend)
  2752. countParams = append(countParams, sencondstart)
  2753. countParams = append(countParams, sencondend)
  2754. countParams = append(countParams, threestart)
  2755. countParams = append(countParams, threeend)
  2756. countParams = append(countParams, fourstart)
  2757. countParams = append(countParams, fourend)
  2758. if orgid > 0 {
  2759. db = db.Where("x.org_id=?", orgid)
  2760. countSQL += " AND x.org_id=?"
  2761. countParams = append(countParams, orgid)
  2762. db = db.Where("x.inspect_date>=?", firststart)
  2763. countSQL += " AND x.inspect_date>=?"
  2764. countParams = append(countParams, firststart)
  2765. db = db.Where("x.inspect_date<=?", fourend)
  2766. countSQL += " AND x.inspect_date<=?"
  2767. countParams = append(countParams, fourend)
  2768. }
  2769. countSQL += ")a GROUP BY nnd"
  2770. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2771. return
  2772. }
  2773. func GetMonthTargetStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2774. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2775. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2776. "SELECT " +
  2777. "CASE " +
  2778. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2779. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2780. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2781. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2782. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '5'" +
  2783. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '6'" +
  2784. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '7'" +
  2785. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '8'" +
  2786. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '9'" +
  2787. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '10'" +
  2788. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '11'" +
  2789. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '12'" +
  2790. " ELSE '其他'" +
  2791. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2792. countParams := make([]interface{}, 0)
  2793. countParams = append(countParams, januaryStartStrUnix)
  2794. countParams = append(countParams, januaryEndStrUnix)
  2795. countParams = append(countParams, febStartStrStrUnix)
  2796. countParams = append(countParams, febEndStrUnix)
  2797. countParams = append(countParams, marchStartStrUnix)
  2798. countParams = append(countParams, marchEndStrUnix)
  2799. countParams = append(countParams, aprStartStrUnix)
  2800. countParams = append(countParams, aprEndStrsUnix)
  2801. countParams = append(countParams, mayStartStrUnix)
  2802. countParams = append(countParams, mayEndStrsUnix)
  2803. countParams = append(countParams, junStartStrUnix)
  2804. countParams = append(countParams, junEndStrsUnix)
  2805. countParams = append(countParams, julStartStrUnix)
  2806. countParams = append(countParams, julEndStrsUnix)
  2807. countParams = append(countParams, augStartStrUnix)
  2808. countParams = append(countParams, augEndStrsUnix)
  2809. countParams = append(countParams, sepStartStrUnix)
  2810. countParams = append(countParams, sepEndStrsUnix)
  2811. countParams = append(countParams, octStartStrUnix)
  2812. countParams = append(countParams, octEndStrsUnix)
  2813. countParams = append(countParams, novStartStrUnix)
  2814. countParams = append(countParams, novEndStrsUnix)
  2815. countParams = append(countParams, decStartStrUnix)
  2816. countParams = append(countParams, decEndStrsUnix)
  2817. if orgId > 0 {
  2818. db = db.Where("x.org_id=?", orgId)
  2819. countSQL += " AND x.org_id=?"
  2820. countParams = append(countParams, orgId)
  2821. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2822. countSQL += " AND x.inspect_date>=?"
  2823. countParams = append(countParams, januaryStartStrUnix)
  2824. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2825. countSQL += " AND x.inspect_date<=?"
  2826. countParams = append(countParams, decEndStrsUnix)
  2827. }
  2828. countSQL += ")a GROUP BY nnd"
  2829. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2830. return
  2831. }
  2832. func GetMonthTargetNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2833. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2834. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2835. "SELECT " +
  2836. "CASE " +
  2837. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2838. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2839. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2840. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2841. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '5'" +
  2842. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '6'" +
  2843. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '7'" +
  2844. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '8'" +
  2845. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '9'" +
  2846. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '10'" +
  2847. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '11'" +
  2848. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '12'" +
  2849. " ELSE '其他'" +
  2850. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2851. countParams := make([]interface{}, 0)
  2852. countParams = append(countParams, januaryStartStrUnix)
  2853. countParams = append(countParams, januaryEndStrUnix)
  2854. countParams = append(countParams, febStartStrStrUnix)
  2855. countParams = append(countParams, febEndStrUnix)
  2856. countParams = append(countParams, marchStartStrUnix)
  2857. countParams = append(countParams, marchEndStrUnix)
  2858. countParams = append(countParams, aprStartStrUnix)
  2859. countParams = append(countParams, aprEndStrsUnix)
  2860. countParams = append(countParams, mayStartStrUnix)
  2861. countParams = append(countParams, mayEndStrsUnix)
  2862. countParams = append(countParams, junStartStrUnix)
  2863. countParams = append(countParams, junEndStrsUnix)
  2864. countParams = append(countParams, julStartStrUnix)
  2865. countParams = append(countParams, julEndStrsUnix)
  2866. countParams = append(countParams, augStartStrUnix)
  2867. countParams = append(countParams, augEndStrsUnix)
  2868. countParams = append(countParams, sepStartStrUnix)
  2869. countParams = append(countParams, sepEndStrsUnix)
  2870. countParams = append(countParams, octStartStrUnix)
  2871. countParams = append(countParams, octEndStrsUnix)
  2872. countParams = append(countParams, novStartStrUnix)
  2873. countParams = append(countParams, novEndStrsUnix)
  2874. countParams = append(countParams, decStartStrUnix)
  2875. countParams = append(countParams, decEndStrsUnix)
  2876. if orgId > 0 {
  2877. db = db.Where("x.org_id=?", orgId)
  2878. countSQL += " AND x.org_id=?"
  2879. countParams = append(countParams, orgId)
  2880. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2881. countSQL += " AND x.inspect_date>=?"
  2882. countParams = append(countParams, januaryStartStrUnix)
  2883. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2884. countSQL += " AND x.inspect_date<=?"
  2885. countParams = append(countParams, decEndStrsUnix)
  2886. }
  2887. countSQL += ")a GROUP BY nnd"
  2888. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2889. return
  2890. }
  2891. func GetMonthcontagionTargeStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2892. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2893. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2894. "SELECT " +
  2895. "CASE " +
  2896. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2897. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2898. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2899. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2900. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '5'" +
  2901. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '6'" +
  2902. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '7'" +
  2903. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '8'" +
  2904. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '9'" +
  2905. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '10'" +
  2906. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '11'" +
  2907. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '12'" +
  2908. " ELSE '其他'" +
  2909. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2910. countParams := make([]interface{}, 0)
  2911. countParams = append(countParams, januaryStartStrUnix)
  2912. countParams = append(countParams, januaryEndStrUnix)
  2913. countParams = append(countParams, febStartStrStrUnix)
  2914. countParams = append(countParams, febEndStrUnix)
  2915. countParams = append(countParams, marchStartStrUnix)
  2916. countParams = append(countParams, marchEndStrUnix)
  2917. countParams = append(countParams, aprStartStrUnix)
  2918. countParams = append(countParams, aprEndStrsUnix)
  2919. countParams = append(countParams, mayStartStrUnix)
  2920. countParams = append(countParams, mayEndStrsUnix)
  2921. countParams = append(countParams, junStartStrUnix)
  2922. countParams = append(countParams, junEndStrsUnix)
  2923. countParams = append(countParams, julStartStrUnix)
  2924. countParams = append(countParams, julEndStrsUnix)
  2925. countParams = append(countParams, augStartStrUnix)
  2926. countParams = append(countParams, augEndStrsUnix)
  2927. countParams = append(countParams, sepStartStrUnix)
  2928. countParams = append(countParams, sepEndStrsUnix)
  2929. countParams = append(countParams, octStartStrUnix)
  2930. countParams = append(countParams, octEndStrsUnix)
  2931. countParams = append(countParams, novStartStrUnix)
  2932. countParams = append(countParams, novEndStrsUnix)
  2933. countParams = append(countParams, decStartStrUnix)
  2934. countParams = append(countParams, decEndStrsUnix)
  2935. if orgId > 0 {
  2936. db = db.Where("x.org_id=?", orgId)
  2937. countSQL += " AND x.org_id=?"
  2938. countParams = append(countParams, orgId)
  2939. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2940. countSQL += " AND x.inspect_date>=?"
  2941. countParams = append(countParams, januaryStartStrUnix)
  2942. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2943. countSQL += " AND x.inspect_date<=?"
  2944. countParams = append(countParams, decEndStrsUnix)
  2945. }
  2946. countSQL += ")a GROUP BY nnd"
  2947. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2948. return
  2949. }
  2950. func GetMonthcontagionTargeNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2951. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2952. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2953. "SELECT " +
  2954. "CASE " +
  2955. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2956. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2957. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2958. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2959. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '5'" +
  2960. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '6'" +
  2961. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '7'" +
  2962. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '8'" +
  2963. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '9'" +
  2964. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '10'" +
  2965. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '11'" +
  2966. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '12'" +
  2967. " ELSE '其他'" +
  2968. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2969. countParams := make([]interface{}, 0)
  2970. countParams = append(countParams, januaryStartStrUnix)
  2971. countParams = append(countParams, januaryEndStrUnix)
  2972. countParams = append(countParams, febStartStrStrUnix)
  2973. countParams = append(countParams, febEndStrUnix)
  2974. countParams = append(countParams, marchStartStrUnix)
  2975. countParams = append(countParams, marchEndStrUnix)
  2976. countParams = append(countParams, aprStartStrUnix)
  2977. countParams = append(countParams, aprEndStrsUnix)
  2978. countParams = append(countParams, mayStartStrUnix)
  2979. countParams = append(countParams, mayEndStrsUnix)
  2980. countParams = append(countParams, junStartStrUnix)
  2981. countParams = append(countParams, junEndStrsUnix)
  2982. countParams = append(countParams, julStartStrUnix)
  2983. countParams = append(countParams, julEndStrsUnix)
  2984. countParams = append(countParams, augStartStrUnix)
  2985. countParams = append(countParams, augEndStrsUnix)
  2986. countParams = append(countParams, sepStartStrUnix)
  2987. countParams = append(countParams, sepEndStrsUnix)
  2988. countParams = append(countParams, octStartStrUnix)
  2989. countParams = append(countParams, octEndStrsUnix)
  2990. countParams = append(countParams, novStartStrUnix)
  2991. countParams = append(countParams, novEndStrsUnix)
  2992. countParams = append(countParams, decStartStrUnix)
  2993. countParams = append(countParams, decEndStrsUnix)
  2994. if orgId > 0 {
  2995. db = db.Where("x.org_id=?", orgId)
  2996. countSQL += " AND x.org_id=?"
  2997. countParams = append(countParams, orgId)
  2998. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2999. countSQL += " AND x.inspect_date>=?"
  3000. countParams = append(countParams, januaryStartStrUnix)
  3001. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  3002. countSQL += " AND x.inspect_date<=?"
  3003. countParams = append(countParams, decEndStrsUnix)
  3004. }
  3005. countSQL += ")a GROUP BY nnd"
  3006. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  3007. return
  3008. }
  3009. func GetQuarterBloodList(orgid int64, januaryStartStrUnix int64, januaryEndStrUnix int64) (record []*models.VmMonitoringRecord, err error) {
  3010. db := XTReadDB().Table("xt_monitoring_record as x")
  3011. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.monitoring_date,x.patient_id,x.user_org_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0", orgid, januaryStartStrUnix, januaryEndStrUnix).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3012. return record, err
  3013. }
  3014. func GetTaregetNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3015. db := XTReadDB().Table("xt_inspection as x")
  3016. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3017. return inspection, err
  3018. }
  3019. func GetConfigurationNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3020. db := XTReadDB().Table("xt_inspection as x")
  3021. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value <> d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3022. return inspection, err
  3023. }
  3024. func GetInspectNoStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3025. db := XTReadDB().Table("xt_inspection as x")
  3026. offset := (page - 1) * limit
  3027. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3028. return inspection, err
  3029. }
  3030. func GetTargetStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3031. db := XTReadDB().Table("xt_inspection as x")
  3032. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3033. return inspection, err
  3034. }
  3035. func GetConfigurationStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3036. db := XTReadDB().Table("xt_inspection as x")
  3037. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value = d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3038. return inspection, err
  3039. }
  3040. func GetStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3041. db := XTReadDB().Table("xt_inspection as x")
  3042. offset := (page - 1) * limit
  3043. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3044. return inspection, err
  3045. }
  3046. func GetDiastolicStand(orgid int64, startime int64, endtime int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3047. db := XTReadDB().Table("xt_monitoring_record as x")
  3048. offset := (page - 1) * limit
  3049. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0)", orgid, startime, endtime).Offset(offset).Limit(limit).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3050. return record, err
  3051. }
  3052. func GetInspectionMoninList(id int64, orgid int64, patientid int64) (models.XtInspection, error) {
  3053. inspection := models.XtInspection{}
  3054. err = XTReadDB().Model(&inspection).Where("item_id=? and org_id = ? and status = 1 and patient_id = ?", id, orgid, patientid).Last(&inspection).Error
  3055. return inspection, err
  3056. }
  3057. func TotalSysStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3058. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3059. if orgid > 0 {
  3060. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3061. }
  3062. if startime > 0 {
  3063. db = db.Where("x.monitoring_date>=?", startime)
  3064. }
  3065. if endtime > 0 {
  3066. db = db.Where("x.monitoring_date<=?", endtime)
  3067. }
  3068. if sysmin > 0 {
  3069. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3070. }
  3071. if syslarge > 0 {
  3072. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3073. }
  3074. if diamin > 0 {
  3075. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3076. }
  3077. if dialarge > 0 {
  3078. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3079. }
  3080. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3081. return record, err
  3082. }
  3083. func TotalSysStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3084. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3085. if orgid > 0 {
  3086. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3087. }
  3088. if startime > 0 {
  3089. db = db.Where("x.monitoring_date>=?", startime)
  3090. }
  3091. if endtime > 0 {
  3092. db = db.Where("x.monitoring_date<=?", endtime)
  3093. }
  3094. if sysmin > 0 {
  3095. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3096. }
  3097. if syslarge > 0 {
  3098. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3099. }
  3100. if diamin > 0 {
  3101. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3102. }
  3103. if dialarge > 0 {
  3104. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3105. }
  3106. offset := (page - 1) * limit
  3107. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3108. return record, err
  3109. }
  3110. func TotalSysNoStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3111. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3112. if orgid > 0 {
  3113. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3114. }
  3115. if startime > 0 {
  3116. db = db.Where("x.monitoring_date>=?", startime)
  3117. }
  3118. if endtime > 0 {
  3119. db = db.Where("x.monitoring_date<=?", endtime)
  3120. }
  3121. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3122. return record, err
  3123. }
  3124. func TotalSysNoStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3125. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3126. if orgid > 0 {
  3127. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3128. }
  3129. if startime > 0 {
  3130. db = db.Where("x.monitoring_date>=?", startime)
  3131. }
  3132. if endtime > 0 {
  3133. db = db.Where("x.monitoring_date<=?", endtime)
  3134. }
  3135. offset := (page - 1) * limit
  3136. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3137. return record, err
  3138. }
  3139. func GetModeIdCount(startime int64, endtime int64, orgid int64, page int64, limit int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3140. table := XTReadDB().Table("xt_schedule as s")
  3141. fmt.Println("table", table)
  3142. db := XTReadDB().Table("xt_dialysis_order as o")
  3143. if orgid > 0 {
  3144. db = db.Where("o.user_org_id = ?", orgid)
  3145. }
  3146. if startime > 0 {
  3147. db = db.Where("o.dialysis_date>=?", startime)
  3148. }
  3149. if endtime > 0 {
  3150. db = db.Where("o.dialysis_date<=?", endtime)
  3151. }
  3152. //offset := (page - 1) * limit
  3153. err = db.Group(" s.patient_id,s.mode_id").Select("s.mode_id, s.patient_id, count(o.id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3154. return order, err
  3155. }
  3156. func GetScheduleModeIdCount(startime int64, endtime int64, orgid int64, page int64, limit int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3157. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  3158. if orgid > 0 {
  3159. db = db.Where("s.user_org_id = ?", orgid)
  3160. }
  3161. if startime > 0 {
  3162. db = db.Where("s.schedule_date>=?", startime)
  3163. }
  3164. if endtime > 0 {
  3165. db = db.Where("s.schedule_date<=?", endtime)
  3166. }
  3167. err = db.Group(" s.patient_id,s.mode_id").Select("s.mode_id,s.patient_id,count(s.id) as count").Scan(&order).Error
  3168. return order, err
  3169. }
  3170. func GetTreatModeList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3171. table := XTReadDB().Table("xt_schedule as s")
  3172. fmt.Println("table", table)
  3173. db := XTReadDB().Table("xt_dialysis_order as o")
  3174. if orgid > 0 {
  3175. db = db.Where("o.user_org_id = ?", orgid)
  3176. }
  3177. if startime > 0 {
  3178. db = db.Where("o.dialysis_date>=?", startime)
  3179. }
  3180. if endtime > 0 {
  3181. db = db.Where("o.dialysis_date<=?", endtime)
  3182. }
  3183. err = db.Group("s.mode_id").Select("s.mode_id, s.patient_id").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3184. return order, err
  3185. }
  3186. func GetCountModeId(startime int64, endtime int64, modeid int64, orgid int64) (order []*models.BloodTreateModeIdCount, err error) {
  3187. table := XTReadDB().Table("xt_schedule as s")
  3188. fmt.Println("table", table)
  3189. db := XTReadDB().Table("xt_dialysis_order as o")
  3190. if orgid > 0 {
  3191. db = db.Where("o.user_org_id = ?", orgid)
  3192. }
  3193. if startime > 0 {
  3194. db = db.Where("o.dialysis_date>=?", startime)
  3195. }
  3196. if endtime > 0 {
  3197. db = db.Where("o.dialysis_date<=?", endtime)
  3198. }
  3199. err = db.Group("o.dialysis_date,s.mode_id").Select("s.mode_id, count(s.mode_id) as count,o.dialysis_date").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 and s.mode_id = ? and o.dialysis_date <> ''", modeid).Scan(&order).Error
  3200. return order, err
  3201. }
  3202. func GetCountRollout(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (lapseto []*models.BloodLapsetoCount, err error) {
  3203. table := XTReadDB().Table("xt_patients as s")
  3204. fmt.Println(table)
  3205. db := XTReadDB().Table("xt_patient_lapseto as x").Where("x.status = 1")
  3206. if startime > 0 {
  3207. db = db.Where("x.lapseto_time >=?", startime)
  3208. }
  3209. if endtime > 0 {
  3210. db = db.Where("x.lapseto_time<=?", endtime)
  3211. }
  3212. if lapsetotype == 0 || sourcetype == 0 {
  3213. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ?", orgid).Scan(&lapseto).Error
  3214. }
  3215. if lapsetotype > 0 {
  3216. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.lapseto = ?", orgid, lapsetotype).Scan(&lapseto).Error
  3217. }
  3218. if sourcetype > 0 {
  3219. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.source = ?", orgid, sourcetype).Scan(&lapseto).Error
  3220. }
  3221. return lapseto, err
  3222. }
  3223. func GetCheckExaminePercent(start_time int64, end_time int64, org_id int64, name_type int64) (total int64) {
  3224. switch name_type {
  3225. case 1:
  3226. key := "%" + "血常规" + "%"
  3227. readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND (item_name Like ? Or project_name Like ?)", start_time, end_time, org_id, key).Group("patient_id").Count(&total)
  3228. break
  3229. case 2:
  3230. //key := "%" + "肝功能" + "%"
  3231. //key1 := "%" + "肾功能" + "%"
  3232. //key2 := "%" + "电解质" + "%"
  3233. //key3 := "%" + "血脂" + "%"
  3234. //readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND ((item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?))", start_time, end_time, org_id, key, key, key1, key1, key2, key2, key3, key3).Group("patient_id").Count(&total)
  3235. break
  3236. case 3:
  3237. //key := "%" + "肝功能" + "%"
  3238. //readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND ((item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?))", start_time, end_time, org_id, key, key, key1, key1, key2, key2, key3, key3).Group("patient_id").Count(&total)
  3239. break
  3240. case 4:
  3241. break
  3242. case 5:
  3243. break
  3244. case 6:
  3245. break
  3246. }
  3247. return
  3248. }
  3249. func GetAllPatientCount(orgid int64) (total int64, err error) {
  3250. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
  3251. return
  3252. }