Skip to content

Commit

Permalink
Initializing TEFCA Select Query (#2662)
Browse files Browse the repository at this point in the history
* Initializing TEFCA Select Query

* logging current status

* saving work

* hiding advanced button, updating documentation

* switching select a query go back to patient-results and adding reminder to remove button

* removing unneeded constants

* switching to rem, adding container to control width

* fixing error, formatting

* fixing width and text of explanatory comma

* fixing font sizes

* fixing scss import error

* removing duplicate customize queries

* removing duplicative uswds

* removing testing button
  • Loading branch information
robertandremitchell authored Oct 7, 2024
1 parent a55c390 commit 0bcf852
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 16 deletions.
2 changes: 1 addition & 1 deletion containers/tefca-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.1",
"private": true,
"scripts": {
"dev": "docker-compose -f docker-compose-dev.yaml up && next dev",
"dev": "docker-compose -f docker-compose-dev.yaml up -d && next dev",
"dev-win": "start docker-compose -f docker-compose-dev.yaml up && next dev",
"dev:db": "docker-compose -f docker-compose-dev.yaml up",
"dev:next": "dotenv -e ./tefca.env.local -e ./tefca.env -- next dev",
Expand Down
5 changes: 3 additions & 2 deletions containers/tefca-viewer/src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ export const stateOptions = [
export type Mode =
| "search"
| "results"
| "patient-results"
| "customize-queries";
| "customize-queries"
| "select-query"
| "patient-results";

/*Type to specify the expected components for each item in a value set that will be
displayed in the CustomizeQuery component*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.searchCallToActionButton {
height: 2.5rem;
}

.selectQueryHeaderText {
line-height: 2.0625rem;
word-wrap: break-word;
font-size: 2.5rem;
}

.selectQueryExplanationText {
padding-top: 0.75rem;
padding-bottom: 1.5rem;
line-height: 2.0625rem;
word-wrap: break-word;
font-size: 1.375rem;
width: 50.6875rem;
}

.queryRow {
display: flex;
align-items: center;
padding-bottom: 1.5rem;
}

.customizeButton {
margin-left: 1.25rem;
margin-top: 0.5rem;
}

.queryDropDown {
display: flex;
width: 20rem;
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"use client";
import React, { useState, useEffect } from "react";
import { Button, Select } from "@trussworks/react-uswds";
import { demoQueryOptions, FHIR_SERVERS, Mode } from "../../../constants";
import Backlink from "../backLink/Backlink";
import { fhirServers } from "../../../fhir-servers";
import styles from "./selectQuery.module.css";

interface SelectQueryProps {
setQueryType: (queryType: string) => void;
setHCO: (hco: string) => void;
setMode: (mode: Mode) => void;
onSubmit: () => void; // Callback when the user submits the query
goBack: () => void;
}

/**
*
* @param root0 - SelectQueryProps
* @param root0.setQueryType - Callback to update the query type
* @param root0.setHCO - Callback to update selected Health Care Organization (HCO)
* @param root0.setMode - Callback to switch mode
* @param root0.onSubmit - Callback for submit action
* @param root0.goBack - back button
* @returns - The selectQuery component.
*/
const SelectQuery: React.FC<SelectQueryProps> = ({
setQueryType,
setHCO,
setMode,
onSubmit,
goBack,
}) => {
const [selectedQuery, setSelectedQuery] = useState<string>("");
const [selectedHCO, setSelectedHCO] = useState<string>(""); // Keep this as string for HCO selection
const [showAdvanced, setShowAdvanced] = useState(false);

// When query changes, update the parent component state
useEffect(() => {
setQueryType(selectedQuery);
}, [selectedQuery, setQueryType]);

const handleQueryChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedQuery(event.target.value);
};

const handleHCOChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedHCO(event.target.value);
setHCO(event.target.value as FHIR_SERVERS); // Update parent component state
};

// Link to go to customize-queries page
const handleClick = () => {
setMode("customize-queries");
};

// Submit and go to results; if no custom query selected, add alert
const handleSubmit = () => {
if (selectedQuery) {
onSubmit();
} else {
alert("Please select a query.");
}
};

return (
<form className="content-container-smaller-width">
{/* Back button */}
<div className="text-bold">
<Backlink onClick={goBack} label={RETURN_TO_STEP_ONE_LABEL} />
</div>
<h1 className={`${styles.selectQueryHeaderText}`}>
Step 3: Select a query
</h1>
<div
className={`font-sans-md text-light ${styles.selectQueryExplanationText}`}
>
We will request all data related to your selected patient and query. By
only showing relevant data for your query, we decrease the burden on our
systems and protect patient privacy. If you would like to customize the
query response, click on the "customize query" button.
</div>
<h3 className="margin-bottom-3">Query</h3>
<div className={styles.queryRow}>
{/* Select a query drop down */}
<Select
id="querySelect"
name="query"
value={selectedQuery}
onChange={handleQueryChange}
className={`${styles.queryDropDown}`}
required
>
<option value="" disabled>
Select query
</option>
{demoQueryOptions.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</Select>
{/* Customize query button */}
<Button
type="button"
className={`usa-button--outline bg-white ${styles.customizeButton}`}
onClick={handleClick}
>
Customize query
</Button>
</div>

{/* Show Advanced options only when `showAdvanced` is true */}
{showAdvanced && (
<div>
<h3 className="margin-bottom-3">Health Care Organization (HCO)</h3>
<Select
id="fhir_server"
name="fhir_server"
value={selectedHCO} // Use selectedHCO for the selected value
onChange={handleHCOChange}
required
defaultValue=""
className={`${styles.queryDropDown}`}
>
<option value="" disabled>
Select HCO
</option>
{Object.keys(fhirServers).map((fhirServer: string) => (
<option key={fhirServer} value={fhirServer}>
{fhirServer}
</option>
))}
</Select>
</div>
)}

{/* Only show the "Advanced" button if `showAdvanced` is false */}
{!showAdvanced && (
<div>
<Button
className={`usa-button--unstyled margin-left-auto ${styles.searchCallToActionButton}`}
type="button"
onClick={() => setShowAdvanced(true)}
>
Advanced...
</Button>
</div>
)}

{/* Submit Button */}
<div className="padding-top-6">
<Button
type="button"
disabled={!selectedQuery}
className={selectedQuery ? "usa-button" : "usa-button disabled"}
onClick={handleSubmit}
>
Submit
</Button>
</div>
</form>
);
};

export default SelectQuery;
export const RETURN_TO_STEP_ONE_LABEL = "Return to Select patient";
38 changes: 26 additions & 12 deletions containers/tefca-viewer/src/app/query/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UseCaseQueryResponse, UseCaseQueryRequest } from "../query-service";
import ResultsView from "./components/ResultsView";
import PatientSearchResults from "./components/PatientSearchResults";
import SearchForm from "./components/searchForm/SearchForm";
import SelectQuery from "./components/selectQuery/selectQuery";
import {
Mode,
QueryTypeToQueryName,
Expand Down Expand Up @@ -67,18 +68,31 @@ const Query: React.FC = () => {
<SiteAlert page={mode} />
<div className="main-container">
{mode === "search" && (
<Suspense fallback="...Loading">
<SearchForm
useCase={useCase}
queryValueSets={queryValuesets}
setUseCase={setUseCase}
setMode={setMode}
setLoading={setLoading}
setUseCaseQueryResponse={setUseCaseQueryResponse}
setOriginalRequest={setOriginalRequest}
setQueryType={setQueryType}
/>
</Suspense>
<>
<Suspense fallback="...Loading">
<SearchForm
useCase={useCase}
queryValueSets={queryValuesets}
setUseCase={setUseCase}
setMode={setMode}
setLoading={setLoading}
setUseCaseQueryResponse={setUseCaseQueryResponse}
setOriginalRequest={setOriginalRequest}
setQueryType={setQueryType}
/>
</Suspense>
</>
)}

{/* Render SelectQuery component when the mode is "select-query" */}
{mode === "select-query" && (
<SelectQuery
setQueryType={setQueryType}
setHCO={() => {}}
setMode={setMode}
goBack={() => setMode("patient-results")}
onSubmit={() => setMode("results")}
/>
)}

{/* Switch the mode to view to show the results of the query */}
Expand Down
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bcf852

Please sign in to comment.