public JsonResult UpdatePatient(ViewModels.Patient model) { DataAccess.Account.UpdatePatient(new Data.Models.Patient() { AdmitFrom = model.AdmitFrom, AdmitFromID = model.AdmitFromID, Avatar = model.Avatar, BirthDate = model.BirthDate, City = model.City, CityId = model.CityId, ContactNumber = model.ContactNumber, Country = model.Country, CountryID = model.CountryID, DischargeTo = model.DischargeTo, DischargeToID = model.DischargeToID, FirstName = model.FirstName, Gender = model.Gender, GenderID = model.GenderID, IDNumber = model.IDNumber, LastName = model.LastName, ID = BaseModel.EncryptId(model.PatientId), MedicalScheme = model.MedicalScheme, MedicalSchemeID = model.MedicalSchemeID, MedicalSchemeNo = model.MedicalSchemeNo, NextOfKinContact = model.NextOfKinContact, NextOfKinEmail = model.NextOfKinEmail, NextOfKinName = model.NextOfKinName, NextOfKinRelationship = model.NextOfKinRelationship, PostalCode = model.PostalCode, Province = model.Province, ProvinceId = model.ProvinceId, Race = model.Race, RaceID = model.RaceID, Street = model.Street, SupportServices = model.SupportServices, Title = model.Title, TitleId = model.TitleId, ResidentialEnvironment = model.ResidentialEnvironment, ResidentialEnvironmentID = model.ResidentialEnvironmentID }, UserHelper.GetCurrentAccount().GetId()); return(Json(new UpdateResult(true))); }
public JsonResult NewPatient(ViewModels.Patient model) { Data.Models.Account account = UserHelper.GetCurrentAccount(); Guid accountId = account.GetId(); try { Data.Patient patient = new Data.Patient() { ResidentialEnvironmentId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.ResidentialEnvironmentID), AdmitFromId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.AdmitFromID), Street = model.Street, DischargeToId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.DischargeToID), FirstName = model.FirstName, PatientId = Guid.NewGuid(), LastName = model.LastName, DateCreatedTimestamp = DateTime.Now, LastUpdateTimestamp = DateTime.Now, LastUpdateAccountId = accountId, IDNumber = model.IDNumber, ContactNumber = model.ContactNumber, ProvinceId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.ProvinceId), CityId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.CityId), PostalCode = model.PostalCode, NextOfKinName = model.NextOfKinName, NextOfKinContact = model.NextOfKinContact, NextOfKinEmail = model.NextOfKinEmail, NextOfKinRelationship = model.NextOfKinRelationship, RaceId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.RaceID), GenderId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.GenderID), BirthDate = Convert.ToDateTime(model.BirthDate), TitleId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.TitleId), CountryId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.CountryID), MedicalSchemeMembershipNumber = model.MedicalSchemeNo, PatientSupportServices = model.SupportServices != null?model.SupportServices.Select(x => new Data.PatientSupportService() { SupportServiceId = x.SupportServiceId, Note = x.Note, LastUpdatedTimestamp = DateTime.Now, LastUpdatedAccountId = UserHelper.GetCurrentAccount().GetId() }).ToList() : null }; if (model.MedicalSchemeID != null) { patient.MedicalSchemeId = SADFM.Data.Models.BaseModel.DecryptId(model.MedicalSchemeID); } DataAccess.Account.AddPatient(patient, accountId); if (UserHelper.SelectedClientId.HasValue) { bool hasClosedCase; Guid?caseId; DataAccess.Patient.AddPatientProvider(new Data.Models.PatientProvider() { AssignedTimestamp = DateTime.Now, DischargedTimestamp = null, ProviderId = BaseModel.EncryptId(UserHelper.SelectedClientId.Value), CaseId = null, AccountID = BaseModel.EncryptId(accountId), PatientId = BaseModel.EncryptId(patient.PatientId), PatientProviderID = null }, accountId, out hasClosedCase, out caseId); } return(Json(new { Success = true, Id = patient.PatientId.ToString("N"), Guid = patient.PatientId.ToString() })); } catch (Exception e) { SADFM.Base.NLogHelper.WriteEvent(NLog.LogLevel.Info, "PatientController.NewPatient" + " ->> " + "Account: " + account.Username + "\r\n" + e.Message); return(Json(new { Success = false, Message = "Error has occurred." })); } }