/// <summary>
        /// Create a codified value
        /// </summary>
        /// <param name="cV"></param>
        /// <returns></returns>
        protected CodeValue CreateCodeValue <T>(CV <T> cv, List <IResultDetail> dtls)
        {
            // Get terminology service from the host context
            ITerminologyService termSvc = Context.GetService(typeof(ITerminologyService)) as ITerminologyService;

            // Code is null then return
            if (cv == null || cv.Code == null || cv.IsNull)
            {
                dtls.Add(new ResultDetail(ResultDetailType.Error, ERR_NO_CODE, (string)null));
                return(null);
            }

            // Return value
            CodeValue retVal = new CodeValue(Util.ToWireFormat(cv.Code));

            if (cv.Code.IsAlternateCodeSpecified || !String.IsNullOrEmpty(cv.CodeSystem))
            {
                retVal.CodeSystem = cv.CodeSystem;
                if (retVal.CodeSystem == null)
                {
                    dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error,
                                                                     String.Format(this.m_localeService.GetString("MSGE04A"),
                                                                                   cv.Code, typeof(T).Name), null));
                }
            }
            else if (String.IsNullOrEmpty(cv.CodeSystem))
            {
                object[] attList = typeof(T).GetCustomAttributes(typeof(StructureAttribute), false);
                if (attList.Length > 0)
                {
                    retVal.CodeSystem = (attList[0] as StructureAttribute).CodeSystem;
                }
            }
            else
            {
                retVal.CodeSystem = cv.CodeSystem;
            }

            // Code system data
            retVal.CodeSystemVersion = cv.CodeSystemVersion;
            retVal.DisplayName       = cv.DisplayName;

            // Validate with termservice
            if (termSvc != null && cv.Code.IsAlternateCodeSpecified)
            {
                var tval = termSvc.Validate(retVal);
                foreach (var dtl in tval.Details)
                {
                    dtls.Add(new VocabularyIssueResultDetail(dtl.IsError ? ResultDetailType.Error : ResultDetailType.Warning, dtl.Message, null));
                }
            }

            if (cv.OriginalText != null && !cv.IsNull)
            {
                retVal.OriginalText = cv.OriginalText.ToString();
            }

            return(retVal);
        }
 public TerminologyController(ITerminologyService service,
                              ICurrentUser currentUser,
                              IStringLocalizer <LanguageSub> localizer)
 {
     curUser            = currentUser;
     stringLocalizer    = localizer;
     terminologyService = service;
 }
Esempio n. 3
0
        /// <summary>
        /// Update a CE
        /// </summary>
        private void UpdateCE(CodeValue codeValue, NHapi.Model.V231.Datatype.CE ce)
        {
            ITerminologyService tservice = Context.GetService(typeof(ITerminologyService)) as ITerminologyService;

            codeValue = tservice.FillInDetails(codeValue);

            ce.Identifier.Value         = codeValue.Code;
            ce.NameOfCodingSystem.Value = codeValue.CodeSystemName;
        }
Esempio n. 4
0
        internal static string OpenEhrTermDefTerm(string codeString, ITerminologyService terminologyService)
        {
            Check.Require(!string.IsNullOrEmpty(codeString), "codeString must not be null or Empty.");

            string termDefText = terminologyService.Terminology(OpenEhrTerminologyIdentifiers.TerminologyIdOpenehr)
                        .RubricForCode(codeString, _language);

            Check.Ensure(!string.IsNullOrEmpty(termDefText));

            return termDefText;
        }
