Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 1x 41x 41x 41x 41x 41x 41x 41x 1x 9x 2x 2x 7x 7x 7x 9x 48x 48x 41x 48x 7x 7x 48x 9x 3x 3x 9x 3x 3x 3x 4x 4x 1x 168x 168x 168x 168x 168x 168x 168x 168x 168x 9x 9x 9x 168x 62x 62x 97x 97x 182x 182x 182x 182x 182x 182x 182x 182x 97x 97x 156x 86x 86x 11x 11x 11x 143x 7x 7x 4x 4x 9x 9x 8x 8x 9x 9x 9x 4x 4x 4x 4x 8x 7x 7x 8x 1x 1x 1x 8x 8x 4x 4x 4x | /**
* Utility functions for handling infoForAllAppointments functionality
*/
/**
* Cleans provider names by removing dashes, commas, numbers, and extra whitespace
*/
export const cleanProviderName = (name: string): string => {
return name
.replace(/[-–—]/g, " ") // Replace various types of dashes with spaces
.replace(/[,;]/g, " ") // Replace commas and semicolons with spaces
.replace(/\d+/g, " ") // Replace numbers with spaces
.replace(/\s+/g, " ") // Replace multiple spaces with single space
.trim(); // Remove leading/trailing whitespace
};
/**
* Optimizes provider names by removing common prefixes when multiple providers share the same info
*/
export const optimizeProviderNames = (providerNames: string[]): string => {
if (providerNames.length <= 1) {
return cleanProviderName(providerNames[0] || "");
}
// Clean all provider names first
const cleanedNames = providerNames.map(cleanProviderName);
// Find the longest common prefix
const first = cleanedNames[0];
let commonPrefix = "";
for (let i = 0; i < first.length; i++) {
const char = first[i];
if (cleanedNames.every((name) => name[i] === char)) {
commonPrefix += char;
} else {
break;
}
}
// If we found a meaningful common prefix (at least 3 characters and ends with a space)
if (commonPrefix.length >= 3 && commonPrefix.endsWith(" ")) {
const prefix = commonPrefix.trim();
const suffixes = cleanedNames.map((name) =>
name.substring(commonPrefix.length)
);
return `${prefix} ${suffixes.join(", ")}`;
}
// If no meaningful common prefix, return as is
return cleanedNames.join(", ");
};
/**
* Interface for provider info data
*/
export interface ProviderInfo {
id?: string | number;
name?: string;
scope?: {
infoForAllAppointments?: string | null;
};
}
/**
* Generates HTML for availability info based on selected providers
*/
export const generateAvailabilityInfoHtml = (
selectedProviders: { [id: string]: boolean },
selectableProviders: ProviderInfo[] | undefined,
selectedProvider: ProviderInfo | undefined,
sanitizeHtml: (html: string) => string
): string => {
// Get all selected providers
const selectedProviderIds = Object.keys(selectedProviders).filter(
(id) => selectedProviders[id]
);
// If no providers are selected but we have a selectedProvider, use that
if (selectedProviderIds.length === 0 && selectedProvider) {
const info = selectedProvider.scope?.infoForAllAppointments || "";
return info && info.trim() ? sanitizeHtml(info.trim()) : "";
}
if (selectedProviderIds.length === 0) {
return "";
}
// Get all selected providers with their info
const selectedProvidersWithInfo = selectedProviderIds
.map((id) => {
const provider = selectableProviders?.find(
(p) => p.id?.toString() === id
);
return {
id: provider?.id,
name: provider?.name,
info: provider?.scope?.infoForAllAppointments || "",
};
})
.filter((provider) => provider.info.trim() !== "");
if (selectedProvidersWithInfo.length === 0) {
return "";
}
// If all providers have the same info, show it without location names
const uniqueInfos = [
...new Set(selectedProvidersWithInfo.map((p) => p.info.trim())),
];
if (uniqueInfos.length === 1) {
return sanitizeHtml(uniqueInfos[0]);
}
// If providers have different info, group them by info and show with provider names
const infoGroups: { [info: string]: string[] } = {};
selectedProvidersWithInfo.forEach((provider) => {
const info = provider.info.trim();
if (!infoGroups[info]) {
infoGroups[info] = [];
}
if (provider.name) {
infoGroups[info].push(provider.name);
}
});
// Generate HTML with provider names and info
let html = "";
let isFirst = true;
Object.entries(infoGroups).forEach(([info, providerNames]) => {
if (providerNames.length === 1) {
const cleanedName = cleanProviderName(providerNames[0]);
html += `<h3${isFirst ? ' class="first-provider"' : ""}>${sanitizeHtml(cleanedName)}</h3>`;
} else {
const optimizedNames = optimizeProviderNames(providerNames);
html += `<h3${isFirst ? ' class="first-provider"' : ""}>${sanitizeHtml(optimizedNames)}</h3>`;
}
html += `<div>${sanitizeHtml(info)}</div>`;
isFirst = false;
});
return sanitizeHtml(html);
};
|