Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/table' into andreasn/rem…
Browse files Browse the repository at this point in the history
…ove-form
  • Loading branch information
rinrub committed Feb 15, 2024
2 parents b7379a7 + 6dcfa16 commit 792ed90
Show file tree
Hide file tree
Showing 38 changed files with 3,085 additions and 250,702 deletions.
28 changes: 27 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
## 14.0.1
## 14.1.0-beta02

---

- Bugfix: fix calculated scoring fields being showed in tables, also added a linebreak after each table

## 14.1.0-beta01

---

- fixed the sorting for tables and also changed logic for standardtable

## 14.0.7

---

- Bugfix: Attachment Validation based on props max value, questionnaire item max attachment size rules and refero constant

## 14.0.5

---

- fixed slidercomponent not showing children

## 14.0.1-beta01

- removing singlequoutes from units on quantity in table
- change the date output to norwegian format

---

## 14.0.0-beta02

- Added table feature to new major version

---

## 14.0.0-beta01

- Added table feature to new major version
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helsenorge/refero",
"version": "14.0.1",
"version": "14.1.0-beta02",
"engines": {
"node": "^18.0.0",
"npm": ">=9.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/components/formcomponents/date/date.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';

import { QuestionnaireItem, QuestionnaireResponseItemAnswer, QuestionnaireResponseItem, Questionnaire } from 'fhir/r4';
import moment, { Moment } from 'moment';
import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';

import { QuestionnaireItem, QuestionnaireResponseItemAnswer, QuestionnaireResponseItem, Questionnaire } from '../../../types/fhir';
import { Resources } from '../../../types/resources';

import { LanguageLocales } from '@helsenorge/core-utils/constants/languages';
Expand Down
5 changes: 3 additions & 2 deletions src/components/formcomponents/group/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Questionnaire, QuestionnaireItem } from '../../../types/fhir';
import { Questionnaire, QuestionnaireItem } from 'fhir/r4';

import { Resources } from '../../../types/resources';

import { RenderContextType } from '../../../constants/renderContextType';
import { getText, renderPrefix } from '../../../util';
import { getGroupItemControl } from '../../../util/group-item-control';
import { Path } from '../../../util/refero-core';
import { RenderContext } from '../../../util/renderContext';
import { Resources } from '../../../types/resources';

