예제 #1
0
        public JsonResult NewCase(ViewModels.Case model)
        {
            string ICD10 = model.ICD10ID.Split(' ')[0];

            SADFM.Data.Models.ListItem icd10_ListItem = SADFM.Data.DataAccess.ListItem.GetList("ICD10", filter: li => li.Name == ICD10).FirstOrDefault();
            if (icd10_ListItem == null)
            {
                return(Json(new { Success = false, Error = "Cannot find ICD" }));
            }

            if (model.CaseId == null)
            {
                Data.Models.Account account = UserHelper.GetCurrentAccount();
                Guid accountId = account.GetId();

                SADFM.Data.Case caseObject = new SADFM.Data.Case()
                {
                    ICD10Id = icd10_ListItem.GetId(),
                    CaseId  = Guid.NewGuid(),
                    DateCreatedTimestamp = DateTime.Now,
                    LastUpdateTimestamp  = DateTime.Now,
                    StartDate            = model.StartDate,
                    EndDate             = model.EndDate,
                    PatientId           = SADFM.Data.Models.BaseModel.DecryptId(model.PatientId),
                    LastUpdateAccountId = UserHelper.GetCurrentAccount().GetId(),
                    ImpairmentGroupId   = model.ImpairmentGroupId != null?BaseModel.DecryptNullableId(model.ImpairmentGroupId) : null,
                                              ReferringDoctor               = model.ReferringDoctor,
                                              ReferringDoctorContact        = model.ReferringDoctorContact,
                                              ReferringDoctorEmail          = model.ReferringDoctorEmail,
                                              ReferringDoctorPracticeNumber = model.ReferringDoctorPracticeNumber,
                                              TreatingDoctor               = model.TreatingDoctor,
                                              TreatingDoctorContact        = model.TreatingDoctorContact,
                                              TreatingDoctorEmail          = model.TreatingDoctorEmail,
                                              TreatingDoctorPracticeNumber = model.TreatingDoctorPracticeNumber,
                                              AdmissionStatusId            = SADFM.Data.Models.BaseModel.DecryptNullableId(model.AdmissionStatusId)
                };



                if (UserHelper.GetCurrentAccount().Permissions.Count(x => x.GetClientId() == UserHelper.SelectedClientId && (x.PermissionDescription.Equals("Clinician"))) != 0)
                {
                    caseObject.PatientProviders.Add(new Data.PatientProvider()
                    {
                        AccountId           = UserHelper.GetCurrentAccount().GetId(),
                        AssignedTimestamp   = DateTime.Now,
                        CreatedTimestamp    = DateTime.Now,
                        LastUpdateAccountId = UserHelper.GetCurrentAccount().GetId(),
                        LastUpdateTimestamp = DateTime.Now,
                        ProviderId          = UserHelper.SelectedClientId.Value,
                        PatientProviderId   = Guid.NewGuid(),
                        PatientId           = SADFM.Data.Models.BaseModel.DecryptId(model.PatientId)
                    });
                }

                DataAccess.Account.AddCase(caseObject, UserHelper.GetCurrentAccount().GetId());

                return(Json(new
                {
                    Success = true,
                    Id = caseObject.CaseId.ToString("N")
                }));
            }
            else
            {
                return(Json(DataAccess.Account.UpdateCase(new Data.Case()
                {
                    CaseId = Data.Models.BaseModel.DecryptId(model.CaseId),
                    StartDate = model.StartDate,
                    EndDate = model.EndDate,
                    ICD10Id = icd10_ListItem.GetId(),
                    PatientId = Data.Models.BaseModel.DecryptId(model.PatientId),
                    ImpairmentGroupId = model.ImpairmentGroupId != null ? BaseModel.DecryptNullableId(model.ImpairmentGroupId) : null,
                    ReferringDoctor = model.ReferringDoctor,
                    ReferringDoctorContact = model.ReferringDoctorContact,
                    ReferringDoctorEmail = model.ReferringDoctorEmail,
                    ReferringDoctorPracticeNumber = model.ReferringDoctorPracticeNumber,
                    TreatingDoctor = model.TreatingDoctor,
                    TreatingDoctorContact = model.TreatingDoctorContact,
                    TreatingDoctorEmail = model.TreatingDoctorEmail,
                    TreatingDoctorPracticeNumber = model.TreatingDoctorPracticeNumber,
                    AdmissionStatusId = SADFM.Data.Models.BaseModel.DecryptNullableId(model.AdmissionStatusId)
                }, UserHelper.GetCurrentAccount().GetId())));
            }
        }
예제 #2
0
        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."
                }));
            }
        }