Skip to content

Commit

Permalink
Merge pull request #18 from jy95/ratio-improvements
Browse files Browse the repository at this point in the history
perf: improvements on the handling of amount
  • Loading branch information
jy95 authored Apr 3, 2024
2 parents af2ae87 + 122f63e commit 1251b7e
Show file tree
Hide file tree
Showing 18 changed files with 451 additions and 317 deletions.
16 changes: 1 addition & 15 deletions __tests__/corner_cases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,6 @@ describe("Corner cases", () => {
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at a rate of 3 pills per ");
});

test("maxDosePerPeriod - no denominator", () => {
const dosage: Dosage = {
maxDosePerPeriod: {
numerator: {
value: 3,
unit: "pills",
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("up to a maximum of 3 pills per ");
expect(result).toBe("at a rate of 3 pills");
});
});
13 changes: 13 additions & 0 deletions __tests__/fromDosageToText/boundsRange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ describe("fromDosageToText - boundsRange", () => {
expect(result).toBe("");
});

test("Empty boundsRange", () => {
const dosage: Dosage = {
timing: {
repeat: {
boundsRange: {},
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("high and low", () => {
const dosage: Dosage = {
timing: {
Expand Down
35 changes: 34 additions & 1 deletion __tests__/fromDosageToText/doseRange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ describe("fromDosageToText - doseRange", () => {
expect(result).toBe("");
});

test("Empty doseRange", () => {
const dosage: Dosage = {
doseAndRate: [
{
doseRange: {},
},
],
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("high and low", () => {
const dosage: Dosage = {
doseAndRate: [
Expand Down Expand Up @@ -78,6 +91,26 @@ describe("fromDosageToText - doseRange", () => {
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("3 pills");
expect(result).toBe("at least 3 pills");
});

test("No units", () => {
const dosage: Dosage = {
doseAndRate: [
{
doseRange: {
low: {
value: 3,
},
high: {
value: 5,
},
},
},
],
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("3 to 5");
});
});
17 changes: 2 additions & 15 deletions __tests__/fromDosageToText/maxDosePerPeriod.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,15 @@ describe("fromDosageToText - maxDosePerPeriod", () => {
expect(result).toBe("up to a maximum of 3 pills every 5 hours");
});

test("no numerator", () => {
const dosage: DosageR4 = {
maxDosePerPeriod: {
denominator: {
value: 5,
unit: "hours",
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("up to a maximum of 1 every 5 hours");
});

test("no denominator value", () => {
test("denominator value equal to 1", () => {
const dosage: DosageR4 = {
maxDosePerPeriod: {
numerator: {
value: 3,
unit: "pills",
},
denominator: {
value: 1,
unit: "hour",
},
},
Expand Down
17 changes: 15 additions & 2 deletions __tests__/fromDosageToText/rateRange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ describe("fromDosageToText - rateRange", () => {
expect(result).toBe("");
});

test("Empty rateRange", () => {
const dosage: Dosage = {
doseAndRate: [
{
rateRange: {},
},
],
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("high and low", () => {
const dosage: Dosage = {
doseAndRate: [
Expand Down Expand Up @@ -60,7 +73,7 @@ describe("fromDosageToText - rateRange", () => {
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at a rate of 5 pills");
expect(result).toBe("at a rate of up to 5 pills");
});

test("low only", () => {
Expand All @@ -78,6 +91,6 @@ describe("fromDosageToText - rateRange", () => {
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at a rate of 3 pills");
expect(result).toBe("at a rate of at least 3 pills");
});
});
24 changes: 18 additions & 6 deletions __tests__/fromDosageToText/rateRatio.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe("fromDosageToText - rateRatio", () => {
expect(result).toBe("");
});

test("Empty rateRatio", () => {
const dosage: Dosage = {
doseAndRate: [
{
rateRatio: {},
},
],
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("numerator and denominator", () => {
const dosage: Dosage = {
doseAndRate: [
Expand Down Expand Up @@ -69,27 +82,26 @@ describe("fromDosageToText - rateRatio", () => {
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at a rate of 1 every 5 hours");
expect(result).toBe("at a rate of every 5 hours");
});

test("no denominator value", () => {
test("no unit", () => {
const dosage: Dosage = {
doseAndRate: [
{
rateRatio: {
numerator: {
value: 3,
unit: "pills",
value: 1,
},
denominator: {
unit: "hour",
value: 128,
},
},
},
],
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at a rate of 3 pills per hour");
expect(result).toBe("at a rate of 1 :128");
});
});
56 changes: 32 additions & 24 deletions src/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,39 @@
"and": "und",
"then": "dann"
},
"amount": {
"range": {
"withUnit": {
"lowAndHigh": "zwischen {{low}} und {{high}} {{unit}}",
"onlyHigh": "bis {{high}} {{unit}}",
"onlyLow": "mindestens {{low}} {{unit}}"
},
"withoutUnit": {
"lowAndHigh": "zwischen {{low}} und {{high}}",
"onlyHigh": "bis {{high}}",
"onlyLow": "mindestens {{low}}"
}
},
"ratio": {
"withUnit": {
"numerator": "{{count}} {{numeratorUnit}}",
"denominator_one": "pro {{denominatorUnit}}",
"denominator_other": "jeder {{count}} {{denominatorUnit}}"
},
"withoutUnit": {
"numerator": "{{count}}",
"denominator_one": ":{{count}}",
"denominator_other": ":{{count}}"
}
},
"quantity": "{{quantity}} {{unit}}"
},
"fields": {
"doseQuantity": "{{quantity}} {{unit}}",
"doseRange": {
"lowAndHigh": "zwischen {{low}} und {{high}} {{unit}}",
"onlyHigh": "bis {{high}} {{unit}}",
"onlyLow": "{{low}} {{unit}}"
},
"doseRange": "{{rangeText}}",
"rateQuantity": "mit einem Verhältnis von {{quantity}} {{unit}}",
"rateRange": {
"lowAndHigh": "mit einem Verhältnis zwischen {{low}} und {{high}} {{unit}}",
"onlyHigh": "mit einem Verhältnis von {{high}} {{unit}}",
"onlyLow": "mit einem Verhältnis von {{low}} {{unit}}"
},
"rateRatio": {
"rateRatio_one": "mit einem Verhältnis von {{quantityNumerator}} {{numeratorUnit}} pro {{denominatorUnit}}",
"rateRatio_other": "mit einem Verhältnis von {{quantityNumerator}} {{numeratorUnit}} jeder {{count}} {{denominatorUnit}}"
},
"rateRange": "mit einem Verhältnis von {{rangeText}}",
"rateRatio": "mit einem Verhältnis von {{ratioText}}",
"duration": "für {{durationText}}",
"durationMax": "(maximal {{durationMaxText}})",
"frequency": {
Expand Down Expand Up @@ -54,11 +70,7 @@
"onlyStart": "ab {{start}}",
"onlyEnd": "bis {{end}}"
},
"boundsRange": {
"lowAndHigh": "für {{low}} bis {{high}} {{unit}}",
"onlyHigh": "bis {{high}} {{unit}}",
"onlyLow": "für mindestens {{low}} {{unit}}"
},
"boundsRange": "für {{rangeText}}",
"count": {
"count_one": "{{count}} Mal nehmen",
"count_other": "{{count}} Mal nehmen"
Expand All @@ -73,10 +85,6 @@
},
"maxDosePerLifetime": "bis zu einer maximalen Menge von {{count}} {{unit}} über die Lebenszeit des Patienten",
"maxDosePerAdministration": "bis zu einer maximalen Menge von {{count}} {{unit}} pro Dosis",
"maxDosePerPeriod": {
"general": "bis zu einer maximalen Menge von {{maxDosePerPeriodText}}",
"maxDosePerPeriod_one": "{{quantityNumerator}} {{numeratorUnit}} pro {{denominatorUnit}}",
"maxDosePerPeriod_other": "{{quantityNumerator}} {{numeratorUnit}} jeder {{count}} {{denominatorUnit}}"
}
"maxDosePerPeriod": "bis zu einer maximalen Menge von {{maxDosePerPeriodText}}"
}
}
56 changes: 32 additions & 24 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,39 @@
"and": "and",
"then": "then"
},
"amount": {
"range": {
"withUnit": {
"lowAndHigh": "{{low}} to {{high}} {{unit}}",
"onlyHigh": "up to {{high}} {{unit}}",
"onlyLow": "at least {{low}} {{unit}}"
},
"withoutUnit": {
"lowAndHigh": "{{low}} to {{high}}",
"onlyHigh": "up to {{high}}",
"onlyLow": "at least {{low}}"
}
},
"ratio": {
"withUnit": {
"numerator": "{{count}} {{numeratorUnit}}",
"denominator_one": "per {{denominatorUnit}}",
"denominator_other": "every {{count}} {{denominatorUnit}}"
},
"withoutUnit": {
"numerator": "{{count}}",
"denominator_one": ":{{count}}",
"denominator_other": ":{{count}}"
}
},
"quantity": "{{quantity}} {{unit}}"
},
"fields": {
"doseQuantity": "{{quantity}} {{unit}}",
"doseRange": {
"lowAndHigh": "{{low}} to {{high}} {{unit}}",
"onlyHigh": "up to {{high}} {{unit}}",
"onlyLow": "{{low}} {{unit}}"
},
"doseRange": "{{rangeText}}",
"rateQuantity": "at a rate of {{quantity}} {{unit}}",
"rateRange": {
"lowAndHigh": "at a rate of {{low}} to {{high}} {{unit}}",
"onlyHigh": "at a rate of {{high}} {{unit}}",
"onlyLow": "at a rate of {{low}} {{unit}}"
},
"rateRatio": {
"rateRatio_one": "at a rate of {{quantityNumerator}} {{numeratorUnit}} per {{denominatorUnit}}",
"rateRatio_other": "at a rate of {{quantityNumerator}} {{numeratorUnit}} every {{count}} {{denominatorUnit}}"
},
"rateRange": "at a rate of {{rangeText}}",
"rateRatio": "at a rate of {{ratioText}}",
"duration": "over {{durationText}}",
"durationMax": "(maximum {{durationMaxText}})",
"frequency": {
Expand Down Expand Up @@ -54,11 +70,7 @@
"onlyStart": "from {{start}}",
"onlyEnd": "to {{end}}"
},
"boundsRange": {
"lowAndHigh": "for {{low}} to {{high}} {{unit}}",
"onlyHigh": "for up to {{high}} {{unit}}",
"onlyLow": "for at least {{low}} {{unit}}"
},
"boundsRange": "for {{rangeText}}",
"count": {
"count_one": "take {{count}} time",
"count_other": "take {{count}} times"
Expand All @@ -73,10 +85,6 @@
},
"maxDosePerLifetime": "up to a maximum of {{count}} {{unit}} for the lifetime of patient",
"maxDosePerAdministration": "up to a maximum of {{count}} {{unit}} per dose",
"maxDosePerPeriod": {
"general": "up to a maximum of {{maxDosePerPeriodText}}",
"maxDosePerPeriod_one": "{{quantityNumerator}} {{numeratorUnit}} per {{denominatorUnit}}",
"maxDosePerPeriod_other": "{{quantityNumerator}} {{numeratorUnit}} every {{count}} {{denominatorUnit}}"
}
"maxDosePerPeriod": "up to a maximum of {{maxDosePerPeriodText}}"
}
}
Loading

0 comments on commit 1251b7e

Please sign in to comment.