Permalink
Browse files

Tilpasset FMK 1.4

  • Loading branch information...
1 parent 35dc522 commit 4ea81632cabd351d4c15e4132bac8df04686d18a @tomtrifork tomtrifork committed Sep 5, 2012
Showing with 1,277 additions and 445 deletions.
  1. +1 −1 build.xml
  2. +14 −14 src/dk/medicinkortet/dosisstructuretext/DailyDosisCalculator.java
  3. +22 −22 src/dk/medicinkortet/dosisstructuretext/DosageTypeCalculator.java
  4. +25 −11 src/dk/medicinkortet/dosisstructuretext/TextHelper.java
  5. +10 −10 src/dk/medicinkortet/dosisstructuretext/Validator.java
  6. +13 −13 src/dk/medicinkortet/dosisstructuretext/longtextconverterimpl/DailyRepeatedConverterImpl.java
  7. +19 −19 src/dk/medicinkortet/dosisstructuretext/longtextconverterimpl/DefaultLongTextConverterImpl.java
  8. +28 −29 src/dk/medicinkortet/dosisstructuretext/longtextconverterimpl/LongTextConverterImpl.java
  9. +17 −17 src/dk/medicinkortet/dosisstructuretext/longtextconverterimpl/TwoDaysRepeatedConverterImpl.java
  10. +20 −20 src/dk/medicinkortet/dosisstructuretext/longtextconverterimpl/WeeklyRepeatedConverterImpl.java
  11. +14 −14 src/dk/medicinkortet/dosisstructuretext/shorttextconverterimpl/LimitedNumberOfDaysConverterImpl.java
  12. +34 −26 ...medicinkortet/dosisstructuretext/shorttextconverterimpl/MorningNoonEveningNightConverterImpl.java
  13. +20 −22 ...nkortet/dosisstructuretext/shorttextconverterimpl/MorningNoonEveningNightInNDaysConverterImp.java
  14. +12 −12 src/dk/medicinkortet/dosisstructuretext/shorttextconverterimpl/ParacetamolConverterImpl.java
  15. +22 −22 src/dk/medicinkortet/dosisstructuretext/shorttextconverterimpl/RepeatedConverterImpl.java
  16. +8 −8 src/dk/medicinkortet/dosisstructuretext/shorttextconverterimpl/ShortTextConverterImpl.java
  17. +12 −12 ...k/medicinkortet/dosisstructuretext/shorttextconverterimpl/SimpleAccordingToNeedConverterImpl.java
  18. +12 −12 ...inkortet/dosisstructuretext/shorttextconverterimpl/SimpleLimitedAccordingToNeedConverterImpl.java
  19. +13 −13 src/dk/medicinkortet/dosisstructuretext/shorttextconverterimpl/SimpleNonRepeatedConverterImpl.java
  20. +17 −18 ...nkortet/dosisstructuretext/shorttextconverterimpl/WeeklyMorningNoonEveningNightConverterImpl.java
  21. +24 −12 ...nkortet/dosisstructuretext/vowrapper/{StructuredDosageWrapper.java → DosageStructureWrapper.java}
  22. +11 −11 src/dk/medicinkortet/dosisstructuretext/vowrapper/DosageWrapper.java
  23. +5 −5 test/dk/medicinkortet/dosisstructuretext/DosageWrapperTest.java
  24. +4 −4 test/dk/medicinkortet/dosisstructuretext/ns2008/LimitedNumberOfDaysConverterTest.java
  25. +2 −2 test/dk/medicinkortet/dosisstructuretext/ns2008/ParacetamolConverterTest.java
  26. +2 −2 test/dk/medicinkortet/dosisstructuretext/ns2009/DailyRepeatedConverterTest.java
  27. +3 −3 test/dk/medicinkortet/dosisstructuretext/ns2009/LimitedNumberOfDaysConverterTest.java
  28. +23 −23 test/dk/medicinkortet/dosisstructuretext/ns2009/LongTextComplexConverterTest.java
  29. +5 −5 test/dk/medicinkortet/dosisstructuretext/ns2009/LongTextConverterTest.java
  30. +17 −17 test/dk/medicinkortet/dosisstructuretext/ns2009/MorningNoonEveningNightConverterTest.java
  31. +2 −2 test/dk/medicinkortet/dosisstructuretext/ns2009/MorningNoonEveningNightInNDaysConverterTest.java
  32. +2 −2 test/dk/medicinkortet/dosisstructuretext/ns2009/ParacetamolConverterTest.java
  33. +16 −16 test/dk/medicinkortet/dosisstructuretext/ns2009/RepeatedConverterTest.java
  34. +4 −4 test/dk/medicinkortet/dosisstructuretext/ns2009/SimpleAccordingToNeedConverterTest.java
  35. +4 −4 test/dk/medicinkortet/dosisstructuretext/ns2009/SimpleLimitedAccordingToNeedConverterTest.java
  36. +4 −4 test/dk/medicinkortet/dosisstructuretext/ns2009/SimpleNonRepeatedConverterTest.java
  37. +4 −4 test/dk/medicinkortet/dosisstructuretext/ns2009/TwoDaysRepeatedConverterTest.java
  38. +7 −7 test/dk/medicinkortet/dosisstructuretext/ns2009/ValidatorTest.java
  39. +3 −3 test/dk/medicinkortet/dosisstructuretext/ns2009/WeeklyMorningNoonEveningNightConverterTest.java
  40. +113 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/DailyRepeatedConverterTest.java
  41. +136 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/LimitedNumberOfDaysConverterTest.java
  42. +94 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/LongTextComplexConverterTest.java
  43. +115 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/MorningNoonEveningNightConverterTest.java
  44. +140 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/MorningNoonEveningNightInNDaysConverterTest.java
  45. +103 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/RepeatedConverterTest.java
  46. +101 −0 test/dk/medicinkortet/dosisstructuretext/ns20120601/SimpleAccordingToNeedConverterTest.java
