common_service.go 80KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  9. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  10. return inspection, err
  11. }
  12. func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
  13. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
  14. return inspection, err
  15. }
  16. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  17. reference := models.XtInspectionReference{}
  18. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  19. return reference, err
  20. }
  21. func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
  22. standard := models.XtQualityControlStandard{}
  23. err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
  24. if err == gorm.ErrRecordNotFound {
  25. return nil, err
  26. }
  27. if err != nil {
  28. return nil, err
  29. }
  30. return &standard, nil
  31. }
  32. func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
  33. err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
  34. return standard, err
  35. }
  36. func SaveInspection(standard *models.XtQualityControlStandard) error {
  37. err := XTWriteDB().Create(&standard).Error
  38. return err
  39. }
  40. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  41. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  42. if orgid > 0 {
  43. db = db.Where("x.user_org_id = ?", orgid)
  44. }
  45. table := XTReadDB().Table("xt_inspection_reference as s")
  46. fmt.Println(table)
  47. offset := (page - 1) * limit
  48. 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,s.unit,s.project_name,s.item_name").Count(&total).
  49. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  50. return standard, total, err
  51. }
  52. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  53. standard := models.XtQualityControlStandard{}
  54. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  55. return standard, err
  56. }
  57. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  58. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  59. return standard, err
  60. }
  61. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  62. 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, "updated_time": time.Now().Unix()}).Error
  63. return err
  64. }
  65. func DeleteConfiguration(id int64) (err error) {
  66. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  67. return err
  68. }
  69. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  70. diseases := models.XtInspectionReference{}
  71. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  72. if err == gorm.ErrRecordNotFound {
  73. return nil, err
  74. }
  75. if err != nil {
  76. return nil, err
  77. }
  78. return &diseases, nil
  79. }
  80. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  81. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  82. return reference, err
  83. }
  84. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  85. configuration := models.XtCheckConfiguration{}
  86. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  87. if err == gorm.ErrRecordNotFound {
  88. return nil, err
  89. }
  90. if err != nil {
  91. return nil, err
  92. }
  93. return &configuration, nil
  94. }
  95. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  96. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  97. return configuration, err
  98. }
  99. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  100. err := XTWriteDB().Create(&configuration).Error
  101. return err
  102. }
  103. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  104. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  105. table := XTReadDB().Table("xt_inspection_reference as r")
  106. fmt.Println(table)
  107. if orgid > 0 {
  108. db = db.Where("x.user_org_id = ?", orgid)
  109. }
  110. offset := (page - 1) * limit
  111. 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).
  112. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  113. return check, total, err
  114. }
  115. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  116. configuration := models.XtCheckConfiguration{}
  117. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  118. return configuration, err
  119. }
  120. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  121. 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
  122. return err
  123. }
  124. func DeleteCheck(id int64) error {
  125. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  126. return err
  127. }
  128. func GetDialysiTotal(startime int64, endtime int64, orgid int64) (order []*models.DialysisOrder, total int64, err error) {
  129. err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  130. return order, total, err
  131. }
  132. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  133. //err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
  134. //return counts, err
  135. err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
  136. return counts, err
  137. }
  138. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  139. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  140. table := readDb.Table("xt_dialysis_order as s")
  141. fmt.Println(table)
  142. 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
  143. return counts, total, err
  144. }
  145. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  146. db := XTReadDB().Table("x.patients as x")
  147. 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 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
  148. return patients, err
  149. }
  150. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  151. db := XTReadDB().Table("x.patients as x")
  152. 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 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
  153. return patients, err
  154. }
  155. func GetPatientTotalCount(orgID int64) (total int64) {
  156. readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
  157. return
  158. }
  159. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  160. 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
  161. return dialysisorder, total, err
  162. }
  163. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  164. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  165. table := XTReadDB().Table("xt_patients as x")
  166. fmt.Println("table", table)
  167. 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
  168. return dialysisorder, total, err
  169. }
  170. func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  171. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and gender = 1", orgid).Count(&total).Find(&patients).Error
  172. return patients, total, err
  173. }
  174. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  175. // 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
  176. // return counts, err
  177. //}
  178. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  179. 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 s.is_infectious = 2 and s.created_time>=? and s.created_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  180. return counts, err
  181. }
  182. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  183. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  184. return patients, total, err
  185. }
  186. func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err error) {
  187. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  188. SELECT
  189. CASE
  190. 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'
  191. 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'
  192. 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'
  193. 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'
  194. ELSE '150'
  195. END
  196. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  197. )a GROUP BY nnd`, orgid).Scan(&counts)
  198. return
  199. }
  200. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  201. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  202. SELECT
  203. CASE
  204. 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'
  205. END
  206. 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<=?
  207. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  208. return
  209. }
  210. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  211. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  212. return patients, err
  213. }
  214. func GetDialysisAgeData(orgID int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  215. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  216. SELECT
  217. CASE
  218. 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'
  219. 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'
  220. 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'
  221. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  222. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1)a GROUP BY nnd`, orgID).Scan(&counts)
  223. return
  224. }
  225. func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {
  226. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  227. return patients, err
  228. }
  229. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  230. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  231. table := XTReadDB().Table("xt_schedule as s")
  232. fmt.Println(table)
  233. d := XTReadDB().Table("xt_patients as p")
  234. fmt.Println(d)
  235. if orgid > 0 {
  236. db = db.Where("o.user_org_id = ?", orgid)
  237. }
  238. if startime > 0 {
  239. db = db.Where("o.dialysis_date>=?", startime)
  240. }
  241. if endtime > 0 {
  242. db = db.Where("o.dialysis_date<=?", endtime)
  243. }
  244. offset := (page - 1) * limit
  245. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  246. return order, total, err
  247. }
  248. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrder, err error) {
  249. table := XTReadDB().Table("xt_schedule as s")
  250. fmt.Println(table)
  251. d := XTReadDB().Table("xt_patients as p")
  252. fmt.Println(d)
  253. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  254. if orgid > 0 {
  255. db = db.Where("o.user_org_id = ?", orgid)
  256. }
  257. if startime > 0 {
  258. db = db.Where("o.dialysis_date>=?", startime)
  259. }
  260. if endtime > 0 {
  261. db = db.Where("o.dialysis_date<=?", endtime)
  262. }
  263. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1 ").Scan(&order).Error
  264. return order, err
  265. }
  266. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  267. table := XTReadDB().Table("xt_schedule as s")
  268. fmt.Println(table)
  269. d := XTReadDB().Table("xt_patients as p")
  270. fmt.Println(d)
  271. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  272. if orgid > 0 {
  273. db = db.Where("o.user_org_id = ?", orgid)
  274. }
  275. if startime > 0 {
  276. db = db.Where("o.dialysis_date>=?", startime)
  277. }
  278. if endtime > 0 {
  279. db = db.Where("o.dialysis_date<=?", endtime)
  280. }
  281. offset := (page - 1) * limit
  282. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  283. return order, total, err
  284. }
  285. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  286. standard := models.XtQualityControlStandard{}
  287. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1", orgid).Last(&standard).Error
  288. return standard, err
  289. }
  290. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  291. configuration := models.XtCheckConfiguration{}
  292. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  293. return configuration, err
  294. }
  295. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  296. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  297. table := XTReadDB().Table("xt_patients as s")
  298. fmt.Println(table)
  299. if id > 0 {
  300. db = db.Where("p.patient_id = ?", id)
  301. }
  302. if orgid > 0 {
  303. db = db.Where("p.user_org_id = ?", orgid)
  304. }
  305. if startime > 0 {
  306. db = db.Where("p.record_date >= ?", startime)
  307. }
  308. if endtime > 0 {
  309. db = db.Where("p.record_date <=?", endtime)
  310. }
  311. offset := (page - 1) * limit
  312. 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
  313. return prescription, total, err
  314. }
  315. func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  316. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  317. table := XTReadDB().Table("xt_patients as s")
  318. fmt.Println(table)
  319. //if len(keywords) > 0 {
  320. // likeKey := "%" + keywords + "%"
  321. // db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  322. //}
  323. if patient_id > 0 {
  324. db = db.Where("s.id = ?", patient_id)
  325. }
  326. if orgid > 0 {
  327. db = db.Where("p.user_org_id = ?", orgid)
  328. }
  329. if startime > 0 {
  330. db = db.Where("p.record_date >= ?", startime)
  331. }
  332. if endtime > 0 {
  333. db = db.Where("p.record_date <=?", endtime)
  334. }
  335. offset := (page - 1) * limit
  336. 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
  337. return prescription, total, err
  338. }
  339. func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
  340. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  341. table := XTReadDB().Table("xt_schedule as s")
  342. fmt.Println(table)
  343. p := XTReadDB().Table("xt_patients as p")
  344. fmt.Println(p)
  345. sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
  346. if orgID > 0 {
  347. db = db.Where("o.user_org_id = ?", orgID)
  348. }
  349. if startime > 0 {
  350. db = db.Where("o.dialysis_date >=?", startime)
  351. }
  352. if endtime > 0 {
  353. db = db.Where("o.dialysis_date<=?", endtime)
  354. }
  355. if lapseto == 0 {
  356. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  357. }
  358. if lapseto > 0 {
  359. db = db.Where("p.lapseto = ?", lapseto)
  360. }
  361. offset := (page - 1) * limit
  362. err = db.Group("o.dialysis_date").Select(sql).Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1").Count(&total).Offset(offset).Limit(limit).Scan(&blood).Error
  363. return blood, total, err
  364. }
  365. func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (ttd []*models.TreatTotalStruct, err error) {
  366. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  367. table := XTReadDB().Table("xt_schedule as s")
  368. fmt.Println(table)
  369. p := XTReadDB().Table("xt_patients as p")
  370. fmt.Println(p)
  371. if orgid > 0 {
  372. db = db.Where("o.user_org_id = ?", orgid)
  373. }
  374. if startime > 0 {
  375. db = db.Where("o.dialysis_date>=?", startime)
  376. }
  377. if endtime > 0 {
  378. db = db.Where("o.dialysis_date<=?", endtime)
  379. }
  380. if lapseto == 0 {
  381. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  382. }
  383. if lapseto > 0 {
  384. db = db.Where("p.lapseto = ?", lapseto)
  385. }
  386. err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  387. return ttd, err
  388. }
  389. func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, err error) {
  390. db := readDb
  391. sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
  392. datesql := " o.dialysis_date as date"
  393. group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
  394. db = db.Table(" xt_dialysis_order AS o").Joins("left join xt_schedule as s on o.patient_id = s.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1")
  395. if orgID > 0 {
  396. db = db.Where("o.user_org_id = ?", orgID)
  397. }
  398. if modeID > 0 {
  399. db = db.Where("s.mode_id=?", modeID)
  400. }
  401. if startime > 0 {
  402. db = db.Where("o.dialysis_date>=?", startime)
  403. }
  404. if endtime > 0 {
  405. db = db.Where("o.dialysis_date<=?", endtime)
  406. }
  407. db = db.Where("o.status=1")
  408. err = db.Select("s.mode_id, count(s.mode_id) as number").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  409. if err != nil {
  410. return
  411. }
  412. var ds []*DialysisTotalDataStruct
  413. err = db.Select(datesql).Group(group).Find(&ds).Error
  414. if err != nil {
  415. return
  416. }
  417. dates := make([]string, 0)
  418. if len(ds) > 0 {
  419. for _, d := range ds {
  420. dates = append(dates, d.Date)
  421. }
  422. db = db.Where("o.dialysis_date IN (?)", dates)
  423. }
  424. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, s.mode_id").Find(&dtd).Error
  425. return
  426. }
  427. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  428. var count int
  429. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  430. table := XTReadDB().Table("xt_inspection_reference as s")
  431. if orgid > 0 {
  432. db = db.Where("x.user_org_id = ?", orgid)
  433. }
  434. fmt.Println(table)
  435. 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
  436. return configuration, err
  437. }
  438. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  439. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  440. table := XTReadDB().Table("xt_inspection_reference as r")
  441. fmt.Println(table)
  442. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  443. fmt.Println(d)
  444. if orgid > 0 {
  445. db = db.Where("x.org_id = ?", orgid)
  446. }
  447. if startime > 0 {
  448. db = db.Where("x.inspect_date >=?", startime)
  449. }
  450. if endtime > 0 {
  451. db = db.Where("x.inspect_date <=?", endtime)
  452. }
  453. 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("project_id,patient_id").Scan(&projectCounts).Error
  454. return
  455. }
  456. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  457. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  458. table := XTReadDB().Table("xt_inspection_reference as r")
  459. fmt.Println(table)
  460. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  461. fmt.Println(d)
  462. if id > 0 {
  463. db = db.Where("x.patient_id=?", id)
  464. }
  465. if orgid > 0 {
  466. db = db.Where("x.org_id = ?", orgid)
  467. }
  468. if startime > 0 {
  469. db = db.Where("x.inspect_date >=?", startime)
  470. }
  471. if endtime > 0 {
  472. db = db.Where("x.inspect_date <=?", endtime)
  473. }
  474. 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").Group("project_id,patient_id").Scan(&projectCounts).Error
  475. return
  476. }
  477. func GetSearchPatientInfo(orgid int64, keywords int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  478. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  479. table := XTReadDB().Table("xt_inspection_reference as r")
  480. fmt.Println(table)
  481. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  482. fmt.Println(d)
  483. p := XTReadDB().Table("xt_patients as p")
  484. fmt.Println(p)
  485. //if len(keywords) > 0 {
  486. // likeKey := "%" + keywords + "%"
  487. // db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  488. //}
  489. if keywords > 0 {
  490. db = db.Where("x.patient_id = ?", keywords)
  491. }
  492. if orgid > 0 {
  493. db = db.Where("x.org_id = ?", orgid)
  494. }
  495. if startime > 0 {
  496. db = db.Where("x.inspect_date >=?", startime)
  497. }
  498. if endtime > 0 {
  499. db = db.Where("x.inspect_date <=?", endtime)
  500. }
  501. 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
  502. return
  503. }
  504. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  505. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  506. table := XTReadDB().Table("xt_inspection_reference ar r")
  507. fmt.Println(table)
  508. 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
  509. return checkconfiguration, err
  510. }
  511. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  512. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  513. table := XTReadDB().Table("xt_inspection_reference ar r")
  514. fmt.Println(table)
  515. 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
  516. return checkconfiguration, err
  517. }
  518. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  519. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  520. table := XTReadDB().Table("xt_patients as s")
  521. fmt.Println("table", table)
  522. if orgid > 0 {
  523. db = db.Where("x.org_id = ?", orgid)
  524. }
  525. if startime > 0 {
  526. db = db.Where("x.inspect_date >= ?", startime)
  527. }
  528. if endtime > 0 {
  529. db = db.Where("x.inspect_date <=?", endtime)
  530. }
  531. offset := (page - 1) * limit
  532. 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
  533. return inspection, total, err
  534. }
  535. func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  536. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  537. table := XTReadDB().Table("xt_inspection_reference as r")
  538. fmt.Println(table)
  539. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  540. pa := XTReadDB().Table("xt_patients as s")
  541. fmt.Println(pa)
  542. fmt.Println(d)
  543. if orgid > 0 {
  544. db = db.Where("x.org_id = ?", orgid)
  545. }
  546. if startime > 0 {
  547. db = db.Where("x.inspect_date >=?", startime)
  548. }
  549. if endtime > 0 {
  550. db = db.Where("x.inspect_date <=?", endtime)
  551. }
  552. 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
  553. return
  554. }
  555. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  556. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  557. table := XTReadDB().Table("xt_inspection_reference as r")
  558. fmt.Println(table)
  559. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  560. pa := XTReadDB().Table("xt_patients as s")
  561. fmt.Println(pa)
  562. fmt.Println(d)
  563. if id > 0 {
  564. db = db.Where("s.id = ?", id)
  565. }
  566. if orgid > 0 {
  567. db = db.Where("x.org_id = ?", orgid)
  568. }
  569. if startime > 0 {
  570. db = db.Where("x.inspect_date >=?", startime)
  571. }
  572. if endtime > 0 {
  573. db = db.Where("x.inspect_date <=?", endtime)
  574. }
  575. 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
  576. return
  577. }
  578. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  579. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  580. table := XTReadDB().Table("xt_inspection_reference as r")
  581. fmt.Println(table)
  582. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  583. pa := XTReadDB().Table("xt_patients as s")
  584. fmt.Println(pa)
  585. fmt.Println(d)
  586. if len(keywords) > 0 {
  587. likeKey := "%" + keywords + "%"
  588. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  589. }
  590. if orgid > 0 {
  591. db = db.Where("x.org_id = ?", orgid)
  592. }
  593. if startime > 0 {
  594. db = db.Where("x.inspect_date >=?", startime)
  595. }
  596. if endtime > 0 {
  597. db = db.Where("x.inspect_date <=?", endtime)
  598. }
  599. 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
  600. return
  601. }
  602. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  603. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  604. if orgid > 0 {
  605. db = db.Where("x.user_org_id = ?", orgid)
  606. }
  607. table := XTReadDB().Table("xt_inspection_reference as s")
  608. fmt.Println(table)
  609. 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,s.unit,s.project_name,s.item_name").
  610. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
  611. return standard, err
  612. }
  613. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  614. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  615. if orgid >= 0 {
  616. db = db.Where("x.user_org_id = ?", orgid)
  617. }
  618. table := XTReadDB().Table("xt_inspection_reference as s")
  619. fmt.Println(table)
  620. 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,s.unit,s.project_name,s.item_name").
  621. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
  622. return standard, err
  623. }
  624. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, 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. if orgid > 0 {
  629. db = db.Where("x.org_id = ?", orgid)
  630. }
  631. if startime > 0 {
  632. db = db.Where("x.inspect_date >=?", startime)
  633. }
  634. if endtime > 0 {
  635. db = db.Where("x.inspect_date <=?", endtime)
  636. }
  637. 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
  638. return inspection, err
  639. }
  640. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  641. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  642. table := XTReadDB().Table("xt_inspection_reference as r")
  643. fmt.Println(table)
  644. if orgid > 0 {
  645. db = db.Where("x.org_id = ?", orgid)
  646. }
  647. if startime > 0 {
  648. db = db.Where("x.inspect_date >=?", startime)
  649. }
  650. if endtime > 0 {
  651. db = db.Where("x.inspect_date <=?", endtime)
  652. }
  653. 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
  654. return inspection, err
  655. }
  656. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspection, err error) {
  657. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  658. table := XTReadDB().Table("xt_inspection_reference as r")
  659. fmt.Println(table)
  660. d := XTReadDB().Table("xt_patients as s")
  661. fmt.Println(d)
  662. d2 := XTReadDB().Table("xt_quality_control_standard as p")
  663. fmt.Println(d2)
  664. if orgid > 0 {
  665. db = db.Where("x.org_id = ?", orgid)
  666. }
  667. if startime > 0 {
  668. db = db.Where("x.inspect_date >=?", startime)
  669. }
  670. if endtime > 0 {
  671. db = db.Where("x.inspect_date <=?", endtime)
  672. }
  673. if lapseto == 0 {
  674. db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  675. }
  676. if lapseto > 0 {
  677. db = db.Where("s.lapseto = ?", lapseto)
  678. }
  679. 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>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
  680. return inspection, err
  681. }
  682. 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) {
  683. if lapseto == 0 {
  684. d := XTReadDB().Table("xt_patients as s")
  685. fmt.Println("d", d)
  686. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  687. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  688. "SELECT " +
  689. "CASE " +
  690. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  691. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  692. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  693. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  694. " ELSE '其他'" +
  695. "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)"
  696. countParams := make([]interface{}, 0)
  697. countParams = append(countParams, firststart)
  698. countParams = append(countParams, firstend)
  699. countParams = append(countParams, sencondstart)
  700. countParams = append(countParams, sencondend)
  701. countParams = append(countParams, threestart)
  702. countParams = append(countParams, threeend)
  703. countParams = append(countParams, fourstart)
  704. countParams = append(countParams, fourend)
  705. if orgid > 0 {
  706. db = db.Where("x.org_id=?", orgid)
  707. countSQL += " AND x.org_id=?"
  708. countParams = append(countParams, orgid)
  709. }
  710. if modetype > 0 {
  711. db = db.Where("x.item_id = ?", modetype)
  712. countSQL += " AND x.item_id=?"
  713. countParams = append(countParams, modetype)
  714. }
  715. if startime > 0 {
  716. db = db.Where("x.inspect_date >= ?", startime)
  717. countSQL += " AND x.inspect_date >=?"
  718. countParams = append(countParams, startime)
  719. }
  720. if endtime > 0 {
  721. db = db.Where("x.inspect_date <= ?", endtime)
  722. countSQL += " AND x.inspect_date <=?"
  723. countParams = append(countParams, endtime)
  724. }
  725. countSQL += ")a GROUP BY nnd"
  726. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  727. }
  728. if lapseto == 1 {
  729. d := XTReadDB().Table("xt_patients as s")
  730. fmt.Println("d", d)
  731. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  732. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  733. "SELECT " +
  734. "CASE " +
  735. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  736. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  737. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  738. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  739. "ELSE '其他'" +
  740. "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)"
  741. countParams := make([]interface{}, 0)
  742. countParams = append(countParams, firststart)
  743. countParams = append(countParams, firstend)
  744. countParams = append(countParams, sencondstart)
  745. countParams = append(countParams, sencondend)
  746. countParams = append(countParams, threestart)
  747. countParams = append(countParams, threeend)
  748. countParams = append(countParams, fourstart)
  749. countParams = append(countParams, fourend)
  750. if orgid > 0 {
  751. db = db.Where("x.org_id=?", orgid)
  752. countSQL += " AND x.org_id=?"
  753. countParams = append(countParams, orgid)
  754. }
  755. if modetype > 0 {
  756. db = db.Where("x.item_id = ?", modetype)
  757. countSQL += " AND x.item_id=?"
  758. countParams = append(countParams, modetype)
  759. }
  760. if startime > 0 {
  761. db = db.Where("x.inspect_date >= ?", startime)
  762. countSQL += " AND x.inspect_date >=?"
  763. countParams = append(countParams, startime)
  764. }
  765. if endtime > 0 {
  766. db = db.Where("x.inspect_date <= ?", endtime)
  767. countSQL += " AND x.inspect_date <=?"
  768. countParams = append(countParams, endtime)
  769. }
  770. countSQL += ")a GROUP BY nnd"
  771. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  772. }
  773. if lapseto == 2 {
  774. d := XTReadDB().Table("xt_patients as s")
  775. fmt.Println("d", d)
  776. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  777. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  778. "SELECT " +
  779. "CASE " +
  780. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  781. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  782. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  783. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  784. " ELSE '其他'" +
  785. "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)"
  786. countParams := make([]interface{}, 0)
  787. countParams = append(countParams, firststart)
  788. countParams = append(countParams, firstend)
  789. countParams = append(countParams, sencondstart)
  790. countParams = append(countParams, sencondend)
  791. countParams = append(countParams, threestart)
  792. countParams = append(countParams, threeend)
  793. countParams = append(countParams, fourstart)
  794. countParams = append(countParams, fourend)
  795. if orgid > 0 {
  796. db = db.Where("x.org_id=?", orgid)
  797. countSQL += " AND x.org_id=?"
  798. countParams = append(countParams, orgid)
  799. }
  800. if modetype > 0 {
  801. db = db.Where("x.item_id = ?", modetype)
  802. countSQL += " AND x.item_id=?"
  803. countParams = append(countParams, modetype)
  804. }
  805. if startime > 0 {
  806. db = db.Where("x.inspect_date >= ?", startime)
  807. countSQL += " AND x.inspect_date >=?"
  808. countParams = append(countParams, startime)
  809. }
  810. if endtime > 0 {
  811. db = db.Where("x.inspect_date <= ?", endtime)
  812. countSQL += " AND x.inspect_date <=?"
  813. countParams = append(countParams, endtime)
  814. }
  815. countSQL += ")a GROUP BY nnd"
  816. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  817. }
  818. return
  819. }
  820. 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) {
  821. if lapseto == 0 {
  822. d := XTReadDB().Table("xt_patients as s")
  823. fmt.Println("d", d)
  824. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  825. table := XTReadDB().Table("xt_inspection_reference as r")
  826. fmt.Println(table)
  827. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  828. "SELECT " +
  829. "CASE " +
  830. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  831. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  832. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  833. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  834. " ELSE '其他'" +
  835. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  836. countParams := make([]interface{}, 0)
  837. countParams = append(countParams, firststart)
  838. countParams = append(countParams, firstend)
  839. countParams = append(countParams, sencondstart)
  840. countParams = append(countParams, sencondend)
  841. countParams = append(countParams, threestart)
  842. countParams = append(countParams, threeend)
  843. countParams = append(countParams, fourstart)
  844. countParams = append(countParams, fourend)
  845. if orgid > 0 {
  846. db = db.Where("x.org_id=?", orgid)
  847. countSQL += " AND x.org_id=?"
  848. countParams = append(countParams, orgid)
  849. }
  850. if modetype > 0 {
  851. db = db.Where("x.item_id = ?", modetype)
  852. countSQL += " AND x.item_id=?"
  853. countParams = append(countParams, modetype)
  854. }
  855. if startime > 0 {
  856. db = db.Where("x.inspect_date >= ? ", startime)
  857. countSQL += " AND x.inspect_date >=?"
  858. countParams = append(countParams, startime)
  859. }
  860. if endtime > 0 {
  861. db = db.Where("x.inspect_date <= ?", endtime)
  862. countSQL += " AND x.inspect_date <=?"
  863. countParams = append(countParams, endtime)
  864. }
  865. countSQL += ")a GROUP BY nnd"
  866. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  867. }
  868. if lapseto == 1 {
  869. d := XTReadDB().Table("xt_patients as s")
  870. fmt.Println("d", d)
  871. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  872. table := XTReadDB().Table("xt_inspection_reference as r")
  873. fmt.Println(table)
  874. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  875. "SELECT " +
  876. "CASE " +
  877. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  878. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  879. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  880. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  881. " ELSE '其他'" +
  882. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  883. countParams := make([]interface{}, 0)
  884. countParams = append(countParams, firststart)
  885. countParams = append(countParams, firstend)
  886. countParams = append(countParams, sencondstart)
  887. countParams = append(countParams, sencondend)
  888. countParams = append(countParams, threestart)
  889. countParams = append(countParams, threeend)
  890. countParams = append(countParams, fourstart)
  891. countParams = append(countParams, fourend)
  892. if orgid > 0 {
  893. db = db.Where("x.org_id=?", orgid)
  894. countSQL += " AND x.org_id=?"
  895. countParams = append(countParams, orgid)
  896. }
  897. if modetype > 0 {
  898. db = db.Where("x.item_id = ?", modetype)
  899. countSQL += " AND x.item_id=?"
  900. countParams = append(countParams, modetype)
  901. }
  902. if startime > 0 {
  903. db = db.Where("x.inspect_date >= ? ", startime)
  904. countSQL += " AND x.inspect_date >=?"
  905. countParams = append(countParams, startime)
  906. }
  907. if endtime > 0 {
  908. db = db.Where("x.inspect_date <= ?", endtime)
  909. countSQL += " AND x.inspect_date <=?"
  910. countParams = append(countParams, endtime)
  911. }
  912. countSQL += ")a GROUP BY nnd"
  913. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  914. }
  915. if lapseto == 2 {
  916. d := XTReadDB().Table("xt_patients as s")
  917. fmt.Println("d", d)
  918. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  919. table := XTReadDB().Table("xt_inspection_reference as r")
  920. fmt.Println(table)
  921. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  922. "SELECT " +
  923. "CASE " +
  924. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  925. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  926. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  927. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  928. " ELSE '其他'" +
  929. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  930. countParams := make([]interface{}, 0)
  931. countParams = append(countParams, firststart)
  932. countParams = append(countParams, firstend)
  933. countParams = append(countParams, sencondstart)
  934. countParams = append(countParams, sencondend)
  935. countParams = append(countParams, threestart)
  936. countParams = append(countParams, threeend)
  937. countParams = append(countParams, fourstart)
  938. countParams = append(countParams, fourend)
  939. if orgid > 0 {
  940. db = db.Where("x.org_id=?", orgid)
  941. countSQL += " AND x.org_id=?"
  942. countParams = append(countParams, orgid)
  943. }
  944. if modetype > 0 {
  945. db = db.Where("x.item_id = ?", modetype)
  946. countSQL += " AND x.item_id=?"
  947. countParams = append(countParams, modetype)
  948. }
  949. if startime > 0 {
  950. db = db.Where("x.inspect_date >= ? ", startime)
  951. countSQL += " AND x.inspect_date >=?"
  952. countParams = append(countParams, startime)
  953. }
  954. if endtime > 0 {
  955. db = db.Where("x.inspect_date <= ?", endtime)
  956. countSQL += " AND x.inspect_date <=?"
  957. countParams = append(countParams, endtime)
  958. }
  959. countSQL += ")a GROUP BY nnd"
  960. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  961. }
  962. return
  963. }
  964. 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) {
  965. if lapseto == 0 {
  966. d := XTReadDB().Table("xt_patients as s")
  967. fmt.Println("d", d)
  968. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  969. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  970. "SELECT " +
  971. "CASE " +
  972. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  973. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  974. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  975. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  976. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  977. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  978. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  979. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  980. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  981. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  982. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  983. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  984. " ELSE '其他'" +
  985. "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)"
  986. countParams := make([]interface{}, 0)
  987. countParams = append(countParams, januaryStartStrUnix)
  988. countParams = append(countParams, januaryEndStrUnix)
  989. countParams = append(countParams, febStartStrStrUnix)
  990. countParams = append(countParams, febEndStrUnix)
  991. countParams = append(countParams, marchStartStrUnix)
  992. countParams = append(countParams, marchEndStrUnix)
  993. countParams = append(countParams, aprStartStrUnix)
  994. countParams = append(countParams, aprEndStrsUnix)
  995. countParams = append(countParams, mayStartStrUnix)
  996. countParams = append(countParams, mayEndStrsUnix)
  997. countParams = append(countParams, junStartStrUnix)
  998. countParams = append(countParams, junEndStrsUnix)
  999. countParams = append(countParams, julStartStrUnix)
  1000. countParams = append(countParams, julEndStrsUnix)
  1001. countParams = append(countParams, augStartStrUnix)
  1002. countParams = append(countParams, augEndStrsUnix)
  1003. countParams = append(countParams, sepStartStrUnix)
  1004. countParams = append(countParams, sepEndStrsUnix)
  1005. countParams = append(countParams, octStartStrUnix)
  1006. countParams = append(countParams, octEndStrsUnix)
  1007. countParams = append(countParams, novStartStrUnix)
  1008. countParams = append(countParams, novEndStrsUnix)
  1009. countParams = append(countParams, decStartStrUnix)
  1010. countParams = append(countParams, decEndStrsUnix)
  1011. if orgid > 0 {
  1012. db = db.Where("x.org_id=?", orgid)
  1013. countSQL += " AND x.org_id=?"
  1014. countParams = append(countParams, orgid)
  1015. }
  1016. if modetype > 0 {
  1017. db = db.Where("x.item_id = ?", modetype)
  1018. countSQL += " AND x.item_id=?"
  1019. countParams = append(countParams, modetype)
  1020. }
  1021. if januaryStartStrUnix > 0 {
  1022. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1023. countSQL += " AND x.inspect_date >=?"
  1024. countParams = append(countParams, januaryStartStrUnix)
  1025. }
  1026. if decEndStrsUnix > 0 {
  1027. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1028. countSQL += " AND x.inspect_date <=?"
  1029. countParams = append(countParams, decEndStrsUnix)
  1030. }
  1031. countSQL += ")a GROUP BY nnd"
  1032. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1033. }
  1034. if lapseto == 1 {
  1035. d := XTReadDB().Table("xt_patients as s")
  1036. fmt.Println("d", d)
  1037. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1038. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1039. "SELECT " +
  1040. "CASE " +
  1041. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1042. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1043. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1044. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1045. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1046. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1047. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1048. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1049. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1050. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1051. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1052. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1053. " ELSE '其他'" +
  1054. "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)"
  1055. countParams := make([]interface{}, 0)
  1056. countParams = append(countParams, januaryStartStrUnix)
  1057. countParams = append(countParams, januaryEndStrUnix)
  1058. countParams = append(countParams, febStartStrStrUnix)
  1059. countParams = append(countParams, febEndStrUnix)
  1060. countParams = append(countParams, marchStartStrUnix)
  1061. countParams = append(countParams, marchEndStrUnix)
  1062. countParams = append(countParams, aprStartStrUnix)
  1063. countParams = append(countParams, aprEndStrsUnix)
  1064. countParams = append(countParams, mayStartStrUnix)
  1065. countParams = append(countParams, mayEndStrsUnix)
  1066. countParams = append(countParams, junStartStrUnix)
  1067. countParams = append(countParams, junEndStrsUnix)
  1068. countParams = append(countParams, julStartStrUnix)
  1069. countParams = append(countParams, julEndStrsUnix)
  1070. countParams = append(countParams, augStartStrUnix)
  1071. countParams = append(countParams, augEndStrsUnix)
  1072. countParams = append(countParams, sepStartStrUnix)
  1073. countParams = append(countParams, sepEndStrsUnix)
  1074. countParams = append(countParams, octStartStrUnix)
  1075. countParams = append(countParams, octEndStrsUnix)
  1076. countParams = append(countParams, novStartStrUnix)
  1077. countParams = append(countParams, novEndStrsUnix)
  1078. countParams = append(countParams, decStartStrUnix)
  1079. countParams = append(countParams, decEndStrsUnix)
  1080. if orgid > 0 {
  1081. db = db.Where("x.org_id=?", orgid)
  1082. countSQL += " AND x.org_id=?"
  1083. countParams = append(countParams, orgid)
  1084. }
  1085. if modetype > 0 {
  1086. db = db.Where("x.item_id = ?", modetype)
  1087. countSQL += " AND x.item_id=?"
  1088. countParams = append(countParams, modetype)
  1089. }
  1090. if januaryStartStrUnix > 0 {
  1091. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1092. countSQL += " AND x.inspect_date >=?"
  1093. countParams = append(countParams, januaryStartStrUnix)
  1094. }
  1095. if decEndStrsUnix > 0 {
  1096. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1097. countSQL += " AND x.inspect_date <=?"
  1098. countParams = append(countParams, decEndStrsUnix)
  1099. }
  1100. countSQL += ")a GROUP BY nnd"
  1101. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1102. }
  1103. if lapseto == 2 {
  1104. d := XTReadDB().Table("xt_patients as s")
  1105. fmt.Println("d", d)
  1106. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1107. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1108. "SELECT " +
  1109. "CASE " +
  1110. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1111. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1112. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1113. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1114. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1115. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1116. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1117. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1118. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1119. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1120. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1121. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1122. " ELSE '其他'" +
  1123. "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)"
  1124. countParams := make([]interface{}, 0)
  1125. countParams = append(countParams, januaryStartStrUnix)
  1126. countParams = append(countParams, januaryEndStrUnix)
  1127. countParams = append(countParams, febStartStrStrUnix)
  1128. countParams = append(countParams, febEndStrUnix)
  1129. countParams = append(countParams, marchStartStrUnix)
  1130. countParams = append(countParams, marchEndStrUnix)
  1131. countParams = append(countParams, aprStartStrUnix)
  1132. countParams = append(countParams, aprEndStrsUnix)
  1133. countParams = append(countParams, mayStartStrUnix)
  1134. countParams = append(countParams, mayEndStrsUnix)
  1135. countParams = append(countParams, junStartStrUnix)
  1136. countParams = append(countParams, junEndStrsUnix)
  1137. countParams = append(countParams, julStartStrUnix)
  1138. countParams = append(countParams, julEndStrsUnix)
  1139. countParams = append(countParams, augStartStrUnix)
  1140. countParams = append(countParams, augEndStrsUnix)
  1141. countParams = append(countParams, sepStartStrUnix)
  1142. countParams = append(countParams, sepEndStrsUnix)
  1143. countParams = append(countParams, octStartStrUnix)
  1144. countParams = append(countParams, octEndStrsUnix)
  1145. countParams = append(countParams, novStartStrUnix)
  1146. countParams = append(countParams, novEndStrsUnix)
  1147. countParams = append(countParams, decStartStrUnix)
  1148. countParams = append(countParams, decEndStrsUnix)
  1149. if orgid > 0 {
  1150. db = db.Where("x.org_id=?", orgid)
  1151. countSQL += " AND x.org_id=?"
  1152. countParams = append(countParams, orgid)
  1153. }
  1154. if modetype > 0 {
  1155. db = db.Where("x.item_id = ?", modetype)
  1156. countSQL += " AND x.item_id=?"
  1157. countParams = append(countParams, modetype)
  1158. }
  1159. if januaryStartStrUnix > 0 {
  1160. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1161. countSQL += " AND x.inspect_date >=?"
  1162. countParams = append(countParams, januaryStartStrUnix)
  1163. }
  1164. if decEndStrsUnix > 0 {
  1165. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1166. countSQL += " AND x.inspect_date <=?"
  1167. countParams = append(countParams, decEndStrsUnix)
  1168. }
  1169. countSQL += ")a GROUP BY nnd"
  1170. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1171. }
  1172. return
  1173. }
  1174. 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) {
  1175. fmt.Println("lapseto=======", lapseto)
  1176. if lapseto == 0 {
  1177. d := XTReadDB().Table("xt_patients as s")
  1178. fmt.Println("d", d)
  1179. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1180. table := XTReadDB().Table("xt_inspection_reference as r")
  1181. fmt.Println(table)
  1182. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1183. "SELECT " +
  1184. "CASE " +
  1185. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1186. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1187. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1188. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1189. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1190. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1191. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1192. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1193. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1194. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1195. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1196. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1197. " ELSE '其他'" +
  1198. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1199. countParams := make([]interface{}, 0)
  1200. countParams = append(countParams, januaryStartStrUnix)
  1201. countParams = append(countParams, januaryEndStrUnix)
  1202. countParams = append(countParams, febStartStrStrUnix)
  1203. countParams = append(countParams, febEndStrUnix)
  1204. countParams = append(countParams, marchStartStrUnix)
  1205. countParams = append(countParams, marchEndStrUnix)
  1206. countParams = append(countParams, aprStartStrUnix)
  1207. countParams = append(countParams, aprEndStrsUnix)
  1208. countParams = append(countParams, mayStartStrUnix)
  1209. countParams = append(countParams, mayEndStrsUnix)
  1210. countParams = append(countParams, junStartStrUnix)
  1211. countParams = append(countParams, junEndStrsUnix)
  1212. countParams = append(countParams, julStartStrUnix)
  1213. countParams = append(countParams, julEndStrsUnix)
  1214. countParams = append(countParams, augStartStrUnix)
  1215. countParams = append(countParams, augEndStrsUnix)
  1216. countParams = append(countParams, sepStartStrUnix)
  1217. countParams = append(countParams, sepEndStrsUnix)
  1218. countParams = append(countParams, octStartStrUnix)
  1219. countParams = append(countParams, octEndStrsUnix)
  1220. countParams = append(countParams, novStartStrUnix)
  1221. countParams = append(countParams, novEndStrsUnix)
  1222. countParams = append(countParams, decStartStrUnix)
  1223. countParams = append(countParams, decEndStrsUnix)
  1224. if orgid > 0 {
  1225. db = db.Where("x.org_id=?", orgid)
  1226. countSQL += " AND x.org_id=?"
  1227. countParams = append(countParams, orgid)
  1228. }
  1229. if modetype > 0 {
  1230. db = db.Where("x.item_id = ?", modetype)
  1231. countSQL += " AND x.item_id=?"
  1232. countParams = append(countParams, modetype)
  1233. }
  1234. if januaryStartStrUnix > 0 {
  1235. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1236. countSQL += " AND x.inspect_date >=?"
  1237. countParams = append(countParams, januaryStartStrUnix)
  1238. }
  1239. if decEndStrsUnix > 0 {
  1240. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1241. countSQL += " AND x.inspect_date <=?"
  1242. countParams = append(countParams, decEndStrsUnix)
  1243. }
  1244. countSQL += ")a GROUP BY nnd"
  1245. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1246. }
  1247. if lapseto == 1 {
  1248. d := XTReadDB().Table("xt_patients as s")
  1249. fmt.Println("d", d)
  1250. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1251. table := XTReadDB().Table("xt_inspection_reference as r")
  1252. fmt.Println(table)
  1253. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1254. "SELECT " +
  1255. "CASE " +
  1256. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1257. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1258. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1259. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1260. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1261. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1262. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1263. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1264. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1265. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1266. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1267. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1268. " ELSE '其他'" +
  1269. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1270. countParams := make([]interface{}, 0)
  1271. countParams = append(countParams, januaryStartStrUnix)
  1272. countParams = append(countParams, januaryEndStrUnix)
  1273. countParams = append(countParams, febStartStrStrUnix)
  1274. countParams = append(countParams, febEndStrUnix)
  1275. countParams = append(countParams, marchStartStrUnix)
  1276. countParams = append(countParams, marchEndStrUnix)
  1277. countParams = append(countParams, aprStartStrUnix)
  1278. countParams = append(countParams, aprEndStrsUnix)
  1279. countParams = append(countParams, mayStartStrUnix)
  1280. countParams = append(countParams, mayEndStrsUnix)
  1281. countParams = append(countParams, junStartStrUnix)
  1282. countParams = append(countParams, junEndStrsUnix)
  1283. countParams = append(countParams, julStartStrUnix)
  1284. countParams = append(countParams, julEndStrsUnix)
  1285. countParams = append(countParams, augStartStrUnix)
  1286. countParams = append(countParams, augEndStrsUnix)
  1287. countParams = append(countParams, sepStartStrUnix)
  1288. countParams = append(countParams, sepEndStrsUnix)
  1289. countParams = append(countParams, octStartStrUnix)
  1290. countParams = append(countParams, octEndStrsUnix)
  1291. countParams = append(countParams, novStartStrUnix)
  1292. countParams = append(countParams, novEndStrsUnix)
  1293. countParams = append(countParams, decStartStrUnix)
  1294. countParams = append(countParams, decEndStrsUnix)
  1295. if orgid > 0 {
  1296. db = db.Where("x.org_id=?", orgid)
  1297. countSQL += " AND x.org_id=?"
  1298. countParams = append(countParams, orgid)
  1299. }
  1300. if modetype > 0 {
  1301. db = db.Where("x.item_id = ?", modetype)
  1302. countSQL += " AND x.item_id=?"
  1303. countParams = append(countParams, modetype)
  1304. }
  1305. if januaryStartStrUnix > 0 {
  1306. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1307. countSQL += " AND x.inspect_date >=?"
  1308. countParams = append(countParams, januaryStartStrUnix)
  1309. }
  1310. if decEndStrsUnix > 0 {
  1311. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1312. countSQL += " AND x.inspect_date <=?"
  1313. countParams = append(countParams, decEndStrsUnix)
  1314. }
  1315. countSQL += ")a GROUP BY nnd"
  1316. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1317. }
  1318. if lapseto == 2 {
  1319. d := XTReadDB().Table("xt_patients as s")
  1320. fmt.Println("d", d)
  1321. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1322. table := XTReadDB().Table("xt_inspection_reference as r")
  1323. fmt.Println(table)
  1324. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1325. "SELECT " +
  1326. "CASE " +
  1327. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1328. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1329. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1330. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1331. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1332. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1333. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1334. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1335. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1336. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1337. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1338. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1339. " ELSE '其他'" +
  1340. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1341. countParams := make([]interface{}, 0)
  1342. countParams = append(countParams, januaryStartStrUnix)
  1343. countParams = append(countParams, januaryEndStrUnix)
  1344. countParams = append(countParams, febStartStrStrUnix)
  1345. countParams = append(countParams, febEndStrUnix)
  1346. countParams = append(countParams, marchStartStrUnix)
  1347. countParams = append(countParams, marchEndStrUnix)
  1348. countParams = append(countParams, aprStartStrUnix)
  1349. countParams = append(countParams, aprEndStrsUnix)
  1350. countParams = append(countParams, mayStartStrUnix)
  1351. countParams = append(countParams, mayEndStrsUnix)
  1352. countParams = append(countParams, junStartStrUnix)
  1353. countParams = append(countParams, junEndStrsUnix)
  1354. countParams = append(countParams, julStartStrUnix)
  1355. countParams = append(countParams, julEndStrsUnix)
  1356. countParams = append(countParams, augStartStrUnix)
  1357. countParams = append(countParams, augEndStrsUnix)
  1358. countParams = append(countParams, sepStartStrUnix)
  1359. countParams = append(countParams, sepEndStrsUnix)
  1360. countParams = append(countParams, octStartStrUnix)
  1361. countParams = append(countParams, octEndStrsUnix)
  1362. countParams = append(countParams, novStartStrUnix)
  1363. countParams = append(countParams, novEndStrsUnix)
  1364. countParams = append(countParams, decStartStrUnix)
  1365. countParams = append(countParams, decEndStrsUnix)
  1366. if orgid > 0 {
  1367. db = db.Where("x.org_id=?", orgid)
  1368. countSQL += " AND x.org_id=?"
  1369. countParams = append(countParams, orgid)
  1370. }
  1371. if modetype > 0 {
  1372. db = db.Where("x.item_id = ?", modetype)
  1373. countSQL += " AND x.item_id=?"
  1374. countParams = append(countParams, modetype)
  1375. }
  1376. if januaryStartStrUnix > 0 {
  1377. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1378. countSQL += " AND x.inspect_date >=?"
  1379. countParams = append(countParams, januaryStartStrUnix)
  1380. }
  1381. if decEndStrsUnix > 0 {
  1382. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1383. countSQL += " AND x.inspect_date <=?"
  1384. countParams = append(countParams, decEndStrsUnix)
  1385. }
  1386. countSQL += ")a GROUP BY nnd"
  1387. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1388. }
  1389. return
  1390. }
  1391. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  1392. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1393. table := readDb.Table("xt_patients as s")
  1394. fmt.Println(table)
  1395. d := readDb.Table(" xt_inspection_reference as r")
  1396. fmt.Println(d)
  1397. if orgid > 0 {
  1398. db = db.Where("x.org_id = ?", orgid)
  1399. }
  1400. if lapstor == 0 {
  1401. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1402. }
  1403. if lapstor == 1 {
  1404. db = db.Where("s.lapseto = 1")
  1405. }
  1406. if lapstor == 2 {
  1407. db = db.Where("s.lapseto = 2")
  1408. }
  1409. if startime > 0 {
  1410. db = db.Where("x.inspect_date >=?", startime)
  1411. }
  1412. if endtime > 0 {
  1413. db = db.Where("x.inspect_date <=?", endtime)
  1414. }
  1415. offset := (page - 1) * limit
  1416. err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no").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").Group("x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  1417. return inspection, total, err
  1418. }
  1419. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1420. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1421. table := readDb.Table("xt_patients as s")
  1422. fmt.Println(table)
  1423. d := readDb.Table(" xt_inspection_reference as r")
  1424. fmt.Println(d)
  1425. d2 := readDb.Table("xt_quality_control_standard as d")
  1426. fmt.Println("d2", d2)
  1427. if orgid > 0 {
  1428. db = db.Where("x.org_id = ?", orgid)
  1429. }
  1430. if lapstor == 0 {
  1431. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1432. }
  1433. if lapstor == 1 {
  1434. table = table.Where("s.lapseto = 1")
  1435. }
  1436. if lapstor == 2 {
  1437. table = table.Where("s.lapseto = 2")
  1438. }
  1439. if startime > 0 {
  1440. db = db.Where("x.inspect_date >=?", startime)
  1441. }
  1442. if endtime > 0 {
  1443. db = db.Where("x.inspect_date <=?", endtime)
  1444. }
  1445. 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
  1446. return inspection, err
  1447. }
  1448. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1449. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1450. table := readDb.Table("xt_patients as s")
  1451. fmt.Println(table)
  1452. d := readDb.Table(" xt_inspection_reference as r")
  1453. fmt.Println(d)
  1454. d2 := readDb.Table("xt_quality_control_standard as d")
  1455. fmt.Println("d2", d2)
  1456. if len(keywords) > 0 {
  1457. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  1458. }
  1459. if orgid > 0 {
  1460. db = db.Where("x.org_id = ?", orgid)
  1461. }
  1462. if lapstor == 0 {
  1463. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1464. }
  1465. if lapstor == 1 {
  1466. table = table.Where("s.lapseto = 1")
  1467. }
  1468. if lapstor == 2 {
  1469. table = table.Where("s.lapseto = 2")
  1470. }
  1471. if startime > 0 {
  1472. db = db.Where("x.inspect_date >=?", startime)
  1473. }
  1474. if endtime > 0 {
  1475. db = db.Where("x.inspect_date <=?", endtime)
  1476. }
  1477. 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
  1478. return inspection, err
  1479. }
  1480. func GetPatientNames(orgid int64, patientid int64) (models.XtPatients, error) {
  1481. patients := models.XtPatients{}
  1482. err := readDb.Where("user_org_id = ? and id = ? and status = 1", orgid, patientid).Find(&patients).Error
  1483. return patients, err
  1484. }
  1485. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  1486. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1487. table := readDb.Table("xt_patients as s")
  1488. fmt.Println(table)
  1489. d := readDb.Table(" xt_inspection_reference as r")
  1490. fmt.Println(d)
  1491. d2 := readDb.Table("xt_quality_control_standard as d")
  1492. fmt.Println("d2", d2)
  1493. if orgid > 0 {
  1494. db = db.Where("x.org_id = ?", orgid)
  1495. }
  1496. if patientid > 0 {
  1497. db = db.Where("x.patient_id = ?", patientid)
  1498. }
  1499. if startime > 0 {
  1500. db = db.Where("x.inspect_date >=?", startime)
  1501. }
  1502. if endtime > 0 {
  1503. db = db.Where("x.inspect_date <=?", endtime)
  1504. }
  1505. if itemid > 0 {
  1506. db = db.Where("x.item_id = ?", itemid)
  1507. }
  1508. 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").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
  1509. return inspection, err
  1510. }
  1511. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1512. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1513. table := readDb.Table("xt_patients as s")
  1514. fmt.Println(table)
  1515. d := readDb.Table(" xt_inspection_reference as r")
  1516. fmt.Println(d)
  1517. d2 := readDb.Table("xt_quality_control_standard as d")
  1518. fmt.Println("d2", d2)
  1519. if orgid > 0 {
  1520. db = db.Where("x.org_id = ?", orgid)
  1521. }
  1522. if patientid > 0 {
  1523. db = db.Where("x.patient_id = ?", patientid)
  1524. }
  1525. if startime > 0 {
  1526. db = db.Where("x.inspect_date >=?", startime)
  1527. }
  1528. if endtime > 0 {
  1529. db = db.Where("x.inspect_date <=?", endtime)
  1530. }
  1531. 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
  1532. return inspection, err
  1533. }