patient_dataconfig_service.go 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package service
  2. import (
  3. "XT_New/models"
  4. "time"
  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 GetPatientCourseOfDisease(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientDiseaseCourse, error) {
  25. var records []*models.PatientDiseaseCourse
  26. 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
  27. if err != nil {
  28. return nil, err
  29. }
  30. return records, nil
  31. }
  32. func GetPatientSickHistory(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientSickHistory, error) {
  33. var records []*models.XtPatientSickHistory
  34. 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
  35. if err != nil {
  36. return nil, err
  37. }
  38. return records, nil
  39. }
  40. func GetPatientSickHistoryByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientSickHistory, error) {
  41. var records []*models.XtPatientSickHistory
  42. 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
  43. if err != nil {
  44. return nil, err
  45. }
  46. return records, nil
  47. }
  48. func GetPatienttPhysiqueByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientPhysiqueCheck, error) {
  49. var records []*models.XtPatientPhysiqueCheck
  50. 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
  51. if err != nil {
  52. return nil, err
  53. }
  54. return records, nil
  55. }
  56. func GetPatientPhysiqueCheck(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientPhysiqueCheck, error) {
  57. var records []*models.XtPatientPhysiqueCheck
  58. 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
  59. if err != nil {
  60. return nil, err
  61. }
  62. return records, nil
  63. }
  64. func GetLastPatientPhysiqueCheck(orgID int64, patientID int64, record_date int64) (records models.XtPatientPhysiqueCheck, err error) {
  65. 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
  66. return records, err
  67. }
  68. func CreatePatientCourseOfDisease(record *models.PatientDiseaseCourse) error {
  69. err := writeDb.Model(&models.PatientDiseaseCourse{}).Create(record).Error
  70. return err
  71. }
  72. func CreatePatientSickHistory(record *models.XtPatientSickHistory) error {
  73. err := writeDb.Model(&models.XtPatientSickHistory{}).Create(record).Error
  74. return err
  75. }
  76. func CreatePatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error {
  77. err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Create(record).Error
  78. return err
  79. }
  80. func GetPatientRescueRecords(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientRescueRecord, error) {
  81. var records []*models.PatientRescueRecord
  82. 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
  83. if err != nil {
  84. return nil, err
  85. }
  86. return records, nil
  87. }
  88. func CreatePatientRescueRecord(record *models.PatientRescueRecord) error {
  89. err := writeDb.Model(&models.PatientRescueRecord{}).Create(record).Error
  90. return err
  91. }
  92. func ModifyPatientCourses(record *models.PatientDiseaseCourse) error {
  93. 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
  94. return err
  95. }
  96. func ModifyPatientSickHistory(record *models.XtPatientSickHistory) error {
  97. err := writeDb.Save(record).Error
  98. //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
  99. return err
  100. }
  101. func ModifyPatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) 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 DeletePatientCoursesInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  107. 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
  108. return err
  109. }
  110. func DeletePatientSickHistoryInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  111. 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
  112. return err
  113. }
  114. func DeletePatientResuceRecordsInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  115. 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
  116. return err
  117. }
  118. func DeletePatientPhysiqueCheckInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  119. 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
  120. return err
  121. }
  122. func GetFaPiaoPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  123. var patient models.Patients
  124. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  125. if err != nil {
  126. if err == gorm.ErrRecordNotFound {
  127. return nil, nil
  128. } else {
  129. return nil, err
  130. }
  131. }
  132. return &patient, nil
  133. }