ParacetamolRule implements MedicationRule<ParacetamolRuleParameters, ParacetamolRuleResult> { @Override public ParacetamolRuleResult applyRule( @Nonnull final ParacetamolRuleParameters parameters, @Nonnull final DateTime actionTimestamp, @Nonnull final Locale locale) { Preconditions.checkNotNull(parameters, "parameters must not be null"); Preconditions.checkNotNull(actionTimestamp, "actionTimestamp must not be null"); Preconditions.checkNotNull(locale, "locale must not be null"); final MedicationParacetamolRuleType medicationParacetamolRuleType = parameters.getMedicationParacetamolRuleType(); if (medicationParacetamolRuleType == MedicationParacetamolRuleType.FOR_THERAPY) { final TherapyDto therapyDto = ((ParacetamolRuleForTherapyParameters)parameters).getTherapyDto(); final List<MedicationDataDto> medicationDataDtoList = ((ParacetamolRuleForTherapyParameters)parameters).getMedicationDataDtoList(); Preconditions.checkNotNull(therapyDto, "therapyDto must not be null"); Preconditions.checkNotNull(medicationDataDtoList, "medicationDataDtoList must not be null"); Preconditions.checkArgument(!medicationDataDtoList.isEmpty(), "medicationDataDtoList must not be empty"); return applyRuleForTherapy( therapyDto, medicationDataDtoList, parameters.getPatientWeight(), parameters.getPatientAgeInYears(), locale); } else if (medicationParacetamolRuleType == MedicationParacetamolRuleType.FOR_THERAPIES) { final List<TherapyDto> therapies = ((ParacetamolRuleForTherapiesParameters)parameters).getTherapies(); final Interval searchInterval = ((ParacetamolRuleForTherapiesParameters)parameters).getSearchInterval(); final String patientId = ((ParacetamolRuleForTherapiesParameters)parameters).getPatientId(); Preconditions.checkNotNull(therapies, "therapies must not be null"); Preconditions.checkNotNull(searchInterval, "searchInterval must not be null"); Preconditions.checkNotNull(patientId, "patientId must not be null"); return applyRuleForTherapies( therapies, parameters.getPatientWeight(), parameters.getPatientAgeInYears(), actionTimestamp, patientId, locale); } else if (medicationParacetamolRuleType == MedicationParacetamolRuleType.FOR_ADMINISTRATION) { final TherapyDoseDto therapyDoseDto = ((ParacetamolRuleForAdministrationParameters)parameters).getTherapyDoseDto(); final String administrationId = ((ParacetamolRuleForAdministrationParameters)parameters).getAdministrationId(); final String taskId = ((ParacetamolRuleForAdministrationParameters)parameters).getTaskId(); final TherapyDto therapyDto = ((ParacetamolRuleForAdministrationParameters)parameters).getTherapyDto(); final Interval searchInterval = ((ParacetamolRuleForAdministrationParameters)parameters).getSearchInterval(); final String patientId = ((ParacetamolRuleForAdministrationParameters)parameters).getPatientId(); Preconditions.checkNotNull(searchInterval, "searchInterval must not be null"); Preconditions.checkNotNull(patientId, "patientId must not be null"); return applyRuleForAdministration( therapyDoseDto, administrationId, taskId, therapyDto, parameters.getPatientWeight(), parameters.getPatientAgeInYears(), searchInterval, actionTimestamp, patientId, locale); } else { throw new IllegalArgumentException("Not supported medication paracetamol rule type"); } }  @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(expected = NullPointerException.class) public void testApplyRuleNoNullParameters() throws Exception { final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( new ParacetamolRuleParameters(), new DateTime(), null); }
@Test(expected = NullPointerException.class) public void testApplyRuleNoNullParameters2() throws Exception { final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( new ParacetamolRuleParameters(), null, new Locale("si Sl")); }
@Test(expected = NullPointerException.class) public void testApplyRuleNoNullParameters3() throws Exception { final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( null, new DateTime(), new Locale("si Sl")); }
@Test(expected = NullPointerException.class) public void testApplyRuleForTherapyNoNullParameters() throws Exception { final ParacetamolRuleForTherapyParameters parameters = new ParacetamolRuleForTherapyParameters(); parameters.setMedicationParacetamolRuleType(MedicationParacetamolRuleType.FOR_THERAPY); parameters.setMedicationDataDtoList(Collections.singletonList(new MedicationDataDto())); final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( parameters, new DateTime(), new Locale("si Sl")); }
@Test(expected = NullPointerException.class) public void testApplyRuleForTherapyNoNullParameters3() throws Exception { final ParacetamolRuleForTherapyParameters parameters = new ParacetamolRuleForTherapyParameters(); parameters.setMedicationParacetamolRuleType(MedicationParacetamolRuleType.FOR_THERAPY); parameters.setMedicationDataDtoList(Collections.emptyList()); final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( parameters, new DateTime(), new Locale("si Sl")); }
@Test(expected = NullPointerException.class) public void testApplyRuleForTherapiesNoNullParameters() throws Exception { final ParacetamolRuleForTherapiesParameters parameters = new ParacetamolRuleForTherapiesParameters(); parameters.setMedicationParacetamolRuleType(MedicationParacetamolRuleType.FOR_THERAPIES); parameters.setTherapies(Collections.emptyList()); parameters.setSearchInterval(new Interval(new DateTime(), new DateTime())); final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( parameters, new DateTime(), new Locale("si Sl")); }
@Test(expected = NullPointerException.class) public void testApplyRuleForTherapiesNoNullParameters3() throws Exception { final ParacetamolRuleForTherapiesParameters parameters = new ParacetamolRuleForTherapiesParameters(); parameters.setMedicationParacetamolRuleType(MedicationParacetamolRuleType.FOR_THERAPIES); parameters.setPatientId("1"); parameters.setTherapies(Collections.emptyList()); final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( parameters, new DateTime(), new Locale("si Sl")); }
@Test(expected = IllegalArgumentException.class) public void testApplyRuleWithUnknownRuleType() throws Exception { final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule( new ParacetamolRuleParameters(), new DateTime(), new Locale("si Sl")); }
@Test public void testApplyRuleWithNoPatientWeight() throws Exception { final Locale locale = new Locale("en"); final ParacetamolRuleForTherapyParameters parameters = new ParacetamolRuleForTherapyParameters(); parameters.setMedicationParacetamolRuleType(MedicationParacetamolRuleType.FOR_THERAPY); parameters.setMedicationDataDtoList(Collections.singletonList(new MedicationDataDto())); parameters.setTherapyDto(new ConstantComplexTherapyDto()); final String errorMessage = "Patient weight is not known, could not apply paracetamol rule."; final ParacetamolRuleResult paracetamolRuleResult = paracetamolRule.applyRule(parameters, new DateTime(), locale); assertTrue(!paracetamolRuleResult.isQuantityOk()); assertEquals(errorMessage, paracetamolRuleResult.getErrorMessage()); }