private void AddVariablesToGroup() { //loop over the vars in the scheme rather than the vars from the linking file to catch the vars without concepts var variablesToAllocate = WorkingSet.OfType <VariableScheme>().Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First().Variables; foreach (var vta in variablesToAllocate) { if (variablesConcepts.Keys.Contains(vta.ItemName.Best)) { if (string.Compare(variablesConcepts[vta.ItemName.Best], "0") == 0) { Trace.WriteLine(" variable with 0 topic: " + vta.ItemName.Best); } else { var variableGroup = WorkingSet.OfType <VariableScheme>().Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First(). VariableGroups.Where(x => string.Compare(x.Concept.ItemName.Best, variablesConcepts[vta.ItemName.Best]) == 0).First(); variableGroup.AddChild(vta); } } else { Trace.WriteLine(" variable not in linking file: " + vta.ItemName.Best); } } }
private void AddQuestionsToGroup() { //loop over the question constructs in the scheme rather than the questions from the linking file to catch the questions without concepts var questionsToAllocate = WorkingSet.OfType <ControlConstructScheme>().Where(x => string.Compare(x.ItemName.Best, this.qcsName, ignoreCase: true) == 0).First().ControlConstructs.OfType <QuestionActivity>(); foreach (var qta in questionsToAllocate) { if (questionsConcepts.Keys.Contains(qta.ItemName.Best)) { if (string.Compare(questionsConcepts[qta.ItemName.Best], "0") == 0) { Trace.WriteLine(" question with 0 topic: " + qta.ItemName.Best); } else { var questionGroup = WorkingSet.OfType <ControlConstructScheme>().Where(x => string.Compare(x.ItemName.Best, this.qcsName, ignoreCase: true) == 0).First(). ControlConstructGroups.Where(x => string.Compare(x.Concept.ItemName.Best, questionsConcepts[qta.ItemName.Best]) == 0).First(); questionGroup.AddChild(qta); } } else { Trace.WriteLine(" question not in linking file: " + qta.ItemName.Best); } } }
private void BuildQuestionGroupHierarchy() { //include level-2 groups into parent level-1 groups var controlConstructScheme = WorkingSet.OfType <ControlConstructScheme>().Where(x => string.Compare(x.ItemName.Best, this.qcsName, ignoreCase: true) == 0).First(); //var level2QuestionGroups = controlConstructScheme.ControlConstructGroups.Where(x => string.Compare(x.Concept.SubclassOf.First().ItemName.Best, "1") != 0); var level2QuestionGroups = controlConstructScheme.ControlConstructGroups.Where(x => x.Concept.SubclassOf.Count() > 0); foreach (var qcg2 in level2QuestionGroups) { var parentConcept = qcg2.Concept.SubclassOf.First(); var parentGroup = controlConstructScheme.ControlConstructGroups.Where(x => x.Concept == parentConcept).First(); parentGroup.ChildGroups.Add(qcg2); } }
private void BuildVariableGroupHierarchy() { //include level-2 groups into parent level-1 groups var variableScheme = WorkingSet.OfType <VariableScheme>().Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First(); //var level2VariableGroups = variableScheme.VariableGroups.Where(x => string.Compare(x.Concept.SubclassOf.First().ItemName.Best, "1") != 0); var level2VariableGroups = variableScheme.VariableGroups.Where(x => x.Concept.SubclassOf.Count() > 0); foreach (var vg2 in level2VariableGroups) { var parentConcept = vg2.Concept.SubclassOf.First(); var parentGroup = variableScheme.VariableGroups.Where(x => x.Concept == parentConcept).First(); parentGroup.ChildGroups.Add(vg2); } }
private void CreateQuestionGroups() { //Get concepts that are used, add the implicit ones and except for "0" create question groups from them in the relevant question scheme and put into the working set this.usedConcepts = questionsConcepts.Values.Distinct().ToList(); //add implicit level-1 groups that are parents of level-2 groups var implicits = new List <string>(); foreach (var uc in this.usedConcepts) { if (uc.Length == 1 + 2 + 2) { if (!usedConcepts.Contains(uc.Substring(0, 3))) { implicits.Add(uc.Substring(0, 3)); } } } this.usedConcepts.AddRange(implicits.Distinct()); //get the concept scheme from the repository //I assume there is only one //if there is none, get concepts from the working set ConceptScheme qcgConceptScheme = new ConceptScheme(); var client = Utility.GetClient(); var facet = new SearchFacet(); facet.ItemTypes.Add(DdiItemType.ConceptScheme); SearchResponse response = client.Search(facet); bool fromRepo = false; if (response.ReturnedResults > 0) { fromRepo = true; qcgConceptScheme = client.GetItem(response.Results[0].CompositeId, ChildReferenceProcessing.Populate) as ConceptScheme; } var controlConstructScheme = WorkingSet.OfType <ControlConstructScheme>().Where(x => string.Compare(x.ItemName.Best, this.qcsName, ignoreCase: true) == 0).First(); foreach (var uc in this.usedConcepts) { if (uc != "0") { ControlConstructGroup qcg = new ControlConstructGroup(); qcg.TypeOfGroup = "ConceptGroup"; Concept qcgConcept = new Concept(); if (fromRepo) { qcgConcept = qcgConceptScheme.Concepts.Where(x => string.Compare(x.ItemName.Best, uc, ignoreCase: true) == 0).First(); } else //from working set { qcgConcept = WorkingSet.OfType <Concept>().Where(x => string.Compare(x.ItemName.Best, uc, ignoreCase: true) == 0).First(); } qcg.Concept = qcgConcept; qcg.ItemName.Add("en-GB", "Question Construct Group - " + qcgConcept.Label.Best); //Trace.WriteLine(" " + qcg.ItemName.Best); controlConstructScheme.ControlConstructGroups.Add(qcg); } } WorkingSet.AddRange(controlConstructScheme.ControlConstructGroups); Trace.WriteLine(" question construct groups: " + controlConstructScheme.ControlConstructGroups.Count().ToString() + " for " + this.qcsName); }
public void Execute() { // Load the DDI 3.2 toplevel file. if (!System.IO.File.Exists(fileName)) { Trace.WriteLine(" missing file: " + fileName); return; } var validator = new DdiValidator(fileName, DdiFileFormat.Ddi32); bool isValid = validator.Validate(); var doc = validator.ValidatedXDocument; var deserializer = new Ddi32Deserializer(); var harmonized = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32); var instance = deserializer.GetDdiInstance(doc.Root); // Get a list of all items contained in the DdiInstance. var gatherer = new ItemGathererVisitor(); instance.Accept(gatherer); var allItems = gatherer.FoundItems; //mesh in the instrument references //nb: ItemName seems to be the empty string rather than null if it does not exist in the ddi file var dataCollections = allItems.OfType <DataCollection>().Where(x => string.Compare(x.ItemName.Best, "") != 0); foreach (var dc in dataCollections) { var instrumentName = dc.ItemName.Best + "-in-000001"; var instruments = WorkingSet.OfType <Instrument>().Where(x => string.Compare(x.UserIds[0].Identifier, instrumentName, ignoreCase: true) == 0); var ic = instruments.Count(); if (ic == 1) { dc.AddChild(instruments.First()); } else if (ic > 1) { Trace.WriteLine(" more than one instrument found for " + instrumentName); } else { Trace.WriteLine(" no instrument found for " + instrumentName); //to do: try repo //var client = Utility.GetClient(); //var facet = new SearchFacet(); //facet.ItemTypes.Add(DdiItemType.Instrument); //SearchResponse response = client.Search(facet); //if (response.ReturnedResults > 1) //{ // var repoInstruments = client.GetItems(response.Results); //} } } //mesh in variable set references //I assume that there may be more than one corresponding dataset (i.e. its log prod, phys prod...) with same base name but with a hyphenated suffix //get all the study units (from toplevel, assumed) and go through all its data collections //find the logical products with a base name matching the data collection name and attach them to the study unit //find physical data product and do the same, -I assume sdk physical product is ddi physical data product?- //find physicalInstance with base alternate title matching data collection name and attach them to the study unit var studyUnits = allItems.OfType <StudyUnit>(); foreach (var su in studyUnits) { foreach (var dc in su.DataCollections.Where(x => string.Compare(x.ItemName.Best, "") != 0)) { var dcName = dc.ItemName.Best; var matchingLogicalProducts = WorkingSet.OfType <LogicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var lpc = matchingLogicalProducts.Count(); //if (lpc == 1) // su.AddChild(matchingLogicalProducts.First()); //else if (lpc > 1) // Trace.WriteLine(" more than one logical product found for " + dcName); if (lpc > 0) { foreach (var lp in matchingLogicalProducts) { su.AddChild(lp); } } else { Trace.WriteLine(" no logical product found for " + dcName); } var matchingPhysicalProducts = WorkingSet.OfType <PhysicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var pdpc = matchingPhysicalProducts.Count(); //if (pdpc == 1) // su.AddChild(matchingPhysicalProducts.First()); //else if (pdpc > 1) // Trace.WriteLine(" more than one physical data product found for " + dcName); if (pdpc > 0) { foreach (var pp in matchingPhysicalProducts) { su.AddChild(pp); } } else { Trace.WriteLine(" no physical data product found for " + dcName); } var matchingPhysicalInstances = WorkingSet.OfType <PhysicalInstance>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var pic = matchingPhysicalInstances.Count(); //if (pic == 1) // su.AddChild(matchingPhysicalInstances.First()); //else if (pic > 1) // Trace.WriteLine(" more than one physical instance found for " + dcName); if (pic > 0) { foreach (var pi in matchingPhysicalInstances) { su.AddChild(pi); } } else { Trace.WriteLine(" no physical instance found for " + dcName); } var matchingResourcePackages = WorkingSet.OfType <ResourcePackage>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var rpc = matchingResourcePackages.Count(); //if (rpc == 1) // su.AddChild(matchingResourcePackages.First()); //else if (rpc > 1) // Trace.WriteLine(" more than one resource package found for " + dcName); if (rpc > 0) { foreach (var rp in matchingResourcePackages) { su.AddChild(rp); } } else { Trace.WriteLine(" no resource package found for " + dcName); } } } // Add the items to the working set. WorkingSet.AddRange(allItems); }
public void Execute() { // The file format is: // [QuestionName] [Tab] [VariableName] // or in the case of multiple source instruments: // [QuestionConstructSchemeName] [tab] [QuestionName] [Tab] [VariableName] // If [QuestionName] or [VariableName] is "0", this is treated as no mapping. // if (!System.IO.File.Exists(fileName)) { Trace.WriteLine(" missing file: " + fileName); return; } // Read each line. string[] lines = File.ReadAllLines(this.fileName); foreach (string line in lines) { // Break the line apart by the tab character. // If there are two parts: // The question construct scheme is the one of the config file. // The left side is the question name. // The right side is the variable name. // If there are three parts, check that the qc scheme is in the configuration, shift the parts string questionConstructScheme; string questionName; string variableName; string[] parts = line.Split(new char[] { '\t' }); if (parts.Length == 2) { questionConstructScheme = this.ccsName; string questionColumn = parts[0].Trim(); string[] questionNameParts = questionColumn.Split(new char[] { '$' }); //remove grid cell info questionName = questionNameParts[0]; variableName = parts[1].Trim(); } else if (parts.Length == 3) { questionConstructScheme = parts[0].Trim(); if (this.ccsNameList.Contains(questionConstructScheme) == false) { Trace.WriteLine(" invalid question scheme: " + line); continue; } string questionColumn = parts[1].Trim(); string[] questionNameParts = questionColumn.Split(new char[] { '$' }); //remove grid cell info questionName = questionNameParts[0]; variableName = parts[2].Trim(); } else { Trace.WriteLine(" invalid line: " + line); continue; } // Skip lines with the question name set to "0". if (questionName == "0") { continue; } // Skip lines with the variable name set to "0". if (variableName == "0") { continue; } //Trace.WriteLine(" Working with [" + ccsName + ", " + vsName + "] " + questionName + " and " + variableName); // The mapping file points to the name of the QuestionConstruct, not the QuestionItem. // Look this up in the right control construct scheme and then look up the question or question grid from that. // Look up the question in the working set. var matchingQuestionConstructs = WorkingSet.OfType <ControlConstructScheme>(). Where(x => string.Compare(x.ItemName.Best, questionConstructScheme, ignoreCase: true) == 0).First(). ControlConstructs.OfType <QuestionActivity>(). Where(x => string.Compare(x.ItemName.Best, questionName, ignoreCase: true) == 0); if (matchingQuestionConstructs.Count() == 0) { Trace.WriteLine(" no question named " + questionName); continue; } else if (matchingQuestionConstructs.Count() > 1) { Trace.WriteLine(" multiple questions named " + questionName); continue; } var questionConstruct = matchingQuestionConstructs.First(); //follow through to question item or grid if ((questionConstruct.Question == null) && (questionConstruct.QuestionGrid == null)) { Trace.WriteLine(" question construct does not have question or question grid: " + questionName); continue; } //question items else if (questionConstruct.Question != null) { var question = questionConstruct.Question; // Look up the variable in the relevant variable scheme in the working set. //var matchingVariables = WorkingSet.OfType<Variable>() var matchingVariables = WorkingSet.OfType <VariableScheme>(). Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First().Variables. Where(x => string.Compare(x.ItemName.Best, variableName, ignoreCase: true) == 0); if (matchingVariables.Count() == 0) { Trace.WriteLine(" [item] no variable named " + variableName); continue; } else if (matchingVariables.Count() > 1) { Trace.WriteLine(" [item] multiple variables named " + variableName); continue; } var variable = matchingVariables.First(); // If we have correct matches, add the question as a source to the variable. variable.SourceQuestions.Add(question); //variable.SourceParameter. } //question grids else { var questionGrid = questionConstruct.QuestionGrid; // Look up the variable in the relevant variable scheme in the working set. //var matchingVariables = WorkingSet.OfType<Variable>() //.Where(x => string.Compare(x.ItemName.Best, variableName, ignoreCase:true) == 0); var matchingVariables = WorkingSet.OfType <VariableScheme>(). Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First().Variables. Where(x => string.Compare(x.ItemName.Best, variableName, ignoreCase: true) == 0); if (matchingVariables.Count() == 0) { Trace.WriteLine(" [grid] no variable named " + variableName); continue; } foreach (var variable in matchingVariables) { //variable.SourceQuestions.Add(questionGrid) } } } }
public void Execute() { // The file format is: // [SourceVariableName] [Tab] [DerivedVariableName], many-to-many if (!System.IO.File.Exists(fileName)) { Console.WriteLine(" missing file: " + fileName); return; } var variableScheme = WorkingSet.OfType <VariableScheme>().Where(x => string.Compare(x.ItemName.Best, this.vsName, ignoreCase: true) == 0).First(); // Read each line. string[] lines = File.ReadAllLines(this.fileName); foreach (string line in lines) { // Break the line apart by the tab character. string[] parts = line.Split(new char[] { '\t' }); if (parts.Length != 2) { Console.WriteLine(" invalid line: " + line); continue; } //swap column 0 and column 1 here if reqs change again string sourceVariable = parts[1].Trim(); string derivedVariable = parts[0].Trim(); if (sourceVariable == "0") { Console.WriteLine(" [item] source variable is 0"); continue; } var matchingSources = variableScheme.Variables.Where(x => string.Compare(x.ItemName.Best, sourceVariable, ignoreCase: true) == 0); if (matchingSources.Count() == 0) { Console.WriteLine(" [item] no variable named " + sourceVariable); continue; } else if (matchingSources.Count() > 1) { Console.WriteLine(" [item] multiple variables named " + sourceVariable); continue; } var source = matchingSources.First(); var matchingDVs = variableScheme.Variables.Where(x => string.Compare(x.ItemName.Best, derivedVariable, ignoreCase: true) == 0); if (matchingDVs.Count() == 0) { Console.WriteLine(" [item] no variable named " + derivedVariable); continue; } else if (matchingDVs.Count() > 1) { Console.WriteLine(" [item] multiple variables named " + derivedVariable); continue; } var dv = matchingDVs.First(); // If we have correct matches, add the qsource as a source variable to the derivedvariable. dv.SourceVariables.Add(source); } }