Exemplo n.º 1
0
        public override async Task <IEnumerable <DataMartDTO> > Update(IEnumerable <DataMartDTO> values)
        {
            await CheckForDuplicates(values);

            var dmDTO = values.FirstOrDefault();

            if (dmDTO.ID == null || dmDTO.ID == Guid.Empty)
            {
                dmDTO.ID = Lpp.Utilities.DatabaseEx.NewGuid();
            }

            Guid networkID = await CNDSEntityUpdater.GetNetworkID(DataContext);

            if (CNDSEntityUpdater.CanUpdateCNDS)
            {
                try
                {
                    using (var cnds = new CNDSEntityUpdater(networkID))
                    {
                        await CNDSEntityUpdater.RegisterOrUpdateDataSources(dmDTO);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message, ex);
                    throw;
                }
            }

            var clientBasedTypeID = DataContext.DataMartTypes.Where(t => t.Name == "Client based").Select(t => t.ID).FirstOrDefault();
            var dm = DataContext.DataMarts.Find(dmDTO.ID);

            if (dm == null)
            {
                dm = new DataMart
                {
                    ID              = dmDTO.ID.Value,
                    Name            = dmDTO.Name,
                    Acronym         = dmDTO.Acronym,
                    OrganizationID  = dmDTO.OrganizationID.Value,
                    DataMartTypeID  = dmDTO.DataMartTypeID == Guid.Empty ? clientBasedTypeID : dmDTO.DataMartTypeID,
                    IsGroupDataMart = dmDTO.IsGroupDataMart,
                    UnattendedMode  = dmDTO.UnattendedMode,
                    IsLocal         = dmDTO.IsLocal,
                    Url             = dmDTO.Url,
                };
                if (dmDTO.AdapterID.HasValue)
                {
                    dm.AdapterID = dmDTO.AdapterID;
                }

                if (dmDTO.ProcessorID.HasValue)
                {
                    dm.ProcessorID = dmDTO.ProcessorID;
                }

                DataContext.DataMarts.Add(dm);
            }
            else
            {
                dm.Name            = dmDTO.Name;
                dm.Acronym         = dmDTO.Acronym;
                dm.OrganizationID  = dmDTO.OrganizationID.Value;
                dm.DataMartTypeID  = dmDTO.DataMartTypeID == Guid.Empty ? clientBasedTypeID : dm.DataMartTypeID;
                dm.IsGroupDataMart = dmDTO.IsGroupDataMart;
                dm.UnattendedMode  = dmDTO.UnattendedMode;
                dm.IsLocal         = dmDTO.IsLocal;
                dm.Url             = dmDTO.Url;

                if (dmDTO.AdapterID.HasValue)
                {
                    dm.AdapterID = dmDTO.AdapterID;
                }

                if (dmDTO.ProcessorID.HasValue)
                {
                    dm.ProcessorID = dmDTO.ProcessorID;
                }
            }

            DataContext.SaveChanges();

            IList <DataMartDTO> returnDM = new List <DataMartDTO>();

            returnDM.Add(dmDTO);
            return(returnDM);
        }
