/// <summary> /// Save a new patient to the database with the data from a viewmodel. Set the /// registrant of the patient with the given data. /// </summary> /// <param name="viewModel">Viewmodel with the new patient data.</param> /// <param name="registrant">Username of the account that is registering the patient.</param> /// <param name="registrantId">Id of the account that is registering the patient.</param> /// <returns>Id of the newly created patient.</returns> public int Create(PatientViewModel viewModel, string registrant, int registrantId) { //Create a new patient from the viewmodel var patient = viewModel.ToNewModel(); //Set initial status to normal patient.PatientStatus = PatientStatus.Normal; //Set the registrant fields with the logged user data patient.RegistrantName = registrant; patient.RegistrantId = registrantId; Repository.Patients.Add(patient); Save(); //Check if status needs to be updated UpdateStatus(patient.Id); return(patient.Id); }