diff --git a/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.test.tsx b/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.test.tsx index eaea0d2ef..2e8d7cdb5 100644 --- a/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.test.tsx +++ b/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.test.tsx @@ -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(); @@ -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")); }); @@ -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" @@ -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(); @@ -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" @@ -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")); }); @@ -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")); }); @@ -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"); @@ -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(); diff --git a/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx b/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx index 1dd5fa5b2..4980eef68 100644 --- a/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx +++ b/src/components/editTestCase/qdm/LeftPanel/ElementsTab/Elements/DataElementsCard/attributes/AttributeSection.tsx @@ -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]); diff --git a/src/util/QdmAttributeHelper.test.tsx b/src/util/QdmAttributeHelper.test.tsx index ce267bd16..4740cb749 100644 --- a/src/util/QdmAttributeHelper.test.tsx +++ b/src/util/QdmAttributeHelper.test.tsx @@ -2,6 +2,7 @@ import { stringifyValue, getDisplayFromId, generateAttributesToDisplay, + determineAttributeTypeList, } from "./QdmAttributeHelpers"; import cqmModels, { CQL } from "cqm-models"; @@ -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); + }); + }); +}); diff --git a/src/util/QdmAttributeHelpers.ts b/src/util/QdmAttributeHelpers.ts index 69ceccc6e..01f4ad8db 100644 --- a/src/util/QdmAttributeHelpers.ts +++ b/src/util/QdmAttributeHelpers.ts @@ -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) @@ -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