Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        private void ProcessConceptSheet(ImportCheckResponse response, SheetData sheetData, WorkbookPart wbPart, bool firstRowIsHeader)
        {
            var rows = sheetData.Descendants <Row>();

            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, wbPart);
                string code           = GetCellValue(codeCell, wbPart);
                string display        = GetCellValue(displayCell, wbPart);
                string codeSystemOid  = GetCellValue(codeSystemOidCell, wbPart);
                string status         = GetCellValue(statusCell, wbPart);
                string statusDateText = GetCellValue(statusDateCell, wbPart);

                var foundValuesetChange = response.ValueSets.SingleOrDefault(y => y.Oid == valuesetOid);
                var foundCodeSystem     = this.tdb.CodeSystems.SingleOrDefault(y => y.Oid == codeSystemOid);

                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 (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;
                }

                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();
                var foundConcept = foundValuesetChange.ChangeType != ImportValueSetChange.ChangeTypes.Add ?
                                   this.tdb.ValueSetMembers.SingleOrDefault(y => y.ValueSet.Oid == foundValuesetChange.Oid && y.Code == code && y.Status == status && y.StatusDate == statusDate) :
                                   null;

                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);
            }
        }