Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
MAT-7734 only display relevant attribute choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecilia Liu committed Oct 30, 2024
1 parent 68e4bd2 commit d088380
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,17 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
userEvent.click(within(typeSelect).getByText("Date"));
expect(typeOptions.length).toEqual(8);
userEvent.click(within(typeSelect).getByText("DateTime"));
const dateInput = (await screen.findByPlaceholderText(
"MM/DD/YYYY"
"MM/DD/YYYY hh:mm aa"
)) as HTMLInputElement;
const dateInput2 = await screen.findByTestId("CalendarIcon");
expect(dateInput).toBeInTheDocument();
expect(dateInput2).toBeInTheDocument();

fireEvent.change(dateInput, { target: { value: "01/01/2023" } });
expect(dateInput.value).toBe("01/01/2023");
fireEvent.change(dateInput, { target: { value: "01/01/2023 08:10 AM" } });
expect(dateInput.value).toBe("01/01/2023 08:10 AM");

const addButton = screen.getByTestId("add-attribute-button");
expect(addButton).toBeInTheDocument();
Expand Down Expand Up @@ -334,7 +334,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
fireEvent.click(within(typeSelect).getByText("Ratio"));
});

Expand Down Expand Up @@ -367,7 +367,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
userEvent.click(within(typeSelect).getByText("DateTime"));
const dateTimeInput = (await screen.findByPlaceholderText(
"MM/DD/YYYY hh:mm aa"
Expand Down Expand Up @@ -444,16 +444,16 @@ describe("AttributeSection", () => {
userEvent.click(typeSelectBtn);
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
userEvent.click(within(typeSelect).getByText("Date"));
userEvent.click(within(typeSelect).getByText("DateTime"));
const dateInput = (await screen.findByPlaceholderText(
"MM/DD/YYYY"
"MM/DD/YYYY hh:mm aa"
)) as HTMLInputElement;
const dateInput2 = await screen.findByTestId("CalendarIcon");
expect(dateInput).toBeInTheDocument();
expect(dateInput2).toBeInTheDocument();

fireEvent.change(dateInput, { target: { value: "01/01/2023" } });
expect(dateInput.value).toBe("01/01/2023");
fireEvent.change(dateInput, { target: { value: "01/01/2023 08:10 AM" } });
expect(dateInput.value).toBe("01/01/2023 08:10 AM");

const addButton = screen.getByTestId("add-attribute-button");
expect(addButton).toBeInTheDocument();
Expand Down Expand Up @@ -489,7 +489,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
userEvent.click(within(typeSelect).getByText("Integer"));
const integerField = (await screen.getByTestId(
"integer-input-field-Integer"
Expand Down Expand Up @@ -529,7 +529,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
fireEvent.click(within(typeSelect).getByText("Decimal"));
});

Expand Down Expand Up @@ -561,7 +561,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
fireEvent.click(within(typeSelect).getByText("DateTime"));
});

Expand Down Expand Up @@ -593,7 +593,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
fireEvent.click(within(typeSelect).getByText("Time"));

const timeInput = await screen.findByLabelText("Time");
Expand Down Expand Up @@ -636,7 +636,7 @@ describe("AttributeSection", () => {
const typeSelect = await screen.findByRole("listbox");
expect(typeSelect).toBeInTheDocument();
const typeOptions = within(typeSelect).getAllByRole("option");
expect(typeOptions.length).toEqual(9);
expect(typeOptions.length).toEqual(8);
fireEvent.click(within(typeSelect).getByText("Quantity"));
const addButton = screen.getByTestId("add-attribute-button");
expect(addButton).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ const AttributeSection = ({
}
// all other attribute cases
else {
const nextTypes = [...determineAttributeTypeList(attr.path, attr.info)];
const nextTypes = [
...determineAttributeTypeList(
attr.path,
attr.info,
selectedDataElement._type
),
];
setTypes(nextTypes);
if (nextTypes?.length === 1) {
formik.setFieldValue("type", nextTypes[0]);
Expand Down
107 changes: 107 additions & 0 deletions src/util/QdmAttributeHelper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
stringifyValue,
getDisplayFromId,
generateAttributesToDisplay,
determineAttributeTypeList,
} from "./QdmAttributeHelpers";
import cqmModels, { CQL } from "cqm-models";

Expand Down Expand Up @@ -498,3 +499,109 @@ describe("generateAttributesToDisplay", () => {
);
});
});

describe("determineAttributeTypeList", () => {
const info_result = {
path: "result",
instance: "Any",
validators: [],
getters: [],
setters: [],
_presplitPath: ["result"],
options: {},
_index: null,
};

describe("info.instance is 'Any'", () => {
test("QDM::CareGoal path = 'targetOutcome' ", () => {
const info = {
path: "targetOutcome",
instance: "Any",
validators: [],
getters: [],
setters: [],
_presplitPath: ["targetOutcome"],
options: {},
_index: null,
};
const result = determineAttributeTypeList(
"targetOutcome",
info,
"QDM::CareGoal"
);
expect(result.length).toBe(5);
});

test("QDM::LaboratoryTestPerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::LaboratoryTestPerformed"
);
expect(result.length).toBe(5);
});

test("QDM::AssessmentPerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::AssessmentPerformed"
);
expect(result.length).toBe(7);
});

test("QDM::DiagnosticStudyPerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::DiagnosticStudyPerformed"
);
expect(result.length).toBe(5);
});

test("QDM::Component path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::Component"
);
expect(result.length).toBe(7);
});

