DiseaseComparison

Reads two disease ListObjects and answers five Checking bundles: the variables only in the first disease, the variables only in the second, the shared variables whose choice sets differ, the shared variables whose choice sets match, and the counts over the two tables.

WHAT IS COMPARED

A disease table carries Variable Order, Variable Name, Variable Section, Main Label, Choice, Choice Values and Status. The name column keys the comparison. Names are matched without regard to case and surrounding spaces. The Choice Values cell is split on " | " and the pieces are compared as a set, without regard to case. A variable whose Choice cell is empty carries no choices, so two such variables are equivalent.

LOOKUPS

The name index of each table is a keyed Collection. Dictionary is missing on Mac Excel. The lists are BetterArray based at 1.

Internal members (not exported)

Factory

Create #

Build a comparison over two disease tables.

Signature:

Public Function Create(ByVal firstTable As ListObject, ByVal secondTable As ListObject, _
                       Optional ByVal firstName As String = "Disease 1", _
                       Optional ByVal secondName As String = "Disease 2") As DiseaseComparison

Parameters:

Returns: DiseaseComparison ready to compare.


Comparison

Compare #

Read both tables and build the five bundles.

Signature:

Public Sub Compare()

Runs once. Every accessor calls it, so a caller can read the bundles straight after Create.


Bundles

OnlyInFirst #

Variables of the first disease the second has no row for.

Signature:

Public Property Get OnlyInFirst() As Checking

OnlyInSecond #

Variables of the second disease the first has no row for.

Signature:

Public Property Get OnlyInSecond() As Checking

DifferingChoices #

Shared variables whose choice sets differ, with the values each side lacks.

Signature:

Public Property Get DifferingChoices() As Checking

EquivalentVariables #

Shared variables whose choice sets match.

Signature:

Public Property Get EquivalentVariables() As Checking

Statistics #

The counts over the two tables.

Signature:

Public Property Get Statistics() As Checking

Reports #

The five bundles in report order, based at 1.

Signature:

Public Property Get Reports() As BetterArray

Only in 1, only in 2, differing choices, equivalent, statistics.


Counts

FirstCount #

Number of variables in the first disease.

Signature:

Public Property Get FirstCount() As Long

SecondCount #

Number of variables in the second disease.

Signature:

Public Property Get SecondCount() As Long

SharedCount #

Number of variable names both diseases carry.

Signature:

Public Property Get SharedCount() As Long

OnlyInFirstCount #

Number of variables only the first disease carries.

Signature:

Public Property Get OnlyInFirstCount() As Long

OnlyInSecondCount #

Number of variables only the second disease carries.

Signature:

Public Property Get OnlyInSecondCount() As Long

MatchingCount #

Number of shared variables whose choice sets match.

Signature:

Public Property Get MatchingCount() As Long

DifferingCount #

Number of shared variables whose choice sets differ.

Signature:

Public Property Get DifferingCount() As Long

EquivalentShare #

Share of the shared variables that are equivalent, between 0 and 1.

Signature:

Public Property Get EquivalentShare() As Double

Answers 0 when the two diseases share no variable.


Reading

ReadTable #

Read the columns a comparison needs into memory.

Signature:

Private Sub ReadTable(ByVal table As ListObject, ByRef data As TDiseaseData)

ColumnValues #

Read one column of the table as a 2D array based at 1.

Signature:

Private Function ColumnValues(ByVal table As ListObject, ByVal header As String, ByVal rowTotal As Long) As Variant

FindColumn #

Find a column by header without regard to case.

Signature:

Private Function FindColumn(ByVal table As ListObject, ByVal header As String) As ListColumn

SplitChoices #

Split a Choice Values cell into a list of trimmed values.

Signature:

Private Function SplitChoices(ByVal choiceName As String, ByVal choiceList As String) As BetterArray

A variable whose Choice cell is empty carries no choices, whatever the values cell holds. Empty pieces are dropped. The list is based at 1.


Collecting

CollectMissing #

Add every variable of one disease the other has no row for.

Signature:

Private Sub CollectMissing(ByRef owner As TDiseaseData, ByRef other As TDiseaseData, _
                           ByVal bundle As Checking, ByVal keyPrefix As String)

CollectShared #

Walk the shared names and sort each into differing or equivalent.

Signature:

Private Sub CollectShared()

AddDifference #

Add the entries of one differing variable.

Signature:

Private Sub AddDifference(ByVal rowIndex As Long, ByVal differingCounter As Long, _
                          ByVal missingFromSecond As BetterArray, ByVal missingFromFirst As BetterArray)

One entry names the variable, then one entry per value in the first disease and missing from the second, then one per value in the second and missing from the first.


CollectStatistics #

Write the counts as one bundle.

Signature:

Private Sub CollectStatistics()

The counts are read from the state here. The public count properties call Compare, and Compare is still running when this sub is called.


Set Helpers

ValuesMissing #

Values of the first list the second list lacks, without regard to case.

Signature:

Private Function ValuesMissing(ByVal source As BetterArray, ByVal other As BetterArray) As BetterArray

VariableWhere #

The "Where?" text of a variable: its name and its section.

Signature:

Private Function VariableWhere(ByRef data As TDiseaseData, ByVal rowIndex As Long) As String

Collection Helpers

AddKeyIfMissing #

Add a key to a collection when it is missing.

Signature:

Private Sub AddKeyIfMissing(ByVal index As Collection, ByVal key As String)

IndexHas #

Test whether a collection carries a key.

Signature:

Private Function IndexHas(ByVal index As Collection, ByVal key As String) As Boolean

IndexRow #

Read the row stored under a key, 0 when the key is missing.

Signature:

Private Function IndexRow(ByVal index As Collection, ByVal key As String) As Long

NewList #

A BetterArray based at 1.

Signature:

Private Function NewList() As BetterArray

Every list here takes pushed values, so it is based at 1 first.


Used in (3 file(s))