Class: Api::V2::Sapio::StudyResource

Inherits:
BaseResource
  • Object
show all
Includes:
StudySearchQuery
Defined in:
app/resources/api/v2/sapio/study_resource.rb

Overview

TODO:

The reference_genome relationship on studies is not accurate and not exposed in this resource. Use the reference_genome relationship on study_metadata instead.

Note:

Access this resource via the /api/v2/sapio/studies/ endpoint.

Note:

Requires the :y26_172_enable_externally_managed_study_restrictions feature flag to be enabled. Returns 404 Not Found otherwise.

Note:

Requests that modify data require a valid Integration Hub API key. If this key is not provided, the request will return a 403 Forbidden response. See the examples for more details.

Note:

It does not subclass Api::V2::StudyResource to decouple it from the default Study resource, which is used by other API consumers.

Note:

When the y26_245_sapio_study_upsert feature flag is enabled, this method behaves as an upsert based on the supplied uuid: if Sequencescape does not already have a Study with that uuid, a new Study is created as described above; if it already has one, that Study is instead marked externally_managed (if not already) and broadcast to mlwarehouse, rather than raising a conflict. No other attributes on the existing Study are changed by this. This means the method CAN be used to transfer an existing Sequencescape study to the external LIMS, once this flag is enabled. When this feature flag is disabled, this method is intended exclusively for creating new studies that originate in an external LIMS, and should NOT be used to transfer an existing Sequencescape study to the external LIMS - supplying a uuid that already exists will return a 409 Conflict instead.

Sapio-specific Study resource for Integration Hub consumers.

Indexing and Searching

For index requests, this resource supports only filtering by name, and it does not allow listing studies without a filter.

Creating a New Externally Managed Study

The POST method creates a new Study that is managed externally, granting ownership to the requesting user.

If a UUID is not provided, one will be generated automatically.

Updating an Existing Study

Existing studies can be updated using the PATCH method. Only studies that have been marked as externally_managed can be updated via this endpoint. Attempts to update a study that is not externally managed will return a 423 Locked response.

For more information about JSON:API see the JSON:API Specifications or look at the JSONAPI::Resources package for Sequencescape's implementation of the JSON:API standard.

Examples:

search studies by name

GET /api/v2/sapio/studies?filter[name]=Test Study

search studies by name with wildcards or exact phrases

GET /api/v2/sapio/studies?filter[name]=*My "test and experiment" ?tudy*"Genomics"

search studies by name and include study_metadata and study_metadata.reference_genome

GET /api/v2/sapio/studies?filter[name]=My Study&include=study_metadata.reference_genome

search studies, include study_metadata, and specify fields

GET /api/v2/sapio/studies?filter[name]=My Study \
  &include=study_metadata.reference_genome \
  &fields[studies]=name,uuid \
  &fields[study_metadata]=study_description,study_abstract

GET request for a specific study by ID

GET /api/v2/sapio/studies/123/

POST request to create a new externally managed study

POST /api/v2/sapio/studies
Content-Type: application/json
X-Sequencescape-Client-Id: <integration_hub_api_key>
{
  "data": {
    "type": "studies",
    "attributes": {
      "name": "Unique study name, max 200 chars",
      "uuid": "11111111-2222-3333-4444-555555666666"
    }
  }
}

POST request that upserts an existing Study

(y26_245_sapio_study_upsert enabled)
POST /api/v2/sapio/studies
Content-Type: application/json
X-Sequencescape-Client-Id: <integration_hub_api_key>
{
  "data": {
    "type": "studies",
    "attributes": {
      "name": "Ignored - the existing Study's name is not changed",
      "uuid": "11111111-2222-3333-4444-555555666666"
    }
  }
}
# Returns 200 OK with the existing Study, now externally_managed,
# instead of 201 Created.

PATCH request to update an existing study

PATCH /api/v2/sapio/studies/123
Content-Type: application/json
X-Sequencescape-Client-Id: <integration_hub_api_key>
{
  "data": {
    "type": "studies",
    "id": "123",
    "attributes": {
      "state": "active"
    }
  }
}

Constant Summary

Constants included from StudySearchQuery

Api::V2::Sapio::StudySearchQuery::MAX_RESULTS

Instance Attribute Summary collapse

Method Summary

Methods inherited from BaseResource

apply_includes, creatable_fields, default_includes, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Attribute Details

#blocked ⇒ Boolean (readonly)

Note:

All rows in production have this column set to false.

Returns Whether the study is blocked.

Returns:

  • (Boolean) —

    Whether the study is blocked.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/resources/api/v2/sapio/study_resource.rb', line 188

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#created_at ⇒ String (readonly)

Returns Timestamp when the study was created.

Returns:

  • (String) —

    Timestamp when the study was created.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'app/resources/api/v2/sapio/study_resource.rb', line 177

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#enforce_accessioning ⇒ Boolean (readonly)

Returns Whether accessioning enforcement is enabled.

Returns:

  • (Boolean) —

    Whether accessioning enforcement is enabled.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'app/resources/api/v2/sapio/study_resource.rb', line 209

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#enforce_data_release ⇒ Boolean (readonly)

Returns Whether data release enforcement is enabled.

Returns:

  • (Boolean) —

    Whether data release enforcement is enabled.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/resources/api/v2/sapio/study_resource.rb', line 205

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#ethically_approved ⇒ Boolean (readonly)

Returns Whether ethical approval is set.

Returns:

  • (Boolean) —

    Whether ethical approval is set.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'app/resources/api/v2/sapio/study_resource.rb', line 201

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#externally_managed ⇒ Boolean (readonly)

Note:

Cannot be updated after creation.

Returns Whether the study is managed by an external LIMS.

Returns:

  • (Boolean) —

    Whether the study is managed by an external LIMS.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'app/resources/api/v2/sapio/study_resource.rb', line 197

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#name ⇒ String (readonly)

Note:

This attribute is required when creating a new study.

Note:

Cannot be updated after creation.

Note:

Maximum length is 200 characters.

Note:

Must be unique across all studies.

Returns The name of the study.

Returns:

  • (String) —

    The name of the study.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/resources/api/v2/sapio/study_resource.rb', line 161

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#state ⇒ String

Returns The state of the study (pending, active, or inactive).

Returns:

  • (String) —

    The state of the study (pending, active, or inactive).



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/resources/api/v2/sapio/study_resource.rb', line 192

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#study_metadata ⇒ StudyMetadataResource (readonly)

Returns The metadata associated with this study, containing additional details like faculty sponsor.

Returns:

  • (StudyMetadataResource) —

    The metadata associated with this study, containing additional details like faculty sponsor



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/resources/api/v2/sapio/study_resource.rb', line 145

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#updated_at ⇒ String (readonly)

Note:

study_metadata association specifies touch: true, so updated_at will reflect changes to the study_metadata as well.

Returns Timestamp when the study was last updated.

Returns:

  • (String) —

    Timestamp when the study was last updated.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/resources/api/v2/sapio/study_resource.rb', line 183

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#user ⇒ UserResource? (readonly)

Returns The user associated with this study.

Returns:

  • (UserResource, nil) —

    The user associated with this study.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/resources/api/v2/sapio/study_resource.rb', line 149

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#uuid ⇒ String

Note:

Cannot be updated after creation.

A version 1 UUID that uniquely identifies the study.

Returns:

  • (String) —

    The UUID of the study.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'app/resources/api/v2/sapio/study_resource.rb', line 167

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end