Skip to content

Commit

Permalink
feat: MaxDosePerAdministration
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed Jan 5, 2025
1 parent 72241d0 commit cf7dfa0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public Translators(FDUConfig config) {
Map.entry(DisplayOrder.RATE_RANGE, new RateRange(config)),
Map.entry(DisplayOrder.RATE_RATIO, new RateRatio(config)),
Map.entry(DisplayOrder.OFFSET_WHEN, new OffsetWhen(config)),
Map.entry(DisplayOrder.MAX_DOSE_PER_LIFETIME, new MaxDosePerLifetime(config))
Map.entry(DisplayOrder.MAX_DOSE_PER_LIFETIME, new MaxDosePerLifetime(config)),
Map.entry(DisplayOrder.MAX_DOSE_PER_ADMINISTRATION, new MaxDosePerAdministration(config))
)
);
this.bundleControl = new MultiResourceBundleControl(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package jy95.fhir.r4.dosage.utils.translators;

import jy95.fhir.r4.dosage.utils.classes.AbstractTranslator;
import jy95.fhir.r4.dosage.utils.config.FDUConfig;
import jy95.fhir.r4.dosage.utils.functions.QuantityToString;
import org.hl7.fhir.r4.model.Dosage;

import java.text.MessageFormat;
import java.util.concurrent.CompletableFuture;

public class MaxDosePerAdministration extends AbstractTranslator {

public MaxDosePerAdministration(FDUConfig config) {
super(config);
}

@Override
public CompletableFuture<String> convert(Dosage dosage) {
var quantity = dosage.getMaxDosePerAdministration();
var bundle = getResources();

return QuantityToString
.convert(bundle, getConfig(), quantity)
.thenApplyAsync((quantityText) -> {
String msg = bundle.getString("fields.maxDosePerAdministration");
return new MessageFormat(msg, getConfig().getLocale()).format(new Object[] {quantityText});
});
}

@Override
public boolean isPresent(Dosage dosage) {
return dosage.hasMaxDosePerAdministration();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package jy95.fhir.r4.dosage.utils.translators;

import jy95.fhir.r4.dosage.utils.AbstractFhirTest;
import jy95.fhir.r4.dosage.utils.classes.FhirDosageUtils;
import jy95.fhir.r4.dosage.utils.types.DisplayOrder;
import org.hl7.fhir.r4.model.Dosage;
import org.hl7.fhir.r4.model.Quantity;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Locale;
import java.util.concurrent.ExecutionException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MaxDosePerAdministrationTest extends AbstractFhirTest {

@ParameterizedTest
@MethodSource("localeProvider")
void testNoMaxDosePerAdministration(Locale locale) throws ExecutionException, InterruptedException {
Dosage dosage = new Dosage();
FhirDosageUtils dosageUtils = getDosageUtilsInstance(locale, DisplayOrder.MAX_DOSE_PER_ADMINISTRATION);
String result = dosageUtils.asHumanReadableText(dosage).get();
assertEquals("", result);
}

@ParameterizedTest
@MethodSource("localeProvider")
void testWithMaxDosePerAdministration(Locale locale) throws ExecutionException, InterruptedException {
Dosage dosage = new Dosage();
Quantity quantity = new Quantity();
quantity.setValue(50);
quantity.setUnit("mg");
dosage.setMaxDosePerAdministration(quantity);
FhirDosageUtils dosageUtils = getDosageUtilsInstance(locale, DisplayOrder.MAX_DOSE_PER_ADMINISTRATION);
String result = dosageUtils.asHumanReadableText(dosage).get();
String expected = getExpectedText(locale);
assertEquals(expected, result);
}

private String getExpectedText(Locale locale) {
if (locale.equals(Locale.ENGLISH)) {
return "up to a maximum of 50 mg per dose";
} else if (locale.equals(Locale.FRENCH)) {
return "jusqu’à un maximum de 50 mg par dose";
} else if (locale.equals(Locale.GERMAN)) {
return "bis zu einer maximalen Menge von 50 mg pro Dosis";
} else {
return "tot een maximum van 50 mg per dosis";
}
}
}

0 comments on commit cf7dfa0

Please sign in to comment.