kids-first / kf-api-dataservice

:file_cabinet: Primary API for interacting with the Kids First data
http://kf-api-dataservice.kidsfirstdrc.org
Apache License 2.0
5 stars 2 forks source link

✨ Auto-populate Sample, Container on Biospecimen create/update #645

Closed znatty22 closed 7 months ago

znatty22 commented 7 months ago

Motivation

643 introduced the Sample and Container tables in order to address the shortcomings of the Biospecimen table. Now we need a way to populate these tables. And since a sample and container may be derived from a biospecimen, we can auto-populate them.

Approach

Each time a biospecimen is created or updated via an HTTP POST/PATCH, derive the sample and container from the input biospecimen and update sample/container tables.

Sample, Container Management

sample-container-flow(1)

  1. Find Sample - check if a sample already exists for this biospecimen

    • Use a specific set of biospecimen attributes to uniquely identify the sample:
    • sample_event_key = concat(participant_id, external_sample_id, age_at_event_days)
    • analyte_type
    • composition
    • source_text_tissue_type
    • source_text_anatomic_site
    • preservation_method
    • method_of_sample_procurement
    • concentration_mg_per_ml
  2. Create Sample - if the sample does not exist - create it using the relevant subset of biospecimen attributes

    • All parameters above, plus:
    • participant_id
    • external_sample_id
    • volume_ul
  3. Update Sample - if the sample exists - update it using the relevant subset of biospecimen attributes

  4. Find Container - check if a container already exists for this biospecimen

    • Use a specific set of biospecimen attributes to uniquely identify the container:
    • biospecimen_id
  5. Create Container - if the container does not exist - create it using the relevant subset of biospecimen attributes

    • All parameters above, plus:
    • sample_id
    • specimen_status
    • volume_ul
  6. Update Container - if the container exists - update it using the relevant subset of biospecimen attributes

  7. Sum Volume - update the the sample's volume_ul field with the sum of it's container volumes

znatty22 commented 7 months ago

Closing for now. New approach is to implement the Sample table only. This is an MVP to meet Portal Beta requirements. Will try to autopopulate the Sample table from Biospecimens similar to approach here