internal static string GetRelationship(string codeA, string codeB)
        {
            string outcome = string.Empty;

            if (codeA == codeB)
            {
                outcome = CODE_RELATIONSHIP_EQUIVALENT;
            }
            // then test Code A is subsumed by Code B - i.e.Code B is the supertype
            else if ((bool)SnomedCtSearch.IsSubsumedBy(codeA, codeB))
            {
                outcome = CODE_RELATIONSHIP_SUBSUMED_BY;
            }
            else if ((bool)SnomedCtSearch.IsSubsumedBy(codeB, codeA))
            {
                // if not...test if Code A subsumes code B - i.e. code A is actually the supertype
                outcome = CODE_RELATIONSHIP_SUBSUMES;
            }

            return(outcome);
        }
        private static Resource FindMatchesOperation(string systemURL, NameValueCollection queryParam)
        {
            string versionVal   = Utilities.GetQueryValue("version", queryParam);
            string focusConcept = Utilities.GetQueryValue("focus", queryParam);
            string exactVal     = Utilities.GetQueryValue("exact", queryParam);

            List <Coding> attributeCodeVals = GetAttributePairs(queryParam);

            if (string.IsNullOrEmpty(systemURL))
            {
                throw new Exception(MISSING_CODESYSTEM);
            }
            else if (string.IsNullOrEmpty(focusConcept))
            {
                throw new Exception(MISSING_FOCUS_CONCEPT);
            }
            else if (attributeCodeVals.Count < 1)
            {
                throw new Exception(MISSING_ATTRIBUTE);
            }
            else if (string.IsNullOrEmpty(exactVal))
            {
                throw new Exception(MISSING_EXACT);
            }
            else if (exactVal.ToLower() != "true")
            {
                throw new Exception(UNSUPPORTED_EXACT_SETTING);
            }

            Parameters param = new Parameters();

            if (systemURL == (FhirSnomed.URI))
            {
                // Get Proximal Primitive(s) of Focus Code
                List <Coding> proximalPrimitiveCodeVals = SnomedCtSearch.GetProximalPrimitives(focusConcept, false);
                if (proximalPrimitiveCodeVals.Count < 1)
                {
                    throw new Exception(INVALID_CODE);
                }

                // load proximal primitves into string array (5 is max number of proximal primitives for any one concept)
                string[] pp      = new string[5];
                int      ppCount = 0;
                foreach (Coding cc in proximalPrimitiveCodeVals)
                {
                    //if (cc.Code != focusConcept)
                    //{
                    pp[ppCount] = cc.Code;
                    ppCount++;
                    //}
                }

                // load attribute types and values into arrays (30 is max number of non-isa relationships for any one concept)
                string[] attType        = new string[30];
                string[] attValue       = new string[30];
                int      attributeCount = 0;
                int      relGroup;
                int      relGroupSize = 1;

                foreach (Coding cc in attributeCodeVals)
                {
                    attType[attributeCount]  = cc.Code;
                    attValue[attributeCount] = cc.Display;
                    int.TryParse(cc.Version, out relGroup);
                    relGroupSize = (relGroup > relGroupSize) ? relGroup : relGroupSize;
                    attributeCount++;
                }

                // get attributes and definition status from focus concept (as may need to add attributes if concept fully-defined)
                List <Coding> focusAttributes = SnomedCtSearch.GetAttributes(focusConcept);

                foreach (Coding cc in focusAttributes)
                {
                    if (cc.System.ToUpper() != "FULLY DEFINED")
                    {
                        break;
                    }

                    bool addFocusAttribute = true;

                    foreach (Coding acv in attributeCodeVals)
                    {
                        if (acv.Code == cc.Code)
                        {
                            addFocusAttribute = false;
                            break;
                        }
                    }

                    if (addFocusAttribute)
                    {
                        for (int rg = 0; rg < relGroupSize; rg++)
                        {
                            attType[attributeCount]  = cc.Code;
                            attValue[attributeCount] = cc.Display;
                            attributeCount++;
                        }
                    }
                }

                List <Coding> matchVals = SnomedCtSearch.GetCompositionMatch(attType, attValue, pp, attributeCount);

                if (matchVals.Count < 1)
                {
                    throw new Exception(NO_EXACT_MATCH);
                }

                List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >();
                foreach (Coding cc in matchVals)
                {
                    tuples.Add(new Tuple <string, Base>("code", new Coding {
                        Code = cc.Code, Display = cc.Display, System = systemURL
                    }));
                    param.Add("match", tuples);
                }
            }
            else
            {
                throw new Exception(FIND_MATCHES_UNSUPPORTED);
            }

            return(param);
        }
