protected string[] processCQLObjectResult(AIMTCGAService.CQLQueryResults response)
        {
            var results = new ArrayList();

            foreach (CQLObjectResult result in response.Items)
            {
                results.Add(XMLSerializingDeserializing.Serialize(result.Any).InnerXml);
            }
            return((string[])results.ToArray(typeof(string)));
        }
Exemplo n.º 2
0
        private CQLQueryResults getAnnotationOfAnnotationCQLInfo()
        {
            object[]    obj      = null;
            Attribute   attrTemp = null;
            Association assoTemp = null;
            var         proxy    = new AIM3DataServicePortTypeClient();

            proxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(AIMDataServiceSettings.Default.AIMDataServiceUrl);
            var associationList = new ArrayList();

            obj = null;
            Association aecAssociation = null;

            foreach (var queryData in _queryParameters.AecQueryParameters)
            {
                var results = new ArrayList();
                if (!queryData.CodeValue.IsEmpty)
                {
                    results.Add(CreateAttribute("codeValue", queryData.CodeValue));
                }
                if (!queryData.CodeMeaning.IsEmpty)
                {
                    results.Add(CreateAttribute("codeMeaning", queryData.CodeMeaning));
                }
                if (!queryData.CodingSchemeDesignator.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeDesignator", queryData.CodingSchemeDesignator));
                }
                if (!queryData.CodingSchemeVersion.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeVersion", queryData.CodingSchemeVersion));
                }
                if (!queryData.Confidence.IsEmpty)
                {
                    results.Add(CreateAttribute("annotatorConfidence", queryData.Confidence));
                }
                if (results.Count > 0)
                {
                    obj = (object[])results.ToArray(typeof(object));
                }
                if (obj != null && obj.Length > 0)
                {
                    Group grpAnnatomicEntityCharacteristic = null;
                    if (obj.Length > 1)
                    {
                        grpAnnatomicEntityCharacteristic = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                        obj = null;
                    }
                    else
                    {
                        attrTemp = obj[0] as Attribute;
                    }

                    aecAssociation = CreateQRAttrAssoGroup.createAssociation("edu.northwestern.radiology.aim.AnatomicEntityCharacteristic", "anatomicEntityCharacteristicCollection", grpAnnatomicEntityCharacteristic, attrTemp, null);
                }
            }

            obj = null;
            if (aecAssociation != null && _queryParameters.AeQueryParameters.Count == 0)
            {
                var queryData = new AimAnatomicEntityQueryData();
                queryData.CodeMeaning = new QueryData(String.Empty, QueryPredicate.LIKE);
                _queryParameters.AeQueryParameters.Add(queryData);
            }
            foreach (var queryData in _queryParameters.AeQueryParameters)
            {
                var results = new ArrayList();
                if (!queryData.CodeValue.IsEmpty)
                {
                    results.Add(CreateAttribute("codeValue", queryData.CodeValue));
                }
                //if (!queryData.CodeMeaning.IsEmpty)
                results.Add(CreateAttribute("codeMeaning", queryData.CodeMeaning));
                if (!queryData.CodingSchemeDesignator.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeDesignator", queryData.CodingSchemeDesignator));
                }
                if (!queryData.CodingSchemeVersion.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeVersion", queryData.CodingSchemeVersion));
                }
                if (!queryData.Confidence.IsEmpty)
                {
                    results.Add(CreateAttribute("annotatorConfidence", queryData.Confidence));
                }
                if (aecAssociation != null)
                {
                    results.Add(aecAssociation);
                }
                if (results.Count > 0)
                {
                    obj = (object[])results.ToArray(typeof(object));
                }
                if (obj != null && obj.Length > 0)
                {
                    Group grpAnnatomicEntity = null;
                    if (obj.Length > 1)
                    {
                        grpAnnatomicEntity = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                        obj = null;
                    }
                    else
                    {
                        attrTemp = obj[0] as Attribute;
                    }
                    associationList.Add(CreateQRAttrAssoGroup.createAssociation("edu.northwestern.radiology.aim.AnatomicEntity", "anatomicEntityCollection", grpAnnatomicEntity, attrTemp, null));
                }
            }

            obj = null;
            Association iocAssociation = null;

            foreach (var queryData in _queryParameters.ImcQueryParameters)
            {
                var results = new ArrayList();
                if (!queryData.CodeValue.IsEmpty)
                {
                    results.Add(CreateAttribute("codeValue", queryData.CodeValue));
                }
                if (!queryData.CodeMeaning.IsEmpty)
                {
                    results.Add(CreateAttribute("codeMeaning", queryData.CodeMeaning));
                }
                if (!queryData.CodingSchemeDesignator.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeDesignator", queryData.CodingSchemeDesignator));
                }
                if (!queryData.CodingSchemeVersion.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeVersion", queryData.CodingSchemeVersion));
                }
                if (!queryData.Confidence.IsEmpty)
                {
                    results.Add(CreateAttribute("annotatorConfidence", queryData.Confidence));
                }
                if (!queryData.Comment.IsEmpty)
                {
                    results.Add(CreateAttribute("comment", queryData.Comment));
                }
                if (results.Count > 0)
                {
                    obj = (object[])results.ToArray(typeof(object));
                }
                if (obj != null && obj.Length > 0)
                {
                    Group grpImagingObservationCharacteristic = null;
                    if (obj.Length > 1)
                    {
                        grpImagingObservationCharacteristic = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                        obj = null;
                    }
                    else
                    {
                        attrTemp = obj[0] as Attribute;
                    }

                    iocAssociation = CreateQRAttrAssoGroup.createAssociation("edu.northwestern.radiology.aim.ImagingObservationCharacteristic", "imagingObservationCharacteristicCollection", grpImagingObservationCharacteristic, attrTemp, null);
                }
            }

            obj = null;
            if (iocAssociation != null && _queryParameters.ImQueryParameters.Count == 0)
            {
                var queryData = new AimImagingObservationQueryData();
                queryData.CodeMeaning = new QueryData(String.Empty, QueryPredicate.LIKE);
                _queryParameters.ImQueryParameters.Add(queryData);
            }
            foreach (var queryData in _queryParameters.ImQueryParameters)
            {
                var results = new ArrayList();
                if (!queryData.CodeValue.IsEmpty)
                {
                    results.Add(CreateAttribute("codeValue", queryData.CodeValue));
                }
                //if (!queryData.CodeMeaning.IsEmpty)
                results.Add(CreateAttribute("codeMeaning", queryData.CodeMeaning));
                if (!queryData.CodingSchemeDesignator.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeDesignator", queryData.CodingSchemeDesignator));
                }
                if (!queryData.CodingSchemeVersion.IsEmpty)
                {
                    results.Add(CreateAttribute("codingSchemeVersion", queryData.CodingSchemeVersion));
                }
                if (!queryData.Comment.IsEmpty)
                {
                    results.Add(CreateAttribute("comment", queryData.Comment));
                }
                if (!queryData.Confidence.IsEmpty)
                {
                    results.Add(CreateAttribute("annotatorConfidence", queryData.Confidence));
                }
                if (iocAssociation != null)
                {
                    results.Add(iocAssociation);
                }
                if (results.Count > 0)
                {
                    obj = (object[])results.ToArray(typeof(object));
                }
                if (obj != null && obj.Length > 0)
                {
                    attrTemp = null;
                    Group grpImagingObservation = null;
                    if (obj.Length > 1)
                    {
                        grpImagingObservation = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                        obj = null;
                    }
                    else
                    {
                        attrTemp = obj[0] as Attribute;
                    }
                    associationList.Add(CreateQRAttrAssoGroup.createAssociation("edu.northwestern.radiology.aim.ImagingObservation", "imagingObservationCollection", grpImagingObservation, attrTemp, null));
                }
            }
            obj = null;
            foreach (var queryData in _queryParameters.UserParameters)
            {
                var results = new ArrayList();
                if (!queryData.IsEmpty)
                {
                    results.Add(CreateAttribute("loginName", queryData));
                    results.Add(CreateAttribute("name", queryData));
                }
                if (results.Count > 0)
                {
                    obj = (object[])results.ToArray(typeof(Attribute));
                }
                if (obj != null && obj.Length > 0)
                {
                    Group grpAnnatomicEntityCharacteristic = null;
                    if (obj.Length > 1)
                    {
                        grpAnnatomicEntityCharacteristic = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.OR);
                        obj = null;
                    }
                    else
                    {
                        attrTemp = obj[0] as Attribute;
                    }
                    associationList.Add(CreateQRAttrAssoGroup.createAssociation("edu.northwestern.radiology.aim.User", "user", grpAnnatomicEntityCharacteristic, attrTemp, null));
                }
            }
            obj = null;
            Group grpAnnotationOfAnnotation = null;

            if (associationList.Count > 0)
            {
                obj = (object[])associationList.ToArray(typeof(Association));
            }
            if (obj != null && obj.Length > 0)
            {
                assoTemp = null;
                if (obj.Length > 1)
                {
                    grpAnnotationOfAnnotation = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                }
                else
                {
                    assoTemp = obj[0] as Association;
                }
            }
            var arg = CreateQRAttrAssoGroup.createQueryRequestCqlQuery("edu.northwestern.radiology.aim.AnnotationOfAnnotation", null, null, assoTemp, grpAnnotationOfAnnotation);
            var doc = XMLSerializingDeserializing.Serialize(arg);

            Console.WriteLine(doc.InnerXml);
            CQLQueryResults result;

            try
            {
                result = proxy.query(arg);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine(ex.Message);
                result = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = null;
                throw new GridServicerException("Error querying AIM data service", e);
            }
            return(result);
        }
        private CQLQueryResults getClinicalTrialProtocolCQLInfo(string endPointUrl)
        {
            object[]        obj;
            CQLQueryResults result;
            Association     assoTrialDataProvenance  = null;
            Association     assoClinicalTrialSubject = null;
            Association     assoClinicalTrialSite    = null;
            Association     assoImage   = null;
            Association     assoSeries  = null;
            Association     assoStudy   = null;
            Association     assoPatient = null;
            var             results     = new ArrayList();
            var             proxy       = new NCIACoreServicePortTypeClient();

            proxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(endPointUrl);
            var items            = new[] { "protocolId", "protocolName" };
            var itemsChoiceType1 = new[] {
                ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames
            };

            assoImage = null;
            if (!_queryParameters.SliceThickness.IsEmpty)
            {
                var attrPatient = CreateAttribute("sliceThickness", _queryParameters.SliceThickness);
                var grpPatient  = CreateQRAttrAssoGroup.createGroup(attrPatient, LogicalOperator.AND);
                assoImage = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Image", "imageCollection", grpPatient);
            }
            results    = new ArrayList();
            assoSeries = null;
            obj        = null;
            if (assoImage != null)
            {
                results.Add(assoImage);
            }
            if (!_queryParameters.Modality.IsEmpty)
            {
                results.Add(CreateAttribute("modality", _queryParameters.Modality));
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null)
            {
                var grpSeries = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoSeries = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Series", "seriesCollection", grpSeries);
            }
            obj       = null;
            assoStudy = null;
            results   = new ArrayList();
            if (assoSeries != null)
            {
                results.Add(assoSeries);
            }
            if (!_queryParameters.StudyInstanceUID.IsEmpty)
            {
                results.Add(CreateAttribute("studyInstanceUID", _queryParameters.StudyInstanceUID));
            }
            assoStudy = null;
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null)
            {
                var groupStudy = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoStudy = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Study", "studyCollection", groupStudy);
            }
            assoTrialDataProvenance = null;
            if (!_queryParameters.ProjectName.IsEmpty)
            {
                var attrTrialDataProvenance = CreateAttribute("project", _queryParameters.ProjectName);
                var grpTrialDataProvenance  = CreateQRAttrAssoGroup.createGroup(attrTrialDataProvenance, LogicalOperator.AND);
                assoTrialDataProvenance = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.TrialDataProvenance", "dataProvenance", grpTrialDataProvenance);
            }
            obj     = null;
            results = new ArrayList();
            if (assoStudy != null)
            {
                results.Add(assoStudy);
            }
            if (assoTrialDataProvenance != null)
            {
                results.Add(assoTrialDataProvenance);
            }
            if (!_queryParameters.PatientBirthDate.IsEmpty)
            {
                results.Add(CreateAttribute("patientBirthDate", _queryParameters.PatientBirthDate));
            }
            if (!_queryParameters.PatientId.IsEmpty)
            {
                results.Add(CreateAttribute("patientId", _queryParameters.PatientId));
            }
            if (!_queryParameters.PatientName.IsEmpty)
            {
                results.Add(CreateAttribute("patientName", _queryParameters.PatientName));
            }
            if (!_queryParameters.PatientSex.IsEmpty)
            {
                results.Add(CreateAttribute("patientSex", _queryParameters.PatientSex));
            }

            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null)
            {
                var patientGroup = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoPatient = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Patient", "patient", patientGroup);
            }
            obj     = null;
            results = new ArrayList();
            if (!_queryParameters.SiteId.IsEmpty)
            {
                results.Add(CreateAttribute("siteId", _queryParameters.SiteId));
            }
            if (!_queryParameters.SiteName.IsEmpty)
            {
                results.Add(CreateAttribute("siteName", _queryParameters.SiteName));
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            Group grpClinicalTrialSite = null;

            if (obj != null)
            {
                grpClinicalTrialSite  = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoClinicalTrialSite = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.ClinicalTrialSite", "site", grpClinicalTrialSite);
            }

            results = new ArrayList();
            if (assoClinicalTrialSite != null)
            {
                results.Add(assoClinicalTrialSite);
            }
            if (assoPatient != null)
            {
                results.Add(assoPatient);
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
                var grpClinicalTrialSubject = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoClinicalTrialSubject = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.ClinicalTrialSubject", "subjectCollection", grpClinicalTrialSubject);
            }

            obj     = null;
            results = new ArrayList();
            if (assoClinicalTrialSubject != null)
            {
                results.Add(assoClinicalTrialSubject);
            }
            if (!_queryParameters.ProtocolId.IsEmpty)
            {
                results.Add(CreateAttribute("protocolId", _queryParameters.ProtocolId));
            }
            if (!_queryParameters.ProtocolName.IsEmpty)
            {
                results.Add(CreateAttribute("protocolName", _queryParameters.ProtocolName));
            }

            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            Group grpClinicalTrialProtocol = null;

            if (obj != null)
            {
                grpClinicalTrialProtocol = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
            }

            var arg = CreateQRAttrAssoGroup.createQueryRequestCqlQuery("gov.nih.nci.ncia.domain.ClinicalTrialProtocol", items, itemsChoiceType1, null, grpClinicalTrialProtocol);
            var doc = XMLSerializingDeserializing.Serialize(arg);

            Console.WriteLine(doc.InnerXml);
            try
            {
                result = proxy.query(arg);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine(ex.Message);
                result = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = null;
                throw new GridServicerException("Error querying NCIA Grid", e);
            }
            return(result);
        }
        private CQLQueryResults getStudyCQLInfo(string endPointUrl)
        {
            object[]        obj;
            CQLQueryResults result;
            Association     assoImage = null;
            Association     assoTrialDataProvenance = null;
            Association     assoSeries                = null;
            Association     assoClinicalTrialSite     = null;
            Association     assoClinicalTrialProtocol = null;
            Association     assoClinicalTrialSubject  = null;
            Association     assoPatient               = null;
            ArrayList       results             = new ArrayList();
            NCIACoreServicePortTypeClient proxy = new NCIACoreServicePortTypeClient();

            proxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(endPointUrl);
            string[] items = new string[] { "additionalPatientHistory",
                                            "admittingDiagnosesCodeSequence", "occupation", "patientAge", "patientSize", "patientWeight",
                                            "studyDate", "studyId", "studyInstanceUID", "studyTime", "timePointDescription", "timePointId" };
            ItemsChoiceType[] itemsChoiceType1 = new ItemsChoiceType[] {
                ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames,
                ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames,
                ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames,
                ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames, ItemsChoiceType.AttributeNames
            };

            // Image
            assoImage = null;
            if (!_queryParameters.SliceThickness.IsEmpty)
            {
                Attribute attrPatient = this.CreateAttribute("sliceThickness", _queryParameters.SliceThickness);
                Group     grpPatient  = CreateQRAttrAssoGroup.createGroup(attrPatient, LogicalOperator.AND);
                assoImage = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Image", "imageCollection", grpPatient);
            }
            // Series
            assoSeries = null;
            obj        = null;
            results    = new ArrayList();
            if (assoImage != null)
            {
                results.Add(assoImage);
            }
            if (!_queryParameters.Modality.IsEmpty)
            {
                results.Add(this.CreateAttribute("modality", _queryParameters.Modality));
            }
            if (results.Count > 0 || assoImage != null)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                Group grpSeries = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoSeries = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Series", "seriesCollection", grpSeries);
            }
            // TrialDataProvenance
            assoTrialDataProvenance = null;
            if (!_queryParameters.ProjectName.IsEmpty)
            {
                Attribute attrTrialDataProvenance = this.CreateAttribute("project", _queryParameters.ProjectName);
                Group     grpTrialDataProvenance  = CreateQRAttrAssoGroup.createGroup(attrTrialDataProvenance, LogicalOperator.AND);
                assoTrialDataProvenance = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.TrialDataProvenance", "dataProvenance", grpTrialDataProvenance);
            }
            // ClinicalTrial Site
            assoClinicalTrialSite = null;
            obj     = null;
            results = new ArrayList();
            if (!_queryParameters.SiteId.IsEmpty)
            {
                results.Add(this.CreateAttribute("siteId", _queryParameters.SiteId));
            }
            if (!_queryParameters.SiteName.IsEmpty)
            {
                results.Add(this.CreateAttribute("siteName", _queryParameters.SiteName));
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                Group grpClinicalTrialSite = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoClinicalTrialSite = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.ClinicalTrialSite", "site", grpClinicalTrialSite);
            }
            // ClinicalTrial Protocol
            assoClinicalTrialProtocol = null;
            obj     = null;
            results = new ArrayList();
            if (!_queryParameters.ProtocolId.IsEmpty)
            {
                results.Add(this.CreateAttribute("protocolId", _queryParameters.ProtocolId));
            }
            if (!_queryParameters.ProtocolName.IsEmpty)
            {
                results.Add(this.CreateAttribute("protocolName", _queryParameters.ProtocolName));
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                Group grpClinicalTrialProtocol = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoClinicalTrialProtocol = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.ClinicalTrialProtocol",
                                                                                    "protocol", grpClinicalTrialProtocol);
            }
            // Clinical Trial Subject
            obj     = null;
            results = new ArrayList();
            assoClinicalTrialSubject = null;
            if (assoClinicalTrialSite != null)
            {
                results.Add(assoClinicalTrialSite);
            }
            if (assoClinicalTrialProtocol != null)
            {
                results.Add(assoClinicalTrialProtocol);
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                Group grpClinicalTrialSubject = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoClinicalTrialSubject = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.ClinicalTrialSubject",
                                                                                   "subjectCollection", grpClinicalTrialSubject);
            }
            // Patient
            obj     = null;
            results = new ArrayList();
            if (assoClinicalTrialSubject != null)
            {
                results.Add(assoClinicalTrialSubject);
            }
            if (assoTrialDataProvenance != null)
            {
                results.Add(assoTrialDataProvenance);
            }
            if (!_queryParameters.PatientBirthDate.IsEmpty)
            {
                results.Add(this.CreateAttribute("patientBirthDate", _queryParameters.PatientBirthDate));
            }
            if (!_queryParameters.PatientId.IsEmpty)
            {
                results.Add(this.CreateAttribute("patientId", _queryParameters.PatientId));
            }
            if (!_queryParameters.PatientName.IsEmpty)
            {
                results.Add(this.CreateAttribute("patientName", _queryParameters.PatientName));
            }
            if (!_queryParameters.PatientSex.IsEmpty)
            {
                results.Add(this.CreateAttribute("patientSex", _queryParameters.PatientSex));
            }
            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                Group patientGroup = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
                assoPatient = CreateQRAttrAssoGroup.createAssociation("gov.nih.nci.ncia.domain.Patient", "patient", patientGroup);
            }

            // Study
            obj     = null;
            results = new ArrayList();
            Group groupStudy = null;

            if (assoSeries != null)
            {
                results.Add(assoSeries);
            }
            if (assoPatient != null)
            {
                results.Add(assoPatient);
            }
            if (!_queryParameters.StudyInstanceUID.IsEmpty)
            {
                results.Add(this.CreateAttribute("studyInstanceUID", _queryParameters.StudyInstanceUID));
            }

            if (results.Count > 0)
            {
                obj = (object[])results.ToArray(typeof(object));
            }
            if (obj != null && obj.Length > 0)
            {
                groupStudy = CreateQRAttrAssoGroup.createGroup(obj, LogicalOperator.AND);
            }
            QueryRequestCqlQuery arg = CreateQRAttrAssoGroup.createQueryRequestCqlQuery("gov.nih.nci.ncia.domain.Study", items, itemsChoiceType1, null, groupStudy);

            XmlDocument doc = XMLSerializingDeserializing.Serialize(arg);

            Console.WriteLine(((System.Xml.XmlDocument)((System.Xml.XmlNode)(doc))).InnerXml);

            try
            {
                result = proxy.query(arg);
            }
            catch (System.Net.WebException ex)
            {
                System.Console.WriteLine(ex.Message);
                result = null;
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                result = null;
                throw new GridServicerException("Error querying NCIA Grid", e);
            }
            return(result);
        }