$id: 'https://myome.com/schema/0.0.1/structs.json'
$schema: 'http://json-schema.org/draft-07/schema#'

title: 'Basic structures'
description: 'Non-idnetifiable structures'
type: object
definitions:

  Gene:
    type: object
    additionalProperties: false
    properties:
      ncbi_gene_id:
        type: string
      primary_symbol:
        type: string
      alternate_symbols:
        type: array
        items:
          type: string
        uniqueItems: true
    examples:
      - ncbi_gene_id: 672
        primary_symbol: 'BRCA1'
        alternate_symbols: ["BRCAI", "BRCC1", "FANCS", "IRIS", "PNCA4", "PSCP"]

  Genotype:
    type: object
    additionalProperties: false
    properties:
      gene_symbol:
        type: string
        examples:
          - "CYP2B6"
          - "CYP2C19"
          - "CYP2D6"
      haplotypes:
        type: string
        examples:
          - "*3/*4"
          - "*5/*17"
          - "*1/*8"

  PGxFinding:
    type: object
    additionalProperties: false
    properties:
      description:
        type: string
      genotype:
        $ref: '#/definitions/Genotype'
      gene_phenotype:
        $ref: 'core.json#/definitions/PGxGenePhenotype'
      reference:
        $ref: '#/definitions/Reference'

  Reference:
    description: >-
      Stores a reference or citation to external data

      The following types of Reference are supported:

        * `doi`: stores a refernece to a [Digital Object Identifier](https://www.doi.org/). **NOTE: pubmed should be preferred over doi for scientific publications.**
        * `pubmed`: stores a reference to a [PubMed](https://pubmed.ncbi.nlm.nih.gov/) identifier as the `value`.  The PubMed identifier may be replaced with the publication title, authors, etc. during rendering. 
        * `url`: stores a reference to a website (typically starting with `https:`).

      The `display` property, if set, contains text that will be used when representing the reference in written docuemnts. 
    type: object
    additionalProperties: false
    required: ["type", "value"]
    properties:
      display:
        description: Text to display for reference
        type: string
      type:
        type: string
        enum: ['doi', 'pubmed', 'url']
      value:
        type: string
      accessed_at:
        $ref: 'core.json#/definitions/UTCTimestamp'
    examples:
      - type: "doi"
        value: "10.1007/10753.1573-2576"
        display: "Inflammation"
      - type: "pubmed"
        value: "123456"
      - type: "url"
        value: "https://cpicpgx.org/guidelines/cpic-guideline-for-proton-pump-inhibitors-and-cyp2c19/"
        display: "CPIC CYP2C19 Guidelines"
        accessed_at: '2018-11-13T20:20:39+00:00'

  Lab:
    type: object
    additionalProperties: false
    properties:
      name:
        type: string
      address:
        $ref: '#/definitions/Address'
      clia_number:
        type: string
      cap_number:
        type: string
      directors:
        type: array
        items:
          $ref: '#/definitions/LabDirector'
    examples:
      - name: MyOme
        address: 930 Brittan Ave, San Carlos, California 94070
        clia_number: null
        cap_number: null
        directors:
          - _id: I/daea778e-11eb-6447
            email: ford@myclinic.com
            fax: 415-555-1212
            name:
              first: Ford
              last: Prefect
              title: Dr.
            phone: +1-415-555-1212
  Signature:
    type: object
    additionalProperties: false
    properties:
      image:
        type: string
        description: >-
          base64 encoded data url
          Tip: Generate with `convert signature.png -quality 70 -geometry 400x400 inline:gif:-`
        examples:
          - data:image/gif;base64,R0lGODlhZAASAPQAAAICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB4eHiAgIAAAAAAAAAAAACH5BAEAAB0AIf8LSW1hZ2VNYWdpY2sOZ2FtbWE9MC40NTQ1NDUALAAAAABkABIAAAX+YCeOZGmeaKqubOuaETRJlPXe+AhBTJT/EkkJ8iumIg6fSGhsOZikyaN5aYoelRLDqqoIlaRFU5IYEzuTUZmLkmQ751HDenj/HBkRhblln8AdFCQNaUYSB0aFIj4VcysLVTlTOggPVQ+AIhcLiC0JcVYLTywKIgygLJkKjgeRJBZzCCSTJQsIBiQJBg4bORayIxMOJ2IdoyIWCcM3jg0VriPDD8AdBwUlFGIHjh0REYKTgi7LIg6lYL3c3B0FNnYsEMpgGCTDDgFnDBULFA0LWD4iCOC2ZQqRBQvSmKN3JFipDms6SIjQp9sIBhSyZFLxgJYIhiImUHCwRUJFMASJKDBQsMGGiAYPEJFJc8EBkQkBT0BRkGCBAkUOAJDr8GbKhT0iEjAoBG3Exg4uKVQyhUrOAEccZq1o9FRcB48iKhR4KGdJBzETF/iwwEDtCUUlXPr5oWgBlJfeRmg4qyTCgjfrUng9AXLujTzBogXu0HZwjqevaEiQYRhHBggkK0fRzLmz58+fQwAAOw==
      user:
        type: string
        examples:
          - 'U/61be-4d38-644f'
      name:
        $ref: '#/definitions/Names'
        examples:
          - first: Random
            last: Person
      email:
        type: string
        format: email
        examples:
          - random.person@somelab.com
      utc_timestamp:
        $ref: 'core.json#/definitions/UTCTimestamp'
  Test:
    type: object
    additionalProperties: false
    properties:
      code:
        type: string
        description: MyOme test code
        examples:
          - acmg59.1
      name:
        type: string
        examples:
          - MyOme ACMG59 Test
      description:
        type: string
        examples:
          - >-
            Genomic DNA obtained from submitted samples was sequenced
            using Illumina technology. Reads were aligned to a reference
            sequence (GRCh37) and sequence changes were identified. For
            some genes, only specific changes were analyzed. Deletions
            and duplications were examined to a resolution of over 3
            exons. Selected variants were annotated and interpreted
            according to ACMG (American College of Medical Genetics)
            guidelines. Only pathogenic or likely pathogenic variants
            are reported. The MyOme Monogenic test covers 100% of all
            reported genes at 30X mean depth and nnnX minimum depth.has
            over 30X mean depthcoverage for all reported genes.
      genes:
        type: array
        examples:
          - ["ACTA2", "ACTC1", "APC", "APOB", "ATP7B", "BMPR1A", "BRCA1", "BRCA2",
            "CACNA1S", "COL3A1", "DSC2", "DSG2", "DSP", "FBN1", "GLA", "KCNH2", "KCNQ1",
            "LDLR", "LMNA", "MEN1", "MLH1", "MSH2", "MSH6", "MUTYH", "MYBPC3", "MYH11",
            "MYH7", "MYL2", "MYL3", "NF2", "OTC", "PCSK9", "PKP2", "PMS2", "PRKAG2", "PTEN",
            "RB1", "RET", "RET", "RYR1", "RYR2", "SCN5A", "SDHAF2", "SDHB", "SDHC", "SDHD",
            "SMAD3", "SMAD4", "STK11", "TGFBR1", "TGFBR2", "TMEM43", "TNNI3", "TNNT2", "TP53",
            "TPM1", "TSC1", "TSC2", "VHL", "WT1"]
      method:
        type: array
        items:
          type: string
        examples:
          -
            - "Genomic DNA obtained from submitted samples was sequenced
              using either Illumina or BGI technology. Reads were aligned
              to a reference sequence and sequence changes were
              identified. For some genes, only specific changes were
              analyzed."
            - "Deletions and duplications were not examined unless
              otherwise indicated above. In some scenarios, independent
              validation of HLA type may have been performed by an
              external lab"
            - "Selected variants were annotated and interpreted according
              to ACMG (American College of Medical Genetics)
              guidelines. Only pathogenic or likely pathogenic variants
              are reported."
            - "For a subset of conditions, a polygenic risk score was
              calculated as discussed in the publications below. Models
              for each condition were evaluated on the UK Biobank
              population."
            - "Some polygenic risk scores may be refined using HLA type. An
              individual's lifetime risk was calculated by adjusting the
              baseline risk (in the US population) according to their
              demographic information and polygenic risk score."
            - "For an individual's response to medication, we report known
              variants in genes associated with response to common
              medications based on guidelines from the Clinical
              Pharmacogenetics Implementation Consortium (CPIC). Genes
              tested include: CYP2B6, CYP2C19, CYP2C9, CYP2D6, CYP3A5,
              HLA-B (rs10484555, rs2395029), HLA-A (rs17179220), IFNL3
              (rs12979860), SLCO1B1, TPMT, NUDT15, UGT1A1.  There may be
              other variants that impact your response to medications not
              examined here."
      limitations:
        type: array
        items:
          type: string
        examples:
          -
            - This test is designed to provide information only for the
              specific monogenic conditions listed in Addendum 2.
              Additional testing information for other monogenic diseases
              is NOT included in the analysis.
            - This test does not examine structural variants, inclusive of
              deletions and duplications, which may be a cause of disease.
            - The PRS test is designed to provide risk estimates only for
              the specific conditions listed above. Additional PRS for
              other polygenic diseases are NOT included in the analysis.
            - PRS calculations do not include additional non-genetic
              factors such as environmental exposure.
            - Sensitivity of the test may be reduced when participant
              demographics differ from the training set which is currently
              a group of UK/British individuals.
            - PRS prediction of disease risk may be reduced in certain
              families with rare, monogenic variants.
            - A history of stem cell or bone marrow transplantation, or
              recent blood transfusion may impact the accuracy of the
              results and must be reported to the PI of the study.
            - Like most tests, this test has a risk of false negative or
              false positive results but is not limited to, sample
              contamination from biological or non-biological sources,
              specimen marking issues, rare genetic variants interfering
              with analysis, and other technical issues and limitations.
            - Testing is unavailable for samples damaged by human error or
              lost/destroyed due to weather, transit issues or other
              problems beyond the control of MyOme.
            - Test results should always be interpreted by a clinician in
              the context of clinical and familial data with the
              availability of genetic counseling when appropriate.
            - Along with factors such as age and diet, genetic variants
              can impact your response to certain medications. You should
              never change your drug regimen except under the guidance of
              your medical professional.
            - Predicted phenotype and allele functionality for medication
              findings may change as new literature, industry standards
              and guidelines emerge.
  Indication:
    type: object
    properties:
      type:
        type: string
        enum: ['text', 'ICD-9', 'ICD-10', 'SNOMED']
      value:
        type: string
    required: ['type', 'value']
    examples:
      - type: 'text'
        value: >-
          Diagnosed with ER/PR-positive breast cancer (age at
          diagnosis: 41 years). No family history of cancer.
  Variation:
    type: object
    additionalProperties: false
    properties:
      hgvs_g:
        $ref: 'core.json#/definitions/HGVSExpression'
      hgvs_t:
        $ref: 'core.json#/definitions/HGVSExpression'
      hgvs_p:
        $ref: 'core.json#/definitions/HGVSExpression'
      display:
        type: string
    required: [display]
    examples:
      - hgvs_g: NC_000017.11:g.43045685T>C
        hgvs_t: NM_007294.4(BRCA1):c.5585A>G
        hgvs_p: NP_009225.1:p.His1862Arg
        display: NM_007294.4(BRCA1):c.5585A>G (p.His1862Arg)
  VariationClassification:
    type: object
    additionalProperties: false
    properties:
      disease:
        type: string
        examples:
          - PMS2 is associated with...
      variation:
        $ref: '#/definitions/Variation'
      gene:
        $ref: '#/definitions/Gene'
      classification:
        $ref: 'core.json#/definitions/ACMGClassification'
      inheritance:
        $ref: 'core.json#/definitions/Inheritance'
      zygosity:
        $ref: 'core.json#/definitions/Zygosity'
      evidence:
        type: string
        examples:
          - 
            This variant has been seen in % of the individuals with
            condition. Has been observed to segreate with disease in at
            least on ene condition.
  
            For these reasons the variant has been classified as pathogenic.
  
            * This variant has been seen in XXX% of the individuals with
              condition. Has been observed to segreate with disease in at
              least on econdition.
            * For these reasons the variant has been classified as pathogenic.
      references:
        type: array
        items:
          $ref: '#/definitions/Reference'

  ############################################################################
  # kinds of people

  Individual:
    type: object
    additionalProperties: false
    properties:
      _id:
        type: string
        examples:
          - 'I/778edaea-6447-11eb'
      names:
        $ref: "#/definitions/Names"
      contact_info:
        type: array
        items:
          $ref: "#/definitions/ContactInfo"
    
    required:
      - names
      - contact_info

    # TODO: create better examples
  Subject:
    allOf:
      - $ref: '#/definitions/Individual'
      - type: object
        properties:
          preferred_name:
            $ref: '#/definitions/Names'
          # TODO: Use demographic struct for this info
          demographics:
            $ref: '#/definitions/Demographics'
            
  Clinician:
    allOf:
      - $ref: '#/definitions/Individual'
      - type: object
        properties:
          credentials:
            type: object
            properties:
              npi:
                $ref: "core.json#/definitions/NPI"

  # IS THIS IDENTIFIABLE? 
  LabDirector:
    allOf:
      - $ref: '#/definitions/Individual'
      - type: object
        properties:
          fax:
            type: string
    examples:
      - _id: I/daea778e-11eb-6447
        email: ford@myclinic.com
        fax: 415-555-1212
        name:
          first: Ford
          last: Prefect
          title: Dr.
        phone: +1-415-555-1212


  ############################################################################
  # utility types

  Address:
    type: object
    additionalProperties: false
    properties:
      street_address:
        type: string
      city:
        type: string
      region:
        type: string
      postal_code:
        type: string
      country:
        type: string
    examples:
      - street_address: '930 Brittan Ave'
        city: 'San Carlos'
        region: 'CA'
        postal_code: '94070'
        country: 'USA'

  ContactInfo:
    type: object
    additionalProperties: false
    properties:
      address:
        $ref: '#/definitions/Address'
      email:
        $ref: 'core.json#/definitions/EmailAddress'
      phone:
        type: string
      fax:
        type: string
      label:
        type: string
        enum:
          - work
          - home
          - other
          
  Demographics:
    type: object
    properties:
      dob:
        $ref: 'core.json#/definitions/Date'
      sex:
        $ref: 'core.json#/definitions/BiologicalSex'
      gender:
        $ref: 'core.json#/definitions/Gender'
      ancestries:
        type: array
        uniqueItems: true
        items:
          $ref: 'core.json#/definitions/Ancestry'
  Link:
    type: object
    properties:
      uri:
        type: string
        format: uri
      display:
        type: string
  Names:
    type: object
    additionalProperties: false
    properties:
      title:
        type: string
        default: null
      first:
        type: string
      middle:
        type: string
      last:
        type: string
    examples:
      - title: 'Dr.'
        first: 'Zaphod'
        middle: 'Vogon'
        last: 'Beeblebrox'

  Text:
    description: >-
      NOT IN USE YET
    type: object
    properties:
      format:
        type: string
        enum: ["plain", "markdown"]
        default: "plain"
      value:
        type: string

  LogItem:
    type: object
    additionalProperties: false
    properties:
      facility:
        type: string
      ts:
        $ref: 'core.json#/definitions/UTCTimestamp'
      level:
        $ref: 'core.json#/definitions/LogLevel'
      text:
        type: string
    examples:
      - facility: 'pipeline'
        level: 'WARNING'
        ts: '2018-11-13T20:20:39+00:00'
        text: 'oops!'
      - facility: 'secondary'
        level: 'INFO'
        ts: '2018-11-13T20:20:39+00:00'
        text: 'Sample is not human!'
