$schema: 'https://json-schema.org/draft/2020-12/schema'

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

  File:
    type: object
    required:
      - uri
      - mimetype
      - description
    properties:
      uri:
        type: string
      mimetype:
        type: string
      description:
        type: string
    examples:
      - uri: "s3://somebucket/path/to/report.json"
        description: "Report in JSON format"
        mimetype: "application/json"
      - uri: "s3://somebucket/path/to/report.pdf"
        description: "Report in PDF format"
        mimetype: "application/pdf"

  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:
      raw_call:
        type: string
        example: "*4/*6"
      rsid_based:
        type: boolean
        example: false
      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:
        oneOf:
          - $ref: 'core.json#/definitions/Date'
          - $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'
    required:
      - name
    examples:
      - name: MyOme
        address: 
          city: San Carlos
          country: USA
          postal_code: "94070"
          region: CA
          street_address: "930 Brittan Ave"
        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/Name'
        examples:
          - first: Random
            last: Person
      email:
        type: string
        format: email
        examples:
          - random.person@somelab.com
      utc_timestamp:
        $ref: 'core.json#/definitions/UTCTimestamp'

  ReportNextSteps:
    type: array
    items: 
      type: string
    example:
      - Women with an estimated lifetime breast cancer risk of 20% or higher should speak with their healthcare provider about American Cancer Society (ACS) guidelines for increased breast cancer surveillance as outlined below, as well as published recommendations for risk-reducing agents and comprehensive risk assessment.
      - Annual mammograms starting at age 40 or 10 years younger than the earliest breast cancer diagnosis in the family (but no earlier than age 30)\n
      - Annual breast MRI starting at age 40 or 10 years younger than the earliest breast cancer diagnosis in the family (but no earlier than age 25)\n
      - These results should be interpreted in the context of the individual's personal medical history and family history. The patient's female relatives may wish to speak with their healthcare provider to undergo a personalized risk assessment.

  SampleRequest:
    type: object
    properties:
      send_kit:
        type: boolean
      send_kit_address:
        $ref: '#/definitions/Address'
      type:
        $ref: "core.json#/definitions/SampleType"
    required: ['send_kit', 'type']
    examples:
      - type: 'Saliva'
        send_kit: true
        send_kit_address:
          city: San Carlos
          country: USA
          postal_code: "94070"
          region: CA
          street_address: "930 Brittan Ave"
  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
    required:
      - classification
    properties:
      disease:
        type: string
        examples:
          - PMS2 is associated with...
      variation:
        $ref: '#/definitions/Variation'
      gene:
        $ref: '#/definitions/Gene'
      classification:
        anyOf:
          - $ref: 'core.json#/definitions/ACMGClassification'
          - const: "NEGATIVE"
      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'

  LabDirector:
    type: object
    required:
      - name
      - npi
    properties:
      name:
        $ref: "#/definitions/Name"
      npi:
        $ref: "core.json#/definitions/NPI"


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

  Address:
    type: object
    additionalProperties: false
    properties:
      street_address:
        type: string
        description: Number and street
      city:
        type: string
        description: City
      region:
        type: string
        description: State, province, or other country-specific region
      postal_code:
        type: string
        description: Country-specific code for geographic districts
      country:
        type: string
        description: Country name or abbreviation
    examples:
      - street_address: '930 Brittan Ave'
        city: 'San Carlos'
        region: 'CA'
        postal_code: '94070'
        country: 'USA'

  ContactInfo:
    type: object
    additionalProperties: false
    properties:
      address:
        description: Address
        $ref: '#/definitions/Address'
      email:
        $ref: 'core.json#/definitions/EmailAddress'
      phone:
        type: string
      fax:
        type: string

  Demographics:
    type: object
    properties:
      dob:
        $ref: 'core.json#/definitions/Date'
      sex:
        $ref: 'core.json#/definitions/BiologicalSex'
      gender:
        $ref: 'core.json#/definitions/Gender'
  Link:
    type: object
    properties:
      uri:
        type: string
        format: uri
      display:
        type: string
  Name:
    type: object
    additionalProperties: false
    properties:
      title:
        type: string
      first:
        type: string
      middle:
        type: string
      last:
        type: string
      degrees:
        type: string
    examples:
      - title: 'Dr.'
        first: 'Zaphod'
        middle: 'Vogon'
        last: 'Beeblebrox'

  ToplineFinding:
    description: Topline finding for reports
    properties:
      finding:
        anyOf:
          - $ref: "core.json#/definitions/MonogenicToplineFinding"
          - $ref: "core.json#/definitions/PRSToplineFinding"
        type: string
      text:
        type: string
    required:
      - finding
      - text

  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!'

  Consent:
    type: object
    properties:
      type:
        $ref: 'core.json#/definitions/ConsentType'
      protocol_id:
        type: string
