public static List<PTPatient> GetPatientsForDoctor(int doctorID, int afterTime) { try { //TODO: get active patients for doctor //TODO: needs testing //TODO: use the decided upon naming convs using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext()) { List<PTPatient> assignedPatients = new List<PTPatient>(); PTPatient tempPatient; var patientList = (from doctorProtocols in db.ProtocolDoctorXrefs join protocols in db.Protocols on doctorProtocols.ProtocolId equals protocols.Id join patients in db.Persons on protocols.PatientId equals patients.Id where doctorProtocols.DoctorId == doctorID && patients.IsActive == true select patients); foreach (Person patient in patientList.ToList()) { tempPatient = new PTPatient(); if (patient.Birthday.HasValue) { tempPatient.birthday = patient.Birthday.Value.ToShortDateString(); } tempPatient.email = patient.User.Email; tempPatient.firstName = patient.FirstName; tempPatient.ID = patient.Id; tempPatient.lastName = patient.LastName; tempPatient.middleName = patient.MiddleName; tempPatient.isActive = patient.IsActive; tempPatient.recentMessageCount = patient.Messages.Where(l => l.Timestamp > afterTime).Count(); assignedPatients.Add(tempPatient); } return assignedPatients; } } catch { return null; } }
public static PTPatient GetPatient(int doctorID, int patientID) { try { //TODO: get a specific patient with all their protocols, exercises, etc //TODO: needs testing using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext()) { PTPatient assignedPatient; PTProtocol tmpProtocol; PTExercise tmpExercise; PTExerciseProgress tmpProgress; var patient = (from doctorProtocols in db.ProtocolDoctorXrefs join protocols in db.Protocols on doctorProtocols.ProtocolId equals protocols.Id join patients in db.Persons on protocols.PatientId equals patients.Id where doctorProtocols.DoctorId == doctorID && patients.Id == patientID select patients).SingleOrDefault(); if (patient != null) { assignedPatient = new PTPatient(); if (patient.Birthday.HasValue) { assignedPatient.birthday = patient.Birthday.Value.ToShortDateString(); } assignedPatient.email = patient.User.Email; assignedPatient.firstName = patient.FirstName; assignedPatient.ID = patient.Id; assignedPatient.lastName = patient.LastName; assignedPatient.middleName = patient.MiddleName; assignedPatient.recentMessageCount = 0; //Check loads protocols and exercises assignedPatient.protocols = new List<PTProtocol>(); foreach (Protocol protocol in patient.Protocols) { tmpProtocol = new PTProtocol(); tmpProtocol.ID = protocol.Id; tmpProtocol.exercises = new List<PTExercise>(); tmpProtocol.name = protocol.Exercises.FirstOrDefault().ProtocolTemplate.Name; tmpProtocol.imageURL = protocol.ImagePath; //TODO: assuming exerciseCategory refers to CategoryId foreach (Exercise exercise in protocol.Exercises) { tmpExercise = new PTExercise(); tmpExercise.ID = exercise.Id; tmpExercise.exerciseCategory = exercise.ExerciseTemplate.CategoryId; tmpExercise.category = exercise.ExerciseTemplate.Category.Name; tmpExercise.days = exercise.Days; tmpExercise.specialInstructions = exercise.SpecialInstruction; tmpExercise.value = exercise.Value; tmpExercise.name = exercise.ExerciseTemplate.Name; if (exercise.EndDate.HasValue) { tmpExercise.endTime = exercise.EndDate.Value; } if (exercise.StartDate.HasValue) { tmpExercise.startTime = exercise.StartDate.Value; } //TODO: default values in general? if (exercise.TimerDuration.HasValue) { tmpExercise.timerDuration = exercise.TimerDuration.Value; } else { tmpExercise.timerDuration = 0; } if (exercise.HasTimer.HasValue) { tmpExercise.hasTimer = exercise.HasTimer.Value; } else { tmpExercise.hasTimer = false; } if (exercise.RepetitionQuantity.HasValue) { tmpExercise.repetitionQuantity = exercise.RepetitionQuantity.Value; } else { tmpExercise.repetitionQuantity = 0; } if (exercise.SetQuantity.HasValue) { tmpExercise.setQuantity = exercise.SetQuantity.Value; } tmpExercise.progress = new List<PTExerciseProgress>(); foreach (ExerciseProgressXref progress in exercise.ExerciseProgressXrefs) { tmpProgress = new PTExerciseProgress(); tmpProgress.ID = progress.Id; //TODO: what is Z expecting for the timestamp tmpProgress.timestamp = progress.Timestamp; tmpProgress.value = progress.Progress.Id; tmpExercise.progress.Add(tmpProgress); } //TODO: really there could be multiple images and stuff...blergh, just overwrite for now foreach (Instruction instruction in exercise.ExerciseTemplate.Instructions) { tmpExercise.instructions += instruction.Text; tmpExercise.imageURL = instruction.InstructionImages.First().ImagePath; tmpExercise.videoURL = instruction.VideoPath; } tmpProtocol.exercises.Add(tmpExercise); } assignedPatient.protocols.Add(tmpProtocol); } return assignedPatient; } } return null; } catch { return null; } }