Skip to content

Commit

Permalink
fix ordering provider address suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
emyl3 committed Jun 22, 2023
1 parent fc47c3c commit 791727f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const OrderingProvider: React.FC<Props> = ({
options={stateCodes.map((c) => ({ label: c, value: c }))}
defaultSelect
className="usa-input--medium"
data-testid="op-state-dropdown"
/>
</div>
</fieldset>
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/app/Settings/Facility/FacilityForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,45 @@ describe("FacilityForm", () => {

expect(saveFacility).toBeCalledTimes(0);
});

it("suggests address validation for ordering provider when address provided", async () => {
render(
<MemoryRouter>
<FacilityForm
facility={validFacility}
deviceTypes={devices}
saveFacility={saveFacility}
/>
</MemoryRouter>
);

const opStreetInput = screen.getAllByLabelText("Street address 1", {
exact: false,
})[1];
await act(
async () => await userEvent.type(opStreetInput, "432 Green Street")
);
const opCityInput = screen.getAllByLabelText("City", {
exact: false,
})[1];
await act(async () => await userEvent.type(opCityInput, "Englewood"));
const stateDropdownElement = screen.getByTestId("op-state-dropdown");
fireEvent.change(stateDropdownElement, { target: { value: "NJ" } });
const opZIPInput = screen.getAllByLabelText("ZIP code", {
exact: false,
})[1];
await act(async () => await userEvent.type(opZIPInput, "07026"));
await clickSaveButton();
await screen.findByText("Address validation");
expect(
screen.getByText(
"Please select an option for ordering provider address to continue:"
)
).toBeInTheDocument();
expect(screen.getByText("432 Green Street")).toBeInTheDocument();
expect(screen.getByText("Englewood, NJ 07026")).toBeInTheDocument();
expect(suggestionIsCloseEnoughSpy).toBeCalledTimes(2);
});
});

describe("when validation is not required for state", () => {
Expand Down
37 changes: 22 additions & 15 deletions frontend/src/app/Settings/Facility/FacilityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ const FacilityForm: React.FC<Props> = (props) => {
};
};

const getOrderingProviderAddress = (
f: Nullable<Facility>
): AddressWithMetaData | undefined => {
if (!f.orderingProvider) {
return undefined;
}

const getOrderingProviderAddress = (f: {
firstName: string | null;
middleName: string | null;
lastName: string | null;
suffix: string | null;
NPI: string | null;
street: string | null;
streetTwo: string | null;
city: string | null;
state: string;
zipCode: string | null;
phone: string | null;
}): AddressWithMetaData | undefined => {
const addressFields: (keyof Facility["orderingProvider"])[] = [
"street",
"streetTwo",
Expand All @@ -167,16 +173,16 @@ const FacilityForm: React.FC<Props> = (props) => {
"zipCode",
];

if (addressFields.every((el) => !f.orderingProvider?.[el]?.trim())) {
if (addressFields.every((el) => !f[el]?.trim())) {
return undefined;
}

return {
street: f.orderingProvider.street || "",
streetTwo: f.orderingProvider.streetTwo,
city: f.orderingProvider.city,
state: f.orderingProvider.state || "",
zipCode: f.orderingProvider.zipCode || "",
street: f.street || "",
streetTwo: f.streetTwo,
city: f.city,
state: f.state || "",
zipCode: f.zipCode || "",
county: "",
};
};
Expand Down Expand Up @@ -208,8 +214,9 @@ const FacilityForm: React.FC<Props> = (props) => {
);
let providerCloseEnough = true;
let suggestedOrderingProviderAddress: AddressWithMetaData | undefined;
const originalOrderingProviderAddress =
getOrderingProviderAddress(facility);
const originalOrderingProviderAddress = getOrderingProviderAddress(
updatedValues.orderingProvider
);
if (originalOrderingProviderAddress) {
suggestedOrderingProviderAddress = await getBestSuggestion(
originalOrderingProviderAddress
Expand Down

0 comments on commit 791727f

Please sign in to comment.