<commit_before>define ['lodash', 'ngmocks', 'expect', 'router'],
  (_, mocks, expect, router) ->
    describe 'Unit Testing Router', ->
      # The mock Router service module.
      Router = null

      # The mock Angular $http service provider.
      $httpBackend = null

      $rootScope = null

      # The mock objects.
      mock =
        subject:
          project: 'QIN_Test'
          collection: 'Breast'
          number: 1
          detail: 'a'
        subject_detail:
          sessions: [
            number: 1
            detail: 'b'
            modeling: [
              name: 'pk_aUjr'
              image_container_name: 'reg_8L3W'
              fxl_k_trans: 2.3
              fxr_k_trans: 2.5
            ]
          ]
          encounters: [
            encounter_type: 'Biopsy'
            outcomes: [
              _cls: 'BreastPathology'
              tnm:
                size: 'T3'
            ]
          ]
        session_detail:
          scan:
            name: 'scan'
            intensity:
              intensities: [2.4]
          registrations: [
            name: 'reg_test'
            intensity:
              intensities: [3.1]
          ]

      beforeEach ->
        # Fake the router service module.
        angular.mock.module('qiprofile.router')

        inject ['Router', '$httpBackend', '$rootScope',
          (_Router_, _$httpBackend_, _$rootScope_) ->
            Router = _Router_
            $httpBackend = _$httpBackend_
            $rootScope = _$rootScope_

            # The mock subjects http call.
            url = encodeURI('/api/subjects?where=' +
                            '{"project":"QIN_Test","collection":"Breast","number":1}')
            $httpBackend.whenGET(url).respond(JSON.stringify(_items: [mock.subject]))

            # The mock subject-detail http call.
            url = encodeURI('/api/subject-detail/a')
            $httpBackend.whenGET(url).respond(JSON.stringify(mock.subject_detail))

            # The mock session-detail http call.
            url = encodeURI('/api/session-detail/b')
            $httpBackend.whenGET(url).respond(JSON.stringify(mock.session_detail))
        ]

      afterEach ->
        $httpBackend.verifyNoOutstandingExpectation()
        $httpBackend.verifyNoOutstandingRequest()

      describe 'Subject Detail', ->
        # Validates the resolved subject.
        validate = (subject) ->
          expect(subject.sessions, "Subject is missing sessions").to.exist
          expect(subject.sessions.length).to.equal(1)
          expect(subject.isMultiSession).to.be.false
          sess = subject.sessions[0]
          expect(sess.subject, "Session is missing a subject").to.exist
          expect(sess.modeling, "Session is missing modeling").to.exist
          # TODO - replace the assignment below for multiple
          # modeling results per session.
          #expect(sess.modeling.length).to.equal(1)
          #mdl = sess.modeling[0]
          mdl = sess.modeling
          expect(mdl.delta_k_trans, "Modeling is missing a delta Ktrans")
            .to.exist
          mock_mdl = mock.subject_detail.sessions[0].modeling[0]
          mock_delta_k_trans = mock_mdl.fxr_k_trans - mock_mdl.fxl_k_trans
          expect(mdl.delta_k_trans, "Delta Ktrans is not #{ mock_delta_k_trans }")
            .to.be.closeTo(mock_delta_k_trans, 0.0000001)

        it 'should fetch the detail with a detail property', ->
          subject = _.clone(mock.subject)
          Router.getSubjectDetail(subject).then ->
            validate(subject)
          # Dispatch the backend request.
          $httpBackend.flush()

        it 'should fetch the detail without a detail property', ->
          subject = _.omit(mock.subject, 'detail')
          Router.getSubjectDetail(subject).then ->
            validate(subject)
          # Dispatch the backend request.
          $httpBackend.flush()

      describe 'Session Detail', ->
        mock_session = null
