public void ParseSearchParam()
        {
            var p1 = new SearchParam("dummy", "exact", new IntegerParamValue(ComparisonOperator.LTE,18),
                    new CombinedParamValue( new StringParamValue("ewout"), new ReferenceParamValue("patient","1")));
            Assert.AreEqual("dummy:exact=<=18,\"ewout\"$patient/1", p1.QueryPair);

            var p2 = new SearchParam("name", isMissing:true);
            Assert.AreEqual("name:missing=true", p2.QueryPair);

            var p3 = SearchParam.FromQueryKeyAndValue("dummy:exact", "<=18,\"ewout\"$patient/1");
            Assert.AreEqual("dummy", p3.Name);
            Assert.AreEqual("exact", p3.Modifier);
            Assert.AreEqual(2, p3.Values.Count());
            Assert.AreEqual(18, ((UntypedParamValue)p3.Values.First()).AsIntegerParam().Value);
            Assert.AreEqual("\"ewout\"$patient/1", ((UntypedParamValue)p3.Values.Skip(1).First()).AsCombinedParam().QueryValue);
        }
        public void SearchConditionByPatientReference()
        {
            var conditions = client.Search(ResourceType.Condition);

            if (conditions.Entries.Count == 0)
                TestResult.Fail("no conditions found - cannot run test");
            
            var condition = conditions.Entries.ByResourceType<Condition>()
                .Where(c => c.Resource.Subject != null && c.Resource.Subject.Type == "Patient")
                .First();

            var patientRef = new ResourceLocation(condition.Resource.Subject.Url);

            var patient = client.Read<Patient>(patientRef.Id);

            if(patient == null)
                TestResult.Fail("failed to find patient condition is referring to");

            var result = client.Search(ResourceType.Condition, "subject", "patient/" + patientRef.Id);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject=)");

            result = client.Search(ResourceType.Condition, "subject._id", patientRef.Id);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject._id=)");

            string patFirstName = patient.Resource.Name[0].Family.First().Substring(2, 3);
            var param = new SearchParam("subject.name", new StringParamValue(patFirstName));
            result = client.Search(ResourceType.Condition, new SearchParam[] { param });
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject.name)");

            result = client.Search(ResourceType.Condition, "subject.identifier", patient.Resource.Identifier[0].Key);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject.identifier)");

        }