Пример #3
0
        private void FillValues(string version, string nzmpCode)
        {
            this.conceptMap = new ConceptMap();

            this.conceptMap.Id  = "NZMP_SCT";
            this.conceptMap.Url = ServerCapability.TERMINZ_CANONICAL + "/ConceptMap/NzMp_Sct";

            this.conceptMap.Name         = this.conceptMap.Id;
            this.conceptMap.Title        = "NZMT medicinal product to SNOMED CT map";
            this.conceptMap.Description  = new Markdown("A mapping between NZMT Medicinal Products and SNOMED CT, published by NZMT in May 2018.");
            this.conceptMap.Version      = "20180501";
            this.conceptMap.Status       = PublicationStatus.Draft;
            this.conceptMap.Experimental = true;
            this.conceptMap.Publisher    = "Ministry of Health";
            this.conceptMap.Date         = new FhirDateTime(2018, 05, 1).Value;
            this.conceptMap.Purpose      = new Markdown("To begin alignment between NZMT and SNOMED CT");
            this.conceptMap.Copyright    = new Markdown("© 2018+ New Zealand Crown Copyright");

            ContactPoint cp = new ContactPoint {
                System = ContactPoint.ContactPointSystem.Email, Value = "*****@*****.**"
            };
            ContactDetail cd = new ContactDetail();

            cd.Telecom.Add(cp);
            cd.Name = "Patients First Ltd";
            this.conceptMap.Contact.Add(cd);

            string sourceCodeSystemUri = NzMt.URI;
            string sourceValueSetUri   = @"http://itp.patientsfirst.org.nz/ValueSet/NzulmMp";

            string targetCodeSystemUri = FhirSnomed.URI;
            string targetValueSetUri   = @"http://snomed.info/sct?fhir_vs";

            this.conceptMap.Source = new FhirUri(sourceValueSetUri);
            this.conceptMap.Target = new FhirUri(targetValueSetUri);

            if ((string.IsNullOrEmpty(version) || version == this.conceptMap.Version))
            {
                List <Coding> map = SnomedCtSearch.GetConceptMap_NZ(REFSET_ID, nzmpCode);

                ConceptMap.GroupComponent gc = new ConceptMap.GroupComponent();
                gc.Source = sourceCodeSystemUri;
                gc.Target = targetCodeSystemUri;

                foreach (Coding mv in map)
                {
                    ConceptMap.ConceptMapEquivalence  cme = ConceptMap.ConceptMapEquivalence.Equivalent;
                    ConceptMap.SourceElementComponent sec = new ConceptMap.SourceElementComponent {
                        Code = mv.Version, Display = mv.System
                    };
                    ConceptMap.TargetElementComponent tec = new ConceptMap.TargetElementComponent {
                        Code = mv.Code, Equivalence = cme, Display = mv.Display
                    };

                    sec.Target.Add(tec);
                    gc.Element.Add(sec);
                }

                this.conceptMap.Group.Add(gc);
            }
        }
        private static Resource LookupOperation(string systemURL, NameValueCollection queryParam)
        {
            CodeSystem codeSys = GetCodeSystem(TerminologyOperation.lookup, systemURL, queryParam);

            if (codeSys.Concept.Count < 1)
            {
                throw new Exception(INVALID_CODE);
            }

            string codeVal = Utilities.GetQueryValue("code", queryParam);
            //string versionVal = Utilities.GetQueryValue("version", queryParam);
            string propertyVal = Utilities.GetQueryValue("property", queryParam);
            string languageVal = Utilities.GetQueryValue("displayLanguage", queryParam);

            if (!string.IsNullOrEmpty(languageVal) && languageVal != "en-NZ")
            {
                throw new Exception(UNSUPPORTED_DISPLAY_LANGUAGE);
            }

            bool displayCode                = false;
            bool displaySystem              = false;
            bool displayVersion             = true;
            bool displayDisplay             = true;
            bool displayDefinition          = false;
            bool displayDesignation         = false;
            bool displayParents             = false;
            bool displayChildren            = false;
            bool displaySubstance           = false;
            bool displayInactive            = false;
            bool displayModuleId            = false;
            bool displaySufficientlyDefined = false;
            bool displayNf              = false;
            bool displayNfTerse         = false;
            bool displayAllAttributes   = false;
            bool displaySingleAttribute = false;
            bool displayTermType        = false;

            // standard properties...defined for all Code Systems

            /*
             * // The following properties are defined for all code systems:
             * // system, version, display, definition, designation, parent, child, and lang.X where X is a language code in a designation
             * // SCT properties
             * // inactive	boolean	Whether the code is active or not (defaults to false). This is derived from the active column in the Concept file of the RF2 Distribution (by inverting the value)
             * // sufficientlyDefined	boolean	True if the description logic definition of the concept includes sufficient conditions (i.e., if the concept is not primitive).
             * // moduleId	code	The SNOMED CT concept id of the module that the concept belongs to.
             * // normalForm	string	Generated Normal form expression for the provided code or expression, with terms
             * // normalFormTerse	string	Generated Normal form expression for the provided code or expression, conceptIds only
             * // In addition, any SNOMED CT relationships where the relationship type is subsumed by Attribute (246061005) automatically become properties. For example, laterality:
             * // Laterality	code	In this case, the URI (See the code system definition) is http://snomed.info/id/272741003, which can be used to unambiguously map to the underlying concept
             */

            if (!string.IsNullOrEmpty(propertyVal))
            {
                string pvl = propertyVal.ToLower();
                displayCode   = (pvl.Contains("code"));
                displaySystem = (pvl.Contains("system"));
                //displayVersion = (pvl.Contains("version")); // always return code system version
                //displayDisplay = true;  // default true - don't see much point in looking up the code and not displaying its description! (otherwise use validate-code)
                displayDefinition          = (pvl.Contains("definition"));
                displayDesignation         = (pvl.Contains("designation"));
                displayParents             = (pvl.Contains("parent"));
                displayChildren            = (pvl.Contains("child"));
                displaySubstance           = (pvl.Contains("substance"));
                displayTermType            = (pvl.Contains("termtype"));
                displayInactive            = (pvl.Contains("inactive"));
                displaySufficientlyDefined = (pvl.Contains("sufficientlydefined"));
                displayModuleId            = (pvl.Contains("moduleid"));
                displayNfTerse             = (pvl.Contains("normalformterse"));
                displayNf            = (pvl.Contains("normalform") && !displayNfTerse);
                displayAllAttributes = (pvl.Contains(FhirSnomed.SCT_ATTRIBUTE_CONCEPT));
                if (!displayAllAttributes)
                {
                    displaySingleAttribute = (pvl.Count(x => Char.IsDigit(x)) > 7);
                }
            }

            List <Coding> loincPropertyVals         = new List <Coding>();
            List <Coding> substanceCodeVals         = new List <Coding>();
            List <Coding> designationCodeVals       = new List <Coding>();
            List <Coding> childCodeVals             = new List <Coding>();
            List <Coding> parentCodeVals            = new List <Coding>();
            List <Coding> propertyCodeVals          = new List <Coding>();
            List <Coding> attributeCodeVals         = new List <Coding>();
            List <Coding> termTypeVals              = new List <Coding>();
            List <Coding> proximalPrimitiveCodeVals = new List <Coding>();

            // CodeSystem-specific actions

            if (systemURL == NzMt.URI)
            {
                string nzulmType = codeSys.Concept[0].Definition;
                string mp_id     = codeSys.Concept[0].ElementId;
                if (displaySubstance)
                {
                    substanceCodeVals = NzUlmSearch.GetConceptSubstanceDataByCode(mp_id, nzulmType);
                }
            }

            if (systemURL == FhirLoinc.URI)
            {
                if (!string.IsNullOrEmpty(propertyVal))
                {
                    loincPropertyVals = LoincSearch.GetPropertiesByCode(codeVal, propertyVal.ToUpper());
                }
            }

            if (systemURL == FhirRxNorm.URI)
            {
                if (displayTermType)
                {
                    termTypeVals = RxNormSearch.GetPropertiesByCode(codeVal);
                }
            }

            if (systemURL == FhirSnomed.URI)
            {
                displaySystem      = true;
                displayDesignation = true;
                displayInactive    = true;

                if (codeSys.Concept.Count > 0)
                {
                    if (displayDesignation)
                    {
                        designationCodeVals = SnomedCtSearch.GetConceptDesignationsByCode(codeVal);
                    }

                    if (displayInactive || displayModuleId || displaySufficientlyDefined)
                    {
                        propertyCodeVals = SnomedCtSearch.GetConceptPropertiesByCode(codeVal);
                    }

                    if (displayChildren)
                    {
                        childCodeVals = SnomedCtSearch.GetChildCodes(codeVal);
                    }

                    if (displayParents)
                    {
                        parentCodeVals = SnomedCtSearch.GetParentCodes(codeVal);
                    }

                    if (displayAllAttributes || displaySingleAttribute)
                    {
                        List <Coding> acv = SnomedCtSearch.GetAttributes(codeVal);
                        if (displayAllAttributes)
                        {
                            attributeCodeVals = acv;
                        }
                        else
                        {
                            foreach (Coding cv in acv)
                            {
                                if (propertyVal.Contains(cv.Code))
                                {
                                    attributeCodeVals.Add(cv);
                                }
                            }
                        }
                    }
                }
            }

            // build return parameters resource using default & requested properties
            Parameters param = new Parameters();

            if (codeSys.Concept != null)
            {
                param.Add("name", codeSys.NameElement);

                foreach (CodeSystem.ConceptDefinitionComponent comp in codeSys.Concept)
                {
                    if (displaySystem)
                    {
                        param.Add("system", codeSys.UrlElement);
                    }
                    if (displayVersion)
                    {
                        param.Add("version", codeSys.VersionElement);
                    }
                    if (displayCode)
                    {
                        param.Add("code", comp.CodeElement);
                    }
                    if (displayDisplay)
                    {
                        param.Add("display", comp.DisplayElement);
                    }
                }

                foreach (Coding prop in loincPropertyVals)
                {
                    // return all of them
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("code", new FhirString(prop.Code)),
                        new Tuple <string, Base>("value", new FhirString(prop.Display))
                    };
                    param.Add("property", tuples);
                }

                foreach (Coding tty in termTypeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        //new Tuple<string, Base>("code", new FhirString(tty.Version)),
                        //new Tuple<string, Base>("value", new FhirString(FhirRxNorm.GetTermType(tty.Version))),
                        //new Tuple<string, Base>("description", new FhirString(tty.Display))
                        new Tuple <string, Base>("use", new Coding {
                            Display = FhirRxNorm.GetTermType(tty.Version), System = FhirRxNorm.URI, Code = tty.Version
                        }),
                        new Tuple <string, Base>("value", new FhirString(tty.Display))
                    };
                    param.Add("termType", tuples);
                }

                foreach (Coding desig in designationCodeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("use", new Coding {
                            Display = desig.System, System = FhirSnomed.URI, Code = FhirSnomed.GetDesignationTypeId(desig.System)
                        }),
                        new Tuple <string, Base>("value", new FhirString(desig.Display))
                    };
                    param.Add("designation", tuples);
                }

                foreach (Coding prop in propertyCodeVals)
                {
                    if ((prop.Code == "inactive" && displayInactive) ||
                        (prop.Code == "sufficientlyDefined" && displaySufficientlyDefined) ||
                        (prop.Code == "moduleId" && displayModuleId))
                    {
                        List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                        {
                            new Tuple <string, Base>("code", new FhirString(prop.Code)),
                            new Tuple <string, Base>("value", new FhirString(prop.Display))
                        };
                        param.Add("property", tuples);
                    }
                }

                if (displayNf || displayNfTerse)
                {
                    string nf = FhirSnomed.GetNormalFormDisplay(codeVal, displayNf);
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("code", new FhirString(displayNf ? "normalForm" : "normalFormTerse")),
                        new Tuple <string, Base>("value", new FhirString(nf))
                    };
                    param.Add("property", tuples);
                }

                foreach (Coding subst in substanceCodeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("use", new Coding {
                            Display = subst.System
                        })
                    };
                    if (!string.IsNullOrEmpty(subst.Code))
                    {
                        tuples.Add(new Tuple <string, Base>("code", new FhirString(subst.Code)));
                    }
                    tuples.Add(new Tuple <string, Base>("value", new FhirString(subst.Display)));
                    param.Add("substance", tuples);
                }

                foreach (Coding parent in parentCodeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("code", new FhirString("Parent")),
                        new Tuple <string, Base>("value", new FhirString(parent.Code)),
                        new Tuple <string, Base>("description", new FhirString(parent.Display))
                    };
                    param.Add("property", tuples);
                }

                foreach (Coding child in childCodeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("code", new FhirString("Child")),
                        new Tuple <string, Base>("value", new FhirString(child.Code)),
                        new Tuple <string, Base>("description", new FhirString(child.Display))
                    };
                    param.Add("property", tuples);
                }

                foreach (Coding attrib in attributeCodeVals)
                {
                    List <Tuple <string, Base> > tuples = new List <Tuple <string, Base> >
                    {
                        new Tuple <string, Base>("code", new Code {
                            Value = attrib.Code
                        }),
                        new Tuple <string, Base>("valueCode", new Code {
                            Value = attrib.Display
                        })
                    };
                    param.Add("property", tuples);
                }
            }

            return(param);
        }
        public static Resource GetRequest(string id, NameValueCollection queryParam)
        {
            Bundle locBundle = new Bundle
            {
                Id   = Guid.NewGuid().ToString(),
                Type = Bundle.BundleType.Searchset
            };

            locBundle.Link.Add(new Bundle.LinkComponent {
                Url = ServerCapability.TERMINZ_CANONICAL + "/Location", Relation = "self"
            });

            Location     location = new Location();
            Organization org      = new Organization();

            string identifier         = GetIdentifier(id, queryParam);
            string address            = Utilities.GetQueryValue("address", queryParam);
            string address_city       = Utilities.GetQueryValue("address-city", queryParam);
            string address_postalcode = Utilities.GetQueryValue("address-postalcode", queryParam);
            string name     = Utilities.GetQueryValue("name", queryParam);
            string type     = Utilities.GetQueryValue("type", queryParam);
            bool   idPassed = !string.IsNullOrEmpty(id);
            int    matches  = 0;

            // facilitate (more efficient) postcode and city filtering at DB layer
            if (!string.IsNullOrEmpty(address_postalcode) && string.IsNullOrEmpty(address))
            {
                address = address_postalcode;
            }

            if (!string.IsNullOrEmpty(address_city) && string.IsNullOrEmpty(address))
            {
                address = address_city;
            }

            if (string.IsNullOrEmpty(identifier) && string.IsNullOrEmpty(name) && string.IsNullOrEmpty(address) && string.IsNullOrEmpty(type))
            {
                return(OperationOutcome.ForMessage("No valid search parameters.", OperationOutcome.IssueType.Invalid, OperationOutcome.IssueSeverity.Error));
            }

            //CodeableConcept hpiFac = new CodeableConcept { Text = "HPI-FAC" };

            try
            {
                List <HpiFacility> facilities = SnomedCtSearch.GetLocations(identifier, name, address, type);

                foreach (HpiFacility fac in facilities)
                {
                    bool addLocation = true;

                    Address locAddress = Utilities.GetAddress(fac.FacilityAddress.Trim());

                    if (!string.IsNullOrEmpty(address_city) && locAddress.City.ToUpper() != address_city.ToUpper())
                    {
                        addLocation = false;
                    }

                    if (!string.IsNullOrEmpty(address_postalcode) && locAddress.PostalCode.ToUpper() != address_postalcode.ToUpper())
                    {
                        addLocation = false;
                    }

                    if (addLocation)
                    {
                        bool addOrg = false;
                        org      = new Organization();
                        location = new Location
                        {
                            Id = fac.FacilityId.Trim()
                        };
                        location.Identifier.Add(new Identifier {
                            Value = fac.FacilityId.Trim(), System = NAMING_SYSTEM_IDENTIFIER
                        });
                        location.Name   = fac.FacilityName.Trim();
                        location.Status = Location.LocationStatus.Active;
                        location.Mode   = Location.LocationMode.Instance;
                        location.Type.Add(new CodeableConcept {
                            Text = fac.FacilityTypeName.Trim()
                        });
                        location.Address = locAddress;
                        AddNarrative(location);

                        if (!string.IsNullOrEmpty(fac.OrganisationId))
                        {
                            try
                            {
                                org = (Organization)AdministrationOrganisation.GetRequest(fac.OrganisationId, null);
                                location.ManagingOrganization = new ResourceReference {
                                    Reference = fac.OrganisationId
                                };
                                addOrg = true;
                            }
                            catch { }
                        }

                        locBundle.AddResourceEntry(location, ServerCapability.TERMINZ_CANONICAL + "/Location/" + fac.FacilityId.Trim());
                        matches++;

                        if (addOrg)
                        {
                            locBundle.AddResourceEntry(org, ServerCapability.TERMINZ_CANONICAL + "/Organization" + "/" + fac.OrganisationId.Trim());
                        }
                    }
                }

                if (matches == 0)
                {
                    return(OperationOutcome.ForMessage("No Locations match search parameter values.", OperationOutcome.IssueType.NotFound, OperationOutcome.IssueSeverity.Information));
                }

                locBundle.Total = matches;
            }
            catch (Exception ex)
            {
                return(OperationOutcome.ForMessage("Error: " + ex.Message, OperationOutcome.IssueType.Invalid, OperationOutcome.IssueSeverity.Error));
            }

            // always return bundle because of contained resources <TODO> implement _include so user can specify this

            return(locBundle);
        }
