public static bool PatientExists(PatientModel patient) { using (var db = new PosEntities()) { var dbPatient = (from dbpnt in db.Patients where dbpnt.PatientNumber == patient.PatientNumber && dbpnt.PatientID != patient.PatientID select dbpnt.PatientNumber).FirstOrDefault(); if (dbPatient == null) return false; else return true; } }
private string GetDefaultNotesText(string userName, PatientModel patient) { int patientAge = (int) DateTime.Now.Subtract(patient.DateOfBirth.Value).Days / 30; //in months bool prematureBirth = patient.PrematureBirth != null && patient.PrematureBirth.Value && patientAge < 6; string examText = PatientRepository.ExamDefaultNotesText(userName, patientAge, prematureBirth); //replacing the special fields if (examText != null) { examText = examText.Replace("[PatientName]", patient.PatientName); examText = examText.Replace("[FirstName]", patient.FirstName); examText = examText.Replace("[LastName]", patient.LastName); examText = examText.Replace("[Age]", GetPatientAge(patient.DateOfBirth.Value)); examText = examText.Replace("[Sex]", GetSex(patient.DateOfBirth.Value, patient.Sex)); } return examText; }
private void SetPatientInfo(PatientModel patient, NotesModel notes) { SetPatientField(notes.patientID, patient.PatientID.ToString()); SetPatientField(notes.hdnPatientID, patient.PatientID.ToString()); SetPatientField(notes.PatientNumber, patient.PatientNumber.ToString()); SetPatientField(notes.Greeting, patient.Greeting); SetPatientField(notes.FirstName, patient.FirstName); SetPatientField(notes.MiddleName, patient.MiddleName); SetPatientField(notes.LastName, patient.LastName); SetPatientField(notes.NickName, patient.NickName); SetPatientField(notes.PatientName, patient.FirstName + " " + patient.LastName); SetPatientField(notes.DOB, patient.DateOfBirth.Value.ToShortDateString()); SetPatientField(notes.Sex, patient.Sex); SetPatientField(notes.PrematureBirth, patient.PrematureBirth == null ? false.ToString() : patient.PrematureBirth.Value.ToString()); SetPatientField(notes.HxFrom, patient.HxFrom); SetPatientField(notes.RefDoctor, patient.ReferredDoctor); SetPatientField(notes.Refd, patient.ReferredFrom); SetPatientField(notes.Allergies, patient.Allergies); SetPatientField(notes.Occupation, patient.Occupation); notes.tbAge.ColourType = (int)PosConstants.ColourType.Normal; }
public static bool PatientSave(PatientModel patient) { if(PosRepository.PatientExists(patient)) { throw new ApplicationException(PosMessage.PatientNumberExists); } using (var db = new PosEntities()) { var dbPatient = (from dbPat in db.Patients where dbPat.PatientID == patient.PatientID select dbPat).FirstOrDefault(); if (dbPatient == null) { //checking for unique patient number dbPatient = new Patient(); db.Patients.Add(dbPatient); } Mapper.Map<PatientModel, Patient>(patient, dbPatient); int result = db.SaveChanges(); if (result > 0) return true; else return false; } }