From 3391737c454235c85c6a31c587763c0049e43d90 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Thu, 19 Dec 2024 02:37:38 +0000 Subject: [PATCH] Add fixtures to generate randomized data --- src/DataFixtures/AppFixtures.php | 17 ++++ src/DataFixtures/MemberCaseFixture.php | 58 +++++++++++ src/DataFixtures/MemberFixture.php | 83 ++++++++++++++++ src/DataFixtures/NoteFixture.php | 110 +++++++++++++++++++++ src/DataFixtures/ReferralFixture.php | 47 +++++++++ src/DataFixtures/ReferralSourceFixture.php | 39 ++++++++ src/DataFixtures/UserFixture.php | 67 +++++++++++++ 7 files changed, 421 insertions(+) create mode 100644 src/DataFixtures/AppFixtures.php create mode 100644 src/DataFixtures/MemberCaseFixture.php create mode 100644 src/DataFixtures/MemberFixture.php create mode 100644 src/DataFixtures/NoteFixture.php create mode 100644 src/DataFixtures/ReferralFixture.php create mode 100644 src/DataFixtures/ReferralSourceFixture.php create mode 100644 src/DataFixtures/UserFixture.php diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php new file mode 100644 index 0000000..987f6fe --- /dev/null +++ b/src/DataFixtures/AppFixtures.php @@ -0,0 +1,17 @@ +persist($product); + + $manager->flush(); + } +} diff --git a/src/DataFixtures/MemberCaseFixture.php b/src/DataFixtures/MemberCaseFixture.php new file mode 100644 index 0000000..bfeb9f4 --- /dev/null +++ b/src/DataFixtures/MemberCaseFixture.php @@ -0,0 +1,58 @@ +getRepository(ReferralSource::class)->findAll(); + $users = $manager->getRepository(User::class)->findAll(); + + $gen = \Faker\Factory::create(); + + for ($x = 0; $x < 50; $x++) { + $case = new MemberCase(); + $case->setCaseNumber($gen->numberBetween(1000000, 9999999)) + ->setDcsCaseId($gen->numberBetween(1000000, 9999999)) + ->setFirstName($gen->firstName()) + ->setLastName($gen->lastName()) + ->setCounty($gen->randomElement(County::class)) + ->setReferralSource($gen->randomElement($sources)) + ->setLevel($gen->randomElement(CaseLevel::class)) + ->setAdmitDate($gen->dateTimeBetween('-1 year', 'now')) + ->setReferralType('DCS') + ; + + $uc = new UserCase(); + $uc->setMemberCase($case); + $uc->setUser($gen->randomElement($users)); + + print "Adding member case {$case->getCaseNumber()}".PHP_EOL; + + $manager->persist($case); + $manager->persist($uc); + } + + $manager->flush(); + } + + public function getDependencies(): array + { + return [ + ReferralSourceFixture::class, + UserFixture::class, + ]; + } +} diff --git a/src/DataFixtures/MemberFixture.php b/src/DataFixtures/MemberFixture.php new file mode 100644 index 0000000..42df05a --- /dev/null +++ b/src/DataFixtures/MemberFixture.php @@ -0,0 +1,83 @@ +getRepository(MemberCase::class)->findAll(); + + foreach ($cases as $case) { + /** @var MemberCase $case */ + $caseLastName = $case->getLastName(); + print "Adding members for case {$case->getCaseName()}".PHP_EOL; + $memCount = $gen->numberBetween(0, 5); + for ($x = 0; $x < $memCount; $x++) { + $isChild = $gen->boolean(); + $isParent = ($isChild ? false : $gen->boolean()); + $isLegalGuardian = (!$isParent && !$isChild ? $gen->boolean() : false); + $dcsApproved = (!$isParent && !$isChild ? $gen->boolean() : false); + $sameLastName = $gen->boolean(); + $mem = new Member(); + $name = $gen->firstName().' '.$gen->lastName(); + $username = strtolower(str_replace(' ', '.', $name)); + $phone = substr(str_replace(['-', '+', ' ', '(', ')'], '', $gen->e164PhoneNumber()), -10); + + $mem->setRelationship($gen->randomElement(RelationshipType::class)) + ->setPersonalId($gen->numberBetween(1000000, 9999999)) + ->setGender($gen->randomElement(GenderType::class)) + ->setRace($gen->randomElement(RaceType::class)) + ->setPhone($phone) + ->setCellPhone($phone) + ->setEmail($username.'@'.$gen->freeEmailDomain()) + ->setAddress($gen->streetAddress()) + ->setCity($gen->city()) + ->setState(State::IN->name) + ->setZip($gen->postcode()) + ->setDob( + $gen->dateTimeBetween( + ($isChild ? '-16 years' : '-50 years'), + ($isParent || $isLegalGuardian ? '-16 years' : '-1 month') + ) + ) + ->setFirstName($gen->firstName()) + ->setLastName($sameLastName ? $caseLastName : $gen->lastName()) + ->setChild($isChild) + ->setParent($isParent) + ->setLegalGuardian($isLegalGuardian) + ->setAdultChild(false) + ->setParentsLiveTogether(false) + ->setDcsApproved($dcsApproved) + ->setCaseId($case) + ; + + print "Adding member {$mem->getFirstName()} {$mem->getLastName()}".PHP_EOL; + + $manager->persist($mem); + } + } + + $manager->flush(); + } + + public function getDependencies(): array + { + return [ + MemberCaseFixture::class, + ReferralFixture::class, + ]; + } +} diff --git a/src/DataFixtures/NoteFixture.php b/src/DataFixtures/NoteFixture.php new file mode 100644 index 0000000..6ffdb68 --- /dev/null +++ b/src/DataFixtures/NoteFixture.php @@ -0,0 +1,110 @@ +getRepository(Referral::class)->findAll(); + + foreach ($refs as $ref) { + /** @var Referral $ref */ + print "Adding notes for referral {$ref->getReferralId()}".PHP_EOL; + $noteCount = $gen->numberBetween(0, 10); + + $case = $ref->getMemberCase(); + $caseMembers = $case->getMembers(); + + for ($x = 0; $x < $noteCount; $x++) { + $startTime = $gen->dateTimeBetween('06:00:00', '14:00:00'); + $endTime = $gen->dateTimeBetween('12:00:00', '21:00:00'); + + if ($startTime > $endTime) { + $tmp = clone $endTime; + $endTime = $startTime; + $startTime = $tmp; + } + + if ($ref->getServiceCode() === ReferralServiceType::VS_THBB) { + $note = new VisitNote(); + $note->setReferral($ref) + ->setDate($gen->dateTimeBetween($case->getAdmitDate()->format('Y-m-d'), 'now')) + ->setStartTime($startTime) + ->setEndTime($endTime) + ->setStatus($gen->randomElement(NoteStatus::class)) + ->setLocation($gen->randomElement(NoteLocation::class)) + ->setMethod(NoteMethod::BILLABLE_SUPERVISED_VISIT) + ->setParentalRole($gen->randomElement(VisitQualityLevel::class)) + ->setChildDevelopment($gen->randomElement(VisitQualityLevel::class)) + ->setAppropriateResponse($gen->randomElement(VisitQualityLevel::class)) + ->setChildAheadOfSelf($gen->randomElement(VisitQualityLevel::class)) + ->setShowsEmpathy($gen->randomElement(VisitQualityLevel::class)) + ->setChildFocused($gen->randomElement(VisitQualityLevel::class)) + ->setNarrative($gen->text(100)) + ->setStrengths($gen->text(100)) + ->setIssues($gen->text(100)) + ->setRecommendation($gen->text(100)) + // ->setMembers( + // ( + // count($caseMembers) > 0 + // ? + // $gen->randomElements($caseMembers, $gen->numberBetween(1, count($caseMembers))) + // : + // null + // ) + // ) + ; + // dd($note); + } else { + $note = new StandardNote(); + $note->setReferral($ref) + ->setDate($gen->dateTimeBetween('-1 year', 'now')) + ->setStartTime($startTime) + ->setEndTime($endTime) + ->setStatus($gen->randomElement(NoteStatus::class)) + ->setLocation($gen->randomElement(NoteLocation::class)) + ->setMethod(NoteMethod::BILLABLE) + ->setNote($gen->text(100)) + // ->setMembers( + // ( + // count($caseMembers) > 0 + // ? + // $gen->randomElements($caseMembers, $gen->numberBetween(1, count($caseMembers))) + // : + // null + // ) + // ) + ; + } + + $manager->persist($note); + } + } + + $manager->flush(); + } + + public function getDependencies(): array + { + return [ + MemberCaseFixture::class, + ReferralFixture::class, + ]; + } +} diff --git a/src/DataFixtures/ReferralFixture.php b/src/DataFixtures/ReferralFixture.php new file mode 100644 index 0000000..268fbcd --- /dev/null +++ b/src/DataFixtures/ReferralFixture.php @@ -0,0 +1,47 @@ +getRepository(MemberCase::class)->findAll(); + + foreach ($cases as $case) { + print "Adding referrals for case {$case->getCaseNumber()}".PHP_EOL; + $refCount = $gen->numberBetween(0, 2); + for ($x = 0; $x < $refCount; $x++) { + $ref = new Referral(); + $ref->setReferralId($gen->numberBetween(1000000, 9999999)) + ->setMemberCase($case) + ->setServiceCode($gen->randomElement(ReferralServiceType::class)) + ->setEndDate($gen->dateTimeBetween('+1 month', '+1 year')) + ->setHours($gen->numberBetween(1, 75)) + ; + + print "Adding referral {$ref->getReferralId()}".PHP_EOL; + + $manager->persist($ref); + } + } + + $manager->flush(); + } + + public function getDependencies(): array + { + return [ + MemberCaseFixture::class, + ]; + } +} diff --git a/src/DataFixtures/ReferralSourceFixture.php b/src/DataFixtures/ReferralSourceFixture.php new file mode 100644 index 0000000..46f6007 --- /dev/null +++ b/src/DataFixtures/ReferralSourceFixture.php @@ -0,0 +1,39 @@ +firstName()} {$gen->lastName()}"; + $username = strtolower(str_replace(' ', '.', $name)); + $src->setName($name) + ->setEmail("{$username}@dcs.in.gov") + ->setCounty((string) $gen->randomElement(County::class)->name) + ->setAgency('DCS') + ->setPhone(str_replace(['-', '+'], '', $gen->phoneNumber())) + ; + + print "Adding referral source {$src->getName()}".PHP_EOL; + + $manager->persist($src); + } + + // $product = new Product(); + // $manager->persist($product); + + $manager->flush(); + } +} diff --git a/src/DataFixtures/UserFixture.php b/src/DataFixtures/UserFixture.php new file mode 100644 index 0000000..37b96a2 --- /dev/null +++ b/src/DataFixtures/UserFixture.php @@ -0,0 +1,67 @@ +getRepository(Company::class)->findOneBy(['name' => 'Counseling Partners, LLC']); + $gen = \Faker\Factory::create(); + for ($x = 0; $x < 20; $x++) { + $user = new User(); + $name = $gen->firstName().' '.$gen->lastName(); + $username = strtolower(str_replace(' ', '.', $name)); + $cw = true; + $cm = $gen->boolean(); + $t = $gen->boolean(); + $su = $gen->boolean(); + $roles = ['ROLE_USER', 'ROLE_CASE_WORKER']; + if ($cm) { + $roles[] = 'ROLE_CASE_MANAGER'; + } + if ($t) { + $roles[] = 'ROLE_THERAPIST'; + } + if ($su) { + $roles[] = 'ROLE_ADMIN'; + } + + $user->setName($name) + ->setUsername($username) + ->setEmail($username.'@counselingpartnersllc.com') + ->setCaseManager($cm) + ->setCaseWorker($cw) + ->setTherapist($t) + ->setSu($su) + ->setRoles($roles) + ->setRateType($gen->randomElement(RateType::class)) + ->setRate($gen->numberBetween(0, 100)) + ->setLevel($gen->randomElement(CaseLevel::class)) + ->setCompany($comp) + ->setPassword($this->userPasswordHasher->hashPassword($user, 'password')) + ; + + print "Creating user $name - $username".PHP_EOL; + + $manager->persist($user); + } + + $manager->flush(); + } +}