Пример #1
0
 public JSONStudy(int _id, string _display_title,
                  text_block _brief_description, text_block _data_sharing_statement,
                  lookup _study_type, lookup _study_status, int?_study_enrolment,
                  lookup _study_gender_elig, age_param _min_age, age_param _max_age,
                  string _provenance_string)
 {
     file_type              = "study";
     id                     = _id;
     display_title          = _display_title;
     brief_description      = _brief_description;
     data_sharing_statement = _data_sharing_statement;
     study_type             = _study_type;
     study_status           = _study_status;
     study_enrolment        = _study_enrolment;
     study_gender_elig      = _study_gender_elig;
     min_age                = _min_age;
     max_age                = _max_age;
     provenance_string      = _provenance_string;
 }
        public JSONStudy CreateStudyObject(int id)
        {
            // Re-initialise these compound properties.
            brief_description      = null;
            data_sharing_statement = null;
            study_type             = null;
            study_status           = null;
            study_gender_elig      = null;
            min_age = null;
            max_age = null;

            study_identifiers   = null;
            study_titles        = null;
            study_topics        = null;
            study_features      = null;
            study_relationships = null;
            linked_data_objects = null;

            // Get the singleton study properties from DB

            var s = repo.FetchDbStudy(id);

            // Instantiate the top level lookup types
            if (s.brief_description != null)
            {
                brief_description = new text_block(s.brief_description, s.bd_contains_html);
            }
            if (s.data_sharing_statement != null)
            {
                data_sharing_statement = new text_block(s.data_sharing_statement, s.dss_contains_html);
            }
            if (s.study_type_id != null)
            {
                study_type = new lookup(s.study_type_id, s.study_type);
            }
            if (s.study_status_id != null)
            {
                study_status = new lookup(s.study_status_id, s.study_status);
            }
            if (s.study_gender_elig_id != null)
            {
                study_gender_elig = new lookup(s.study_gender_elig_id, s.study_gender_elig);
            }
            if (s.min_age != null)
            {
                min_age = new age_param(s.min_age, s.min_age_units_id, s.min_age_units);
            }
            if (s.max_age != null)
            {
                max_age = new age_param(s.max_age, s.max_age_units_id, s.max_age_units);
            }

            // instantiate a (json) study object and
            // fill it with study level details

            JSONStudy jst = new JSONStudy(s.id, s.display_title, brief_description,
                                          data_sharing_statement, study_type, study_status, s.study_enrolment,
                                          study_gender_elig, min_age, max_age, s.provenance_string);

            // add the study identifier details

            var db_study_identifiers = new List <DBStudyIdentifier>(repo.FetchDbStudyIdentifiers(id));

            if (db_study_identifiers.Count > 0)
            {
                study_identifiers = new List <study_identifier>();
                foreach (DBStudyIdentifier t in db_study_identifiers)
                {
                    study_identifiers.Add(new study_identifier(t.id, t.identifier_value,
                                                               new lookup(t.identifier_type_id, t.identifier_type),
                                                               new lookup(t.identifier_org_id, t.identifier_org),
                                                               t.identifier_date, t.identifier_link));
                }
            }


            // add the study title details

            var db_study_titles = new List <DBStudyTitle>(repo.FetchDbStudyTitles(id));

            if (db_study_titles.Count > 0)
            {
                study_titles = new List <study_title>();
                foreach (DBStudyTitle t in db_study_titles)
                {
                    study_titles.Add(new study_title(t.id, new lookup(t.title_type_id, t.title_type), t.title_text,
                                                     t.lang_code, t.comments));
                }
            }


            // add the study feature details
            var db_study_features = new List <DBStudyFeature>(repo.FetchDbStudyFeatures(id));

            if (db_study_features.Count > 0)
            {
                study_features = new List <study_feature>();
                foreach (DBStudyFeature t in db_study_features)
                {
                    study_features.Add(new study_feature(t.id, new lookup(t.feature_type_id, t.feature_type),
                                                         new lookup(t.feature_value_id, t.feature_value)));
                }
            }


            // add the study topic details
            var db_study_topics = new List <DBStudyTopic>(repo.FetchDbStudyTopics(id));

            if (db_study_topics.Count > 0)
            {
                study_topics = new List <study_topic>();
                foreach (DBStudyTopic t in db_study_topics)
                {
                    study_topics.Add(new study_topic(t.id, new lookup(t.topic_type_id, t.topic_type),
                                                     t.mesh_coded, t.topic_code, t.topic_value, t.topic_qualcode,
                                                     t.topic_qualvalue, t.original_value));
                }
            }


            // add the study relationships, if any
            var db_study_relationships = new List <DBStudyRelationship>(repo.FetchDbStudyRelationships(id));

            if (db_study_relationships.Count > 0)
            {
                study_relationships = new List <study_relationship>();
                foreach (DBStudyRelationship t in db_study_relationships)
                {
                    study_relationships.Add(new study_relationship(t.id,
                                                                   new lookup(t.relationship_type_id, t.relationship_type),
                                                                   t.target_study_id));
                }
            }


            // add the related objects data
            var db_study_object_links = new List <DBStudyObjectLink>(repo.FetchDbStudyObjectLinks(id));

            if (db_study_object_links.Count > 0)
            {
                linked_data_objects = new List <int>();
                foreach (DBStudyObjectLink t in db_study_object_links)
                {
                    linked_data_objects.Add(t.object_id);
                }
            }


            // return the resulting 'json ready' study
            jst.study_identifiers   = study_identifiers;
            jst.study_titles        = study_titles;
            jst.study_features      = study_features;
            jst.study_topics        = study_topics;
            jst.study_relationships = study_relationships;
            jst.linked_data_objects = linked_data_objects;

            return(jst);
        }