Exemple #1
0
        public JobResponse <AnalysisResults> Get(Guid jobId)
        {
            var response = SasClientObject.Getjob(jobId);

            // If no data was received the process is still running, return an empty list
            if (response.Status != SasJobs.Messages.StatusCode.Done)
            {
                return(new JobResponse <AnalysisResults>(response, null));
            }

            // no data was returned
            if (response.Data.Tables.Count == 0)
            {
                return(new JobResponse <AnalysisResults>(response, null));
            }

            // Save analysis results
            var     resultData = new AnalysisResults(response.Data);
            Project project    = this.projectRepository.Find(resultData.SubmissionId, resultData.Profile ?? "");

            if (project != null)
            {
                var study = project.Studies.FirstOrDefault(s =>
                                                           s.SupplementNumber.Equals(resultData.SupplementId, StringComparison.InvariantCultureIgnoreCase) &&
                                                           s.StudyCode.Equals(resultData.StudyId, StringComparison.InvariantCultureIgnoreCase));
                if (study != null)
                {
                    var revision = new ProjectRevision
                    {
                        RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                        Name       = project.ProjectName,
                        Date       = DateTime.Now,
                        Owner      = Users.GetCurrentUserName(),
                        Action     = ActionTypes.Save
                    };
                    project.RevisionHistory.Add(revision);

                    study.RevisionId       = revision.RevisionId;
                    study.Concentration    = resultData.Concentration;
                    study.Pharmacokinetics = resultData.Pharmacokinetics;
                    study.Analytes         = null; // deprecated
                    study.Parameters       = null; // deprecated

                    this.projectRepository.CreateOrUpdate(project);
                }
            }

            // Clear individual data before sending the response back
            if (resultData.Concentration != null && resultData.Concentration.Sections != null)
            {
                resultData.Concentration.Sections.ForEach(s => s.SubSections = null);
            }
            if (resultData.Pharmacokinetics != null && resultData.Pharmacokinetics.Sections != null)
            {
                resultData.Pharmacokinetics.Sections.ForEach(s => s.SubSections = null);
            }

            return(new JobResponse <AnalysisResults>(response, resultData));
        }
        public string Save([FromBody] List <StudySettings> revisedMappingsList, string projectName = null)
        {
            if (revisedMappingsList != null && revisedMappingsList.Any())
            {
                string  submissionId = revisedMappingsList[0].NDAName;
                string  userName     = Users.GetCurrentUserName();
                Project project;

                // Generate a new configuration name from user and date
                if (projectName == null)
                {
                    var currentDate = DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
                    projectName = String.Format("{0}_{1}", userName, currentDate);
                }
                else // Attempt to load the project and save the studies into it
                {
                    project = this.projectRepository.Find(submissionId, projectName);

                    // If existing config file found and it contains studies
                    if (project != null && project.Studies.Any())
                    {
                        // Create a saved revision
                        var savedRevision = new ProjectRevision
                        {
                            RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                            Name       = projectName,
                            Date       = DateTime.Now,
                            Owner      = userName,
                            Action     = ActionTypes.Save
                        };
                        project.RevisionHistory.Add(savedRevision);

                        // For each study we want to save
                        foreach (var updatedStudy in revisedMappingsList)
                        {
                            // Find the study if existing
                            var oldStudy = project.Studies.FirstOrDefault(
                                s => s.StudyCode == updatedStudy.StudyCode &&
                                s.SupplementNumber == updatedStudy.SupplementNumber);

                            // if it does exist, update it
                            if (oldStudy != null)
                            {
                                oldStudy.RevisionId = savedRevision.RevisionId;

                                oldStudy.StudyDesign          = updatedStudy.StudyDesign;
                                oldStudy.StudyError           = updatedStudy.StudyError;
                                oldStudy.Cumulative           = updatedStudy.Cumulative;
                                oldStudy.SubjectCTCorrelation = updatedStudy.SubjectCTCorrelation;
                                oldStudy.ScatterPlot          = updatedStudy.ScatterPlot;
                                oldStudy.Demographictable     = updatedStudy.Demographictable;
                                oldStudy.UseEx               = updatedStudy.UseEx;
                                oldStudy.UseExRef            = updatedStudy.UseExRef;
                                oldStudy.UseSuppdm           = updatedStudy.UseSuppdm;
                                oldStudy.DisablePcCleanup    = updatedStudy.DisablePcCleanup;
                                oldStudy.UseCustomArms       = updatedStudy.UseCustomArms;
                                oldStudy.UseCustomPcVisit    = updatedStudy.UseCustomPcVisit;
                                oldStudy.UseCustomPcPctptnum = updatedStudy.UseCustomPcPctptnum;
                                oldStudy.UseCustomPpVisit    = updatedStudy.UseCustomPpVisit;

                                oldStudy.Cohorts            = updatedStudy.Cohorts;
                                oldStudy.StudyMappings      = updatedStudy.StudyMappings;
                                oldStudy.ArmMappings        = updatedStudy.ArmMappings;
                                oldStudy.PcVisitMappings    = updatedStudy.PcVisitMappings;
                                oldStudy.PcPctptnumMappings = updatedStudy.PcPctptnumMappings;
                                oldStudy.PpVisitMappings    = updatedStudy.PpVisitMappings;

                                oldStudy.Reports = updatedStudy.Reports;
                            }
                            else // Study not found, store it directly
                            {
                                updatedStudy.ProfileName = projectName;
                                project.Studies.Add(updatedStudy);
                            }
                        }
                        this.projectRepository.CreateOrUpdate(project);
                        return(projectName);
                    }
                }

                // project not found, store the whole list
                revisedMappingsList.ForEach(s =>
                                            { s.ProfileName = projectName; s.RevisionId = 1; });
                project = new Project
                {
                    ProjectName     = projectName,
                    SubmissionId    = submissionId,
                    Studies         = revisedMappingsList,
                    RevisionHistory = new List <ProjectRevision>()
                };
                var revision = new ProjectRevision
                {
                    RevisionId = 1,
                    Name       = projectName,
                    Owner      = userName,
                    Date       = DateTime.Now,
                    Action     = ActionTypes.Create
                };
                project.RevisionHistory.Add(revision);

                // Save user mappings
                this.projectRepository.CreateOrUpdate(project);
                return(projectName);
            }

            return(null);
        }