Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lab value display #2931

Merged
merged 16 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion containers/ecr-viewer/seed-scripts/create-seed-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _process_files(args):
:return: A list of fhir bundles
"""
print("Converting files...")
subfolders = ["LA"]
subfolders = ["ME"]
mcmcgrath13 marked this conversation as resolved.
Show resolved Hide resolved

# Holds all of the rquests we are going to make
requests = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ exports[`Utils safeParse should remove comments 1`] = `
</ul>
</DocumentFragment>
`;

exports[`Utils safeParse should remove empty nodes 1`] = `
<DocumentFragment>
<br />
<span>
hiya
</span>
</DocumentFragment>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,6 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Contact
</div>
<div
class="grid-col maxw7 text-pre-line p-list"
>


</div>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -465,7 +445,7 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
Contact
</div>
<div
class="grid-col maxw7 text-pre-line text-italic text-base"
class="grid-col maxw7 text-pre-line p-list text-italic text-base"
>
No data
</div>
Expand Down Expand Up @@ -546,25 +526,6 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Occupation
</div>
<div
class="grid-col maxw7 text-pre-line p-list text-italic text-base"
>
No data
</div>
</div>
<div
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@ exports[`LabInfo should match snapshot test 1`] = `
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Lab Performing Name
</div>
<div
class="grid-col maxw7 text-pre-line p-list"
>
PROVIDENCE ST. JOSEPH MEDICAL CENTER LABORATORY (CLIA 05D0672675)
</div>
</div>
<div
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
Expand Down Expand Up @@ -1327,7 +1308,6 @@ NASHVILLE, TN
<p>
VUMC CERNER LAB - 04/18/2022 2:57 PM CDT
</p>

<p>
MICROARRAY REPORT NARRATIVE
</p>
Expand Down
8 changes: 8 additions & 0 deletions containers/ecr-viewer/src/app/tests/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ describe("Utils", () => {
expect(actual).toStrictEqual(jsx);
});

it("should remove empty nodes", () => {
const str = `<p></p><br/><span>hiya</span>`;
const parsed = safeParse(str);
const { asFragment } = render(parsed);
expect(asFragment()).toMatchSnapshot();
cleanup();
});

it("should map xml-y HTML", () => {
const str = `<paragraph>hi there</paragraph><content ID="abc">I'm content</content><list><item>one</item><item>two</item></list>`;
const parsed = safeParse(str);
Expand Down
32 changes: 26 additions & 6 deletions containers/ecr-viewer/src/app/view-data/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ export const safeParse = (val: string): RenderableNode => {
* @returns - One string or element.
*/
export const arrayToElement = (vals: RenderableNode[]) => {
// Filter out empty nodes.
const trimmed = vals.map(trimEmptyElements).filter(Boolean);

// An empty array is returned for an empty input
if (vals.length === 0) {
if (trimmed.length === 0) {
return "";
} else if (vals.length === 1) {
} else if (trimmed.length === 1) {
return vals[0];
}

// Wrap the items in a fragment and make sure they all have keys.
// It reduces the cases to handle elsewhere in the logic and avoids
// dupblicate key warnings.
const res = (
// duplicate key warnings.
return (
<>
{vals.map((item, ind) => {
{trimmed.map((item, ind) => {
// Make sure items always have a key
const key = `el-${ind}`;
return typeof item !== "object" ? (
Expand All @@ -111,5 +114,22 @@ export const arrayToElement = (vals: RenderableNode[]) => {
})}
</>
);
return res;
};

/**
* Return "" if an element is empty, otherwise return the element.
* <br /> are returned as is as it shouldn't have content in it.
* @param val - A RenderableNode.
* @returns - A string or element.
*/
const trimEmptyElements = (val: RenderableNode) => {
if (typeof val === "string") {
return val.trim();
}

// allowed to be empty - self-closing
if (val.type == "br") return val;

// got children? go ahead
return val.props.children ? val : "";
};
Loading