ParacetamolRule implements MedicationRule<ParacetamolRuleParameters, ParacetamolRuleResult> { ParacetamolRuleResult calculateRuleResult( final double dose, final double patientWeight, final Long patientAge, final List<NamedExternalDto> medications, final Locale locale) { final ParacetamolRuleResult result = new ParacetamolRuleResult(); result.setMedications(medications); final boolean patientUnderaged = isPatientUnderaged(patientAge); final double underageDoseLimit = getUnderageDoseLimit(patientWeight); final boolean underageOverdose = patientUnderaged && dose > underageDoseLimit; final double adultDoseLimit = getAdultDoseLimit(patientWeight); final boolean adultOverdose = dose > adultDoseLimit; result.setQuantityOk(!underageOverdose && !adultOverdose); result.setAdultRulePercentage(Math.ceil(dose / adultDoseLimit * 100)); result.setUnderageRulePercentage(patientUnderaged ? Math.ceil(dose / underageDoseLimit * 100) : null); if (patientUnderaged && result.getUnderageRulePercentage() > result.getAdultRulePercentage()) { result.setRule(getUnderageRuleDescription(locale)); } if (adultOverdose) { result.setRule(getAdultRuleDescription(locale, adultDoseLimit)); } return result; }  @Required void setMedicationsOpenEhrDao(final MedicationsOpenEhrDao medicationsOpenEhrDao); @Required void setMedicationsDao(final MedicationsDao medicationsDao); @Required void setMedicationsBo(final MedicationsBo medicationsBo); @Required void setMedicationsTasksProvider(final MedicationsTasksProvider medicationsTasksProvider); @Required void setMedicationDataProvider(final MedicationFromEhrConverter.MedicationDataProvider medicationDataProvider); @Required void setMedicationsValueHolder(final ValueHolder<Map<Long, MedicationHolderDto>> medicationsValueHolder); @Required void setIngredientCalculator(final IngredientCalculator ingredientCalculator); @Required void setAdministrationFromEhrConverter(final AdministrationFromEhrConverter administrationFromEhrConverter); @Required void setAdministrationUtils(final AdministrationUtils administrationUtils); @Override ParacetamolRuleResult applyRule(
      @Nonnull final ParacetamolRuleParameters parameters,
      @Nonnull final DateTime actionTimestamp,
      @Nonnull final Locale locale);  }
@Test public void testCalculateParacetamolRuleResultForAdultPatient() { final long patientAgeInYears = 20L; final double patientWeight = 20.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 2000.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertTrue(paracetamolRuleResult.isQuantityOk()); }
@Test public void testCalculateParacetamolRuleResultUnderagedPatient() { final long patientAgeInYears = 2L; final double patientWeight = 20.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 2000.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertTrue(paracetamolRuleResult.getRule().startsWith("60mg/")); assertEquals(167, paracetamolRuleResult.getUnderageRulePercentage().intValue()); assertTrue(!paracetamolRuleResult.isQuantityOk()); }
@Test public void testCalculateParacetamolRuleResultUnderagedPatient2() { final long patientAgeInYears = 2L; final double patientWeight = 10.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 2000.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertTrue(paracetamolRuleResult.getRule().startsWith("60mg/")); assertEquals(334, paracetamolRuleResult.getUnderageRulePercentage().intValue()); assertTrue(!paracetamolRuleResult.isQuantityOk()); }
@Test public void testCalculateParacetamolRuleResult100Percente() { final long patientAgeInYears = 20L; final double patientWeight = 60.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 4000.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertEquals(100, paracetamolRuleResult.getAdultRulePercentage().intValue()); assertTrue(paracetamolRuleResult.isQuantityOk()); }
@Test public void testCalculateParacetamolRuleResultNear100Percente() { final long patientAgeInYears = 20L; final double patientWeight = 60.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 4001.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertEquals(101, paracetamolRuleResult.getAdultRulePercentage().intValue()); assertTrue(!paracetamolRuleResult.isQuantityOk()); }
@Test public void testCalculateParacetamolRuleResultUnderagedPatient3() { final long patientAgeInYears = 2L; final double patientWeight = 10.0; final double patientHeight = 150.0; final DateTime actionTimeStamp = new DateTime(2016, 1, 20, 12, 0, 0); final Locale locale = new Locale("en_GB"); final double dailyDosage = 600.0; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.calculateRuleResult( dailyDosage, patientWeight, patientAgeInYears, Collections.emptyList(), locale); assertNotNull(paracetamolRuleResult); assertTrue(paracetamolRuleResult.isQuantityOk()); }