private ValueSetConcept Convert(ValueSetMember member) { ValueSetConcept concept = new ValueSetConcept() { code = member.Code, codeSystemName = member.CodeSystem.Name, displayName = member.DisplayName, type = VocabType.L, level = "1" }; if (IdentifierHelper.IsIdentifierOID(member.CodeSystem.Oid)) { string oid; IdentifierHelper.GetIdentifierOID(member.CodeSystem.Oid, out oid); concept.codeSystem = oid; } else if (IdentifierHelper.IsIdentifierII(member.CodeSystem.Oid)) { string oid, ext; IdentifierHelper.GetIdentifierII(member.CodeSystem.Oid, out oid, out ext); concept.codeSystem = oid; } return(concept); }
private void ExcelImportConcept(ValueSet valueSet, ImportValueSetChange.ConceptChange checkConcept) { ValueSetMember member = null; if (checkConcept.ChangeType == ImportValueSetChange.ChangeTypes.None) { return; } if (checkConcept.ChangeType == ImportValueSetChange.ChangeTypes.Update) { member = this.tdb.ValueSetMembers.Single(y => y.Id == checkConcept.Id); if (member.DisplayName != checkConcept.DisplayName) { member.DisplayName = checkConcept.DisplayName; } } else // Add { CodeSystem codeSystem = this.tdb.CodeSystems.Single(y => y.Oid == checkConcept.CodeSystemOid); member = new ValueSetMember() { ValueSet = valueSet, Code = checkConcept.Code, DisplayName = checkConcept.DisplayName, CodeSystem = codeSystem, Status = checkConcept.Status, StatusDate = checkConcept.StatusDate }; this.tdb.ValueSetMembers.Add(member); } }
private void SaveConceptProperties(IObjectRepository tdb, ValueSetMember member, ConceptItem concept) { if (member.Code != concept.Code) { member.Code = concept.Code; } if (member.DisplayName != concept.DisplayName) { member.DisplayName = concept.DisplayName; } CodeSystem foundCodeSystem = tdb.CodeSystems.Single(y => y.Id == concept.CodeSystemId); if (member.CodeSystem != foundCodeSystem) { member.CodeSystem = foundCodeSystem; } if (member.Status != concept.Status) { member.Status = concept.Status; } if (member.StatusDate != concept.StatusDate) { member.StatusDate = concept.StatusDate; } }
private V CreateImportValueSetMember(Trifolia.DB.ValueSet currentValueSet, VadsClient.ValueSetConcept vadsConcept) { ValueSetMember currentMember = currentValueSet != null? currentValueSet.Members.SingleOrDefault(y => y.Code == vadsConcept.conceptCode && y.CodeSystem.Oid == vadsConcept.codeSystemOid) : null; V importValueSetMember = Activator.CreateInstance <V>(); importValueSetMember.Code = vadsConcept.conceptCode; importValueSetMember.CodeSystemOid = vadsConcept.codeSystemOid; importValueSetMember.DisplayName = vadsConcept.codeSystemConceptName; importValueSetMember.Status = ConvertStatus(vadsConcept.status); importValueSetMember.StatusDate = vadsConcept.statusDate; importValueSetMember.ImportStatus = DetermineValueSetMemberStatus(importValueSetMember, currentMember); return(importValueSetMember); }
private void FindOrAddValueSetMember(IObjectRepository tdb, ValueSet tdbValueSet, ImportValueSetMember valueSetMember) { if (valueSetMember.ImportStatus == "None") { return; } ValueSetMember foundValueSetMember = tdbValueSet.Members.SingleOrDefault(y => y.Code == valueSetMember.Code && y.CodeSystem.Oid == valueSetMember.CodeSystemOid); CodeSystem codeSystem = FindOrAddCodeSystem(tdb, valueSetMember.CodeSystemOid, valueSetMember.CodeSystemName); string code = TruncateString(valueSetMember.Code, 254); string displayName = TruncateString(valueSetMember.DisplayName, 254); if (foundValueSetMember == null) { foundValueSetMember = new ValueSetMember(); foundValueSetMember.ValueSet = tdbValueSet; tdb.ValueSetMembers.Add(foundValueSetMember); } if (foundValueSetMember.Code != code) { foundValueSetMember.Code = code; } if (foundValueSetMember.DisplayName != displayName) { foundValueSetMember.DisplayName = displayName; } if (foundValueSetMember.CodeSystem != codeSystem) { foundValueSetMember.CodeSystem = codeSystem; foundValueSetMember.CodeSystemId = codeSystem.Id; } if (foundValueSetMember.Status != valueSetMember.Status) { foundValueSetMember.Status = valueSetMember.Status; } if (foundValueSetMember.StatusDate != valueSetMember.StatusDate) { foundValueSetMember.StatusDate = valueSetMember.StatusDate; } }
private void AddImportMember(Model.ImportValueSet importValueSet, DateTime?versionDate, ValueSet currentValueSet, Model.ImportValueSetMember importValueSetMember, bool includeHead, string relationshipType) { if (includeHead) { ValueSetMember currentMember = currentValueSet != null? currentValueSet.Members.SingleOrDefault(y => y.Code == importValueSetMember.Code && y.CodeSystem.Oid == importValueSetMember.CodeSystemOid) : null; importValueSetMember.ImportStatus = DetermineValueSetMemberStatus(importValueSetMember, currentMember); importValueSet.Members.Add(importValueSetMember); } if (!string.IsNullOrEmpty(relationshipType)) { PopulateCodeSystemMembers(importValueSet, versionDate, importValueSetMember.CodeSystemOid, currentValueSet, importValueSetMember.Code, relationshipType == "TransitiveClosure" ? "TransitiveClosure" : null); } }
private void PopulateContentMembers(Model.ImportValueSet importValueSet, DateTime?versionDate, XmlNodeList contentNodes, ValueSet currentValueSet) { foreach (XmlNode cContentNode in contentNodes) { string codeSystemOid = cContentNode.Attributes["codeSystem"].Value; XmlNodeList codeNodes = cContentNode.SelectNodes("mif:codeBasedContent", this.nsManager); foreach (XmlNode cCodeNode in codeNodes) { string code = cCodeNode.Attributes["code"].Value; string relationshipType = null; bool includeHead = cCodeNode.Attributes["includeHeadCode"] != null?bool.Parse(cCodeNode.Attributes["includeHeadCode"].Value) : true; XmlNode includeRelatedCodesNode = cCodeNode.SelectSingleNode("mif:includeRelatedCodes[@relationshipName='Generalizes']", this.nsManager); if (includeRelatedCodesNode != null) { relationshipType = includeRelatedCodesNode.Attributes["relationshipTraversal"] != null ? includeRelatedCodesNode.Attributes["relationshipTraversal"].Value : null; } V importMember = Activator.CreateInstance <V>(); importMember.CodeSystemOid = codeSystemOid; importMember.Code = code; importMember.StatusDate = versionDate; importMember.Status = "active"; PopulateConceptFields(importMember); ValueSetMember currentMember = currentValueSet != null? currentValueSet.Members.SingleOrDefault(y => y.Code == code && y.CodeSystem.Oid == codeSystemOid) : null; importMember.ImportStatus = DetermineValueSetMemberStatus(importMember, currentMember); AddImportMember(importValueSet, versionDate, currentValueSet, importMember, includeHead, relationshipType); } } }
private bool ImportRetrieveValueSet(string retrieveValueSetResponse) { List <CodeSystem> codeSystems = this.tdb.CodeSystems.ToList(); int importCount = 0; XmlDocument doc = new XmlDocument(); XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("svs", SVS_NS); try { doc.LoadXml(retrieveValueSetResponse); } catch (Exception ex) { Logging.Log.For(this).Error("Error parsing response from VSAC: " + ex.Message); throw ex; } var svsValueSetNodes = doc.SelectNodes("/svs:RetrieveMultipleValueSetsResponse/svs:DescribedValueSet", nsManager); if (svsValueSetNodes.Count > 1) { string msg = "Found " + svsValueSetNodes.Count + " value sets in results. Not continuing."; Logging.Log.For(this).Error(msg); throw new Exception(msg); } foreach (XmlElement svsValueSetNode in svsValueSetNodes) { string svsValueSetId = svsValueSetNode.Attributes["ID"].Value; Logging.Log.For(this).Debug("Parsing VSAC value set " + svsValueSetId); string svsValueSetVersion = svsValueSetNode.Attributes["version"].Value; string identifier = string.Format("urn:oid:{0}", svsValueSetId); string name = svsValueSetNode.Attributes["displayName"].Value; var purposeNode = svsValueSetNode.SelectSingleNode("svs:Purpose", nsManager); string description = purposeNode != null ? purposeNode.InnerText : string.Empty; string source = string.Format(VSAC_SOURCE_URL_FORMAT, svsValueSetId); description += string.Format("{0}This value set was imported on {1} with a version of {2}.", description.Length > 0 ? "\n\n" : string.Empty, DateTime.Now.ToShortDateString(), svsValueSetVersion); if (!string.IsNullOrEmpty(description)) { if (description.StartsWith("(") && description.EndsWith(")")) { description = description.Substring(1, description.Length - 2).Trim(); } } ValueSet foundValueSet = (from vs in this.tdb.ValueSets join vsi in this.tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId where vsi.Type == ValueSetIdentifierTypes.Oid && vsi.Identifier.Trim().ToLower() == identifier.Trim().ToLower() select vs) .FirstOrDefault(); if (foundValueSet == null) { Logging.Log.For(this).Debug("No existing value set with the same identifier found, creating a new one"); foundValueSet = new ValueSet(); foundValueSet.LastUpdate = DateTime.Now; this.tdb.ValueSets.Add(foundValueSet); foundValueSet.Identifiers.Add(new ValueSetIdentifier() { Type = ValueSetIdentifierTypes.Oid, Identifier = identifier, IsDefault = true }); } else if (foundValueSet.ImportSource.HasValue && foundValueSet.ImportSource != ValueSetImportSources.VSAC) { string msg = "This value set was imported from another source. It cannot be re-imported from a different source."; Logging.Log.For(this).Error(msg); throw new Exception(msg); } else { Logging.Log.For(this).Debug("Found already-existing value set with identifier " + identifier + ". Going to update it."); } if (foundValueSet.Name != name) { foundValueSet.Name = name; } if (foundValueSet.ImportSource != ValueSetImportSources.VSAC) { foundValueSet.ImportSource = ValueSetImportSources.VSAC; } if (foundValueSet.ImportSourceId != svsValueSetId) { foundValueSet.ImportSourceId = svsValueSetId; } if (foundValueSet.Description != description) { foundValueSet.Description = description; } if (foundValueSet.Source != source) { foundValueSet.Source = source; } foundValueSet.Intensional = false; foundValueSet.IntensionalDefinition = string.Empty; foundValueSet.Code = null; foundValueSet.IsIncomplete = false; foundValueSet.LastUpdate = DateTime.Now; Logging.Log.For(this).Debug("Done setting meta-data properties of value set. Removing existing members from value set first."); // Remove all existing codes in the value set so they can be re-added this.tdb.ValueSetMembers.RemoveRange(foundValueSet.Members); Logging.Log.For(this).Debug(foundValueSet.Members.Count() + " codes already exist in the value set and are being removed to be overwritten"); // Add all codes to value set var svsConceptNodes = svsValueSetNode.SelectNodes("svs:ConceptList/svs:Concept", nsManager); Logging.Log.For(this).Debug("Found " + svsConceptNodes.Count + " codes in the VSAC value set. Parsing all codes for import"); foreach (XmlElement svsConceptNode in svsConceptNodes) { string svsCodeSystemOid = "urn:oid:" + svsConceptNode.Attributes["codeSystem"].Value; CodeSystem foundCodeSystem = codeSystems.FirstOrDefault(y => y.Oid.Trim().ToLower() == svsCodeSystemOid.Trim().ToLower()); if (foundCodeSystem == null) { foundCodeSystem = new CodeSystem() { Name = svsConceptNode.Attributes["codeSystemName"].Value, Oid = svsCodeSystemOid }; this.tdb.CodeSystems.Add(foundCodeSystem); codeSystems.Add(foundCodeSystem); } ValueSetMember svsMember = new ValueSetMember() { Code = svsConceptNode.Attributes["code"].Value, DisplayName = svsConceptNode.Attributes["displayName"].Value, CodeSystem = foundCodeSystem, Status = "active" }; if (svsMember.DisplayName != null && svsMember.DisplayName.Length > 1021) { Logging.Log.For(this).Debug("Found code " + svsMember.Code + " has more than 1024 characters for a display name. Truncating."); svsMember.DisplayName = "..." + svsMember.DisplayName.Substring(svsMember.DisplayName.Length - 1021); } foundValueSet.Members.Add(svsMember); } importCount++; } return(importCount > 0); }
public void SaveValueSetConcepts(SaveValueSetConceptsModel model) { using (IObjectRepository auditedTdb = DBContext.CreateAuditable(CheckPoint.Instance.UserName, CheckPoint.Instance.HostAddress)) { var valueSet = auditedTdb.ValueSets.Single(y => y.Id == model.ValueSetId); if (model.Concepts != null) { foreach (var concept in model.Concepts) { ValueSetMember member = null; if (concept.Id != null) { member = valueSet.Members.Single(y => y.Id == concept.Id); } else { member = new ValueSetMember(); valueSet.Members.Add(member); } if (member.Code != concept.Code) { member.Code = concept.Code; } if (member.DisplayName != concept.DisplayName) { member.DisplayName = concept.DisplayName; } if (member.CodeSystemId != concept.CodeSystemId) { member.CodeSystemId = concept.CodeSystemId; } if (member.Status != concept.Status) { member.Status = concept.Status; } if (member.StatusDate != concept.StatusDate) { member.StatusDate = concept.StatusDate; } } } if (model.RemovedConcepts != null) { foreach (var concept in model.RemovedConcepts) { ValueSetMember member = valueSet.Members.Single(y => y.Id == concept.Id); auditedTdb.ValueSetMembers.Remove(member); } } auditedTdb.SaveChanges(); } }
private void ProcessConceptSheet(ImportCheckResponse response, SheetData sheetData, WorkbookPart wbPart, bool firstRowIsHeader) { var rows = sheetData.Descendants <Row>(); Dictionary <string, CodeSystem> cachedCodeSystems = new Dictionary <string, CodeSystem>(); SharedStringTablePart shareStringPart = wbPart.GetPartsOfType <SharedStringTablePart>().FirstOrDefault(); SharedStringItem[] items = shareStringPart != null?shareStringPart.SharedStringTable.Elements <SharedStringItem>().ToArray() : null; foreach (var row in rows) { if (firstRowIsHeader && row.RowIndex.Value == 1) { continue; } var cells = row.Descendants <Cell>(); if (cells.Count() < 6) { response.Errors.Add(string.Format("Row {0} on concept sheet does not have the required number of cells (6)", row.RowIndex.Value)); continue; } Cell valuesetOidCell = cells.SingleOrDefault(y => y.CellReference == "A" + row.RowIndex.Value.ToString()); Cell codeCell = cells.SingleOrDefault(y => y.CellReference == "B" + row.RowIndex.Value.ToString()); Cell displayCell = cells.SingleOrDefault(y => y.CellReference == "C" + row.RowIndex.Value.ToString()); Cell codeSystemOidCell = cells.SingleOrDefault(y => y.CellReference == "D" + row.RowIndex.Value.ToString()); Cell statusCell = cells.SingleOrDefault(y => y.CellReference == "E" + row.RowIndex.Value.ToString()); Cell statusDateCell = cells.SingleOrDefault(y => y.CellReference == "F" + row.RowIndex.Value.ToString()); string valuesetOid = GetCellValue(valuesetOidCell, items); string code = GetCellValue(codeCell, items); string display = GetCellValue(displayCell, items); string codeSystemOid = GetCellValue(codeSystemOidCell, items); string status = GetCellValue(statusCell, items); string statusDateText = GetCellValue(statusDateCell, items); if (string.IsNullOrEmpty(valuesetOid)) { response.Errors.Add(string.Format("Row {0}'s value set identifier on concepts sheet is not identifier", row.RowIndex.Value)); continue; } if (!valuesetOid.StartsWith("http://") && !valuesetOid.StartsWith("https://") && !valuesetOid.StartsWith("urn:oid:")) { response.Errors.Add(string.Format("Row {0}'s value set identifier on concepts sheet must be correctly formatted as one of: http[s]://XXXX or urn:oid:XXXX", row.RowIndex.Value)); continue; } if (string.IsNullOrEmpty(codeSystemOid)) { response.Errors.Add(string.Format("Row {0}'s code system identifier on the concept sheet is not specified", row.RowIndex.Value)); continue; } if (!codeSystemOid.StartsWith("http://") && !codeSystemOid.StartsWith("https://") && !codeSystemOid.StartsWith("urn:oid:")) { response.Errors.Add(string.Format("Row {0}'s code system identifier on concepts sheet must be correctly formatted as one of: http[s]://XXXX or urn:oid:XXXX", row.RowIndex.Value)); continue; } var foundValueSetChange = response.ValueSets.SingleOrDefault(y => y.Oid == valuesetOid); CodeSystem foundCodeSystem = cachedCodeSystems.ContainsKey(codeSystemOid) ? cachedCodeSystems[codeSystemOid] : null; if (foundCodeSystem == null) { foundCodeSystem = this.tdb.CodeSystems.SingleOrDefault(y => y.Oid == codeSystemOid); if (foundCodeSystem == null) { response.Errors.Add(string.Format("Could not find specified code system {0} on row {1} of concept sheet.", codeSystemOid, row.RowIndex.Value)); continue; } cachedCodeSystems.Add(codeSystemOid, foundCodeSystem); } if (foundValueSetChange == null) { response.Errors.Add(string.Format("Row {0} on concept sheet does not have a valid valueset OID.", row.RowIndex.Value)); continue; } if (string.IsNullOrEmpty(code)) { response.Errors.Add(string.Format("Row {0} on concept sheet does not have a valid code.", row.RowIndex.Value)); continue; } if (string.IsNullOrEmpty(display)) { response.Errors.Add(string.Format("Row {0} on concept sheet does not have a valid display name.", row.RowIndex.Value)); continue; } if (!string.IsNullOrEmpty(status) && status.ToLower() != "active" && status.ToLower() != "inactive") { response.Errors.Add(string.Format("Row {0} on concept sheet does not have a valid status ('active' or 'inactive').", row.RowIndex.Value)); continue; } DateTime parsedStatusDate = DateTime.MinValue; int parsedStatusDateInt = 0; if (!string.IsNullOrEmpty(statusDateText) && !Int32.TryParse(statusDateText, out parsedStatusDateInt) && !DateTime.TryParse(statusDateText, out parsedStatusDate)) { response.Errors.Add(string.Format("Row {0} on concept sheet does not have a valid date (format 'mm/dd/yyyy').", row.RowIndex.Value)); continue; } DateTime?statusDate = null; if (parsedStatusDateInt > 0) { statusDate = FromExcelSerialDate(parsedStatusDateInt); } else if (parsedStatusDate != DateTime.MinValue) { statusDate = parsedStatusDate; } ImportValueSetChange.ConceptChange conceptChange = new ImportValueSetChange.ConceptChange(); ValueSetMember foundConcept = null; if (foundValueSetChange.ValueSet != null) { foundConcept = foundValueSetChange.ValueSet.Members.SingleOrDefault(y => y.Code == code && y.Status == status && y.StatusDate == statusDate); } if (foundConcept == null) { conceptChange.ChangeType = ImportValueSetChange.ChangeTypes.Add; } else { conceptChange.Id = foundConcept.Id; if (foundConcept.DisplayName != display) { conceptChange.ChangeType = ImportValueSetChange.ChangeTypes.Update; } } conceptChange.Code = code; conceptChange.DisplayName = display; conceptChange.CodeSystemOid = codeSystemOid; conceptChange.CodeSystemName = foundCodeSystem.Name; conceptChange.Status = status; conceptChange.StatusDate = statusDate; foundValueSetChange.Concepts.Add(conceptChange); } }
public ValueSet Convert(FhirValueSet fhirValueSet, ValueSet valueSet = null) { string fhirDescription = fhirValueSet.Description != null ? fhirValueSet.Description.Value : null; if (valueSet == null) { valueSet = new ValueSet(); } if (valueSet.Name != fhirValueSet.Name) { valueSet.Name = fhirValueSet.Name; } if (valueSet.Description != fhirDescription) { valueSet.Description = fhirDescription; } if (fhirValueSet.Identifier == null) { throw new Exception("ValueSet.identifier.value is required"); } this.PopulateIdentifier(valueSet, fhirValueSet); if (fhirValueSet.Expansion != null) { foreach (var expContains in fhirValueSet.Expansion.Contains) { // Skip members that don't have a code or a code system if (string.IsNullOrEmpty(expContains.Code) || string.IsNullOrEmpty(expContains.System)) { continue; } CodeSystem codeSystem = this.tdb.CodeSystems.SingleOrDefault(y => y.Oid == expContains.System); if (codeSystem == null) { codeSystem = new CodeSystem() { Oid = expContains.System, Name = expContains.System }; this.tdb.CodeSystems.Add(codeSystem); } ValueSetMember newMember = valueSet.Members.SingleOrDefault(y => y.CodeSystem == codeSystem && y.Code == expContains.Code); if (newMember == null) { newMember = new ValueSetMember() { CodeSystem = codeSystem, Code = expContains.Code } } ; if (newMember.DisplayName != expContains.Display) { newMember.DisplayName = expContains.Display; } DateTime versionDateVal = DateTime.MinValue; if (!DateTime.TryParse(fhirValueSet.Version, out versionDateVal)) { DateTime.TryParse(fhirValueSet.Date, out versionDateVal); } DateTime?versionDate = versionDateVal != DateTime.MinValue ? (DateTime?)versionDateVal : null; if (newMember.StatusDate != versionDate) { newMember.StatusDate = versionDate; } if (newMember.StatusDate != null && newMember.Status != "active") { newMember.Status = "active"; } valueSet.Members.Add(newMember); } } return(valueSet); } }
public int SaveValueSet(SaveValueSetModel model) { using (IObjectRepository auditedTdb = DBContext.Create()) { auditedTdb.AuditChanges(CheckPoint.Instance.UserName, CheckPoint.Instance.OrganizationName, CheckPoint.Instance.HostAddress); ValueSetModel valueSetModel = model.ValueSet; ValueSet valueSet = auditedTdb.ValueSets.SingleOrDefault(y => y.Id == valueSetModel.Id); if (valueSet == null) { valueSet = new ValueSet(); auditedTdb.ValueSets.AddObject(valueSet); } // Set properties for the value set if (valueSetModel.Code != valueSet.Code) { valueSet.Code = valueSetModel.Code; } if (valueSetModel.Description != valueSet.Description) { valueSet.Description = valueSetModel.Description; } if (valueSetModel.IntentionalDefinition != valueSet.IntensionalDefinition) { valueSet.IntensionalDefinition = valueSetModel.IntentionalDefinition; } var isIncomplete = !valueSetModel.IsComplete; if (isIncomplete != valueSet.IsIncomplete) { valueSet.IsIncomplete = isIncomplete; } if (valueSetModel.IsIntentional != valueSet.Intensional) { valueSet.Intensional = valueSetModel.IsIntentional; } if (valueSetModel.Name != valueSet.Name) { valueSet.Name = valueSetModel.Name; } if (valueSetModel.Oid != valueSet.Oid) { valueSet.Oid = valueSetModel.Oid; } if (valueSetModel.SourceUrl != valueSet.Source) { valueSet.Source = valueSetModel.SourceUrl; } // Remove concepts if (model.RemovedConcepts != null) { foreach (var concept in model.RemovedConcepts) { var valueSetMember = auditedTdb.ValueSetMembers.Single(y => y.Id == concept.Id && y.ValueSetId == valueSet.Id); auditedTdb.ValueSetMembers.DeleteObject(valueSetMember); } } // Update concepts if (model.Concepts != null) { foreach (var concept in model.Concepts) { ValueSetMember valueSetMember = auditedTdb.ValueSetMembers.SingleOrDefault(y => y.Id == concept.Id && y.ValueSetId == valueSet.Id); if (valueSetMember == null) { valueSetMember = new ValueSetMember(); valueSetMember.ValueSet = valueSet; auditedTdb.ValueSetMembers.AddObject(valueSetMember); } this.SaveConceptProperties(auditedTdb, valueSetMember, concept); } } auditedTdb.SaveChanges(); return(valueSet.Id); } }
protected string DetermineValueSetMemberStatus(ImportValueSetMember importValueSetMember, ValueSetMember currentMember) { if (currentMember == null) { return("Add"); } else { bool valueSetMemberIsChanged = importValueSetMember.Code != currentMember.Code || importValueSetMember.CodeSystemOid != currentMember.CodeSystem.Oid || importValueSetMember.DisplayName != currentMember.DisplayName || importValueSetMember.Status != currentMember.Status || importValueSetMember.StatusDate != currentMember.StatusDate; if (valueSetMemberIsChanged) { return("Update"); } } return("None"); }
public void ImportValueSets(List <TrifoliaValueSet> models) { var codeSystems = this.tdb.CodeSystems.ToList().Union(this.addedCodeSystems); var allValueSetIdentifiers = (from vs in this.tdb.ValueSets join vsi in this.tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId select vsi.Identifier).ToList(); foreach (var model in models) { // Skip value sets that don't have an identifier if (model.Identifier.Count == 0) { continue; } var foundIdentifiers = (from modelIdentifier in model.Identifier join valueSetIdentifier in allValueSetIdentifiers on modelIdentifier.value.Trim().ToLower() equals valueSetIdentifier.Trim().ToLower() select modelIdentifier.value); // Skip value sets that already exist if (foundIdentifiers.Count() > 0) { continue; } ValueSet newValueSet = new ValueSet() { Name = model.name, Description = model.Description, IsIncomplete = model.isIncomplete, Source = model.source, Intensional = model.intensional, IntensionalDefinition = model.IntensionalDefinition, LastUpdate = DateTime.Now }; // Add identifiers to the value set foreach (var modelIdentifier in model.Identifier) { ValueSetIdentifier newValueSetIdentifier = new ValueSetIdentifier() { Identifier = modelIdentifier.value, Type = (ValueSetIdentifierTypes)Enum.Parse(typeof(ValueSetIdentifierTypes), modelIdentifier.type), IsDefault = modelIdentifier.value == model.defaultIdentifier || model.Identifier.Count == 1 }; newValueSet.Identifiers.Add(newValueSetIdentifier); } // Add members to the value set foreach (var modelMember in model.Member) { DateTime statusDate = DateTime.Now; DateTime.TryParse(modelMember.statusDate, out statusDate); string modelIdentifier = modelMember.codeSystemIdentifier; CodeSystem codeSystem = codeSystems.SingleOrDefault(y => y.Oid == modelIdentifier); if (codeSystem == null) { continue; } ValueSetMember newMember = new ValueSetMember() { Code = modelMember.code, DisplayName = modelMember.displayName, Status = modelMember.status.ToString(), StatusDate = !string.IsNullOrEmpty(modelMember.statusDate) && modelMember.statusSpecified ? statusDate : (DateTime?)null, CodeSystem = codeSystem }; newValueSet.Members.Add(newMember); } this.tdb.ValueSets.Add(newValueSet); this.addedValueSets.Add(newValueSet); } }