View
@@ -4,7 +4,7 @@
<property file="build.properties" />
<property file="revision.properties" />
- <property name="trifork-common" value="${basedir}/../../trifork-common"/>
+ <property name="trifork-common" value="${basedir}/../trifork-common"/>
<import file="${trifork-common}/etc/build-common.xml"/>
<property name="test.instrument" value="true"/>
@@ -25,7 +25,7 @@
import java.math.BigDecimal;
import dk.medicinkortet.dosisstructuretext.vowrapper.DosageWrapper;
-import dk.medicinkortet.dosisstructuretext.vowrapper.StructuredDosageWrapper;
+import dk.medicinkortet.dosisstructuretext.vowrapper.DosageStructureWrapper;
/**
* Class for calculating the avg. daily dosis from the dosage structure.
@@ -43,37 +43,37 @@ public static DailyDosis calculate(DosageWrapper dosage) {
else if(dosage.isFreeText())
return new DailyDosis();
else
- return calculateFromStructuredDosage(dosage.getDosageTimes());
+ return calculateFromStructuredDosage(dosage.getDosageStructure());
}
- private static DailyDosis calculateFromStructuredDosage(StructuredDosageWrapper dosageTimes) {
+ private static DailyDosis calculateFromStructuredDosage(DosageStructureWrapper dosageStructure) {
// If the dosage isn't repeated it doesn't make sense to calculate an average
// unless all daily doses are equal
- if(dosageTimes.getIterationInterval()==0)
- if(!dosageTimes.allDaysAreTheSame())
+ if(dosageStructure.getIterationInterval()==0)
+ if(!dosageStructure.allDaysAreTheSame())
return new DailyDosis();
// If the structured dosage contains any doses according to need
// we cannot calculate an average dosis
- if(dosageTimes.containsAccordingToNeedDose())
+ if(dosageStructure.containsAccordingToNeedDose())
return new DailyDosis();
// If there is a dosage for day zero (meaning not related to a specific day)
// we cannot calculate an average dosis
- if(dosageTimes.getDay(0)!=null)
+ if(dosageStructure.getDay(0)!=null)
return new DailyDosis();
// Otherwise we will calculate an average dosage.
// If the iteration interval is zero, the dosage is not repeated. This means
// that the dosage for each day is given.
- if(dosageTimes.getIterationInterval()==0)
+ if(dosageStructure.getIterationInterval()==0)
return calculateAvg(
- dosageTimes.getSumOfDoses(),
- new BigDecimal(dosageTimes.getMaxDay().getDayNumber()),
- dosageTimes.getUnit());
+ dosageStructure.getSumOfDoses(),
+ new BigDecimal(dosageStructure.getMaxDay().getDayNumber()),
+ dosageStructure.getUnit());
// Else the dosage is repeated, and the iteration interval states after how many days
else
return calculateAvg(
- dosageTimes.getSumOfDoses(),
- new BigDecimal(dosageTimes.getIterationInterval()),
- dosageTimes.getUnit());
+ dosageStructure.getSumOfDoses(),
+ new BigDecimal(dosageStructure.getIterationInterval()),
+ dosageStructure.getUnit());
}
@@ -24,7 +24,7 @@
import dk.medicinkortet.dosisstructuretext.vowrapper.DayWrapper;
import dk.medicinkortet.dosisstructuretext.vowrapper.DosageWrapper;
-import dk.medicinkortet.dosisstructuretext.vowrapper.StructuredDosageWrapper;
+import dk.medicinkortet.dosisstructuretext.vowrapper.DosageStructureWrapper;
public class DosageTypeCalculator {
@@ -34,64 +34,64 @@ public static DosageType calculate(DosageWrapper dosage) {
else if(dosage.isFreeText())
return DosageType.Unspecified;
else
- return calculateFromStructuredDosage(dosage.getDosageTimes());
+ return calculateFromStructuredDosage(dosage.getDosageStructure());
}
- private static DosageType calculateFromStructuredDosage(StructuredDosageWrapper dosageTimes) {
- if(isAccordingToNeed(dosageTimes))
+ private static DosageType calculateFromStructuredDosage(DosageStructureWrapper dosageStructure) {
+ if(isAccordingToNeed(dosageStructure))
return DosageType.AccordingToNeed;
- else if(isOneTime(dosageTimes))
+ else if(isOneTime(dosageStructure))
return DosageType.OneTime;
- else if(isTemporary(dosageTimes))
+ else if(isTemporary(dosageStructure))
return DosageType.Temporary;
- else if(isFixed(dosageTimes))
+ else if(isFixed(dosageStructure))
return DosageType.Fixed;
else
return DosageType.Combined;
}
- private static boolean isAccordingToNeed(StructuredDosageWrapper dosageTimes) {
+ private static boolean isAccordingToNeed(DosageStructureWrapper dosageStructure) {
// If the dosage contains only according to need doses, it is quite simply just
// an according to need dosage
- return dosageTimes.containsAccordingToNeedDosesOnly();
+ return dosageStructure.containsAccordingToNeedDosesOnly();
}
- private static boolean isTemporary(StructuredDosageWrapper dosageTimes) {
+ private static boolean isTemporary(DosageStructureWrapper dosageStructure) {
// If there is no end date defined the dosage must not be iterated
- if(dosageTimes.getEndDateOrDateTime()==null && dosageTimes.getIterationInterval()>0)
+ if(dosageStructure.getEndDateOrDateTime()==null && dosageStructure.getIterationInterval()>0)
return false;
// If there is an according to need dose in the dosage it is not a (clean)
// temporary dosage.
- if(dosageTimes.containsAccordingToNeedDose())
+ if(dosageStructure.containsAccordingToNeedDose())
return false;
return true;
}
- private static boolean isFixed(StructuredDosageWrapper dosageTimes) {
+ private static boolean isFixed(DosageStructureWrapper dosageStructure) {
// If there is an end date defined the dosage isn't fixed
- if(dosageTimes.getEndDateOrDateTime()!=null)
+ if(dosageStructure.getEndDateOrDateTime()!=null)
return false;
// If the dosage isn't iterated it isn't fixed
- if(dosageTimes.getIterationInterval()==0)
+ if(dosageStructure.getIterationInterval()==0)
return false;
// If there is an according to need dose in the dosage it is not a (clean)
// temporary dosage.
- if(dosageTimes.containsAccordingToNeedDose())
+ if(dosageStructure.containsAccordingToNeedDose())
return false;
return true;
}
- private static boolean isOneTime(StructuredDosageWrapper dosageTimes) {
- boolean isSameDayDateInterval = dosageTimes.startsAndEndsSameDay();
+ private static boolean isOneTime(DosageStructureWrapper dosageStructure) {
+ boolean isSameDayDateInterval = dosageStructure.startsAndEndsSameDay();
// If we have and end date it must be the same day as the start date
- if(dosageTimes.getEndDateOrDateTime()!=null && !isSameDayDateInterval)
+ if(dosageStructure.getEndDateOrDateTime()!=null && !isSameDayDateInterval)
return false;
// We don't want to have a day 0 defined, as it contains only meaningful information
// if the dosage is given according to need
- if(dosageTimes.getDay(0)!=null)
+ if(dosageStructure.getDay(0)!=null)
return false;
// The dose must be defined for day 1
- DayWrapper day = dosageTimes.getDay(1);
+ DayWrapper day = dosageStructure.getDay(1);
if(day==null)
return false;
// There must be exactly one dose
@@ -101,7 +101,7 @@ private static boolean isOneTime(StructuredDosageWrapper dosageTimes) {
if(day.containsAccordingToNeedDose())
return false;
// If the dosage isn't iterated we are happy now
- if(dosageTimes.getIterationInterval()==0)
+ if(dosageStructure.getIterationInterval()==0)
return true;
// If the dosage is iterated the end date must be defined as the same day as the start day
return isSameDayDateInterval;
@@ -102,24 +102,38 @@ public static String unitToPlural(String s) {
else
return s;
}
+
+ public static String getUnit(DoseWrapper dose, String unit, String unitSingular, String unitPlural) {
+ if(unit!=null)
+ return correctUnit(dose, unit);
+ else
+ return chooseUnit(dose, unitSingular, unitPlural);
+ }
+
+ private static String correctUnit(DoseWrapper dose, String unit) {
+ if(hasPluralUnit(dose))
+ return unitToPlural(unit);
+ else
+ return unitToSingular(unit);
+ }
- public static String correctUnit(DoseWrapper dose, String unit) {
+ private static String chooseUnit(DoseWrapper dose, String unitSingular, String unitPlural) {
+ if(hasPluralUnit(dose))
+ return unitPlural;
+ else
+ return unitSingular;
+ }
+
+ private static boolean hasPluralUnit(DoseWrapper dose) {
if(dose.getDoseQuantity()!=null) {
- if(dose.getDoseQuantity().doubleValue()>1.0)
- return unitToPlural(unit);
- else
- return unitToSingular(unit);
+ return dose.getDoseQuantity().doubleValue()>1.0;
}
else if(dose.getMaximalDoseQuantity()!=null) {
- if(dose.getMaximalDoseQuantity().doubleValue()>1.0)
- return unitToPlural(unit);
- else
- return unitToSingular(unit);
+ return dose.getMaximalDoseQuantity().doubleValue()>1.0;
}
else {
- return unit;
+ return false;
}
}
-
}
@@ -27,7 +27,7 @@
import dk.medicinkortet.dosisstructuretext.vowrapper.DayWrapper;
import dk.medicinkortet.dosisstructuretext.vowrapper.DosageWrapper;
import dk.medicinkortet.dosisstructuretext.vowrapper.DoseWrapper;
-import dk.medicinkortet.dosisstructuretext.vowrapper.StructuredDosageWrapper;
+import dk.medicinkortet.dosisstructuretext.vowrapper.DosageStructureWrapper;
public class Validator {
@@ -39,18 +39,18 @@ public static void validate(DosageWrapper dosage) {
throw new IllegalArgumentException("The DosageStructure must only contain one child element");
if(dosage.isStructured())
- validate(dosage.getDosageTimes());
+ validate(dosage.getDosageStructure());
}
- public static void validate(StructuredDosageWrapper dosageTimes) {
- if(dosageTimes.getStartDateOrDateTime()==null)
+ public static void validate(DosageStructureWrapper dosageStructure) {
+ if(dosageStructure.getStartDateOrDateTime()==null)
throw new IllegalArgumentException("Start date or date time is required");
- if(dosageTimes.getUnit()==null)
+ if(!dosageStructure.hasUnitOrUnits())
throw new IllegalArgumentException("Unit is required");
- if(dosageTimes.getDays()==null || dosageTimes.getDays().size()==0)
+ if(dosageStructure.getDays()==null || dosageStructure.getDays().size()==0)
throw new IllegalArgumentException("At least one day is required");
int previousDayNumber = -1;
- for(DayWrapper day: dosageTimes.getDays()) {
+ for(DayWrapper day: dosageStructure.getDays()) {
if(day.getDayNumber() <= previousDayNumber)
throw new IllegalArgumentException("Day numbers must be ascending, found day numbers "+previousDayNumber+" and "+day.getDayNumber());
previousDayNumber = day.getDayNumber();
@@ -64,9 +64,9 @@ public static void validate(StructuredDosageWrapper dosageTimes) {
if(dose.getDoseQuantity()==null && ((dose.getMinimalDoseQuantity()==null && dose.getMaximalDoseQuantity()!=null) || (dose.getMinimalDoseQuantity()!=null && dose.getMaximalDoseQuantity()==null)))
throw new IllegalArgumentException("Doses must not contain a min-max quantity with open interval ends, found for "+dose.getLabel()+" dose day "+day.getDayNumber());
}
- if(dosageTimes.getIterationInterval()>0)
- if(day.getDayNumber()>dosageTimes.getIterationInterval())
- throw new IllegalArgumentException("If the iteration interval is not zero (i.e. the dose is iterated) the day number must not exceed the iteration interval, the iteration interval is "+dosageTimes.getIterationInterval()+" and a day number "+day.getDayNumber()+" was found");
+ if(dosageStructure.getIterationInterval()>0)
+ if(day.getDayNumber()>dosageStructure.getIterationInterval())
+ throw new IllegalArgumentException("If the iteration interval is not zero (i.e. the dose is iterated) the day number must not exceed the iteration interval, the iteration interval is "+dosageStructure.getIterationInterval()+" and a day number "+day.getDayNumber()+" was found");
// Remove doses with "0" dose quantity
ArrayList<DoseWrapper> toRemove = new ArrayList<DoseWrapper>();
@@ -24,45 +24,45 @@
import dk.medicinkortet.dosisstructuretext.vowrapper.DayWrapper;
import dk.medicinkortet.dosisstructuretext.vowrapper.DosageWrapper;
-import dk.medicinkortet.dosisstructuretext.vowrapper.StructuredDosageWrapper;
+import dk.medicinkortet.dosisstructuretext.vowrapper.DosageStructureWrapper;
public class DailyRepeatedConverterImpl extends LongTextConverterImpl {
@Override
public boolean canConvert(DosageWrapper dosage) {
- if(dosage.getDosageTimes()==null)
+ if(dosage.getDosageStructure()==null)
return false;
- StructuredDosageWrapper dosageTimes = dosage.getDosageTimes();
- if(dosageTimes.getIterationInterval()!=1)
+ DosageStructureWrapper dosageStructure = dosage.getDosageStructure();
+ if(dosageStructure.getIterationInterval()!=1)
return false;
- if(dosageTimes.getStartDateOrDateTime().equals(dosageTimes.getEndDateOrDateTime()))
+ if(dosageStructure.getStartDateOrDateTime().equals(dosageStructure.getEndDateOrDateTime()))
return false;
- if(dosageTimes.getDays().size()!=1)
+ if(dosageStructure.getDays().size()!=1)
return false;
- if(dosageTimes.getDays().get(0).getDayNumber()!=1)
+ if(dosageStructure.getDays().get(0).getDayNumber()!=1)
return false;
- if(!dosageTimes.allDosesHaveTheSameSupplText()) // Special case needed for 2008 NS as it may contain multiple texts
+ if(!dosageStructure.allDosesHaveTheSameSupplText()) // Special case needed for 2008 NS as it may contain multiple texts
return false;
return true;
}
@Override
public String doConvert(DosageWrapper dosage) {
- return convert(dosage.getDosageTimes());
+ return convert(dosage.getDosageStructure());
}
- public String convert(StructuredDosageWrapper dosageTimes) {
+ public String convert(DosageStructureWrapper dosageStructure) {
StringBuilder s = new StringBuilder();
- appendDosageStart(s, dosageTimes);
+ appendDosageStart(s, dosageStructure);
s.append(" og gentages hver dag:\n");
s.append(INDENT+"Doseringsforløb:\n");
- appendDays(s, dosageTimes);
+ appendDays(s, dosageStructure);
return s.toString();
}
@Override
- protected String makeDaysLabel(StructuredDosageWrapper dosageTimes, DayWrapper day) {
+ protected String makeDaysLabel(DosageStructureWrapper dosageStructure, DayWrapper day) {
return "";
}
Oops, something went wrong.

0 comments on commit 4ea8163

Please sign in to comment.