# Instance-Based Learning Following Physician Reasoning for Assistance during Medical Consultation
## 5 Medical Consultation Flows
### Selecting an Already Defined Case Type  
The selection of an already defined case type allows the physician to efficiently reuse previously registered information. Algorithm 3 details how to apply a case type during a medical consultation. Algorithm 3 starts by evaluating the _chronic_ attribute of a case type \(CT^{M}\) (lines 1-2). If the case type is identified as chronic, a specific method for applying a chronic case is called (line 3). Otherwise, all elements referenced in the _components_ attribute are determined, and its units of thought are marked as in use according _setUnitsInUse_ auxiliary procedure. The auxiliary procedure encapsulates the logic of how units of thought are activated. The algorithm continues by showing all units marked as in use, and highlighting the units that are exclusive for physician use (lines 8-9). Finally, each message agent that has \(CT^{M}\) as a trigger condition is presented to the physician (line 10). Procedure _setUnitsInUse_ iterates over all conceptual elements of a case type (line 12). All units included in each conceptual element are identified (line 13), and each unit of thought is marked as in use according the values of its attributes (lines 14-25). ```
1:CT\({}^{M}\) = \(<\)name, components, chronic, chronicComponents\(>\) is selected
2:if chronic then
3: applyChronicCaseType(P, CT\({}^{M}\)) (Algorithm 4)
4:else
5: elements \(\leftarrow\) getAllElementsIncludedIn(components)
6: setUnitsInUse(elements,CT\({}^{M}\))
7:endif
8: Show all units with _issue_ attribute in true
9: Highlight all units with _expl_ attribute in true
10: Show message agents that have CT\({}^{M}\) as a trigger condition
11:proceduresetUnitsInUse(elements,CT\({}^{M}\))
12:for element in elements do
13: units \(\leftarrow\) getAllUnitsIncludedIn(elements)
14:for unit in units do
15:switch ()
16:case unit.exph:
17: unit.inuse = true
18:case isTime(unit.ctSchedule, CT\({}^{M}\));
19: unit.inuse = true
20:case element.display \(\wedge\) isEmpty(unit.ctSchedule);
21: unit.inuse = true
22:case otherwise:
23: unit.inuse = false
24:endswitch
25:endfor
26:endfor
```  
**Algorithm 3** applyCaseType(\(P,CT^{M}\))  
```
1:CT\({}^{M}\) = \(<\)name, components, chronic, chronicComponents\(>\) is selected
2:if chronic then
3: applyChronicCaseType(P, CT\({}^{M}\)) (Algorithm 4)
4:else
5: elements \(\leftarrow\) getAllElementsIncludedIn(components)
6: setUnitsInUse(elements,CT\({}^{M}\))
7:endif
8: Show all units with _issue_ attribute in true
9: Highlight all units with _expl_ attribute in true
10: Show message agents that have CT\({}^{M}\) as a trigger condition
11:proceduresetUnitsInUse(elements,CT\({}^{M}\))
12:for element in elements do
13: units \(\leftarrow\) getAllUnitsIncludedIn(elements)
14:for unit in units do
15:switch ()
16:case unit.exph:
17: unit.inuse = true
18:case isTime(unit.ctSchedule, CT\({}^{M}\));
19: unit.inuse = true
20:case element.display \(\wedge\) isEmpty(unit.ctSchedule);
21: unit.inuse = true
22:case otherwise:
23: unit.inuse = false
24:endswitch
25:endfor

### Chronic Patients Flow

A case type \(CT^{M}\) can be marked as a chronic case type \(CT^{M}_{chron}\) at any time. When a \(CT^{M}_{chron}\) is marked as chronic, its _chron_ attribute is activated and its _chronicComponents_ attribute is initialized with an empty set. The chronic components are defined the first time that the case type is used to monitor a chronic patient. Algorithm 4 details how a physician can apply a chronic case type \(CT^{M}_{chron}\). Algorithm 4 analyzes if it is the first time that a chronic case type \(CT^{M}_{chron}\) is used with a patient being evaluated (lines 1-2). In that case, elements referenced in usual conceptual components are determined, and its units of thought are activated by calling _setUnitsInUse_ procedure (lines 3-4).