Пример #6
0
        private void FillValues(TerminologyOperation termOp, string version, string code, string filter, int offsetNo, int countNo)
        {
            this.valueSet = new ValueSet();

            this.valueSet.Id  = "intensional-case-2";
            this.valueSet.Url = "http://www.healthintersections.com.au/fhir/ValueSet/intensional-case-2";
            this.valueSet.Identifier.Add(new Identifier {
                Value = this.valueSet.Id
            });
            this.valueSet.Name         = this.valueSet.Id;
            this.valueSet.Title        = "Terminology Services Test: Intensional case #2";
            this.valueSet.Description  = new Markdown("All Snomed codes that are subsumed by 38341003 (Hypertensive disorder, systemic arterial)");
            this.valueSet.Version      = "R4";
            this.valueSet.Status       = PublicationStatus.Active;
            this.valueSet.Experimental = true;
            this.valueSet.Date         = Hl7.Fhir.Model.Date.Today().Value;
            this.valueSet.Publisher    = "Grahame Grieve";
            this.valueSet.Copyright    = new Markdown("This value set includes content from SNOMED CT, which is copyright © 2002+ International Health Terminology Standards Development Organisation (IHTSDO), and distributed by agreement between IHTSDO and HL7. Implementer use of SNOMED CT is not covered by this agreement");

            ContactPoint cp = new ContactPoint {
                System = ContactPoint.ContactPointSystem.Email, Value = "*****@*****.**"
            };
            ContactDetail cd = new ContactDetail();

            cd.Telecom.Add(cp);
            this.valueSet.Contact.Add(cd);

            ValueSet.ConceptSetComponent cs = new ValueSet.ConceptSetComponent();
            cs.System  = FhirSnomed.URI;
            cs.Version = FhirSnomed.CURRENT_VERSION;
            cs.Filter.Add(new ValueSet.FilterComponent {
                Property = "concept", Op = FilterOperator.IsA, Value = "38341003"
            });

            string codeCode       = string.Empty;
            string codeDisplay    = string.Empty;
            string codeDefinition = string.Empty;

            if (string.IsNullOrEmpty(version) || version == cs.Version)
            {
                if (string.IsNullOrEmpty(version) || version == cs.Version)
                {
                    if (termOp == TerminologyOperation.expand || termOp == TerminologyOperation.validate_code)
                    {
                        List <Coding> codeVals = new List <Coding>();
                        codeVals = SnomedCtSearch.GetSubsumedCodes("38341003", true);
                        ValueSet.ExpansionComponent es = new ValueSet.ExpansionComponent();
                        foreach (Coding codeVal in codeVals)
                        {
                            if (TerminologyValueSet.MatchValue(codeVal.Code, codeVal.Display, code, filter))
                            {
                                es.Contains.Add(new ValueSet.ContainsComponent {
                                    Code = codeVal.Code, Display = codeVal.Display, System = cs.System
                                });
                            }
                        }
                        this.valueSet = TerminologyValueSet.AddExpansion(this.valueSet, es, offsetNo, countNo);
                    }
                    else
                    {
                        this.valueSet.Compose = new ValueSet.ComposeComponent();
                        this.valueSet.Compose.Include.Add(cs);
                    }
                }
            }
        }
