department-of-veterans-affairs / va.gov-cms

Editor-centered management for Veteran-centered content.
https://prod.cms.va.gov
GNU General Public License v2.0
99 stars 69 forks source link

Cross-product: Remove already created services from the options when adding a new service #17674

Open omahane opened 7 months ago

omahane commented 7 months ago

Glossary for new people

Problem Statement

On the Create Service content form, Editors first select their facility, then select a Service name from a dropdown, for the type of Service they would like to create for their facility. (Services map to VA Service taxonomy terms for the Facility type.)

Currently, the "Service name" dropdown displays all Services for the facility type, regardless of whether a Facility Service for that Service+Facility combination has already been created. This means an editor may select a Facility, Service, populate the entire Create Service form (which is time consuming), and then receive a validation error on save saying that the given Facility Service already exists & cannot be saved.

**Example screenshot** ![Screenshot 2024-08-16 at 1 33 16 PM](https://github.com/user-attachments/assets/e694776e-2f47-465b-bcaa-701c0450c76a)

We should only show options in the "Service name" dropdown for Services that do not exist as a Facility Service for the given Facility.

Question

Do we need to handle this for VAMC System Health Service as well? That one acts differently, and you don't select a Facillity, you select a VAMC System section. Should it have its own ticket, or does it make sense to roll up into this ticket?

User story

As an editor, when creating a new Facility Service, I want to choose from Services that are not already in use on a Facility Service for my Facility.

Implementation steps

Example

Using a hook in the IEF (This is for reference only. Remove before closing ticket.)

As of 2024-03-28 (commit 4e254ffd1492344e12d422e8577609772bdbef95), the inline entity form (IEF) on Vet Centers reduces the options on services by the following code in va_gov_vet_center/va_gov_vet_center.module:

 /**
   * Implements hook_inline_entity_form_alter().
   */
  function va_gov_vet_center_inline_entity_form_entity_form_alter(&$entity_form, FormStateInterface $form_state) {
    // Disable service name field for existing Vet Center Facility Services.
    $node_id = $entity_form['#entity']->id();
    if ($entity_form['#bundle'] === 'vet_center_facility_health_servi' && isset($node_id)) {
      $entity_form['field_service_name_and_descripti']['#disabled'] = TRUE;
    }
  }

We need to be able to do the same when the list of possible services is being shown on the form regardless of IEF. Ideally, this would happen for VAMC, Vet Center and VBA.

Using a PHP service

As of 2024-07-24, there's a hasService function in va_gov_vet_center/src/Service/RequiredServices.php. This is the sort of thing we would like to know for any facility type, again, ideally.

If so, we'd need to create a new service that accounts for the differences in the facility services.

Acceptance Criteria

davidmpickett commented 7 months ago

@omahane This is one that we weren't able to get to in refinement this week but is on the list of potential tickets for next sprint. Can you take a look and see if async refinement if feasible?

omahane commented 6 months ago

The size of this issue depends on the following:

davidmpickett commented 5 months ago

This doesn't TRULY block #18003. The Allow Only One functionality works correctly for Vet Center Editors when they try to add a duplicate service via Add Content.

screencapture-staging-cms-va-gov-node-add-vet-center-facility-health-servi-2024-05-24-15_47_52

However, in order to replicate the existing functionality of the IEF, this has been included in scope, so makes sense to do before the final step.

davidmpickett commented 5 months ago

Removed this as a blocker to #18003 as this is a nice to have and not critical to achieving the functionality

davidmpickett commented 5 months ago

@omahane estimate on LOE here?

omahane commented 3 months ago

I would like to refine this before estimating. I put that we should consider all facility services when doing this, but we can also just do Vet Center. The effort required would differ.

Agile6MSkinner commented 2 months ago

@jilladams will split out VAMC health services into a separate ticket

I will change epics.