diff --git a/CHANGES b/CHANGES index 50e5f93f..aaf87115 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +## 15.0.9 + +--- + +- Bugfix: + - fix a bug with sorting strings that looks like numbers. now trying to parse all stings as numbers and if they are numbers, sort as numbers + ## 15.0.8 --- diff --git a/package-lock.json b/package-lock.json index 77bd40c1..e58bc217 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@helsenorge/refero", - "version": "15.0.8", + "version": "15.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@helsenorge/refero", - "version": "15.0.8", + "version": "15.0.9", "license": "MIT", "dependencies": { "@types/react-collapse": "^5.0.1", diff --git a/package.json b/package.json index 1866b1d3..bbc34e85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@helsenorge/refero", - "version": "15.0.8", + "version": "15.0.9", "engines": { "node": "^18.0.0", "npm": ">=9.0.0" diff --git a/src/components/formcomponents/table/tables/utils.ts b/src/components/formcomponents/table/tables/utils.ts index c803fe82..ae1b4b4c 100644 --- a/src/components/formcomponents/table/tables/utils.ts +++ b/src/components/formcomponents/table/tables/utils.ts @@ -131,7 +131,7 @@ type ItemTypeToDataTypeMap = { }; export const getPrimitiveValueFromItemType = < ItemType extends keyof ItemTypeToDataTypeMap, - DisplayType extends ItemTypeToDataTypeMap[ItemType] + DisplayType extends ItemTypeToDataTypeMap[ItemType], >( type: IItemType, res: QuestionnaireResponseItemAnswer, @@ -165,7 +165,7 @@ export const getPrimitiveValueFromItemType = < } }; export function getQuestionnaireResponseItemAnswer( - type: typeof ItemType[keyof typeof ItemType], + type: (typeof ItemType)[keyof typeof ItemType], result: never[] ): QuestionnaireResponseItemAnswer | Array { switch (type) { @@ -235,7 +235,7 @@ export const getValueIfDataReceiver = ( }); } - return getQuestionnaireResponseItemAnswer(item.type as Exclude, result); + return getQuestionnaireResponseItemAnswer(item.type as Exclude<(typeof ItemType)[keyof typeof ItemType], 'url'>, result); } return undefined; }; @@ -243,7 +243,7 @@ export const getValueIfDataReceiver = ( export const convertValuesToStrings = (values: Array): string[] => values.map(value => value.toString()); export const extractValuesFromAnswer = ( - type: typeof ItemType[keyof typeof ItemType], + type: (typeof ItemType)[keyof typeof ItemType], questionnaireAnswer?: QuestionnaireResponseItemAnswer | QuestionnaireResponseItemAnswer[] ): Array => { if (questionnaireAnswer === undefined) { @@ -255,7 +255,7 @@ export const extractValuesFromAnswer = ( }; export const transformAnswersToListOfStrings = ( - type: typeof ItemType[keyof typeof ItemType], + type: (typeof ItemType)[keyof typeof ItemType], answer?: QuestionnaireResponseItemAnswer | QuestionnaireResponseItemAnswer[] ): string[] => { const value = extractValuesFromAnswer(type, answer); @@ -397,10 +397,28 @@ export const sortByItemType = (aValue: string, bValue: string, sortOrder: SortDi case ItemType.STRING: case ItemType.TEXT: case ItemType.OPENCHOICE: - return compareStrings(aValue, bValue, sortOrder); + case ItemType.CHOICE: + return isNumber(aValue, bValue) ? compareNumbers(aValue, bValue, sortOrder) : compareStrings(aValue, bValue, sortOrder); default: - return compareStrings(aValue, bValue, sortOrder); + return isNumber(aValue, bValue) ? compareNumbers(aValue, bValue, sortOrder) : compareStrings(aValue, bValue, sortOrder); + } +}; +const isNumber = (aValue: string, bValues: string): boolean => { + return isNumberString(aValue) && isNumberString(bValues); +}; +const isNumberString = (str: string): boolean => { + str = str.trim(); + + if (str === '') { + return false; + } + const numberRegex = /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/; + + if (!numberRegex.test(str)) { + return false; } + const number = Number(str); + return !isNaN(number); }; const extractNumber = (value: string | undefined): number => { diff --git a/src/preview/FormFillerPreview.tsx b/src/preview/FormFillerPreview.tsx index 685ea886..e8bb4f70 100644 --- a/src/preview/FormFillerPreview.tsx +++ b/src/preview/FormFillerPreview.tsx @@ -12,7 +12,7 @@ import LanguageLocales from '@helsenorge/core-utils/constants/languages'; import FormFillerSidebar from './FormFillerSidebar'; import { emptyPropertyReplacer } from './helpers'; import { getResources } from './resources/referoResources'; -import skjema from './skjema/Test_Slider_New-nb-NO-v01.json'; +import skjema from './skjema/q.json'; import { ReferoContainer } from '../components'; import rootReducer from '../reducers'; diff --git a/src/preview/skjema/Test_Slider_New-nb-NO-v01.json b/src/preview/skjema/Test_Slider_New-nb-NO-v01.json deleted file mode 100644 index 90a3b997..00000000 --- a/src/preview/skjema/Test_Slider_New-nb-NO-v01.json +++ /dev/null @@ -1 +0,0 @@ -{"title":"Test_Slider","resourceType":"Questionnaire","language":"nb-NO","name":"Test_Slider_New","status":"draft","publisher":"NHN","meta":{"profile":["http://ehelse.no/fhir/StructureDefinition/sdf-Questionnaire"],"tag":[{"system":"urn:ietf:bcp:47","code":"nb-NO","display":"Bokmål"}],"security":[{"code":"3","display":"Helsehjelp (Full)","system":"urn:oid:2.16.578.1.12.4.1.1.7618"}]},"contact":[{"name":"http://www.nhn.no"}],"subjectType":["Patient"],"extension":[{"url":"http://helsenorge.no/fhir/StructureDefinition/sdf-sidebar","valueCoding":{"system":"http://helsenorge.no/fhir/ValueSet/sdf-sidebar","code":"1"}},{"url":"http://helsenorge.no/fhir/StructureDefinition/sdf-information-message","valueCoding":{"system":"http://helsenorge.no/fhir/ValueSet/sdf-information-message","code":"1"}},{"url":"http://helsenorge.no/fhir/StructureDefintion/sdf-itemControl-visibility","valueCodeableConcept":{"coding":[{"system":"http://helsenorge.no/fhir/CodeSystem/AttachmentRenderOptions","code":"hide-help","display":"Hide help texts"},{"system":"http://helsenorge.no/fhir/CodeSystem/AttachmentRenderOptions","code":"hide-sublabel","display":"Hide sublabel texts"}]}}],"id":"4ddf2198-1aae-4bf6-8978-c4d65a8ae674","version":"01","item":[{"linkId":"a827a63d-a5a1-4ded-8305-b6fd8e3bc959","type":"group","text":"Test","item":[{"linkId":"d9686593-fb6f-4576-8226-14dbb18db97d","type":"choice","text":"Velg verdi - tittel-verdier vises - ingen min og max","code":[{"code":"label","display":"Display value","system":"http://helsenorge.no/fhir/CodeSystem/SliderDisplayType"},{"code":"LabelLeft","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"},{"code":"LabelRight","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"}],"required":false,"answerOption":[{"valueCoding":{"id":"3e476885-6590-435e-f106-93cdeac8a0ff","code":"ja","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"Ja","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":1}]}},{"valueCoding":{"id":"521edf2c-9298-40c3-9de9-784d60b400ea","code":"nei","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"Nei","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":2}]}},{"valueCoding":{"id":"14a0e76e-199a-4216-d68b-4c00a43c437b","code":"vet-ikke","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"Vet ikke","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":99}]}}],"extension":[{"url":"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl","valueCodeableConcept":{"coding":[{"system":"http://hl7.org/fhir/ValueSet/questionnaire-item-control","code":"slider"}]}}]},{"linkId":"2d0a0edb-37bb-4632-86e1-b2b22f86efc5","type":"choice","text":"Velg verdi - Desimal-verdier vises - med min og max ","code":[{"code":"ordnialValue","display":"Display value","system":"http://helsenorge.no/fhir/CodeSystem/SliderDisplayType"},{"code":"LabelLeft","display":"Max","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"},{"code":"LabelRight","display":"Min","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"}],"required":false,"answerOption":[{"valueCoding":{"id":"3e476885-6590-435e-f106-93cdeac8a0ff","code":"1","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"1","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":1}]}},{"valueCoding":{"id":"521edf2c-9298-40c3-9de9-784d60b400ea","code":"2","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"2","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":2}]}},{"valueCoding":{"id":"14a0e76e-199a-4216-d68b-4c00a43c437b","code":"3","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"3","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":3}]}},{"valueCoding":{"id":"9f6579df-815d-429b-8517-55dbac46b65e","code":"4","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"4","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":4}]}},{"valueCoding":{"id":"19e46df5-c933-446b-849d-b6aceef8c9b4","code":"5","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"5","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":5}]}}],"extension":[{"url":"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl","valueCodeableConcept":{"coding":[{"system":"http://hl7.org/fhir/ValueSet/questionnaire-item-control","code":"slider"}]}}]},{"linkId":"c2cddf5d-b1db-4187-a158-8e3b30cdb84e","type":"choice","text":"Velg verdi - Desimal-verdier vises - med min og max og emojii","code":[{"code":"ordnialValue","display":"Display value","system":"http://helsenorge.no/fhir/CodeSystem/SliderDisplayType"},{"code":"LabelLeft","display":"Max","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"},{"code":"LabelRight","display":"Min","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"}],"required":false,"answerOption":[{"valueCoding":{"id":"3e476885-6590-435e-f106-93cdeac8a0ff","code":"1","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"1","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":1},{"url":"http://hl7.org/fhir/StructureDefinition/valueset-label","valueString":"😀"}]}},{"valueCoding":{"id":"521edf2c-9298-40c3-9de9-784d60b400ea","code":"2","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"2","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":2},{"url":"http://hl7.org/fhir/StructureDefinition/valueset-label","valueString":"😀"}]}},{"valueCoding":{"id":"14a0e76e-199a-4216-d68b-4c00a43c437b","code":"3","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"3","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":3},{"url":"http://hl7.org/fhir/StructureDefinition/valueset-label","valueString":"😀"}]}},{"valueCoding":{"id":"9f6579df-815d-429b-8517-55dbac46b65e","code":"4","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"4","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":4},{"url":"http://hl7.org/fhir/StructureDefinition/valueset-label","valueString":"😀"}]}},{"valueCoding":{"id":"19e46df5-c933-446b-849d-b6aceef8c9b4","code":"5","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"5","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":5},{"url":"http://hl7.org/fhir/StructureDefinition/valueset-label","valueString":"😀"}]}}],"extension":[{"url":"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl","valueCodeableConcept":{"coding":[{"system":"http://hl7.org/fhir/ValueSet/questionnaire-item-control","code":"slider"}]}}]},{"linkId":"44fa071b-7a7c-49bd-847c-8e98e2d9afe3","type":"choice","text":"Velg verdi - Desimal-verdier vises - med min og max og Skåring","code":[{"code":"ordnialValue","display":"Display value","system":"http://helsenorge.no/fhir/CodeSystem/SliderDisplayType"},{"code":"LabelLeft","display":"Max","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"},{"code":"LabelRight","display":"Min","system":"http://helsenorge.no/fhir/CodeSystem/SliderLabels"},{"system":"http://ehelse.no/Score","code":"score","display":"score"},{"system":"http://ehelse.no/scoringFormulas","code":"QS","display":"Question score"}],"required":false,"answerOption":[{"valueCoding":{"id":"3e476885-6590-435e-f106-93cdeac8a0ff","code":"1","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"1","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":1}]}},{"valueCoding":{"id":"521edf2c-9298-40c3-9de9-784d60b400ea","code":"2","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"2","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":2}]}},{"valueCoding":{"id":"14a0e76e-199a-4216-d68b-4c00a43c437b","code":"3","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"3","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":3}]}},{"valueCoding":{"id":"9f6579df-815d-429b-8517-55dbac46b65e","code":"4","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"4","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":4}]}},{"valueCoding":{"id":"19e46df5-c933-446b-849d-b6aceef8c9b4","code":"5","system":"urn:uuid:cb9deff9-b5bd-4f64-80af-7f98d55ca7ce","display":"5","extension":[{"url":"http://hl7.org/fhir/StructureDefinition/ordinalValue","valueDecimal":5}]}}],"extension":[{"url":"http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl","valueCodeableConcept":{"coding":[{"system":"http://hl7.org/fhir/ValueSet/questionnaire-item-control","code":"slider"}]}}]},{"linkId":"9db61c61-ed15-4bff-838a-10a6fef20866","type":"integer","text":"Sum","code":[{"system":"http://ehelse.no/Score","code":"score","display":"score"},{"system":"http://ehelse.no/scoringFormulas","code":"TS","display":"Total score"}],"required":false}],"required":false}]} \ No newline at end of file diff --git a/src/preview/skjema/kun_qest.json b/src/preview/skjema/q.json similarity index 100% rename from src/preview/skjema/kun_qest.json rename to src/preview/skjema/q.json