protected override void ProcessRecord() { VSACImporter importer = new VSACImporter(this.tdb); importer.Authenticate(this.VSACUsername, this.VSACPassword); if (importer.ImportValueSet(this.Oid)) { this.WriteObject("Successfully imported value set"); } else { this.WriteObject("No value set imported"); } }
public ImportValueSetResponseModel ImportValueSet(ImportValueSetModel model) { ImportValueSetResponseModel responseModel = new ImportValueSetResponseModel(); using (IObjectRepository auditedTdb = DBContext.CreateAuditable(CheckPoint.Instance.UserName, CheckPoint.Instance.HostAddress)) { try { switch (model.Source) { case ValueSetImportSources.VSAC: if (!CheckPoint.Instance.HasSecurables(SecurableNames.IMPORT_VSAC)) { throw new AuthorizationException("You do not have the securable required to import from VSAC"); } Logging.Log.For(this).Debug("Starting VSAC import for " + model.Id); User currentUser = CheckPoint.Instance.GetUser(auditedTdb); VSACImporter importer = new VSACImporter(auditedTdb); if (string.IsNullOrEmpty(currentUser.UMLSApiKey)) { responseModel.Message = "Your profile does not have your UMLS API Key. <a href=\"/Account/MyProfile\">Update your profile</a> to import from VSAC."; Logging.Log.For(this).Debug("User does not have UMLS API Key stored."); break; } if (!importer.Authenticate(currentUser.UMLSApiKey.DecryptStringAES())) { responseModel.Message = "Invalid UMLS username/password associated with your profile."; Logging.Log.For(this).Debug("User's UMLS credentials are invalid for VSAC import"); break; } importer.ImportValueSet(model.Id); responseModel.Success = true; break; case ValueSetImportSources.PHINVADS: if (!CheckPoint.Instance.HasSecurables(SecurableNames.IMPORT_PHINVADS)) { throw new AuthorizationException("You do not have the securable required to import from PHIN VADS"); } Logging.Log.For(this).Debug("Starting PHIN VADS import for " + model.Id); PhinVadsValueSetImportProcessor <ImportValueSet, ImportValueSetMember> processor = new PhinVadsValueSetImportProcessor <ImportValueSet, ImportValueSetMember>(); ImportValueSet valueSet = processor.FindValueSet(auditedTdb, model.Id); processor.SaveValueSet(auditedTdb, valueSet); responseModel.Success = true; break; default: responseModel.Message = "Unknown or unsupported source"; break; } if (responseModel.Success) { auditedTdb.SaveChanges(); } } catch (WebException wex) { Logging.Log.For(this).Error("An error occurred while importing value set " + model.Id + " from " + model.Source, wex); if (wex.Response != null && wex.Response is HttpWebResponse && ((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound) { responseModel.Message = string.Format("Value set with identifier \"{0}\" was not found on the terminology server.", model.Id); } else { responseModel.Message = wex.Message; } responseModel.Success = false; } catch (Exception ex) { Logging.Log.For(this).Error("An error occurred while importing value set " + model.Id + " from " + model.Source, ex); responseModel.Message = ex.Message; responseModel.Success = false; } } return(responseModel); }