<commit_msg>Add encounter and treatment tests.<commit_after>define ['lodash', 'ngmocks', 'expect', 'router', 'moment'],
  (_, mocks, expect, router, moment) ->
    describe 'Unit Testing Router', ->
      # The mock Router service module.
      Router = null

      # The mock Angular $http service provider.
      $httpBackend = null

      $rootScope = null

      # The mock objects.
      mock =
        subject:
          project: 'QIN_Test'
          collection: 'Breast'
          number: 1
          detail: 'a'
        subject_detail:
          sessions: [
            number: 1
            detail: 'b'
            modeling: [
              name: 'pk_aUjr'
              image_container_name: 'reg_8L3W'
              fxl_k_trans: 2.3
              fxr_k_trans: 2.5
            ]
          ]
          encounters: [
            encounter_type: 'Biopsy'
            date: moment('July 12, 2013').valueOf()
            outcomes: [
              _cls: 'BreastPathology'
              tnm:
                size: 'T3'
            ]
          ]
          treatments: [
            treatment_type: 'neodjuvant'
            begin_date: moment('June 4, 2013').valueOf()
            end_date: moment('July 16, 2013').valueOf()
          ]
        session_detail:
          scan:
            name: 'scan'
            intensity:
              intensities: [2.4]
          registrations: [
            name: 'reg_test'
            intensity:
              intensities: [3.1]
          ]

      beforeEach ->
        # Fake the router service module.
        angular.mock.module('qiprofile.router')

        inject ['Router', '$httpBackend', '$rootScope',
          (_Router_, _$httpBackend_, _$rootScope_) ->
            Router = _Router_
            $httpBackend = _$httpBackend_
            $rootScope = _$rootScope_

            # The mock subjects http call.
            url = encodeURI('/api/subjects?where=' +
                            '{"project":"QIN_Test","collection":"Breast","number":1}')
            $httpBackend.whenGET(url).respond(JSON.stringify(_items: [mock.subject]))

            # The mock subject-detail http call.
            url = encodeURI('/api/subject-detail/a')
            $httpBackend.whenGET(url).respond(JSON.stringify(mock.subject_detail))

            # The mock session-detail http call.
            url = encodeURI('/api/session-detail/b')
            $httpBackend.whenGET(url).respond(JSON.stringify(mock.session_detail))
        ]

      afterEach ->
        $httpBackend.verifyNoOutstandingExpectation()
        $httpBackend.verifyNoOutstandingRequest()

      describe 'Subject Detail', ->
        # Validates the resolved subject.
        validate = (subject) ->
          # There should be encounters.
          expect(subject.encounters, "Subject is missing encounters").to.exist
          expect(subject.encounters.length).to.equal(1)
          enc = subject.encounters[0]
          expect(enc.encounter_type, "Encounter type is incorrect")
            .to.equal(mock.subject_detail.encounters[0].encounter_type)
          # There should be treatments.
          expect(subject.treatments, "Subject is missing treatments").to.exist
          expect(subject.treatments.length).to.equal(1)
          trt = subject.treatments[0]
          expect(trt.treatment_type, "Treatment type is incorrect")
            .to.equal(mock.subject_detail.treatments[0].treatment_type)
          expect(trt.begin_date.valueOf(), "Treatment begin date is incorrect")
            .to.equal(mock.subject_detail.treatments[0].begin_date)
          # There should be sessions.
          expect(subject.sessions, "Subject is missing sessions").to.exist
          expect(subject.sessions.length).to.equal(1)
          expect(subject.isMultiSession).to.be.false
          sess = subject.sessions[0]
          # There should be a parent subject.
          expect(sess.subject, "Session is missing a subject").to.exist
          # Validate the modeling.
          expect(sess.modeling, "Session is missing modeling").to.exist
          # TODO - replace the assignment below for multiple
          # modeling results per session.
          #expect(sess.modeling.length).to.equal(1)
          #mdl = sess.modeling[0]
          mdl = sess.modeling
          expect(mdl.delta_k_trans, "Modeling is missing a delta Ktrans")
            .to.exist
          mock_mdl = mock.subject_detail.sessions[0].modeling[0]
          mock_delta_k_trans = mock_mdl.fxr_k_trans - mock_mdl.fxl_k_trans
          expect(mdl.delta_k_trans, "Delta Ktrans is not #{ mock_delta_k_trans }")
            .to.be.closeTo(mock_delta_k_trans, 0.0000001)

        it 'should fetch the detail with a detail property', ->
          subject = _.clone(mock.subject)
          Router.getSubjectDetail(subject).then ->
            validate(subject)
          # Dispatch the backend request.
          $httpBackend.flush()

        it 'should fetch the detail without a detail property', ->
          subject = _.omit(mock.subject, 'detail')
          Router.getSubjectDetail(subject).then ->
            validate(subject)
          # Dispatch the backend request.
          $httpBackend.flush()

      describe 'Session Detail', ->
        mock_session = null

{'fraction_non_alphanumeric': 0.10579016107966914, 'fraction_numerical': 0.0087070091423596, 'mean_word_length': 1.8440111420612812, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4010971', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2539, 'n_words': 549}