Exemplo n.º 2
0
        public async Task <Guid> Copy(Guid datamartID)
        {
            var existing = await(from dm in DataContext.DataMarts where dm.ID == datamartID && dm.DataMartTypeID != CNDSImportedDataMartTypeID select dm).SingleOrDefaultAsync();

            if (existing == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The DataMart could not be found."));
            }

            if (!await DataContext.HasPermissions <DataMart>(Identity, existing, PermissionIdentifiers.DataMart.Copy))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "You do not have permission to copy the specified DataMart."));
            }

            string newAcronym = "New " + existing.Acronym;
            string newName    = "New " + existing.Name;

            while (await(from p in DataContext.DataMarts where !p.Deleted && (p.Name == newName && p.Acronym == newAcronym) select p).AnyAsync())
            {
                newAcronym = "New " + newAcronym;
                newName    = "New " + newName;
            }

            var datamart = new DataMart
            {
                Acronym                                    = newAcronym,
                StartDate                                  = DateTime.Today,
                Name                                       = newName,
                DataMartType                               = existing.DataMartType,
                DataMartTypeID                             = existing.DataMartTypeID,
                AvailablePeriod                            = existing.AvailablePeriod,
                ContactEmail                               = existing.ContactEmail,
                ContactFirstName                           = existing.ContactFirstName,
                ContactLastName                            = existing.ContactLastName,
                ContactPhone                               = existing.ContactPhone,
                SpecialRequirements                        = existing.SpecialRequirements,
                UsageRestrictions                          = existing.UsageRestrictions,
                Deleted                                    = existing.Deleted,
                HealthPlanDescription                      = existing.HealthPlanDescription,
                OrganizationID                             = existing.OrganizationID,
                Organization                               = existing.Organization,
                IsGroupDataMart                            = existing.IsGroupDataMart,
                UnattendedMode                             = existing.UnattendedMode,
                Description                                = existing.Description,
                EndDate                                    = existing.EndDate,
                DataUpdateFrequency                        = existing.DataUpdateFrequency,
                InpatientEHRApplication                    = existing.InpatientEHRApplication,
                OutpatientEHRApplication                   = existing.OutpatientEHRApplication,
                LaboratoryResultsAny                       = existing.LaboratoryResultsAny,
                LaboratoryResultsClaims                    = existing.LaboratoryResultsClaims,
                LaboratoryResultsTestName                  = existing.LaboratoryResultsTestName,
                LaboratoryResultsDates                     = existing.LaboratoryResultsDates,
                LaboratoryResultsTestLOINC                 = existing.LaboratoryResultsTestLOINC,
                LaboratoryResultsTestSNOMED                = existing.LaboratoryResultsTestSNOMED,
                LaboratoryResultsSpecimenSource            = existing.LaboratoryResultsSpecimenSource,
                LaboratoryResultsTestDescriptions          = existing.LaboratoryResultsTestDescriptions,
                LaboratoryResultsOrderDates                = existing.LaboratoryResultsOrderDates,
                LaboratoryResultsTestResultsInterpretation = existing.LaboratoryResultsTestResultsInterpretation,
                LaboratoryResultsTestOther                 = existing.LaboratoryResultsTestOther,
                LaboratoryResultsTestOtherText             = existing.LaboratoryResultsTestOtherText,
                InpatientEncountersAny                     = existing.InpatientEncountersAny,
                InpatientEncountersEncounterID             = existing.InpatientEncountersEncounterID,
                InpatientEncountersProviderIdentifier      = existing.InpatientEncountersProviderIdentifier,
                InpatientDatesOfService                    = existing.InpatientDatesOfService,
                InpatientICD9Procedures                    = existing.InpatientICD9Procedures,
                InpatientICD10Procedures                   = existing.InpatientICD10Procedures,
                InpatientICD9Diagnosis                     = existing.InpatientICD9Diagnosis,
                InpatientICD10Diagnosis                    = existing.InpatientICD10Diagnosis,
                InpatientSNOMED                            = existing.InpatientSNOMED,
                InpatientHPHCS                             = existing.InpatientHPHCS,
                InpatientDisposition                       = existing.InpatientDisposition,
                InpatientDischargeStatus                   = existing.InpatientDischargeStatus,
                InpatientOther                             = existing.InpatientOther,
                InpatientOtherText                         = existing.InpatientOtherText,
                OutpatientEncountersAny                    = existing.OutpatientEncountersAny,
                OutpatientEncountersEncounterID            = existing.OutpatientEncountersEncounterID,
                OutpatientEncountersProviderIdentifier     = existing.OutpatientEncountersProviderIdentifier,
                OutpatientClinicalSetting                  = existing.OutpatientClinicalSetting,
                OutpatientDatesOfService                   = existing.OutpatientDatesOfService,
                OutpatientICD9Procedures                   = existing.OutpatientICD9Procedures,
                OutpatientICD10Procedures                  = existing.OutpatientICD10Procedures,
                OutpatientICD9Diagnosis                    = existing.OutpatientICD9Diagnosis,
                OutpatientICD10Diagnosis                   = existing.OutpatientICD10Diagnosis,
                OutpatientSNOMED                           = existing.OutpatientSNOMED,
                OutpatientHPHCS                            = existing.OutpatientHPHCS,
                OutpatientOther                            = existing.OutpatientOther,
                OutpatientOtherText                        = existing.OutpatientOtherText,
                ERPatientID                                = existing.ERPatientID,
                EREncounterID                              = existing.EREncounterID,
                EREnrollmentDates                          = existing.EREnrollmentDates,
                EREncounterDates                           = existing.EREncounterDates,
                ERClinicalSetting                          = existing.ERClinicalSetting,
                ERICD9Diagnosis                            = existing.ERICD9Diagnosis,
                ERICD10Diagnosis                           = existing.ERICD10Diagnosis,
                ERHPHCS                                    = existing.ERHPHCS,
                ERNDC                                      = existing.ERNDC,
                ERSNOMED                                   = existing.ERSNOMED,
                ERProviderIdentifier                       = existing.ERProviderIdentifier,
                ERProviderFacility                         = existing.ERProviderFacility,
                EREncounterType                            = existing.EREncounterType,
                ERDRG                                      = existing.ERDRG,
                ERDRGType                                  = existing.ERDRGType,
                EROther                                    = existing.EROther,
                EROtherText                                = existing.EROtherText,
                DemographicsAny                            = existing.DemographicsAny,
                PatientBehaviorInstruments                 = existing.PatientBehaviorInstruments,
                PharmacyDispensingAny                      = existing.PharmacyDispensingAny,
                OtherClaims                                = existing.OtherClaims,
                Registeries                                = existing.Registeries,
                OtherInpatientEHRApplication               = existing.OtherInpatientEHRApplication,
                OtherOutpatientEHRApplication              = existing.OtherOutpatientEHRApplication,
                DataModel                                  = existing.DataModel,
                OtherDataModel                             = existing.OtherDataModel,
                IsLocal                                    = existing.IsLocal,
                Url = existing.Url ?? ""
            };

            DataContext.DataMarts.Add(datamart);

            var dmDTO = new DataMartDTO {
                ID             = datamart.ID,
                Name           = datamart.Name,
                Acronym        = datamart.Acronym,
                OrganizationID = datamart.OrganizationID,
                AdapterID      = datamart.AdapterID
            };


            Guid networkID = await CNDSEntityUpdater.GetNetworkID(DataContext);

            if (CNDSEntityUpdater.CanUpdateCNDS)
            {
                try
                {
                    using (var cnds = new CNDSEntityUpdater(networkID))
                    {
                        IList <Guid> ids = new List <Guid>();
                        ids.Add(datamartID);
                        ids.Add(datamart.OrganizationID);
                        var networkEntity = await CNDSEntityUpdater.GetCNDSEntityIdentifiers(ids);

                        Guid?cndsOrganizationID = networkEntity.Where(x => x.NetworkEntityID == datamart.OrganizationID).Select(x => x.EntityID).FirstOrDefault();
                        var  cndsDataSourceID   = networkEntity.Where(x => x.NetworkEntityID == datamartID).Select(o => o.EntityID).FirstOrDefault();

                        var availDMMetadata = await CNDSEntityUpdater.CNDS.Domain.List("$filter=EntityType eq Lpp.CNDS.DTO.Enums.EntityType'2'");

                        var oldMetadata = await CNDSEntityUpdater.CNDS.DataSources.ListDataSourceDomains(cndsDataSourceID);

                        List <MetadataDTO> meta = new List <MetadataDTO>();
                        foreach (var metadata in availDMMetadata.Where(x => x.ParentDomainID == null))
                        {
                            meta.Add(cnds.GetMetadataChildren(metadata.ID, availDMMetadata, oldMetadata, null, null));
                        }
                        dmDTO.Metadata = meta;

                        await CNDSEntityUpdater.RegisterOrUpdateDataSources(dmDTO);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message, ex);
                    throw;
                }
            }

            await DataContext.SaveChangesAsync();

            //DataMart Acls
            var existingDataMartAcls = await(from a in DataContext.DataMartAcls where a.DataMartID == existing.ID select a).ToArrayAsync();

            foreach (var existingDataMartAcl in existingDataMartAcls)
            {
                var count = await DataContext.Database.ExecuteSqlCommandAsync(@"IF NOT EXISTS(SELECT NULL FROM AclDataMarts WHERE DataMartID = @DataMartID AND SecurityGroupID = @SecurityGroupID AND PermissionID = @PermissionID)
	INSERT INTO AclDataMarts (DataMartID, SecurityGroupID, PermissionID, Allowed, Overridden) VALUES (@DataMartID, @SecurityGroupID, @PermissionID, @Allowed, 1)"    , new SqlParameter("DataMartID", datamart.ID), new SqlParameter("SecurityGroupID", existingDataMartAcl.SecurityGroupID), new SqlParameter("PermissionID", existingDataMartAcl.PermissionID), new SqlParameter("Allowed", existingDataMartAcl.Allowed));
            }

            return(datamart.ID);
        }