private static Resource ValidateCodeOperation(string systemURL, NameValueCollection queryParam)
        {
            string codeVal     = Utilities.GetQueryValue("code", queryParam);
            string displayVal  = Utilities.GetQueryValue("display", queryParam);
            string languageVal = Utilities.GetQueryValue("displayLanguage", queryParam);

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

            FhirBoolean validCode    = new FhirBoolean(false);
            FhirString  validDisplay = new FhirString();

            if (FhirSnomed.IsValidURI(systemURL))
            {
                validCode    = new FhirBoolean(FhirSnomed.ValidateCode(codeVal, displayVal, out string prefTerm));
                validDisplay = new FhirString(prefTerm);
            }
            else
            {
                CodeSystem codeSys = GetCodeSystem(TerminologyOperation.validate_code, systemURL, queryParam);

                foreach (CodeSystem.ConceptDefinitionComponent cc in codeSys.Concept)
                {
                    if (string.IsNullOrEmpty(displayVal))
                    {
                        validCode    = new FhirBoolean(true);
                        validDisplay = new FhirString(cc.Display);
                    }
                    else if (displayVal.Trim().ToLower() == cc.Display.Trim().ToLower())
                    {
                        validCode    = new FhirBoolean(true);
                        validDisplay = new FhirString(cc.Display);
                    }
                    else
                    {
                        validDisplay = new FhirString(cc.Display);
                    }
                }
            }

            // build return parameters resource from search result

            Parameters param = new Parameters();

            param.Add("result", validCode);

            if (validCode.Value == false)
            {
                param.Add("message", new FhirString("The code/display value " + codeVal + " / " + displayVal + " passed is incorrect"));
            }

            if (!string.IsNullOrEmpty(validDisplay.Value))
            {
                param.Add("display", validDisplay);
            }

            return(param);
        }
        private static CodeSystem GetCodeSystem(TerminologyOperation termOp, string systemURL, NameValueCollection queryParam)
        {
            CodeSystem codeSys = new CodeSystem();

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

            // NB: these won't be passed in a GET request & the POST processing places the atomic elements in the queryParam collection
            //string codingVal = Utilities.GetQueryValue("coding", queryParam);
            //string codeableConceptVal = Utilities.GetQueryValue("codeableConcept", queryParam)

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

            if (systemURL == NzRegion.URI)
            {
                NzRegion nzr = new NzRegion(termOp, versionVal, codeVal, string.Empty, -1, -1);
                codeSys = nzr.codeSystem;
            }
            else if (systemURL == NzEthnicityL1.URI)
            {
                NzEthnicityL1 nzEth1 = new NzEthnicityL1(termOp, versionVal, codeVal, string.Empty, -1, -1);
                codeSys = nzEth1.codeSystem;
            }
            else if (systemURL == NzEthnicityL2.URI)
            {
                NzEthnicityL2 nzEth2 = new NzEthnicityL2(termOp, versionVal, codeVal, string.Empty, -1, -1);
                codeSys = nzEth2.codeSystem;
            }
            else if (systemURL == NzEthnicityL3.URI)
            {
                NzEthnicityL3 nzEth3 = new NzEthnicityL3(termOp, versionVal, codeVal, string.Empty, -1, -1);
                codeSys = nzEth3.codeSystem;
            }
            else if (systemURL == NzEthnicityL4.URI)
            {
                NzEthnicityL4 nzEth4 = new NzEthnicityL4(termOp, versionVal, codeVal, string.Empty, -1, -1);
                codeSys = nzEth4.codeSystem;
            }
            else if (systemURL == NzMt.URI)
            {
                NzMt nzmt = new NzMt(termOp, versionVal, codeVal, string.Empty, string.Empty, -1, -1);
                codeSys = nzmt.codeSystem;
            }
            else if (systemURL == FhirLoinc.URI)
            {
                FhirLoinc loinc = new FhirLoinc(termOp, versionVal, codeVal, string.Empty, string.Empty, -1, -1, string.Empty);
                codeSys = loinc.codeSystem;
            }
            else if (systemURL == FhirRxNorm.URI)
            {
                FhirRxNorm rxnorm = new FhirRxNorm(termOp, versionVal, codeVal, string.Empty, string.Empty, -1, -1);
                codeSys = rxnorm.codeSystem;
            }
            else if (FhirSnomed.IsValidURI(systemURL))
            {
                FhirSnomed snomed = new FhirSnomed(termOp, versionVal, codeVal, string.Empty, string.Empty, -1, -1, string.Empty, string.Empty);
                codeSys = snomed.codeSystem;
            }
            else
            {
                throw new Exception(UNSUPPORTED_CODESYSTEM);
            }

            return(codeSys);
        }