-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/jy95/fhir/r4/dosage/utils/translators/MaxDosePerAdministration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/jy95/fhir/r4/dosage/utils/translators/MaxDosePerAdministrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} |