@Test public final void testApplyChanges() throws InvalidIdentifierException { final RiskModel riskModel = createRiskModel("Thoracic 30-day Mortality"); final EditRiskModel editRiskModel = EditRiskModel.fromRiskModel(riskModel, fModelService); final ImmutableList<EditModelTerm> newTerms = ImmutableList.of( EditModelTerm.forConstant(0.23f), EditModelTerm.forVariable("dnr", 12.3f), EditModelTerm.forRule(SampleModels.ageAndFsRule().getDisplayName(), 0.5f)); final HashSet<ModelTerm> expectedTerms = new HashSet<>(); for (final EditModelTerm newTerm : newTerms) { expectedTerms.add(newTerm.build(fModelService)); } editRiskModel.setModelName("NewModelName"); editRiskModel.getTerms().clear(); editRiskModel.getTerms().addAll(newTerms); assertEquals("NewModelName", editRiskModel.getModelName()); assertEquals(DisplayNameConditions.DISPLAY_NAME_MAX, editRiskModel.getMaxDisplayNameLength()); editRiskModel.applyChanges(riskModel, fModelService); assertEquals("NewModelName", riskModel.getDisplayName()); assertEquals(expectedTerms, riskModel.getTerms()); }
@Test public final void testCalculateDependentModels() { // Setup final BooleanVariable var = SampleModels.dnrVariable(); // Use an EditBooleanVar to test since it is a very basic // implementation of EditBaseVar. final EditBaseVar ev = new EditBooleanVar(var, fModelService); // Verification assertEquals(ImmutableSet.of(fModelService.getThoracicModel()), ev.getDependentModels()); }
@Test public final void testCardiacAge() { final DiscreteNumericalVariable var = SampleModels.cardiacAgeVariable(); final Patient patient = SampleCalculations.dummyPatientWithVitals(1); final Collection<DiscreteNumericalVariable> vars = ImmutableSet.of(var); // Use VariableEntry to generate the expected dynamic values. final VariableEntry expected = new VariableEntry(vars) .putDynamicValue( VariableEntry.makeNumericalInputName(var.getKey()), String.valueOf(patient.getAge())); verifyRetrievedValue(vars, patient, expected.getDynamicValues()); }
/** * This method returns a DiscreteNumericalVariable with the specified key and retriever, but with * dummy information for the other fields in the variable. * * @param key the key to use for the variable * @param retriever the ValueRetriever for this variable * @return the constructed DiscreteNumericalVariable */ private DiscreteNumericalVariable makeDiscreteNumerical( final String key, final ValueRetriever retriever) { final Category wbcWnl = new Category(new MultiSelectOption("WNL"), 11.0f, true); final Category wbcHigh = new Category(new MultiSelectOption(">11.0"), Float.POSITIVE_INFINITY, false); final DiscreteNumericalVariable var = new DiscreteNumericalVariable( "Generic Display Name", SampleModels.labVariableGroup(), ImmutableSet.of(wbcWnl, wbcHigh), key); var.setValidRange(new NumericalRange(2.0f, true, 50.0f, true)); var.setUnits("generic units"); var.setRetriever(retriever); return var; }
/** * Constructs a sample RiskModel for our testing. * * @param name * @return */ private RiskModel createRiskModel(String name) { final ProcedureVariable procedureVar = SampleModels.procedureVariable(); final NumericalVariable ageVar = SampleModels.ageVariable(); final DiscreteNumericalVariable wbcVar = SampleModels.wbcVariable(); final MultiSelectVariable fsVar = SampleModels.functionalStatusVariable(); // Note: intentionally including this edge-case variable to test ordering. final BooleanVariable wbcIsNormalVar = SampleModels.wbcIsNormalVariable(); final Set<DerivedTerm> derivedTerms = new HashSet<DerivedTerm>(); derivedTerms.add(new DerivedTerm(6.0f, fTestRule)); return SampleModels.makeSampleRiskModel( name, derivedTerms, procedureVar, wbcIsNormalVar, ageVar, wbcVar, fsVar); }
/** Tests the {@link EditRiskModel} class. */ public class EditRiskModelTest { private final MockModelService fModelService = new MockModelService(); private final Rule fTestRule = SampleModels.ageAndFsRule(); /** * Constructs a sample RiskModel for our testing. * * @param name * @return */ private RiskModel createRiskModel(String name) { final ProcedureVariable procedureVar = SampleModels.procedureVariable(); final NumericalVariable ageVar = SampleModels.ageVariable(); final DiscreteNumericalVariable wbcVar = SampleModels.wbcVariable(); final MultiSelectVariable fsVar = SampleModels.functionalStatusVariable(); // Note: intentionally including this edge-case variable to test ordering. final BooleanVariable wbcIsNormalVar = SampleModels.wbcIsNormalVariable(); final Set<DerivedTerm> derivedTerms = new HashSet<DerivedTerm>(); derivedTerms.add(new DerivedTerm(6.0f, fTestRule)); return SampleModels.makeSampleRiskModel( name, derivedTerms, procedureVar, wbcIsNormalVar, ageVar, wbcVar, fsVar); } @Test public final void testApplyChanges() throws InvalidIdentifierException { final RiskModel riskModel = createRiskModel("Thoracic 30-day Mortality"); final EditRiskModel editRiskModel = EditRiskModel.fromRiskModel(riskModel, fModelService); final ImmutableList<EditModelTerm> newTerms = ImmutableList.of( EditModelTerm.forConstant(0.23f), EditModelTerm.forVariable("dnr", 12.3f), EditModelTerm.forRule(SampleModels.ageAndFsRule().getDisplayName(), 0.5f)); final HashSet<ModelTerm> expectedTerms = new HashSet<>(); for (final EditModelTerm newTerm : newTerms) { expectedTerms.add(newTerm.build(fModelService)); } editRiskModel.setModelName("NewModelName"); editRiskModel.getTerms().clear(); editRiskModel.getTerms().addAll(newTerms); assertEquals("NewModelName", editRiskModel.getModelName()); assertEquals(DisplayNameConditions.DISPLAY_NAME_MAX, editRiskModel.getMaxDisplayNameLength()); editRiskModel.applyChanges(riskModel, fModelService); assertEquals("NewModelName", riskModel.getDisplayName()); assertEquals(expectedTerms, riskModel.getTerms()); } @Test public final void testGetTermSummaries() { /* Setup */ final RiskModel riskModel = createRiskModel("Thoracic 30-day Mortality"); final float constant = 0.34f; riskModel.setConstantTerm(new ConstantTerm(constant)); final EditRiskModel editRiskModel = EditRiskModel.fromRiskModel(riskModel, fModelService); // Constant first, then the Rules and then the rest final ImmutableList<ModelTermSummary> expectedSummaries = ImmutableList.of( new ModelTermSummary("Constant", "", constant), new ModelTermSummary(fTestRule.getDisplayName(), "Rule", 6.0f), new ModelTermSummary("Age", "Numerical", 2.0f), new ModelTermSummary("Functional Status = Independent", "Multi-Select", 3.0f), new ModelTermSummary("Functional Status = Partially dependent", "Multi-Select", 3.0f), new ModelTermSummary("Functional Status = Totally dependent", "Multi-Select", 3.0f), new ModelTermSummary("Procedure", "Procedure (RVU Multiplier)", 1.0f), new ModelTermSummary("White Blood Count = WNL", "Discrete Numerical", 4.0f), new ModelTermSummary("White Blood Count = >11.0", "Discrete Numerical", 4.0f), new ModelTermSummary("White Blood Count is Normal", "Checkbox", 5.0f)); /* Behavior */ ImmutableList<ModelTermSummary> actualSummaries = editRiskModel.makeTermSummaries(fModelService); /* Verification */ assertEquals(expectedSummaries, actualSummaries); } }