test("QDM::ProcedurePerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::ProcedurePerformed"
);
expect(result.length).toBe(5);
});

test("QDM::InterventionPerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::InterventionPerformed"
);
expect(result.length).toBe(5);
});

test("QDM::PhysicalExamPerformed path = 'result' ", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::PhysicalExamPerformed"
);
expect(result.length).toBe(8);
});

test("default", () => {
const result = determineAttributeTypeList(
"result",
info_result,
"QDM::default"
);
expect(result.length).toBe(5);
});
});
});
53 changes: 40 additions & 13 deletions src/util/QdmAttributeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,44 @@ export const ENTITY_TYPES = [
"Location",
];

const BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE = [
"Integer",
"Decimal",
"Code",
"Quantity",
"Ratio",
];

const getAttributeTypesForAnyInstance = (name: string) => {
switch (name) {
case "QDM::CareGoal":
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
case "QDM::LaboratoryTestPerformed":
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
case "QDM::AssessmentPerformed":
return [...BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE, "DateTime", "Time"];
case "QDM::DiagnosticStudyPerformed":
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
case "QDM::Component":
return [...BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE, "DateTime", "Time"];
case "QDM::ProcedurePerformed":
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
case "QDM::InterventionPerformed":
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
case "QDM::PhysicalExamPerformed":
return [
...BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE,
"Date",
"DateTime",
"Time",
];
default:
return BASIC_ATTRIBUTE_TYPES_FOR_ANY_INSTANCE;
}
};

// This code came over from Bonnie
export const determineAttributeTypeList = (path, info) => {
export const determineAttributeTypeList = (path, info, _type) => {
// if is array type we need to find out what type it should be
if (info.instance == "Array")
if (info.$isMongooseDocumentArray)
Expand All @@ -62,18 +98,9 @@ export const determineAttributeTypeList = (path, info) => {
else return ["???"];
// TODO: Handle situation of unknown type better.
// If this is an any type, there will be more options than one.
else if (info.instance == "Any")
// TODO: Filter these more if possible
return [
"Code",
"Quantity",
"Ratio",
"Integer",
"Decimal",
"Date",
"DateTime",
"Time",
];
else if (info.instance == "Any") {
return getAttributeTypesForAnyInstance(_type);
}
// It this is an AnyEntity type
else if (info.instance == "AnyEntity") return ENTITY_TYPES;
// If it is an interval, it may be one of DateTime or one of Quantity
Expand Down

0 comments on commit d088380

Please sign in to comment.