/// <summary> /// Fill in code details /// </summary> public CodeValue FillInDetails(CodeValue codeValue) { CodeValue retVal = null; string codeKey = String.Format("{0}@{1}", codeValue.CodeSystem, codeValue.Code); if (!m_cachedCodeLookups.TryGetValue(codeKey, out retVal)) { // Does this code need details filled in? // CTS should only be used for valid if (!m_configuration.FillInCodeSets.Contains(codeValue.CodeSystem)) { return(codeValue); } // Fill in code details MessageRuntime mrt = new MessageRuntime(); // Host URI mrt.Url = m_configuration.MessageRuntimeUrl; if (!String.IsNullOrEmpty(m_configuration.ProxyAddress)) { mrt.Proxy = new WebProxy(m_configuration.ProxyAddress); } CD ret = mrt.fillInDetails(CreateCTSConceptDescriptor(codeValue), new ST() { v = ApplicationContext.Current.Configuration.JurisdictionData.DefaultLanguageCode }); // Create the CodeValue from the CD retVal = CreateCodeValue(ret); AddCachedCode(codeKey, retVal); } return(retVal); }
/// <summary> /// Validate a Code /// </summary> public ConceptValidationResult Validate(CodeValue code) { if (code == null) { return new ConceptValidationResult() { Outcome = ValidationOutcome.Valid } } ; string codeKey = String.Format("{0}@{1}", code.CodeSystem, code.Code); CodeValue tCodeCache = null; ConceptValidationResult retVal = new ConceptValidationResult(); // Check cache first if (!m_cachedCodeLookups.TryGetValue(codeKey, out tCodeCache)) { MessageRuntime mrt = new MessageRuntime(); // Host URI mrt.Url = m_configuration.MessageRuntimeUrl; if (!String.IsNullOrEmpty(m_configuration.ProxyAddress)) { mrt.Proxy = new WebProxy(m_configuration.ProxyAddress); } // CTS Doesn't need to be used to validate ISO639 Language Codes, so we can regex match this if (code.CodeSystem == "2.16.840.1.113883.6.99") { if (new Regex("\\w{2}\\-?\\w{0,2}").IsMatch(code.Code)) { return new ConceptValidationResult() { Outcome = ValidationOutcome.Valid } } ; else { return new ConceptValidationResult() { Outcome = ValidationOutcome.Invalid } }; } // Attempt to validate the code try { CD codeToValidate = CreateCTSConceptDescriptor(code); var response = mrt.validateCode(null, CreateCTSConceptDescriptor(code), null, new BL() { v = true }, new BL() { v = false }); // Translate response if (response.nErrors.v == 0 && response.nWarnings.v == 0) { retVal.Outcome = ValidationOutcome.Valid; } else if (response.nErrors.v != 0) { retVal.Outcome = ValidationOutcome.Error; } else if (response.nWarnings.v != 0) { retVal.Outcome = ValidationOutcome.ValidWithWarning; } // Details foreach (var dtl in response.detail) { retVal.AddDetail(dtl.isError.v, String.Format("{0}:{1} ({2}@{3})", dtl.error_id.v, dtl.errorText.v, code.CodeSystem, code.Code), dtl.error_id.v); } return(retVal); } catch (Exception e) { Trace.TraceError(e.ToString()); retVal.Outcome = ValidationOutcome.Error; retVal.AddDetail(true, e.Message, "INTERR"); } } else { if (!tCodeCache.DisplayName.Equals(code.DisplayName)) { retVal.AddDetail(false, String.Format("{0}:{1} ({2}@{3})", "0001", "Incorrect display name for code", code.CodeSystem, code.Code), "W001"); } } return(retVal); }