From f59099695b041569acd91193130bfd22a8b707a8 Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Fri, 16 Feb 2024 08:00:56 -0600 Subject: [PATCH] VACMS-17114: Refactors office visits logic to be more ... logical --- .../src/Service/PostFacilityServiceVamc.php | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/docroot/modules/custom/va_gov_post_api/src/Service/PostFacilityServiceVamc.php b/docroot/modules/custom/va_gov_post_api/src/Service/PostFacilityServiceVamc.php index 6fb9051ddc..6989f29f28 100644 --- a/docroot/modules/custom/va_gov_post_api/src/Service/PostFacilityServiceVamc.php +++ b/docroot/modules/custom/va_gov_post_api/src/Service/PostFacilityServiceVamc.php @@ -346,6 +346,40 @@ protected function getOnlineScheduling(string $online_scheduling_avail) { return $map[$online_scheduling_avail]; } + /** + * Finds the best way to visit, among options chosen. + * + * @param string $office_visits + * The machine value of the Office visits option. + */ + protected function chooseBestOfficeVisitOption(string $office_visits) { + switch ($office_visits) { + + case 'yes_with_or_without_appointment': + $text = $office_visits; + break; + + case 'yes_first_come_first_served_basis': + case 'yes_appointment_only': + $text = ($this->officeVisits === 'yes_with_or_without_appointment') + ? $this->officeVisits + : $office_visits; + break; + + case 'no': + $text = ($this->officeVisits === 'yes_with_or_without_appointment' + || $this->officeVisits === 'yes_first_come_first_served_basis' + || $this->officeVisits === 'yes_appointment_only') + ? $this->officeVisits + : $office_visits; + break; + + default: + $text = $office_visits; + } + return $this->stringNullify($text); + } + /** * Builds the array of service locations. * @@ -380,10 +414,7 @@ protected function getServiceLocations(): array { // Set the office visits policy to non-default for the service. $office_visits = $location->get('field_office_visits')->value; - $this->officeVisits = (($this->officeVisits !== "yes_with_or_without_appointment") - || !isset($this->officeVisits)) - ? $this->stringNullify($office_visits) - : $this->officeVisits; + $this->officeVisits = $this->chooseBestOfficeVisitOption($office_visits); // Set the appointment text values to the non-default for the service. $field_appt_intro_text_type = $location->get('field_appt_intro_text_type')->value;