public PatientInfoViewModel(tPatient patientInfo) { _doctorListViewModel = new DoctorListViewModel(); _doctorListViewModel.DoctorSelectEvent += (selectedDoctor) => { if (selectedDoctor != null) { DoctorId = selectedDoctor.DoctorId; DoctorName = selectedDoctor.FirstName + " " + selectedDoctor.LastName; } }; CopyPatientProperties(patientInfo); CommandSavePatientDetail = new RelayCommand<object>((parameter) => SavePatientData(parameter), (parameter)=> CanSave(parameter)); showDoctorCommand = new RelayCommand(ShowDoctor); }
private void SavePatientData(object parameter) { bool newlyAdd = PatientId == 0 ? true : false; // DoctorId = _DoctorId; var patient = new tPatient { PatientId = PatientId, FirstName = FirstName, LastName = LastName, DOB = DOB, SSN = SSN, DoctorId = DoctorId }; DataLayer.DB_SERVER db = new DataLayer.DB_SERVER(); if (newlyAdd) { db.Patient.Add(patient); db.SaveChanges(); PatientId = patient.PatientId; } else { var patientInDB = db.Patient.FirstOrDefault(e => e.PatientId == PatientId); if (patientInDB != null) { patientInDB.FirstName = FirstName; patientInDB.LastName = LastName; patientInDB.DOB = DOB; patientInDB.SSN = SSN; patientInDB.DoctorId = DoctorId; db.SaveChanges(); } } if (newlyAdd) if (PatentInsertedAction != null) PatentInsertedAction(PatientId); var commandParameter = Convert.ToInt16(parameter); if (commandParameter != null && commandParameter != 0) //save and next tab if (SaveAndNextTabAction != null) SaveAndNextTabAction.Invoke(); }
private void CopyPatientProperties(tPatient patientInfo) { PatientId = patientInfo.PatientId; FirstName = patientInfo.FirstName; LastName = patientInfo.LastName; SSN = patientInfo.SSN; DOB = patientInfo.PatientId == 0 ? System.DateTime.Now : patientInfo.DOB; DoctorId = patientInfo.DoctorId; if (patientInfo.PatientId != 0) { DB_SERVER _db = new DataLayer.DB_SERVER(); var patientDoctor= _db.Doctor.FirstOrDefault(e => e.DoctorId == patientInfo.DoctorId); DoctorId = patientDoctor.DoctorId; DoctorName = patientDoctor.FirstName + " " + patientDoctor.LastName; } }