public function testSpecificationIsTrue()
 {
     $questionnaire = new Questionnaire(new Person());
     $drinks = $questionnaire->getDrinking()->getWeekdayDrinks()->setBeerCiderBottleAmount(1);
     $questionnaire->getDrinking()->setDoYouDrink(Drinking::DOES_DRINK)->setWhichDaysDoYouDrink('mon, tues')->setBingingFrequency(Drinking::BINGE_NEVER)->setWeekdayDrinks($drinks);
     $this->assertTrue(DrinkingLTE2DaysLTE3UnitsSpecification::isSatisfiedBy($questionnaire));
 }
 public function testSpecificationIsTrue()
 {
     $questionnaire = new Questionnaire((new Person())->setGender(Person::GENDER_MALE));
     $drinks = $questionnaire->getDrinking()->getWeekdayDrinks()->setBeerCiderBottleAmount(2);
     $questionnaire->getDrinking()->setDoYouDrink(Drinking::DOES_DRINK)->setWhichDaysDoYouDrink('mon, tues, wed, thur')->setBingingFrequency(Drinking::BINGE_NEVER)->setWeekdayDrinks($drinks);
     $this->assertTrue(DrinkingBetween3And5DaysWithinSuggestedLimitsSpecification::isSatisfiedBy($questionnaire));
 }
 public function testSpecificationIsTrue()
 {
     $days = array('mon' => 80, 'tues' => 80);
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getMoving()->setAerobicActivityDays($days);
     $this->assertTrue(AmberMovingAmberAerobicLowDaysRedStrengthSpecification::isSatisfiedBy($questionnaire));
 }
 public function testSpecificationIsFalse()
 {
     $questionnaire = new Questionnaire((new Person())->setGender(Person::GENDER_FEMALE));
     $questionnaire->getDrinking()->setWhichDaysDoYouDrink('mon');
     $questionnaire->getDrinking()->getWeekdayDrinks()->setSpiritsAmount(8);
     $this->assertFalse(DrinkingDoesNotExceedDailyLimitsForGenderSpecification::isSatisfiedBy($questionnaire));
 }
 public function testSpecificationIsFalseAndIAmMale()
 {
     $questionnaire = new Questionnaire((new Person())->setGender(Person::GENDER_MALE));
     $drinks = (new Drinks())->setBeerCiderPintAmount(3);
     $questionnaire->getDrinking()->setDoYouDrink(Drinking::DOES_DRINK)->setWhichDaysDoYouDrink('mon, tue, wed')->setWeekdayDrinks($drinks);
     $this->assertFalse(DrinkingUnitsInLowerRiskForGenderSpecification::isSatisfiedBy($questionnaire));
 }
 public function testSpecificationIsTrue()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getDrinking()->setWhichDaysDoYouDrink('sat, sun');
     $questionnaire->getDrinking()->getWeekendDrinks()->setBeerCiderPintAmount(2);
     $this->assertTrue(DrinkingExceedsThreeUnitsSpecification::isSatisfiedBy($questionnaire));
 }
 public function testCreateQuestionnaire()
 {
     $this->createQuestionnaire();
     $this->assertNotNull($this->result);
     $this->assertStringStartsWith('FIRST_NAME ', $this->result->getPerson()->getFirstName());
     $this->assertNotEmpty($this->result->getId());
 }
 /**
  * @inheritdoc
  */
 public function calculateScore(Questionnaire $questionnaire)
 {
     if ($questionnaire->getMoving()->isCompleted()) {
         $this->extractMovingScore($questionnaire);
     }
     return $this->getRag();
 }
 /**
  * @param Questionnaire $questionnaire
  * @param TranslatorInterface $translator
  * @return array
  */
 public static function extractResultsNarrative(Questionnaire $questionnaire, TranslatorInterface $translator)
 {
     if (true === $questionnaire->isCompleted()) {
         self::prepareResultsNarrative($questionnaire, $translator);
     }
     return self::$resultsNarrative;
 }
 public function testSpecificationIsTrue()
 {
     $days = array('mon' => 30, 'tues' => 30, 'wed' => 30);
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getMoving()->setAerobicActivityDays($days);
     $this->assertTrue(AerobicTimeLT150MinsDaysGTE3Specification::isSatisfiedBy($questionnaire));
 }
 /**
  * @param Questionnaire $questionnaire
  * @param Document      $document
  */
 protected function addSignedInCompletedRecords(Questionnaire $questionnaire, Document &$document)
 {
     if (true === $questionnaire->isCompleted() && true === $questionnaire->getPerson()->isSignedUp()) {
         $document->addRecord(new Record($questionnaire, $this->getContainer()->get('translator')));
     }
     $this->updateQuestionnaireAddressAndStatus($questionnaire);
 }
 public function testICanGetAPositiveNarrativeAfterQuitting()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getAboutYou()->getFeelings()->setEnergy(100)->setMood(20);
     $questionnaire->getSmoking()->setDoYouSmoke('quit')->setCompletedDate(new \DateTime());
     $expected = array('smoking' => array('smoking_green_quit'));
     $this->assertEquals($expected, $this->instance->buildNarrative($questionnaire)->getMessages());
 }
 public function testIGetARedMessageWithSnacksWarningEating()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getEating()->setProteinChoice('ham')->setCheeseChoice('hard cheese')->setPotatoesChoice('chips')->setDailySnackChoice('sweets, crisps, biscuits, cake')->setCompletedDate(new \DateTime());
     $questionnaire->getAboutYou()->getFeelings()->setWeight(25);
     $expected = array('eating' => array('eating_red', 'eating_red_low_weight'));
     $this->assertEquals($expected, $this->instance->buildNarrative($questionnaire)->getMessages());
 }
 public function testExtractMotivations()
 {
     $expectedKeys = array("motivationsWeight", "motivationsEnergy", "motivationsBodyPain", "motivationsFeelYounger", "motivationsIndependence", "motivationsAlertness", "motivationsSocialLife", "motivationsAppearance", "motivationsFamily", "motivationsCompleted");
     $export = HowAreYouHelper::extractMotivations($this->instance->getAboutYou()->getMotivations());
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $export);
     }
 }
 public function testIGetARedMessageWithFitnessQuestionForMoving()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getMoving()->setCompletedDate(new \DateTime());
     $questionnaire->getAboutYou()->getFeelings()->setFitness(21);
     $expected = array('moving' => array('moving_red', 'moving_red_low_fitness'));
     $this->assertEquals($expected, $this->instance->buildNarrative($questionnaire)->getMessages());
 }
 /**
  * @param Questionnaire $questionnaire
  * @return Questionnaire
  */
 public function populateAddressDetailsFromPostCode(Questionnaire $questionnaire)
 {
     $address = $questionnaire->getPerson()->getAddress();
     if ($this->hasPostCode($address) && $this->loadAuthorityForPostCode($address)) {
         $questionnaire->getPerson()->setAddress($address);
     }
     return $questionnaire;
 }
 public function testExtractSmoking()
 {
     $expectedKeys = array("smokingDoYouSmoke", "smokingCompleted", "smokingRag");
     $questionnaire = new Questionnaire(new Person());
     $export = SmokingHelper::extractSmoking($questionnaire->getSmoking());
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $export);
     }
 }
 public function testExtractMoving()
 {
     $expectedKeys = array("movingAerobicActivityDuration", "movingAerobicActivityDays", "strengtheningActivityDays", "movingCompleted", "movingRag");
     $questionnaire = new Questionnaire(new Person());
     $export = MovingHelper::extractMoving($questionnaire->getMoving());
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $export);
     }
 }
 public function testGetDrinking()
 {
     $expectedKeys = array("drinkingDoYouDrink", "drinkingFrequency", "weekdayDrinksBeerCiderPintAmount", "weekdayDrinksBeerCiderBottleAmount", "weekdayDrinksWineAmount", "weekdayDrinksSpiritsPintAmount", "weekdayDrinksCompleted", "weekendDrinksBeerCiderPintAmount", "weekendDrinksBeerCiderBottleAmount", "weekendDrinksWineAmount", "weekendDrinksSpiritsPintAmount", "weekendDrinksCompleted", "occasionalDrinksBeerCiderPintAmount", "occasionalDrinksBeerCiderBottleAmount", "occasionalDrinksWineAmount", "occasionalDrinksSpiritsPintAmount", "occasionalDrinksCompleted", "hasBinged", "drinkingCompleted", "drinkingRag");
     $questionnaire = new Questionnaire(new Person());
     $export = DrinkingHelper::extractDrinking($questionnaire->getDrinking());
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $export);
     }
 }
 /**
  * @param Questionnaire $questionnaire
  */
 protected function extractSmokingScore(Questionnaire $questionnaire)
 {
     $doYouSmoke = $questionnaire->getSmoking()->getDoYouSmoke();
     if ($doYouSmoke === 'yes' || $doYouSmoke === 'sometimes') {
         $this->populateRag(self::RAG_RED, self::SCORE_RED);
     } else {
         $this->populateRag(self::RAG_GREEN, self::SCORE_GREEN);
     }
 }
 public function testICanExcludeAndGetTheSameSymptom()
 {
     $questionnaire = new Questionnaire(new Person());
     $possibles = $questionnaire->getAboutYou()->getFeelings()->getNormalisedValues();
     $exclusions = array_keys($possibles);
     array_shift($exclusions);
     $expected = array_keys($possibles)[0];
     $this->assertEquals($expected, SymptomGenerator::generateRelatedSymptom($possibles, $exclusions));
 }
 public function testExtractEating()
 {
     $expectedKeys = array("eatingProteinChoice", "eatingDrinksChoice", "eatingPotatoesChoice", "eatingBreakfastChoice", "eatingCheeseChoice", "eatingFruitAndVegChoice", "eatingDailySnackChoice", "eatingComplete", "eatingRag");
     $questionnaire = new Questionnaire(new Person());
     $export = EatingHelper::extractEating($questionnaire->getEating());
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $export);
     }
 }
 /**
  * @param Questionnaire $questionnaire
  */
 protected function buildRedSmokingBehaviours(Questionnaire $questionnaire)
 {
     $symptom = SymptomGenerator::generateRelatedSymptom($questionnaire->getAboutYou()->getFeelings()->getNormalisedValues());
     if (SmokingIsOccasionalSpecification::isSatisfiedBy($questionnaire)) {
         $this->getMessageForOccasionalSmoker($questionnaire->getAboutYou()->getFeelings()->getNormalisedValues()[$symptom], $symptom);
     } else {
         $this->getMessageForSmoker($questionnaire->getAboutYou()->getFeelings()->getNormalisedValues()[$symptom], $symptom);
     }
 }
 public function testIHave150MinutesAnd3OrMoreDaysIAmAerobicGreen()
 {
     $aerobic = array('mon' => 50, 'tue' => 50, 'wed' => 50);
     $questionnaire = new Questionnaire(new Person());
     $moving = $questionnaire->getMoving();
     $moving->setAerobicActivityDays($aerobic)->setCompletedDate(new \DateTime());
     $questionnaire->setMoving($moving);
     $this->assertTrue(AerobicIsGreenSpecification::isSatisfiedBy($questionnaire));
 }
 public function testIHaveLessThan60MinutesAndLessThanThreeDaysIAmAerobicRed()
 {
     $aerobic = array('mon' => 15, 'tue' => 15);
     $questionnaire = new Questionnaire(new Person());
     $moving = $questionnaire->getMoving();
     $moving->setAerobicActivityDays($aerobic)->setCompletedDate(new \DateTime());
     $questionnaire->setMoving($moving);
     $this->assertTrue(AerobicIsRedSpecification::isSatisfiedBy($questionnaire));
 }
 public function testIHave60OrMoreMinutesAndLessThanTwoDaysIAmAerobicAmber()
 {
     $aerobic = array('mon' => 50, 'wed' => 40);
     $questionnaire = new Questionnaire(new Person());
     $moving = $questionnaire->getMoving();
     $moving->setAerobicActivityDays($aerobic)->setCompletedDate(new \DateTime());
     $questionnaire->setMoving($moving);
     $this->assertFalse(AerobicIsGreenSpecification::isSatisfiedBy($questionnaire));
     $this->assertFalse(AerobicIsRedSpecification::isSatisfiedBy($questionnaire));
 }
 public function testAnyNonSmokerIsGreen()
 {
     $questionnaire = new Questionnaire(new Person());
     $smoking = $questionnaire->getSmoking();
     $smoking->setDoYouSmoke("no i've quit")->setCompletedDate(new \DateTime());
     $questionnaire->setSmoking($smoking);
     $result = $this->instance->calculateScore($questionnaire);
     $this->assertEquals(SmokingScore::RAG_GREEN, $result['rag']);
     $this->assertEquals(SmokingScore::SCORE_GREEN, $result['value']);
 }
 public function testIGetAnGreenRagWithMaxVeg()
 {
     $person = new Person();
     $questionnaire = new Questionnaire($person);
     $eating = $questionnaire->getEating();
     $eating->setFruitAndVegChoice(5)->setCompletedDate(new \DateTime());
     $rag = $this->instance->calculateScore($questionnaire);
     $this->assertEquals(EatingScore::RAG_GREEN, $rag['rag']);
     $this->assertEquals(EatingScore::SCORE_GREEN, $rag['value']);
 }
 /**
  * @inheritDoc
  */
 public static function isSatisfiedBy(Questionnaire $questionnaire)
 {
     $maxUnits = DrinkingScore::getDailyMaxUnits($questionnaire->getDrinking());
     $gender = $questionnaire->getPerson()->getGender();
     switch ($gender) {
         case Person::GENDER_FEMALE:
             return $maxUnits > DrinkingScore::DAILY_CUTOFF_UNITS_FEMALE;
         case Person::GENDER_MALE:
             return $maxUnits > DrinkingScore::DAILY_CUTOFF_UNITS_MALE;
     }
 }
 public function testICanGetANarrativeWithMaxFeeling()
 {
     $questionnaire = new Questionnaire(new Person());
     $questionnaire->getAboutYou()->getFeelings()->setEnergy(100)->setMood(100)->setWeight(100)->setFatigue(100)->setFitness(100)->setStress(100);
     $questionnaire->getSmoking()->setDoYouSmoke('sometimes')->setCompletedDate(new \DateTime());
     $expected = array('smoking_red_sometimes');
     $results = $this->instance->buildNarrative($questionnaire)->getMessages()['smoking'];
     foreach ($expected as $value) {
         $this->assertTrue(in_array($value, $results));
     }
 }