Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aq_10 #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/calculation_suite/calculations/AQ_10/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Autism Spectrum Quotient (AQ) Adolescent Version (AQ-10)

## Introduction

A quick referral guide for parents to complete about a teenager aged 12-15 years old with suspected autism who does not have a learning disability

## Calculation

Only 1 point can be scored for each question. Possible answers are "Definitely Agree", "Slightly Agree", "Slightly Disagree" and "Definitely Disagree".
Questions 1, 5, 8 and 10 - score 1 point for Definitely or Slightly Agree.
Questions 2, 3, 4, 6, 7 and 9 - score 1 point for Definitely or Slightly Disagree.
AQ-10 total score for the 10 items ranges from 0 to 10.

## Interpretation

If the individual scores 6 or above, consider referring them for a specialist diagnostic assessment.

## Use

This is the adolescent version of the test recommended in the NICE clinical guideline [CG142](https://www.nice.org.uk/guidance/CG142).

## References

[1] Allison C, Auyeung B, and Baron-Cohen S, (2012) Journal of the American Academy of Child and Adolescent Psychiatry 51(2):202-12.
[2] [Autism Research Centre](https://docs.autismresearchcentre.com/tests/AQ10-Adolescent.pdf)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const best_response = {
AQ10_Q01: 0,
AQ10_Q02: 0,
AQ10_Q03: 0,
AQ10_Q04: 0,
AQ10_Q05: 0,
AQ10_Q06: 0,
AQ10_Q07: 0,
AQ10_Q08: 0,
AQ10_Q09: 0,
AQ10_Q10: 0,
}

export const worst_response = {
AQ10_Q01: 1,
AQ10_Q02: 1,
AQ10_Q03: 1,
AQ10_Q04: 1,
AQ10_Q05: 1,
AQ10_Q06: 1,
AQ10_Q07: 1,
AQ10_Q08: 1,
AQ10_Q09: 1,
AQ10_Q10: 1,
}

/**
* Expected score: 6
*/
export const random_response = {
AQ10_Q01: 1,
AQ10_Q02: 0,
AQ10_Q03: 1,
AQ10_Q04: 0,
AQ10_Q05: 0,
AQ10_Q06: 1,
AQ10_Q07: 1,
AQ10_Q08: 1,
AQ10_Q09: 0,
AQ10_Q10: 1,
}
132 changes: 132 additions & 0 deletions src/calculation_suite/calculations/AQ_10/aq_10.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { expect } from 'chai'

import { InvalidInputsError } from '../../errors'
import { execute_test_calculation } from '../../helper_functions/execute_test_calculation'
import { get_result_ids_from_calculation_output } from '../../helper_functions/get_result_ids_from_calculation_output'
import { view_result } from '../../helper_functions/view_result'
import { view_status } from '../../helper_functions/view_status'
import { MISSING_STATUS } from '../../PARAMETERS'
import { CALCULATIONS } from '../calculation_library'
import { get_input_ids_from_calculation_blueprint } from '../shared_functions'
import {
best_response,
random_response,
worst_response,
} from './__testdata__/aq_10_test_responses'
import { AQ10_INPUTS } from './definition'
import { aq_10 } from './aq_10'

const BEST_SCORE = 0
const WORST_SCORE = 10

const aq_10_calculation = execute_test_calculation(aq_10)

describe('aq_10', function () {
it('aq_10 calculation function should be available as a calculation', function () {
expect(CALCULATIONS).to.have.property('aq_10')
})

describe('basic assumptions', function () {
const outcome = aq_10_calculation(best_response)

it('should return 2 calculation results', function () {
expect(outcome).to.have.length(2)
})

it('should have the expected calculation result ids', function () {
const EXPECTED_CALCULATION_ID = ['AQ10_SCORE', 'AQ10_INTERPRETATION']

const configured_calculation_id =
get_result_ids_from_calculation_output(outcome)

expect(configured_calculation_id).to.eql(EXPECTED_CALCULATION_ID)
})
})

describe('validation', function () {
describe('the score includes the correct input fields', function () {
it('should have all the expected input ids configured', function () {
const EXPECTED_INPUT_IDS = [
'AQ10_Q01',
'AQ10_Q02',
'AQ10_Q03',
'AQ10_Q04',
'AQ10_Q05',
'AQ10_Q06',
'AQ10_Q07',
'AQ10_Q08',
'AQ10_Q09',
'AQ10_Q10',
]

const configured_input_ids =
get_input_ids_from_calculation_blueprint(AQ10_INPUTS)

expect(EXPECTED_INPUT_IDS).to.eql(configured_input_ids)
})
})

describe('when an answer is not not one of the allowed answers', function () {
it('should throw an InvalidInputsError', function () {
expect(() =>
aq_10_calculation({
AQ10_Q01: -1,
})
).to.throw(InvalidInputsError)
})
})

describe('when called with an empty response', function () {
const outcome = aq_10_calculation({})

it('should return undefined result and a missing status for the score', function () {
const score = view_result('AQ10_SCORE')(outcome)
const status = view_status('AQ10_SCORE')(outcome)

expect(score).to.eql(undefined)
expect(status).to.eql(MISSING_STATUS)
})

it('should return undefined result and a missing status for the interpretation', function () {
const score = view_result('AQ10_INTERPRETATION')(outcome)
const status = view_status('AQ10_INTERPRETATION')(outcome)

expect(score).to.eql(undefined)
expect(status).to.eql(MISSING_STATUS)
})
})
})

describe('score calculation', function () {
describe('when called with the best response', function () {
const outcome = aq_10_calculation(best_response)

it('should return the best score', function () {
const score = view_result('AQ10_SCORE')(outcome)

expect(score).to.eql(BEST_SCORE)
})
})

describe('when called with the worst response', function () {
const outcome = aq_10_calculation(worst_response)

it('should return the worst score', function () {
const score = view_result('AQ10_SCORE')(outcome)

expect(score).to.eql(WORST_SCORE)
})
})

describe('when called with a random response', function () {
const outcome = aq_10_calculation(random_response)

it('should return the expected score', function () {
const score = view_result('AQ10_SCORE')(outcome)
const EXPECTED_SCORE = 6

expect(score).to.eql(EXPECTED_SCORE)
})
})
})
})
64 changes: 64 additions & 0 deletions src/calculation_suite/calculations/AQ_10/aq_10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import R from 'ramda'

import type {
CalculationType,
InputType,
WIPCalculationResultType,
} from '../../../types/calculations.types'
import { rawInputValueLens } from '../../helper_functions/calculation_variants/api/input/lenses'
import { add_raw_values_to_inputs } from '../../helper_functions/calculation_variants/simple_calculation'
import { create_calculation } from '../../helper_functions/create_calculation'
import { MISSING_MESSAGE } from '../../PARAMETERS'
import { is_numeric } from '../shared_functions'
import { AQ10_INPUTS, AQ10_OUTPUT } from './definition'

const calculate_score = (
inputs_with_answers: Array<InputType>
): WIPCalculationResultType => {
const valid_inputs = R.compose(
R.filter(is_numeric),
R.map(input => R.view(rawInputValueLens, input))
)(inputs_with_answers)

if (valid_inputs.length !== AQ10_INPUTS.length)
return [
{
id: 'AQ10_SCORE',
score: MISSING_MESSAGE,
},
{
id: 'AQ10_INTERPRETATION',
score: MISSING_MESSAGE,
},
]

const total_score = R.sum(valid_inputs)

return [
{
id: 'AQ10_SCORE',
score: total_score,
},
{
id: 'AQ10_INTERPRETATION',
score:
'If the individual scores 6 or above, consider referring them for a specialist diagnostic assessment.',
},
]
}

export const specific_steps_aq_10_calc = [
calculate_score,
add_raw_values_to_inputs(AQ10_INPUTS),
]

export const aq_10: CalculationType = create_calculation({
calculation_name:
'Autism Spectrum Quotient (AQ) - Adolescent Version - (AQ-10)',
readme_location: __dirname,
calculation_steps: specific_steps_aq_10_calc,
calculation_definition: {
input_definition: AQ10_INPUTS,
output_definition: AQ10_OUTPUT,
},
})
Loading
Loading