parametric incentives ¶
Shift incentives can hold configurable parameters to be managed via UI. The configured incentive data will be attached as ‘metadata’ to the shift_incentive record, and inspectable at runtime for UI/behaviour changes.
UI ¶
The ShiftEditor.vue uses IncentiveSwitch.vue component for toggling incentives ‘on’ or ‘off’.
During IncentiveSwitch setup, the developer can add specific configurable incentive blocks to be dynamically available.
import flex_time from '../Incentive/flex_time.vue';
...
components: { flex_time },
If an available incentive has the internal code ‘flex_time’, the flex_time.vue component will be shown in the UI.
<component
:is="shiftIncentive.code"
:shift-incentive="shiftIncentive"
:shift="shift"
@changed="incentiveChanged"
/>
This is achieved with the ‘component’ dynamic functionality in Vue2. The ‘incentiveChanged’ method is invoked on any @changed events thrown in the specified component.
The ‘incentiveChanged’ method in IncentiveSwitch passes the event up to the parent
incentiveChanged(shiftIncentiveMetadata) {
this.shiftIncentive.metadata = shiftIncentiveMetadata;
this.$emit('incentiveChanged', shiftIncentiveMetadata);
},
ShiftEditor.vue has incentiveChanged method which catches the incoming data and reformats it as serialized JSON hidden field (updateRealIncentives).
incentiveChanged(shiftIncentiveMetadata) {
// use of Vue.set forces rerender in the <incentive-switch> loop
// whereas this.shift.incentives[item.code] = item did not
const filteredIncentiveMetadata = { ...shiftIncentiveMetadata };
delete filteredIncentiveMetadata.incentive;
// avoid circular JSON - shiftIncentive object doesn't need a full incentive
Vue.set(this.shift.incentives[filteredIncentiveMetadata.code], 'metadata', filteredIncentiveMetadata);
this.updateRealIncentives();
},
metadata ¶
The shift_incentive.metadata object holds any arbitrary key/value pairs needed for the specific incentive in question. For ‘flex_time’, we hold ‘start’ and ‘end’ and ‘min_hours’ keys with hospital supplied values. The data can be inspected in the vet portal to modify the UI/take process as needed (prevent user from taking shift without the flex hour time matching the required parameters, for example).
mail ¶
Shift model has ‘renderIncentives’ which is used in mail templates to render out a list of related incentives.
The method has been expanded to attempt to render out parametric incentive
data, as needed. ShiftIncentiveService is passed a prepared list of shift incentive
data, and each ‘code’ is inspected. If there is a custom method render_
Example
public function render_flex_time($metadata): string
{
$string = '';
$string .= 'From '.$metadata['start'];
$string .= ' through '.$metadata['end'];
$string .= ' with minimum '.($metadata['min_hours'] ?? 'n/a').' hours';
return $string;
}