Пример #1
0
        public static DataTable NDARDataStructureElements_to_DataTable(NDAR_DataStructure ds)
        {
            if (ds != null)
            {
                //Create the data table for the dataElements
                DataTable dt = NDAR_dataElements();

                foreach (NDAR_DataElement de in ds.dataElements)
                {
                    DataRow row = dt.NewRow();

                    row["shortName"]     = !string.IsNullOrWhiteSpace(ds.shortName) ? (object)ds.shortName : (object)DBNull.Value;
                    row["id"]            = !(de.id == null) ? (object)de.id : (object)DBNull.Value;
                    row["dataElementId"] = !(de.dataElementId == null) ? (object)de.dataElementId : (object)DBNull.Value;
                    row["name"]          = !string.IsNullOrWhiteSpace(de.name) ? (object)de.name : (object)DBNull.Value;
                    row["description"]   = !string.IsNullOrWhiteSpace(de.description.Replace("\"", "")) ? (object)de.description.Replace("\"", "") : (object)DBNull.Value;
                    row["type"]          = !string.IsNullOrWhiteSpace(de.type) ? (object)de.type : (object)DBNull.Value;


                    row["required"]   = !string.IsNullOrWhiteSpace(de.required) ? (object)de.required : (object)DBNull.Value;
                    row["position"]   = !(de.position == null) ? (object)de.position : (object)DBNull.Value;
                    row["valueRange"] = !string.IsNullOrWhiteSpace(de.valueRange) ? (object)de.valueRange : (object)DBNull.Value;
                    row["notes"]      = !string.IsNullOrWhiteSpace(de.notes) ? (object)de.notes : (object)DBNull.Value;

                    int maxleng = (de.description.Length > 50) ? 50 : de.description.Length;

                    row["uwfld"] = DBNull.Value;
                    //row["uwfld"] = " ,   as " + de.name + " /* (" + de.valueRange + ") " + de.description.Substring(0, maxleng - 1) + " */";
                    row["fx"]     = DBNull.Value;
                    row["param1"] = DBNull.Value;
                    row["param2"] = DBNull.Value;

                    dt.Rows.Add(row);
                }

                return(dt);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public static NDAR_DataStructure GetNDARDataStructure(string shortName)
        {
            NDAR_DataStructure ds = new NDAR_DataStructure();
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            WebClient wc = new WebClient();

            try
            {
                wc.Headers.Add("Accept", "application/json");

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


                string ds_string = wc.DownloadString(@"https://ndar.nih.gov/api/datadictionary/v2/datastructure/" + shortName);

                //read the top level of the JSON data
                JToken token = JObject.Parse(ds_string);


                ds.shortName = GetTokenValue_string(token, "shortName");
                ds.title     = GetTokenValue_string(token, "title");
                //ds.sources = token.SelectToken("sources").ToString();
                //ds.categories = token.SelectToken("categories").ToString();
                ds.dataType     = GetTokenValue_string(token, "dataType");
                ds.status       = GetTokenValue_string(token, "status");
                ds.publicStatus = GetTokenValue_string(token, "publicStatus");
                //ds.publishDate = GetTokenValue_int(token, "publishDate");
                //ds.modifiedDate = GetTokenValue_int(token, "modifiedDate");
                ds.dataElements = new List <NDAR_DataElement>();

                JArray deTokens = (JArray)token.SelectToken("dataElements");

                foreach (JToken deToken in deTokens)
                {
                    NDAR_DataElement de = new NDAR_DataElement();

                    de.required  = GetTokenValue_string(deToken, "required");
                    de.id        = GetTokenValue_int(deToken, "id");
                    de.condition = GetTokenValue_string(deToken, "condition");
                    de.name      = GetTokenValue_string(deToken, "name");

                    //de.aliases = deToken.SelectToken("aliases").ToString();
                    de.filterElement = GetTokenValue_string(deToken, "filterElement");
                    de.position      = GetTokenValue_int(deToken, "position");
                    de.name          = GetTokenValue_string(deToken, "name");
                    de.type          = GetTokenValue_string(deToken, "type");
                    de.size          = GetTokenValue_int(deToken, "size");
                    de.description   = GetTokenValue_string(deToken, "description");
                    de.valueRange    = GetTokenValue_string(deToken, "valueRange");
                    de.notes         = GetTokenValue_string(deToken, "notes");
                    //de.translations = deToken.SelectToken("").ToString();

                    ds.dataElements.Add(de);
                }
            }
            catch (Exception)
            {
                ds = null;
            }


            return(ds);
        }