Esempio n. 5
0
        private void testService(ITerminologyService svc)
        {
            var vsUrl  = "http://hl7.org/fhir/ValueSet/data-absent-reason";
            var result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason");

            Assert.True(result.Success);

            result = svc.ValidateCode(vsUrl, code: "NaNX", system: "http://hl7.org/fhir/data-absent-reason");
            Assert.False(result.Success);

            result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason",
                                      display: "Not a Number");
            Assert.True(result.Success);

            // The spec is not clear on the behaviour of incorrect displays - so don't test it here
            //result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason",
            //    display: "Not any Number");
            //Assert.True(result.Success);

            result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/v3-AcknowledgementDetailCode", code: "_AcknowledgementDetailNotSupportedCode",
                                      system: "http://hl7.org/fhir/v3/AcknowledgementDetailCode");
            Assert.True(result.Success);

            Assert.Throws <ValueSetUnknownException>(() => svc.ValidateCode("http://hl7.org/fhir/ValueSet/crappy", code: "4322002", system: "http://snomed.info/sct"));

            var coding = new Coding("http://hl7.org/fhir/data-absent-reason", "NaN");

            result = svc.ValidateCode(vsUrl, coding: coding);
            Assert.True(result.Success);

            coding.Display = "Not a Number";
            result         = svc.ValidateCode(vsUrl, coding: coding);
            Assert.True(result.Success);

            coding.Code = "NaNX";
            result      = svc.ValidateCode(vsUrl, coding: coding);
            Assert.False(result.Success);
            coding.Code = "NaN";

            var cc = new CodeableConcept("http://hl7.org/fhir/data-absent-reason", "NaNX", "Not a Number");

            result = svc.ValidateCode(vsUrl, codeableConcept: cc);
            Assert.False(result.Success);

            cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "asked"));
            result = svc.ValidateCode(vsUrl, codeableConcept: cc);
            DebugDumpOutputXml(result);

            Assert.True(result.Success);
        }
Esempio n. 6
0
        internal static bool ValidateCObject(CObject cObject, ITerminologyService terminologyService)
        {
            AmValidator amValidator = new AmValidator(terminologyService);

            try
            {
                amValidator.Validate(cObject);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(RmInvariantException))
                    return false;
                else
                    throw ex;
            }

            return true;
        }