export const getColumns = (item: QuestionnaireItem): Array<string> => {
const seenColumns = {};
Expand Down
14 changes: 8 additions & 6 deletions src/components/formcomponents/table/TableContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react';

import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';

import {
Coding,
Questionnaire,
Expand All @@ -11,7 +8,9 @@ import {
QuestionnaireResponseItem,
QuestionnaireResponseItemAnswer,
Resource,
} from '../../../types/fhir';
} from 'fhir/r4';
import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';

import LanguageLocales from '@helsenorge/core-utils/constants/languages';

Expand Down Expand Up @@ -75,20 +74,23 @@ const TableContainer = ({
<>
<h3>{headline}</h3>
<TableHn1 items={items} questionnaireResponse={questionnaireResponse} />
<br />
</>
);
case TableCodes.tableHn2:
return (
<>
<h3>{headline}</h3>
<TableHn2 items={items} tableCodesCoding={tableCodesCoding} questionnaireResponse={questionnaireResponse} />
<br />
</>
);
case TableCodes.gtable:
return (
<>
<h3>{headline}</h3>
<GTable items={items} questionnaireResponse={questionnaireResponse} tableCodesCoding={tableCodesCoding} />
<br />
</>
);
case TableCodes.table:
Expand All @@ -101,10 +103,11 @@ const TableContainer = ({
resource={resource}
tableCodesCoding={tableCodesCoding}
/>
<br />
</>
);
default:
return <>{'Nothing found'}</>;
return <></>;
}
}
};
Expand All @@ -113,7 +116,6 @@ const mapStateToProps = (state: GlobalState, props: Props): EnhancedProps => {
const group = props.item;
const tableType = getCodingTextTableValues(group)[0];
const resource = getFormDefinition(state)?.Content?.contained;

return {
headline: group.text ?? '',
tableCodesCoding: group.code ?? [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import {
QuestionnaireResponseItemAnswer,
QuestionnaireItemEnableWhen,
QuestionnaireItemEnableBehaviorCodes,
QuestionnaireItem,
QuestionnaireResponse,
} from '../../../../../types/fhir';
import { QuestionnaireResponseItemAnswer, QuestionnaireItemEnableWhen, QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4';
import ItemType from '../../../../../constants/itemType';
import { extractValuesFromAnswer, getPrimitiveValueFromItemType, getQuestionnaireResponseItemAnswer, isConditionEnabled } from '../utils';
import * as questionnaireFunctions from '../utils';

import * as fhirUtils from '../../../../../util/refero-core';
import { QuestionnaireItemEnableBehaviorCodes } from '../../../../../types/fhirEnums';

jest.mock('../../../../../util/refero-core');

Expand Down
1 change: 1 addition & 0 deletions src/components/formcomponents/table/tables/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const DATEFORMATS = {
DATE: 'DD.MM.YYYY',
DATETIME: 'DD MM YYYY HH:mm',
TIME: 'HH:mm',
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';

import { Coding, QuestionnaireItem, QuestionnaireResponse } from '../../../../../types/fhir';
import { Coding, QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4';

import { TableBody, Table as HnTable, TableRow, TableCell, SortDirection } from '@helsenorge/designsystem-react/components/Table';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ describe('gtable-utils-spec', () => {
];
const columns = columnsForRowIndex(answerItems, 0);
expect(columns).toEqual([
{ id: 'default-question-linkId', index: 0, value: 'Answer 1' },
{ id: 'default-question-linkId', index: 1, value: 'Another Answer 1' },
{ id: 'default-question-linkId', index: 0, value: 'Answer 1', type: ItemType.TEXT },
{ id: 'default-question-linkId', index: 1, value: 'Another Answer 1', type: ItemType.TEXT },
]);
});

Expand All @@ -137,8 +137,8 @@ describe('gtable-utils-spec', () => {
];
const columns = columnsForRowIndex(answerItems, 1);
expect(columns).toEqual([
{ id: 'default-question-linkId', index: 0, value: '' },
{ id: 'default-question-linkId', index: 1, value: '' },
{ id: 'default-question-linkId', index: 0, value: '', type: ItemType.TEXT },
{ id: 'default-question-linkId', index: 1, value: '', type: ItemType.TEXT },
]);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IItemType } from '../../../../../constants/itemType';

export interface IGTable {
id: string;
headerRow: IGTableHeaderItem[];
Expand All @@ -17,5 +19,6 @@ export interface IGTableRow {
export interface IGTableColumn {
id: string;
index: number;
type?: IItemType;
value: string;
}
20 changes: 14 additions & 6 deletions src/components/formcomponents/table/tables/gtable/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Coding, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from 'fhir/r4';
import * as uuid from 'uuid';

import { Coding, QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from '../../../../../types/fhir';

import { SortDirection } from '@helsenorge/designsystem-react/components/Table';

import { IGTable, IGTableColumn, IGTableHeaderItem, IGTableRow } from './interface';
import codeSystems from '../../../../../constants/codingsystems';
import { QuestionnaireItemWithAnswers } from '../interface';
import { getCodeFromCodingSystem, getEnabledQuestionnaireItemsWithAnswers, getPrimitiveValueFromItemType } from '../utils';
import { getCodeFromCodingSystem, getEnabledQuestionnaireItemsWithAnswers, getPrimitiveValueFromItemType, sortByItemType } from '../utils';

export const getNumberOfRowsGTable = (items: QuestionnaireResponseItem[]): number => {
if (items.length === 0) {
Expand All @@ -31,16 +30,19 @@ export const getValueFromAnswer = (rowIdx: number, item?: QuestionnaireItemWithA
export const columnsForRowIndex = (answerItems: QuestionnaireItemWithAnswers[], rowIdx: number): IGTableColumn[] => {
return Array.from({ length: answerItems.length }, (_, colIdx) => {
const item = answerItems[colIdx];

if (!item) {
return {
id: `empty-${rowIdx}-${colIdx}`,
index: colIdx,
type: undefined,
value: '',
};
}
return {
id: item.linkId,
index: colIdx,
type: item.type,
value: getValueFromAnswer(rowIdx, item),
};
});
Expand Down Expand Up @@ -96,10 +98,16 @@ export const sortTableRows = (table: IGTable, columnIndex: number, sortOrder: So
headerRow: table.headerRow,
id: table.id,
rows: table.rows.sort((a, b) => {
const aValue = a?.columns.length > columnIndex ? a?.columns[columnIndex]?.value || '' : '';
const bValue = b?.columns.length > columnIndex ? b?.columns[columnIndex]?.value || '' : '';
if (a.columns.length <= columnIndex || b.columns.length <= columnIndex) {
return 0;
}

const aColumn = a.columns[columnIndex];
const bColumn = b.columns[columnIndex];
const aValue = aColumn.value || '';
const bValue = bColumn.value || '';

return sortOrder === SortDirection.asc ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
return sortByItemType(aValue, bValue, sortOrder, aColumn.type);
}),
};
return sortedTable;
Expand Down
2 changes: 1 addition & 1 deletion src/components/formcomponents/table/tables/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QuestionnaireItem, QuestionnaireResponseItem } from '../../../../types/fhir';
import { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';

export type QuestionnaireItemWithAnswers = QuestionnaireItem & {
answer?: QuestionnaireResponseItem['answer'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { QuestionnaireItem, QuestionnaireResponse } from '../../../../../types/fhir';
import { QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4';

import { Table as HnTable, TableBody, TableCell, TableRow } from '@helsenorge/designsystem-react/components/Table';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from '../../../../../types/fhir';
import { QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem } from 'fhir/r4';

import { ITableH1, ITableH1Column, ITableH1Row, TABLE_HN1_TABLE_TYPES } from './interface';
import ItemType from '../../../../../constants/itemType';
Expand Down Expand Up @@ -28,7 +28,6 @@ export const getTableHN1bodyObject = (

export const createColumnsFromAnswers = (item: QuestionnaireResponseItem): ITableH1Column[] => {
const combinedAnswer = transformAnswersToListOfStrings((item as QuestionnaireItem).type, item.answer || []).join(', ');

const columns: ITableH1Column[] = [
{
id: `${item.linkId}-question`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Coding } from '../../../../../types/fhir';
import { Coding } from 'fhir/r4';

import { HeaderCategory, SortDirection, TableHead, TableHeadCell, TableRow } from '@helsenorge/designsystem-react/components/Table';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';

import { Coding, QuestionnaireItem, QuestionnaireResponse } from '../../../../../types/fhir';
import { Coding, QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4';

import { Table as HnTable, SortDirection, TableBody, TableCell, TableRow } from '@helsenorge/designsystem-react/components/Table';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IItemType } from '../../../../../constants/itemType';

export interface ITableH2Column {
id: string;
text: string;
type?: IItemType;
index: number;
}

Expand Down
9 changes: 6 additions & 3 deletions src/components/formcomponents/table/tables/table-hn2/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Coding, QuestionnaireItem, QuestionnaireResponse } from '../../../../../types/fhir';
import { Coding, QuestionnaireItem, QuestionnaireResponse } from 'fhir/r4';

import { SortDirection } from '@helsenorge/designsystem-react/components/Table';

Expand All @@ -12,6 +12,7 @@ import {
findIndexByCode,
getCodeFromCodingSystem,
getEnabledQuestionnaireItemsWithAnswers,
sortByItemType,
transformAnswersToListOfStrings,
} from '../utils';

Expand Down Expand Up @@ -56,6 +57,7 @@ export const createColumnsForRow = (
return {
id: item.linkId,
index: findIndexByCode(item, codeSystems.TableColumn),
type: item.type,
text: getValueFromItemsToShow(item, itemsToShow),
};
});
Expand Down Expand Up @@ -101,8 +103,9 @@ export const sortTableRows = (table: ITableH2Row[], columnIndex: number, sortOrd
return table.sort((a, b) => {
const aValue = a?.columns.length > columnIndex ? a?.columns[columnIndex]?.text || '' : '';
const bValue = b?.columns.length > columnIndex ? b?.columns[columnIndex]?.text || '' : '';

return sortOrder === SortDirection.asc ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
const aColumn = a.columns[columnIndex];
const type = aColumn?.type;
return sortByItemType(aValue, bValue, sortOrder, type);
});
};
export const findCodeForColumnToSortBy = (coding: Coding[]): Coding | undefined => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';

import { Coding, QuestionnaireItem, QuestionnaireResponse, Resource } from '../../../../../types/fhir';
import { Coding, QuestionnaireItem, QuestionnaireResponse, Resource } from 'fhir/r4';

import { Table as HnTable, ModeType, SortDirection, TableBody, TableCell, TableRow } from '@helsenorge/designsystem-react/components/Table';

Expand All @@ -18,6 +18,7 @@ interface Props {

export const StandardTable = ({ items, questionnaireResponse, resource, tableCodesCoding }: Props): JSX.Element => {
const displayToSortBy = getDisplayToSortBy(tableCodesCoding);

const [sortDir, setSortDir] = useState<SortDirection | undefined>(transformCodingToSortDirection(tableCodesCoding));
const [table, setTable] = useState<IStandardTable>(
getStandardTableObject(items, questionnaireResponse, resource, sortDir, displayToSortBy)
Expand Down
Loading

0 comments on commit 792ed90

Please sign in to comment.