Utility Model
Overview
The utility model represents a toolbox of helpful functions that are used internally by Clinical Office components and services, but also available for any use you may have. The list of available functions increases on a regular basis, so please check back for updates.
Import
Any function you use in your MPage must be specifically imported into the component or service it is being used in.
e.g.
import { inList, camelWords } from '@clinicaloffice/mpage-developer';
Methods
_window(): anyReturns a reference to the window containing the DOM document.
altReplacer(key: any, value: any): anyUsed by the MPage Service when converting JavaScript objects to JSON and only active when the public variable alternateReplacer is set to true in the MPage Service. The altReplacer is different from the replacer function in that it converts all numerical array values to floating point numbers regardless of the column name.
asciiToHex(asciiString: string): stringConverts Ascii text to a hexadecimal string.
camelWords(camelString: string): stringConverts a camel word string into a human-readable string. Primarily used by the MPage Table component to convert the JavaScript field names into column titles. For example, camelWords('patientName') will return 'Patient Name'.
compare( a: any, b: any, isAsc: boolean = true): numberSimple compare method to be used by a JavaScript sort method.
const sortedValues = workingValues.sort((a, b) => compare(a.value.toLowerCase(), b.value.toLowerCase()));decodeBase64(data: string): string
Decodes an encoded base-64 string into its raw string value.
distinct( T string[] | number[] | boolean[], K string[]: Pick<T, K>[]Returns a distinct list of values from an object array.
const rawList = [
{name: 'Smith, Bob', age: 54},
{name: 'Smith, Mary', age: 50},
{name: 'Townsend, James', age: 28},
{name: 'Myers, Mike', age: 54},
{name: 'Jones, Tammy', age: 54},
];
const distinctAges = distinct(rawList, 'age'); // returns [54, 50, 28]
encodeBase64(data: string): string
Converts a string to an encoded base-64 string.
getCSSVariableValue( variableName: string): stringReturns the contents of a CSS variable.
const fs = getCSSVariableValue('--font-size');
getHorizontalScrollbarHeight(): number
Calculates and returns the height of a horizontal scroll-bar. Useful when trying to calculate sizes of <div> elements that will display a horizontal scrollbar.
getSortField( direction: string, position: any): any hexToAscii(hexString: string): stringConverts a hexadecimal string into Ascii text.
inList( testValue: any, compareList: any[]): booleanReturns true if the testValue exists inside the compareList array.
if (inList('john', ['bob', 'mary', 'john', 'mike'])) {
return 'John is here';
}
isStringNumeric(
value: string): boolean
Returns true if the incoming string is a number.
isStringNumeric('1.2'); // true
isStringNumeric('One point two'); // false
randomString(): string
Generates a random string in the format of the current time in milliseconds + '_' + a random number between 0 and 100.
replacer(key: any, value: any): anyUsed by the MPage Service when converting JavaScript objects to JSON and only active when the public variable alternateReplacer is set to false (default) in the MPage Service. The replacer method will convert all numeric fields that end with the names Cd, Id or Float to decimal numbers allowing for proper floating point conversion in CCL when converted from JSON to a record structure.
replaceUnicode(value: string): stringReplaces Unicode quotes with base Ascii single or double quotes and removes other Unicode characters from a string. Useful if saving data to a custom table as CCL does not handle Unicode special characters properly.
stringWidth( stringValue: string, font: string): numberCalculates and returns the pixel size of a string of text using a specific font. Used internally by the MPage Table control to calculate default column widths.
stripHtmlTags( htmlText: string): stringRemoves all HTML tags from a string.
underscoreToCamel( inputString: string): stringConverts a string with underscores to camel case.
underscoreToCamel('name_full_formatted'); // Returns nameFullFormatted
validDateString(dateString: string): boolean
Performs a regular expression to determine if the incoming date string follows a pattern of /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/