patient_dataconfig_service.go 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package service
  2. import (
  3. "time"
  4. "XT_New/models"
  5. "github.com/jinzhu/gorm"
  6. )
  7. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  8. var patient models.Patients
  9. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1 and lapseto = 1", patientID, orgID).First(&patient).Error
  10. if err != nil {
  11. if err == gorm.ErrRecordNotFound {
  12. return nil, nil
  13. } else {
  14. return nil, err
  15. }
  16. }
  17. return &patient, nil
  18. }
  19. func GetPatientByIDOne(orgID int64, patientID int64) (models.Patients, error) {
  20. var patient models.Patients
  21. err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  22. return patient, err
  23. }
  24. func GetPatientByIDTwoOne(patientID int64) (models.Patients, error) {
  25. var patient models.Patients
  26. err = readDb.Model(&models.Patients{}).Where("id = ? and status=1", patientID).First(&patient).Error
  27. return patient, err
  28. }
  29. func GetPatientCourseOfDisease(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientDiseaseCourse, error) {
  30. var records []*models.PatientDiseaseCourse
  31. err := readDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  32. if err != nil {
  33. return nil, err
  34. }
  35. return records, nil
  36. }
  37. func GetPatientSickHistory(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientSickHistory, error) {
  38. var records []*models.XtPatientSickHistory
  39. err := readDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  40. if err != nil {
  41. return nil, err
  42. }
  43. return records, nil
  44. }
  45. func GetPatientSickHistoryByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientSickHistory, error) {
  46. var records []*models.XtPatientSickHistory
  47. err := readDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error
  48. if err != nil {
  49. return nil, err
  50. }
  51. return records, nil
  52. }
  53. func GetPatienttPhysiqueByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientPhysiqueCheck, error) {
  54. var records []*models.XtPatientPhysiqueCheck
  55. err := readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error
  56. if err != nil {
  57. return nil, err
  58. }
  59. return records, nil
  60. }
  61. func GetPatientPhysiqueCheck(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientPhysiqueCheck, error) {
  62. var records []*models.XtPatientPhysiqueCheck
  63. err := readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  64. if err != nil {
  65. return nil, err
  66. }
  67. return records, nil
  68. }
  69. func GetLastPatientPhysiqueCheck(orgID int64, patientID int64, record_date int64) (records models.XtPatientPhysiqueCheck, err error) {
  70. err = readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and record_date = ? and status = 1", orgID, patientID, record_date).Order("record_time desc").Last(&records).Error
  71. return records, err
  72. }
  73. func CreatePatientCourseOfDisease(record *models.PatientDiseaseCourse) error {
  74. err := writeDb.Model(&models.PatientDiseaseCourse{}).Create(record).Error
  75. return err
  76. }
  77. func CreatePatientSickHistory(record *models.XtPatientSickHistory) error {
  78. err := writeDb.Model(&models.XtPatientSickHistory{}).Create(record).Error
  79. return err
  80. }
  81. func CreatePatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error {
  82. err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Create(record).Error
  83. return err
  84. }
  85. func GetPatientRescueRecords(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientRescueRecord, error) {
  86. var records []*models.PatientRescueRecord
  87. err := readDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  88. if err != nil {
  89. return nil, err
  90. }
  91. return records, nil
  92. }
  93. func CreatePatientRescueRecord(record *models.PatientRescueRecord) error {
  94. err := writeDb.Model(&models.PatientRescueRecord{}).Create(record).Error
  95. return err
  96. }
  97. func ModifyPatientCourses(record *models.PatientDiseaseCourse) error {
  98. err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgID, record.PatientID, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
  99. return err
  100. }
  101. func ModifyPatientSickHistory(record *models.XtPatientSickHistory) error {
  102. err := writeDb.Save(record).Error
  103. //err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgId, record.PatientId, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
  104. return err
  105. }
  106. func ModifyPatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error {
  107. err := writeDb.Save(record).Error
  108. //err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgId, record.PatientId, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
  109. return err
  110. }
  111. func DeletePatientCoursesInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  112. err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  113. return err
  114. }
  115. func DeletePatientSickHistoryInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  116. err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  117. return err
  118. }
  119. func DeletePatientResuceRecordsInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  120. err := writeDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  121. return err
  122. }
  123. func DeletePatientPhysiqueCheckInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  124. err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  125. return err
  126. }
  127. func GetFaPiaoPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  128. var patient models.Patients
  129. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  130. if err != nil {
  131. if err == gorm.ErrRecordNotFound {
  132. return nil, nil
  133. } else {
  134. return nil, err
  135. }
  136. }
  137. return &patient, nil
  138. }
  139. func GetPatientByIDThree(orgID int64, patientID int64) (*models.Patients, error) {
  140. var patient models.Patients
  141. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  142. if err != nil {
  143. if err == gorm.ErrRecordNotFound {
  144. return nil, nil
  145. } else {
  146. return nil, err
  147. }
  148. }
  149. return &patient, nil
  150. }
  151. func GetLongDoctorAdvice(org_id int64, patient_id int64, start_time int64, end_time int64) (advice []*models.DoctorAdvice, err error) {
  152. err = XTReadDB().Where("user_org_id = ? and status=1 and patient_id = ? and created_time >=? and created_time<=? and advice_type=1", org_id, patient_id, 1514736000, end_time).Find(&advice).Error
  153. return advice, err
  154. }