Пример #7
0
        private void FillValues(string version, string sctid)
        {
            this.conceptMap = new ConceptMap();

            this.conceptMap.Id  = "SCT_NZREAD";
            this.conceptMap.Url = ServerCapability.TERMINZ_CANONICAL + "/ConceptMap/Sct_NzRead";
            //this.conceptMap.Identifier = new Identifier { System = "urn:ietf:rfc:3986", Value = "urn:uuid:53cd62ee-033e-414c-9f58-3ca97b5ffc3b" };

            this.conceptMap.Name  = this.conceptMap.Id;
            this.conceptMap.Title = "SNOMED CT to NZ Read Codes";

            string caveat = string.Empty;

            if (string.IsNullOrEmpty(sctid))
            {
                caveat = " Definition only - complete map too large to download (over 100k elements).";
            }

            this.conceptMap.Description  = new Markdown("A mapping between SNOMED CT and the NZ Read Codes, published by NHS Digital and augmented for use in NZ." + caveat);
            this.conceptMap.Version      = "20190501";
            this.conceptMap.Status       = PublicationStatus.Draft;
            this.conceptMap.Experimental = true;
            this.conceptMap.Publisher    = "Ministry of Health";
            this.conceptMap.Date         = new FhirDateTime(2019, 05, 01).Value;
            this.conceptMap.Purpose      = new Markdown("Used by the NZ Ministry of Social Development to help process SNOMED - coded work capacity medical certificates.");
            this.conceptMap.Copyright    = new Markdown("© 2010+ New Zealand Crown Copyright");

            ContactPoint cp = new ContactPoint {
                System = ContactPoint.ContactPointSystem.Email, Value = "*****@*****.**"
            };
            ContactDetail cd = new ContactDetail();

            cd.Telecom.Add(cp);
            cd.Name = "Patients First Ltd";
            this.conceptMap.Contact.Add(cd);

            string sourceCodeSystemUri = FhirSnomed.URI;
            string sourceValueSetUri   = @"http://snomed.info/sct?fhir_vs";

            string targetCodeSystemUri = @"http://health.govt.nz/read-codes";
            string targetValueSetUri   = @"http://health.govt.nz/read-codes/fhir_vs";

            this.conceptMap.Source = new FhirUri(sourceValueSetUri);
            this.conceptMap.Target = new FhirUri(targetValueSetUri);

            if ((string.IsNullOrEmpty(version) || version == this.conceptMap.Version) && !string.IsNullOrEmpty(sctid))
            {
                List <Coding> map = SnomedCtSearch.GetConceptMap_NZ(REFSET_ID, sctid);

                ConceptMap.GroupComponent gc = new ConceptMap.GroupComponent();
                gc.Source = sourceCodeSystemUri;
                gc.Target = targetCodeSystemUri;

                foreach (Coding mv in map)
                {
                    ConceptMap.ConceptMapEquivalence  cme = ConceptMap.ConceptMapEquivalence.Equivalent;
                    ConceptMap.SourceElementComponent sec = new ConceptMap.SourceElementComponent {
                        Code = mv.Version, Display = mv.System
                    };
                    ConceptMap.TargetElementComponent tec = new ConceptMap.TargetElementComponent {
                        Code = mv.Code, Equivalence = cme, Display = mv.Display
                    };

                    sec.Target.Add(tec);
                    gc.Element.Add(sec);
                }

                this.conceptMap.Group.Add(gc);
            }
        }
        public static Resource GetRequest(string id, NameValueCollection queryParam)
        {
            Bundle orgBundle = new Bundle
            {
                Id   = Guid.NewGuid().ToString(),
                Type = Bundle.BundleType.Searchset
            };

            orgBundle.Link.Add(new Bundle.LinkComponent {
                Url = ServerCapability.TERMINZ_CANONICAL + "/Organization", Relation = "self"
            });

            Organization organization = new Organization();

            string identifier         = GetIdentifier(id, queryParam);
            string address            = Utilities.GetQueryValue("address", queryParam);
            string address_city       = Utilities.GetQueryValue("address-city", queryParam);
            string address_postalcode = Utilities.GetQueryValue("address-postalcode", queryParam);
            string name     = Utilities.GetQueryValue("name", queryParam);
            string type     = Utilities.GetQueryValue("type", queryParam);
            bool   idPassed = !string.IsNullOrEmpty(id);
            int    matches  = 0;

            // facilitate (more efficient) postcode and city filtering at DB layer
            if (!string.IsNullOrEmpty(address_postalcode) && string.IsNullOrEmpty(address))
            {
                address = address_postalcode;
            }

            if (!string.IsNullOrEmpty(address_city) && string.IsNullOrEmpty(address))
            {
                address = address_city;
            }

            if (string.IsNullOrEmpty(identifier) && string.IsNullOrEmpty(name) && string.IsNullOrEmpty(address) && string.IsNullOrEmpty(type))
            {
                return(OperationOutcome.ForMessage("No valid search parameters.", OperationOutcome.IssueType.Invalid, OperationOutcome.IssueSeverity.Error));
            }

            //CodeableConcept hpiFac = new CodeableConcept { Text = "HPI-ORG" };

            List <HpiOrganisation> organisations = SnomedCtSearch.GetOrganisations(identifier, name, address, type);

            foreach (HpiOrganisation org in organisations)
            {
                bool addOrg = true;

                Address orgAddress = Utilities.GetAddress(org.OrganisationAddress.Trim());

                if (!string.IsNullOrEmpty(address_city) && orgAddress.City.ToUpper() != address_city.ToUpper())
                {
                    addOrg = false;
                }

                if (!string.IsNullOrEmpty(address_postalcode) && orgAddress.PostalCode.ToUpper() != address_postalcode.ToUpper())
                {
                    addOrg = false;
                }

                if (addOrg)
                {
                    organization = new Organization
                    {
                        Id = org.OrganisationId.Trim()
                    };
                    organization.Identifier.Add(new Identifier {
                        Value = org.OrganisationId.Trim(), System = NAMING_SYSTEM_IDENTIFIER
                    });
                    organization.Name   = org.OrganisationName.Trim();
                    organization.Active = true;
                    organization.Type.Add(new CodeableConcept {
                        Text = org.OrganisationTypeName.Trim()
                    });
                    organization.Address.Add(orgAddress);
                    AddNarrative(organization);
                    orgBundle.AddResourceEntry(organization, ServerCapability.TERMINZ_CANONICAL + "/Organization/ " + org.OrganisationId.Trim());
                    matches++;
                }
            }

            if (matches == 0)
            {
                return(OperationOutcome.ForMessage("No Organisations match search parameter values.", OperationOutcome.IssueType.NotFound, OperationOutcome.IssueSeverity.Information));
            }
            else if (matches == 1 && idPassed)
            {
                return(organization);
            }

            orgBundle.Total = matches;

            return(orgBundle);
        }
