-
-
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
8 changed files
with
106 additions
and
2 deletions.
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
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/MaxDosePerPeriod.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.RatioToString; | ||
import org.hl7.fhir.r4.model.Dosage; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class MaxDosePerPeriod extends AbstractTranslator { | ||
|
||
public MaxDosePerPeriod(FDUConfig config) { | ||
super(config); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> convert(Dosage dosage) { | ||
var ratio = dosage.getMaxDosePerPeriod(); | ||
var bundle = getResources(); | ||
|
||
return RatioToString | ||
.convert(bundle, getConfig(), ratio) | ||
.thenApplyAsync((ratioText) -> { | ||
String msg = bundle.getString("fields.maxDosePerPeriod"); | ||
return new MessageFormat(msg, getConfig().getLocale()).format(new Object[] {ratioText}); | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean isPresent(Dosage dosage) { | ||
return dosage.hasMaxDosePerPeriod(); | ||
} | ||
} |
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
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
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
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
58 changes: 58 additions & 0 deletions
58
src/test/java/jy95/fhir/r4/dosage/utils/translators/MaxDosePerPeriodTest.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,58 @@ | ||
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.hl7.fhir.r4.model.Ratio; | ||
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 MaxDosePerPeriodTest extends AbstractFhirTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("localeProvider") | ||
void testNoMaxDosePerPeriod(Locale locale) throws ExecutionException, InterruptedException { | ||
Dosage dosage = new Dosage(); | ||
FhirDosageUtils dosageUtils = getDosageUtilsInstance(locale, DisplayOrder.MAX_DOSE_PER_PERIOD); | ||
String result = dosageUtils.asHumanReadableText(dosage).get(); | ||
assertEquals("", result); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("localeProvider") | ||
void testWithMaxDosePerPeriod(Locale locale) throws ExecutionException, InterruptedException { | ||
Dosage dosage = new Dosage(); | ||
Ratio ratio = new Ratio(); | ||
Quantity numerator = new Quantity(10); | ||
numerator.setUnit("mg"); | ||
ratio.setNumerator(numerator); | ||
Quantity denominator = new Quantity(1); | ||
denominator.setCode("d"); | ||
denominator.setSystem("http://hl7.org/fhir/ValueSet/units-of-time"); | ||
ratio.setDenominator(denominator); | ||
dosage.setMaxDosePerPeriod(ratio); | ||
FhirDosageUtils dosageUtils = getDosageUtilsInstance(locale, DisplayOrder.MAX_DOSE_PER_PERIOD); | ||
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 10 mg per day"; | ||
} else if (locale.equals(Locale.FRENCH)) { | ||
return "jusqu’à un maximum de 10 mg par jour"; | ||
} else if (locale.equals(Locale.GERMAN)) { | ||
return "bis zu einer maximalen Menge von 10 mg pro Tag"; | ||
} else { | ||
return "tot een maximum van 10 mg per dag"; | ||
} | ||
} | ||
} |