Esempio n. 7
0
        internal static bool ValidateCAttribute(CAttribute cAttribute, ITerminologyService terminologyService)
        {
            AmValidator amValidator = new AmValidator(terminologyService);

            try
            {
                amValidator.Validate(cAttribute);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(RmInvariantException))
                {
                    return(false);
                }
                else
                {
                    throw ex;
                }
            }

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// True if the archetype is valid overall; various tests should be used, including checks on
        /// node_ids, internal references, and constraint references.
        /// </summary>
        /// <returns></returns>
        public bool IsValid(ITerminologyService terminologyService)
        {
            if (!(this.NodeIdsValid() && this.InternalReferencesValid() && this.ConstraintReferencesValid()))
            {
                return(false);
            }
            try
            {
                AmValidator.Validate(this, terminologyService);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(RmInvariantException))
                {
                    return(false);
                }

                throw ex;
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Convert a code from FHIR to internal
        /// </summary>
        internal CodeValue ConvertCode(CodeableConcept codeableConcept, List <IResultDetail> dtls)
        {
            var coding = codeableConcept.GetPrimaryCode();
            // Get the oid
            CodeValue retVal = new CodeValue(coding.Code, MessageUtil.TranslateFhirDomain(coding.System.ToString()));

            retVal.DisplayName = coding.Display;

            ITerminologyService termSvc = ApplicationContext.CurrentContext.GetService(typeof(ITerminologyService)) as ITerminologyService;

            if (termSvc != null)
            {
                var validationDtls = termSvc.Validate(retVal);
                if (validationDtls.Outcome != SVC.Core.Terminology.ValidationOutcome.Valid)
                {
                    foreach (var dtl in validationDtls.Details)
                    {
                        dtls.Add(new VocabularyIssueResultDetail(dtl.IsError ? ResultDetailType.Error : ResultDetailType.Warning, dtl.Message, null));
                    }
                }
            }
            return(retVal);
        }
Esempio n. 10
0
        /// <summary>
        /// Convert a code
        /// </summary>
        internal CodeableConcept ConvertCode(CodeValue codeValue)
        {
            ITerminologyService itermSvc = ApplicationContext.CurrentContext.GetService(typeof(ITerminologyService)) as ITerminologyService;

            if (itermSvc != null)
            {
                codeValue = itermSvc.FillInDetails(codeValue);
            }

            // Attempt to lookup the OID
            var oid    = ApplicationContext.ConfigurationService.OidRegistrar.FindData(codeValue.CodeSystem);
            var retVal = new CodeableConcept();
            var coding = new Coding();

            // Code system
            if (oid == null)
            {
                coding.System = new Uri(String.Format("urn:oid:{0}", codeValue.CodeSystem));
            }
            else if (codeValue.CodeSystem == "urn:ietf:rfc:3986")
            {
                coding.System = new Uri(codeValue.CodeSystem);
            }
            else
            {
                coding.System = new Uri(oid.Ref != null ? oid.Ref.ToString() : string.Format("urn:oid:{0}", codeValue.CodeSystem));
            }

            // Display name
            coding.Display = codeValue.DisplayName;

            // Mnemonic
            coding.Code = new PrimitiveCode <string>(codeValue.Code);

            return(retVal);
        }
Esempio n. 11
0
 public BindingValidator(ITerminologyService service, string path)
 {
     _service = service;
     _path    = path;
 }
 public BindingValidationTests(ValidationFixture fixture)
 {
     _resolver    = fixture.Resolver;
     _validator   = fixture.Validator;
     _termService = new LocalTerminologyService(_resolver);
 }
Esempio n. 13
0
        public static void Validate(Archetype archetype, ITerminologyService terminologyService)
        {
            AmValidator amValidator = new AmValidator(terminologyService);

            amValidator.ValidateArchetype(archetype);
        }
Esempio n. 14
0
        /// <summary>
        /// True if the archetype is valid overall; various tests should be used, including checks on
        /// node_ids, internal references, and constraint references.
        /// </summary>
        /// <returns></returns>
        public bool IsValid(ITerminologyService terminologyService)
        {
            if (!(this.NodeIdsValid() && this.InternalReferencesValid() && this.ConstraintReferencesValid()))
                return false;
            try
            {
                AmValidator.Validate(this, terminologyService);
            }
            catch(Exception ex)
            {
                if (ex.GetType() == typeof(RmInvariantException))
                    return false;

                throw ex;
            }

            return true;
        }
Esempio n. 15
0
 public ValidationContext(AcceptValidationError acceptErrorDelegate, FetchOperationalObject fetchObjectDelegate, ITerminologyService terminologyService)
     : this(acceptErrorDelegate, fetchObjectDelegate)
 {
     Check.Require(terminologyService != null, "terminologyService must not be null.");
     this.terminologyService = terminologyService;
 }
Esempio n. 16
0
 protected AmValidator(ITerminologyService terminologyService)
     : base(terminologyService)
 {
 }
Esempio n. 17
0
        public static void Validate(Archetype archetype, ITerminologyService terminologyService)
        {
            AmValidator amValidator = new AmValidator(terminologyService);

            amValidator.ValidateArchetype(archetype);
        }
Esempio n. 18
0
        internal static string OpenEhrTermDefTerm(string codeString, ITerminologyService terminologyService)
        {
            Check.Require(!string.IsNullOrEmpty(codeString), "codeString must not be null or Empty.");

            string termDefText = terminologyService.Terminology(OpenEhrTerminologyIdentifiers.TerminologyIdOpenehr)
                        .RubricForCode(codeString, _language);

            Check.Ensure(!string.IsNullOrEmpty(termDefText));

            return termDefText;
        }
Esempio n. 19
0
 protected AmValidator(ITerminologyService terminologyService)
     : base(terminologyService)
 {
 }
Esempio n. 20
0
        internal static bool ValidValueTermDef(DvCodedText dvCodedText, CAttribute cAttribute, ITerminologyService terminologyService)
        {
            string value = string.Empty;
            if (dvCodedText.DefiningCode.TerminologyId.Value == OpenEhrTerminologyIdentifiers.TerminologyIdOpenehr)

                value = OpenEhrTermDefTerm(dvCodedText.DefiningCode.CodeString, terminologyService);

            else if (dvCodedText.DefiningCode.TerminologyId.Value == "local")
                value = LocalTermDefText(dvCodedText.DefiningCode.CodeString, cAttribute);

            if (!string.IsNullOrEmpty(value)
                && !string.IsNullOrEmpty(dvCodedText.Value)
                && value != dvCodedText.Value)
            {
                return false;
            }
            if (!string.IsNullOrEmpty(value) && string.IsNullOrEmpty(dvCodedText.Value))
                dvCodedText.Value = value;

            return true;
        }
Esempio n. 21
0
        /// <summary>
        /// Create alternate registered role
        /// </summary>
        private MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.IdentifiedEntity CreateRegisteredRoleAlt(Person person, List <IResultDetail> details)
        {
            ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService;
            ITerminologyService         termService   = Context.GetService(typeof(ITerminologyService)) as ITerminologyService;

            var retVal = new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.IdentifiedEntity();

            var relations         = person.FindAllComponents(HealthServiceRecordSiteRoleType.RepresentitiveOf);
            var maskingIndicators = person.FindComponent(HealthServiceRecordSiteRoleType.FilterOf) as MaskingIndicator;
            var queryParameter    = person.FindComponent(HealthServiceRecordSiteRoleType.CommentOn | HealthServiceRecordSiteRoleType.ComponentOf) as QueryParameters;

            // Masking indicators
            if (maskingIndicators != null)
            {
                retVal.ConfidentialityCode = CreateCV <String>(maskingIndicators.MaskingCode, details);
            }
            else
            {
                retVal.ConfidentialityCode = new CV <String>("N");
            }

            retVal.Id         = CreateIISet(person.AlternateIdentifiers, details);
            retVal.StatusCode = ConvertStatus(person.Status, details);

            // Query parameter (i.e. the match strength)
            if (queryParameter != null)
            {
                retVal.SubjectOf = new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.Subject(
                    new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.ObservationEvent(
                        (queryParameter.MatchingAlgorithm & MatchAlgorithm.Soundex) != 0 ? "PHON" : "PTNM",
                        new REAL(queryParameter.Confidence)
                {
                    Precision = 2
                }
                        )
                    );
            }

            object gend = new CV <AdministrativeGender>()
            {
                NullFlavor = NullFlavor.NoInformation
            };

            Util.TryFromWireFormat(person.GenderCode, typeof(CV <AdministrativeGender>), out gend);

            // Set the identified person
            retVal.IdentifiedPerson = new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.Person(
                null,
                null,
                gend as CV <AdministrativeGender>,
                CreateTS(person.BirthTime, details),
                person.DeceasedTime != null,
                CreateTS(person.DeceasedTime, details),
                person.BirthOrder.HasValue ? (BL)true : null,
                person.BirthOrder,
                null,
                null,
                null,
                null);

            // Create names
            retVal.IdentifiedPerson.Name = new LIST <PN>();
            if (person.Names != null)
            {
                foreach (var name in person.Names)
                {
                    retVal.IdentifiedPerson.Name.Add(CreatePN(name, details));
                }
            }
            else
            {
                retVal.IdentifiedPerson.Name.NullFlavor = NullFlavor.NoInformation;
            }

            // Create telecoms
            retVal.IdentifiedPerson.Telecom = new LIST <TEL>();
            if (person.TelecomAddresses != null)
            {
                foreach (var tel in person.TelecomAddresses)
                {
                    retVal.IdentifiedPerson.Telecom.Add(CreateTEL(tel, details));
                }
            }
            else
            {
                retVal.IdentifiedPerson.Telecom.NullFlavor = NullFlavor.NoInformation;
            }

            // Create addresses
            retVal.IdentifiedPerson.Addr = new LIST <AD>();
            if (person.Addresses != null)
            {
                foreach (var addr in person.Addresses)
                {
                    retVal.IdentifiedPerson.Addr.Add(CreateAD(addr, details));
                }
            }
            else
            {
                retVal.IdentifiedPerson.Addr.NullFlavor = NullFlavor.NoInformation;
            }

            // Create AsOtherIds
            retVal.IdentifiedPerson.AsOtherIDs = new List <MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.OtherIDs>();
            if (person.OtherIdentifiers != null)
            {
                foreach (var othId in person.OtherIdentifiers)
                {
                    var otherIdentifier = new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.OtherIDs(
                        CreateII(othId.Value, details),
                        CreateCV <String>(othId.Key, details),
                        null);
                    // Any extensions that apply to this?
                    var extId   = person.FindExtension(o => o.Name == "AssigningIdOrganizationId" && o.PropertyPath == String.Format("OtherIdentifiers[{0}{1}]", otherIdentifier.Id.Root, otherIdentifier.Id.Extension));
                    var extName = person.FindExtension(o => o.Name == "AssigningIdOrganizationName" && o.PropertyPath == String.Format("OtherIdentifiers[{0}{1}]", otherIdentifier.Id.Root, otherIdentifier.Id.Extension));
                    if (extId != null || extName != null)
                    {
                        otherIdentifier.AssigningIdOrganization = new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.IdOrganization(
                            extId != null ? CreateII(extId.Value as DomainIdentifier, details) : null,
                            extName != null ? extName.Value as String : null
                            );
                    }
                    retVal.IdentifiedPerson.AsOtherIDs.Add(otherIdentifier);
                }
            }

            // Languages
            if (person.Language != null)
            {
                foreach (var lang in person.Language)
                {
                    // Translate the code
                    var langCode = new CodeValue(lang.Language, configService.OidRegistrar.GetOid("ISO639-1").Oid);

                    if (termService != null)
                    {
                        langCode = termService.Translate(langCode, configService.OidRegistrar.GetOid("ISO639-3").Oid);
                    }

                    retVal.IdentifiedPerson.LanguageCommunication.Add(new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.LanguageCommunication(
                                                                          CreateCV <String>(langCode, details),
                                                                          (lang.Type & LanguageType.Preferred) != 0
                                                                          ));
                }
            }

            // Personal Relationships
            if (relations != null)
            {
                foreach (PersonalRelationship relation in relations)
                {
                    if (!String.IsNullOrEmpty(relation.RelationshipKind))
                    {
                        retVal.IdentifiedPerson.PersonalRelationship.Add(new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.PersonalRelationship(
                                                                             relation.RelationshipKind,
                                                                             new MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.ParentPerson(
                                                                                 CreateII(relation.AlternateIdentifiers[0], details),
                                                                                 CreatePN(relation.LegalName, details)
                                                                                 )
                                                                             ));
                    }
                }
            }

            return(retVal);
        }
 public FallbackTerminologyService(LocalTerminologyService local, ITerminologyService fallback)
 {
     _localService    = local;
     _fallbackService = fallback;
 }
Esempio n. 23
0
 public ValidationContext(AcceptValidationError acceptErrorDelegate, FetchOperationalObject fetchObjectDelegate, ITerminologyService terminologyService)
     : this(acceptErrorDelegate, fetchObjectDelegate)
 {
     Check.Require(terminologyService != null, "terminologyService must not be null.");
     this.terminologyService = terminologyService;
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MedicationFormStrengthRequestHandler"/> class.
 /// </summary>
 /// <param name="terminologyService">The terminology service.</param>
 public MedicationFormStrengthRequestHandler(ITerminologyService terminologyService)
 {
     _terminologyService = terminologyService;
 }
Esempio n. 25
0
        internal static bool ValidValueTermDef(DvCodedText dvCodedText, CAttribute cAttribute, ITerminologyService terminologyService)
        {
            string value = string.Empty;
            if (dvCodedText.DefiningCode.TerminologyId.Value == OpenEhrTerminologyIdentifiers.TerminologyIdOpenehr)

                value = OpenEhrTermDefTerm(dvCodedText.DefiningCode.CodeString, terminologyService);

            else if (dvCodedText.DefiningCode.TerminologyId.Value == "local")
                value = LocalTermDefText(dvCodedText.DefiningCode.CodeString, cAttribute);

            if (!string.IsNullOrEmpty(value)
                && !string.IsNullOrEmpty(dvCodedText.Value)
                && value != dvCodedText.Value)
            {
                return false;
            }
            if (!string.IsNullOrEmpty(value) && string.IsNullOrEmpty(dvCodedText.Value))
                dvCodedText.Value = value;

            return true;
        }