+`import * as _ from "lodash"`
+
 `import ObjectHelper from "../object/object-helper.coffee"`
 
 # The cancer stages correspond to TNM scores, assuming no

  ['3B', '3B','3B', '3C']
]

###*
 * The static breast utility.
 *

 * @static
###
Breast =
  ###*
   * The breast cancer grade determinants, consisting of the
   * following properties:
   * * *RANGES* - the three grade score ranges, as follows:
   *   - Grade 1: score 3,5
   *   - Grade 2: score 6,7
   *   - Grade 3: score 8,9
   * * *SCORES* - the grade score factor properties
   *   `tubularFormation`, `mitoticCount` and `nuclearPleomorphism`
   *
   * @property Grade
   * @static
  ###
  Grade:
    RANGES: [[3..5], [6..7], [8..9]]
    SCORES: ['tubularFormation', 'mitoticCount', 'nuclearPleomorphism']

  ###*
   * @method extend
   * @param encounter the Breast patient clinical encounter
   * @return the augmented clinical encounter object
  ###
  extend: (encounter) ->
    if encounter.pathology
      for tumor in encounter.pathology.tumors
        ###*
         * The Breast pathology.
         *
         * @module clinical
         * @class BreastPathology
        ###
        if tumor.rcb
          RCB.extend(tumor.rcb, tumor)

        assay = _.get(tumor, 'geneticExpression.normalizedAssay')
        if assay
          ###*
           * The Breast gene expression normalized assay.
           *
           * @module clinical
           * @class BreastNormalizedAssay
          ###
          Object.defineProperties assay,
            ###*
             * Returns the cancer recurrence score. This score is calculated from
             * a genetic expression assay according to algorithm in Figure 1 of
             * the following paper:
             *
             *   Paik, et al., 'A Multigene Assay to Predict Recurrence of
             *   Tamoxifen-Treated, Node-Negative Breast Cancer',
             *   N Engl J Med 2004; 351:2817-2826
             *   (http://www.nejm.org/doi/full/10.1056/NEJMoa041588)
             *
             * 1f metastasis exists (M1), then the stage is 4.
             * Otherwise, the stage is determined by T and N scores as
             * defined in the tumor type factory STAGES associative
             * lookup table.
             *
             * @class BreastNormalizedAssay
             * @property recurrenceScore
            ###
            recurrenceScore:
              get: ->
                _recurrenceScore(this)
        ###*
         * The Breast pathology.
         *
         * @module clinical
         * @class BreastPathology
        ###

  ###*
   * @module clinical
   * @class Breast
   * @method stageExtent
   * @return the sorted stage values
  ###
  stageExtent: ->
    # Stage 4 is not in the STAGES look-up table, but is a
    # possible stage computed as 'IV' in the stage method
    # below.
    plus4 = _.partialRight(_.union, ['4'])
    # Flatten, augment, uniquify and sort the stages.
    _.flow(_.flatten, plus4, _.uniq, _.sort)(STAGES)

  ###*
   * Returns the cancer stage.
   *
   * 1f metastasis exists (M1), then the stage is 4.
   * Otherwise, the stage is determined by T and N scores as
   * defined in the tumor type factory STAGES associative
   * lookup table.
   *
   * @module clinical
   * @class Breast
   * @method stage
   * @param tnm the TNM object
   * @return the cancer stage object, as described in tnm.coffee
   *    stage
  ###
  stage: (tnm) ->
    # M1 => stage IV.
    # TODO - shouldn't this be '4'? Is there a test case for this?
    #   Since the value is romanized prior to display, this bug might
    #   be hidden. Same with the Sarcoma stage.
    if tnm.metastasis
      return 'IV'
    # The T and N scores.
    # TODO - factor in the size suffix.
    t = tnm.size.tumorSize
    n = tnm.lymphStatus

    # Lookup (T, N) in the stage table.
    # If not found, then throw an error.
    find = (table, value) ->
      result = table[value] or
        throw new ReferenceError("Unsupported #{ tnm.tumorType }" +
                                 " TNM: #{ ObjectHelper.prettyPrint(tnm) }")

    _.reduce([t, n], find, STAGES)

`export { Breast as default }`