Пример #9
0
        private void FillValues(string version, string readcode)
        {
            this.conceptMap = new ConceptMap();

            this.conceptMap.Id  = "NZREAD_SCT";
            this.conceptMap.Url = ServerCapability.TERMINZ_CANONICAL + "/ConceptMap/NzRead_Sct";
            //this.conceptMap.Identifier = new Identifier { System = "urn:ietf:rfc:3986", Value = "urn:uuid:53cd62ee-033e-414c-9f58-3ca97b5ffc3b" };

            this.conceptMap.Name  = this.conceptMap.Id;
            this.conceptMap.Title = "NZ Read Codes to SNOMED CT";

            string caveat = string.Empty;

            if (string.IsNullOrEmpty(readcode))
            {
                caveat = " Definition only - complete map too large to download (over 100k elements).";
            }

            this.conceptMap.Description  = new Markdown("A mapping between the NZ Read Codes and SNOMED CT, published by NHS Digital and augmented for use in NZ." + caveat);
            this.conceptMap.Version      = "20190501";
            this.conceptMap.Status       = PublicationStatus.Draft;
            this.conceptMap.Experimental = true;
            this.conceptMap.Publisher    = "Ministry of Health";
            this.conceptMap.Date         = new FhirDateTime(2019, 05, 01).Value;
            this.conceptMap.Purpose      = new Markdown("To help primary care facilities translate legacy Read Codes");
            this.conceptMap.Copyright    = new Markdown("© 2010+ New Zealand Crown Copyright");

            ContactPoint cp = new ContactPoint {
                System = ContactPoint.ContactPointSystem.Email, Value = "*****@*****.**"
            };
            ContactDetail cd = new ContactDetail();

            cd.Telecom.Add(cp);
            cd.Name = "Patients First Ltd";
            this.conceptMap.Contact.Add(cd);

            string sourceCodeSystemUri = @"http://health.govt.nz/read-codes";
            string sourceValueSetUri   = @"http://health.govt.nz/read-codes/fhir_vs";

            string targetCodeSystemUri = FhirSnomed.URI;
            string targetValueSetUri   = @"http://snomed.info/sct?fhir_vs";

            this.conceptMap.Source = new FhirUri(sourceValueSetUri);
            this.conceptMap.Target = new FhirUri(targetValueSetUri);

            if ((string.IsNullOrEmpty(version) || version == this.conceptMap.Version) && !string.IsNullOrEmpty(readcode))
            {
                // add any missing periods to end of code and default Term ID of '00'
                //readcode = readcode.PadRight(5, '.');
                //readcode = readcode + (readcode.Length == 5 ? "00" : "");

                List <Coding> map = SnomedCtSearch.GetConceptMap_NZ(REFSET_ID, readcode);

                ConceptMap.GroupComponent gc = new ConceptMap.GroupComponent();
                gc.Source = sourceCodeSystemUri;
                gc.Target = targetCodeSystemUri;

                foreach (Coding mv in map)
                {
                    ConceptMap.ConceptMapEquivalence  cme = ConceptMap.ConceptMapEquivalence.Equivalent;
                    ConceptMap.SourceElementComponent sec = new ConceptMap.SourceElementComponent {
                        Code = mv.Version, Display = mv.System
                    };
                    ConceptMap.TargetElementComponent tec = new ConceptMap.TargetElementComponent {
                        Code = mv.Code, Equivalence = cme, Display = mv.Display
                    };

                    sec.Target.Add(tec);
                    gc.Element.Add(sec);
                }

                this.conceptMap.Group.Add(gc);
            }
        }