private void addReferencesToDataset(DataSet data, StudySettings study) { if (this.Settings.References == null || study.Cohorts == null) { return; } var references = new DataTable("references"); references.Columns.Add("Cohort", typeof(string)); references.Columns.Add("Number", typeof(int)); references.Columns.Add("Reference", typeof(string)); // Merge with study cohorts list to obtain the cohort number var cohortReferences = this.Settings.References.Join(study.Cohorts, c1 => c1.Cohort, c2 => c2.Name, (c1, c2) => new Cohort { Name = c2.Name, Number = c2.Number, Reference = c1.Reference }); foreach (var cohort in cohortReferences) { references.Rows.Add( cohort.Name, cohort.Number, cohort.Reference); } if (data.Tables.Contains("references")) { data.Tables.Remove("references"); } data.Tables.Add(references); }
private void DeleteAnalysisResults(StudySettings studyMetadata) { // Delete report settings var study = new MappingController().LoadStudy(studyMetadata.NDAName, studyMetadata.ProfileName, studyMetadata.SupplementNumber, studyMetadata.StudyCode); // Delete reports study.Reports = new List <Report>(); study.Analytes = null; study.Parameters = null; study.Concentration = null; study.Pharmacokinetics = null; new MappingController().SaveStudy(study, study.NDAName, study.ProfileName, study.SupplementNumber, study.StudyCode); // Delete the output files var userName = Users.GetCurrentUserName(); var studyPath = string.Format(@"\\{0}\Output Files\PKView\{1}\{2}\{3}\{4}\{5}", iPortalApp.AppServerName, userName, study.ProfileName, study.NDAName, study.SupplementNumber, study.StudyCode); var studyFolder = new DirectoryInfo(studyPath); if (studyFolder.Exists) { studyFolder.Delete(true); } }
/// <summary> /// Add report settings to the dataset to be sent to SAS /// </summary> /// <param name="data">dataset where the tables will be added</param> /// <param name="study">study this repor relates to</param> internal void AddMetaSettingsToDataset(DataSet data, StudySettings study, string StudyCode) { // Report name var reportConfig = new DataTable("reportConfig"); reportConfig.Columns.Add("Name", typeof(string)); reportConfig.Columns.Add("Value", typeof(string)); reportConfig.Columns.Add("StudyCode", typeof(string)); reportConfig.Rows.Add("Name", this.Name, StudyCode); data.Tables.Add(reportConfig); // exclude subject information var excludesubjectinfo = new DataTable("excludesubject"); excludesubjectinfo.Columns.Add("BigthanExcludeSD", typeof(float)); excludesubjectinfo.Columns.Add("SmallthanExcludeSD", typeof(float)); excludesubjectinfo.Columns.Add("ExcludeParameters1", typeof(string)); excludesubjectinfo.Columns.Add("ExcludeParameters2", typeof(string)); excludesubjectinfo.Columns.Add("percent", typeof(int)); excludesubjectinfo.Rows.Add( this.BigthanExcludeSD, this.SmallthanExcludeSD, this.ExcludeParameters1, this.ExcludeParameters2, this.percent); data.Tables.Add(excludesubjectinfo); // exclude edited subject data //this.excludedatatable = null; //data.Tables.Add(this.excludedatatable); // Add different data tables depending on the type of report this.Type = 2; switch (this.Type) { case 1: // Pk tables addReferencesToDataset(data, study); addAnalytesToDataset(data); addParametersToDataset(data); addStatisticalMethodToDataset(data); addPkSortingOptionsToDataset(data); break; case 2: // Forest plots addMetaReferencesToDataset(data, study, StudyCode); addMetaAnalytesToDataset(data, StudyCode); addMetaParametersToDataset(data, StudyCode); addMetaStatisticalMethodToDataset(data, StudyCode); addMetaPkSortingOptionsToDataset(data, StudyCode); break; case 3: // NCA Analysis addConcentrationToDataset(data, study); addPharmacokineticsToDataset(data, study); break; } }
public DateTime?GenerateReport([FromBody] StudySettings revisedMappings, int reportId) { // Apply Ex setting for reference computation revisedMappings.UseEx = revisedMappings.UseExRef; DataSet data = revisedMappings.ToReportGenerationDataSet(reportId); Report newReport = revisedMappings.Reports[reportId]; JobResponse response; Guid id; // Clean up old report files first DeleteReportFiles(revisedMappings, newReport.Name); // Use different SAS Api calls for different types of report switch (newReport.Type) { case 1: id = SasClientObject.NewJob(data, "GenerateReport"); break; case 2: id = SasClientObject.NewJob(data, "GenerateForestPlot"); break; case 3: id = SasClientObject.NewJob(data, "GenerateNcaAnalysis"); break; default: return(null); } // Wait for job response do { System.Threading.Thread.Sleep(500); response = SasClientObject.Getjob(id); } while (response.Status == SasJobs.Messages.StatusCode.Running); // if done save report and return creation date if (response.Status == SasJobs.Messages.StatusCode.Done) { // Set the creation date newReport.CreationDate = DateTime.Now; newReport.Generated = true; // If success, save the settings and return the creation date DoSaveReport(revisedMappings.NDAName, revisedMappings.SupplementNumber, revisedMappings.StudyCode, revisedMappings.ProfileName, newReport); // If nca, generate script if (newReport.Type == 3) { var scriptBuilder = new NcaBuilder(revisedMappings, newReport); scriptBuilder.Create(); } return(newReport.CreationDate); } else { return(null); } }
private void DeleteReportFiles(StudySettings study, string reportName) { var userName = Users.GetCurrentUserName(); var reportPath = string.Format(@"\\{0}\Output Files\PKView\{1}\{2}\{3}\{4}\{5}\{6}", iPortalApp.AppServerName, userName, study.ProfileName, study.NDAName, study.SupplementNumber, study.StudyCode, reportName); var reportFolder = new DirectoryInfo(reportPath); if (reportFolder.Exists) { reportFolder.Delete(true); } }
public int SaveReport([FromBody] StudySettings revisedMappings, int reportId) { var newReport = revisedMappings.Reports[reportId]; newReport.Generated = false; // Save report settings into the user study profile (FIXME: Improve profile management) DoSaveReport(revisedMappings.NDAName, revisedMappings.SupplementNumber, revisedMappings.StudyCode, revisedMappings.ProfileName, newReport); return(0); }
public string Run([FromBody] StudySettings revisedMappings) { // Apply Ex setting used for reference computation revisedMappings.UseEx = revisedMappings.UseExRef; DataSet data = revisedMappings.ToMappingDataSet(true); // Delete old analysis results DeleteAnalysisResults(revisedMappings); // Run the analysis code return(SasClientObject.NewJob(data, "RunStudyAnalysis").ToString()); }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } StudySettings s = (StudySettings)obj; m_startingGain = s.m_startingGain; m_increaseFactor = s.m_increaseFactor; m_decreaseFactor = s.m_decreaseFactor; m_fixedNumberOfReversalPoints = s.m_fixedNumberOfReversalPoints; m_usedNumberOfReversalPoints = s.m_usedNumberOfReversalPoints; return((m_startingGain == s.m_startingGain) && (m_increaseFactor == s.m_increaseFactor) && (m_decreaseFactor == s.m_decreaseFactor) && (m_fixedNumberOfReversalPoints == s.m_fixedNumberOfReversalPoints) && (m_usedNumberOfReversalPoints == s.m_usedNumberOfReversalPoints)); }
public IDictionary <string, IEnumerable <string> > GetReference([FromBody] StudySettings revisedMappings) { // Apply Ex setting for reference computation revisedMappings.UseEx = revisedMappings.UseExRef; DataSet data = revisedMappings.ToMappingDataSet(); JobResponse response; var id = SasClientObject.NewJob(data, "ListReferences"); do { System.Threading.Thread.Sleep(500); response = SasClientObject.Getjob(id); } while (response.Status == SasJobs.Messages.StatusCode.Running); // return the potential references if (response.Status == SasJobs.Messages.StatusCode.Done) { var resultsTable = response.Data.Tables[0]; if (resultsTable.Rows.Count > 0) { var referenceTable = new Dictionary <string, IEnumerable <string> >(); foreach (var row in resultsTable.AsEnumerable()) { var cohort = row["CohortDescription"].ToString(); if (!referenceTable.ContainsKey(cohort)) { referenceTable.Add(cohort, new List <string>()); } var reference = row["Reference"].ToString().Trim(); if (!String.IsNullOrWhiteSpace(reference)) { ((List <string>)referenceTable[cohort]) .Add(reference); } } return(referenceTable); } } return(null); }
public int DeleteReport([FromBody] StudySettings revisedMappings, int reportId) { // Save report settings into the user study profile (FIXME: Improve profile management) var study = new MappingController().LoadStudy(revisedMappings.NDAName, revisedMappings.ProfileName, revisedMappings.SupplementNumber, revisedMappings.StudyCode, null, true); var reportName = revisedMappings.Reports[reportId].Name; // Add or replace report var reportList = study.Reports.Where(report => report.Name != reportName).ToList(); study.Reports = reportList; new MappingController().SaveStudy(study, study.NDAName, study.ProfileName, study.SupplementNumber, study.StudyCode); // Delete report files DeleteReportFiles(study, reportName); return(0); }
public int GenerateDemographicSummary([FromBody] StudySettings revisedMappings) { // Apply Ex setting for reference computation revisedMappings.UseEx = revisedMappings.UseExRef; DataSet data = revisedMappings.ToMappingDataSet(true); JobResponse response; Guid id; id = SasClientObject.NewJob(data, "Reports_DemographicSummary"); // Wait for job response do { System.Threading.Thread.Sleep(500); response = SasClientObject.Getjob(id); } while (response.Status == SasJobs.Messages.StatusCode.Running); // Return the completion code return(response.Status == SasJobs.Messages.StatusCode.Done ? 0 : -1); }
/// <summary> /// Add Excluded data to the dataset to be sent to SAS /// </summary> /// <param name="data">dataset where the tables will be added</param> /// <param name="study">study this repor relates to</param> internal void AddExcludedataToDataset(DataSet data, StudySettings study) { // exclude data var excludedata = new DataTable("Excludedata"); excludedata = study.excludedatatable; excludedata.TableName = "Excludedata"; for (int i = excludedata.Rows.Count - 1; i >= 0; i--) { DataRow dr = excludedata.Rows[i]; if (study.ExcludeIndex[i] == "False") { dr.Delete(); } } excludedata.AcceptChanges(); data.Tables.Add(excludedata); }
public MetaBuilder(StudySettings study, Report report) { this.template = new TemplateEngine(); // Location of the template this.templateFolder = HostingEnvironment.MapPath(@"~\Content\templates\PkView"); this.template.TemplatePath = Path.Combine(this.templateFolder, "MetaForestPlot.sas"); // Location where the script will be created this.outputFolder = string.Format( @"\\{0}\Output Files\PKView\{1}\{2}\{3}\{4}\{5}\{6}", iPortalApp.AppServerName, Users.GetCurrentUserName(), study.ProfileName, study.NDAName, study.SupplementNumber, "Meta", "Package"); string scriptName = String.Format("MetaForestPlot.sas"); this.template.OutputPath = Path.Combine(this.outputFolder, scriptName); }
public int?DetermineStudyDesign([FromBody] StudySettings revisedMappings) { DataSet data = revisedMappings.ToMappingDataSet(); JobResponse response; var id = SasClientObject.NewJob(data, "DetermineStudyDesign"); //var id = SasClientObject.NewJob(data, "variabilitytest4"); do { System.Threading.Thread.Sleep(500); response = SasClientObject.Getjob(id); } while (response.Status == SasJobs.Messages.StatusCode.Running); // return the potential references if (response.Status == SasJobs.Messages.StatusCode.Done) { var resultsTable = response.Data.Tables[0]; if (resultsTable.Rows.Count > 0) { var studyDesign = resultsTable.AsEnumerable().First()["StudyDesign"].ToString(); switch (studyDesign.ToLower()) { case "unknown": return(1); case "sequential": return(2); case "parallel": return(3); case "crossover": return(4); default: return(0); } } } return(null); }
/// <summary> /// Add the pk data to the SAS input, already subset by the UI options /// </summary> /// <param name="data"></param> private void addPharmacokineticsToDataset(DataSet data, StudySettings study) { var pharmacokinetics = new DataTable("pharmacokinetics"); pharmacokinetics.Columns.Add("Selected", typeof(string)); pharmacokinetics.Columns.Add("Result", typeof(double)); pharmacokinetics.Columns.Add("Parameter", typeof(string)); pharmacokinetics.Columns.Add("Treatment", typeof(string)); pharmacokinetics.Columns.Add("Specimen", typeof(string)); pharmacokinetics.Columns.Add("Analyte", typeof(string)); pharmacokinetics.Columns.Add("Period", typeof(string)); pharmacokinetics.Columns.Add("Arm", typeof(string)); pharmacokinetics.Columns.Add("Cohort", typeof(string)); pharmacokinetics.Columns.Add("Subject", typeof(string)); // Load individual concentration from xml file var fullStudy = new MappingController().LoadStudy(study.NDAName, study.ProfileName, study.SupplementNumber, study.StudyCode, null, true); // Find the subset of selected pk string period = this.Settings.SelectedPeriod; string specimen = this.Settings.SelectedPpSpecimen; if (period == "noPeriod") { period = null; } if (specimen == "noSpecimen") { specimen = null; } var selectedSections = fullStudy.Pharmacokinetics.Sections.Where(s => s.Cohort == this.Settings.SelectedCohort && s.Analyte == this.Settings.SelectedPpAnalyte && s.Period == period && s.Specimen == specimen); // Create a dictionary of pk parameter mappings var pkParameterMappings = new Dictionary <string, List <string> >(); addParameterSelectionToTable(pkParameterMappings, this.Settings.SelectedAuct, "AUCT"); addParameterSelectionToTable(pkParameterMappings, this.Settings.SelectedAucInfinity, "AUCI"); addParameterSelectionToTable(pkParameterMappings, this.Settings.SelectedCmax, "CMAX"); addParameterSelectionToTable(pkParameterMappings, this.Settings.SelectedThalf, "THALF"); addParameterSelectionToTable(pkParameterMappings, this.Settings.SelectedTmax, "TMAX"); // Add the pk data to the table foreach (PkDataSection section in selectedSections) { foreach (PkDataSubSection subsection in section.SubSections) { foreach (IndividualPk individual in subsection.Individual) { // Add each value to the dataset foreach (var pkValue in individual.PkValues) { // Add one row for each selection of the pk parameter or one row with empty selection List <string> selections; if (!pkParameterMappings.TryGetValue(pkValue.Parameter, out selections)) { selections = new List <string> { "" } } ; string suffix = ""; int i = 1; foreach (var selection in selections) { pharmacokinetics.Rows.Add( selection, pkValue.Value.HasValue ? (object)pkValue.Value.Value : DBNull.Value, pkValue.Parameter + suffix, section.TreatmentOrGroup, section.Specimen ?? "", section.Analyte, subsection.Period ?? section.Period ?? "", subsection.Arm ?? "", section.Cohort, individual.Subject); suffix = "__" + i++; } } } } } data.Tables.Add(pharmacokinetics); }
/// <summary> /// Add the concentration data table to the SAS input, already subset by the UI options /// </summary> /// <param name="data"></param> /// <param name="study"></param> private void addConcentrationToDataset(DataSet data, StudySettings study) { var concentration = new DataTable("concentration"); concentration.Columns.Add("Result", typeof(double)); concentration.Columns.Add("NominalTime", typeof(double)); concentration.Columns.Add("Treatment", typeof(string)); concentration.Columns.Add("Specimen", typeof(string)); concentration.Columns.Add("Analyte", typeof(string)); concentration.Columns.Add("Period", typeof(string)); concentration.Columns.Add("Arm", typeof(string)); concentration.Columns.Add("Cohort", typeof(string)); concentration.Columns.Add("Subject", typeof(string)); // Load individual concentration from xml file (FIXME) var fullStudy = new MappingController().LoadStudy(study.NDAName, study.ProfileName, study.SupplementNumber, study.StudyCode, null, true); // Find the subset of selected curves string period = this.Settings.SelectedPeriod; string specimen = this.Settings.SelectedPcSpecimen; if (period == "noPeriod") { period = null; } if (specimen == "noSpecimen") { specimen = null; } var selectedSections = fullStudy.Concentration.Sections.Where(s => s.Cohort == this.Settings.SelectedCohort && s.Analyte == this.Settings.SelectedPcAnalyte && s.Period == period && s.Specimen == specimen); // Add the concentration curves to the table foreach (ConcentrationDataSection section in selectedSections) { foreach (ConcentrationDataSubSection subsection in section.SubSections) { foreach (IndividualConcentration individual in subsection.Individual) { var curvePoints = individual.Concentration; // trim the curve to the selected range if a range is found if (this.Settings.StartTime.HasValue && this.Settings.EndTime.HasValue) { curvePoints = curvePoints.Where(p => p.NominalTime >= this.Settings.StartTime.Value && p.NominalTime <= this.Settings.EndTime.Value).ToList(); } // Add each point in the curve to the dataset foreach (var point in curvePoints) { concentration.Rows.Add( point.Value.HasValue ? (object)point.Value.Value : DBNull.Value, point.NominalTime.HasValue ? (object)point.NominalTime.Value : DBNull.Value, section.TreatmentOrGroup, section.Specimen ?? "", section.Analyte, subsection.Period ?? section.Period ?? "", subsection.Arm ?? "", section.Cohort, individual.Subject); } } } } data.Tables.Add(concentration); }
public DateTime?VariabilityMetaAnalysis([FromBody] List <StudySettings> revisedMappingsList, int reportId) { // Apply Ex setting for reference computation //revisedMappings.UseEx = revisedMappings.UseExRef; Report newReport0 = revisedMappingsList[0].Reports[reportId]; StudySettings revisedMappings = revisedMappingsList[0]; DataSet data = new DataSet(); for (int i = 0; i < revisedMappingsList.Count; i++) { DataSet data1 = revisedMappingsList[i].ToVariabilityMetaAnalysisGenerationDataSet(reportId); if (data1 != null) { data.Merge(data1); } } JobResponse response; Guid id; //// Clean up old report files first //DeleteReportFiles(revisedMappings, newReport.Name); // Use different SAS Api calls for different types of report id = SasClientObject.NewJob(data, "GenerateMetaVariability"); //id = SasClientObject.NewJob(data, "variabilitytest4"); // Wait for job response do { System.Threading.Thread.Sleep(500); response = SasClientObject.Getjob(id); } while (response.Status == SasJobs.Messages.StatusCode.Running); // if done save report and return creation date if (response.Status == SasJobs.Messages.StatusCode.Done) { // Set the creation date // If success, save the settings and return the creation date for (int i = 0; i < revisedMappingsList.Count; i++) { Report newReport = revisedMappingsList[i].Reports[reportId]; newReport.CreationDate = DateTime.Now; newReport.Generated = true; DoSaveVariabilityMetaAnalysisReport(revisedMappingsList[i].NDAName, revisedMappingsList[i].SupplementNumber, revisedMappingsList[i].StudyCode, revisedMappingsList[i].ProfileName, newReport); } //var scriptBuilder = new MetaBuilder(revisedMappings, newReport0); //scriptBuilder.Create(); return(DateTime.Now); } else { return(null); } }
public NcaBuilder(StudySettings study, Report report) { this.template = new TemplateEngine(); // Location of the template this.templateFolder = HostingEnvironment.MapPath(@"~\Content\templates\PkView"); this.template.TemplatePath = Path.Combine(this.templateFolder, "NcaAnalysisTemplate.sas.tpl"); // Location where the script will be created this.outputFolder = string.Format( @"\\{0}\Output Files\PKView\{1}\{2}\{3}\{4}\{5}\{6}", iPortalApp.AppServerName, Users.GetCurrentUserName(), study.ProfileName, study.NDAName, study.SupplementNumber, study.StudyCode, report.Name); string scriptName = String.Format("ncaRun_{0}_{1}.sas", report.Settings.SelectedPcSpecimen ?? report.Settings.SelectedPpSpecimen ?? "BLOOD", report.Settings.SelectedPcAnalyte); this.template.OutputPath = Path.Combine(this.outputFolder, scriptName); // Parameters for the template to customize the script this.template.LoadParameters(new { SCRIPT_NAME = scriptName, GENERATION_DATE = DateTime.Now.ToShortDateString(), SUBMISSION = study.NDAName, STUDY = study.StudyCode, LEVEL = report.Settings.SelectedPcAnalyte, }); // Load pk parameters adding a suffix when they are repeated var pkct = new Dictionary <string, int>(); this.template.LoadParameter("FIRMAUCI", report.Settings.SelectedAucInfinity); pkct[report.Settings.SelectedAucInfinity] = 1; var pkMap = new Dictionary <string, string> { { "FIRMAUCT", report.Settings.SelectedAuct }, { "FIRMCMAX", report.Settings.SelectedCmax }, { "FIRMTHALF", report.Settings.SelectedThalf }, { "FIRMTMAX", report.Settings.SelectedTmax } }; // Load each parameter foreach (var mapping in pkMap) { string firmPk = mapping.Value; if (!String.IsNullOrWhiteSpace(firmPk) && pkct.ContainsKey(firmPk)) { firmPk += "__" + pkct[firmPk]++; } else { pkct[firmPk] = 1; } this.template.LoadParameter(mapping.Key, firmPk); } }
public string SaveStudy([FromBody] StudySettings revisedMappings, string SubmissionId, string profileName, string SupplementNumber, string StudyCode) { return(this.Save(new List <StudySettings> { revisedMappings }, profileName)); }