UtilityService
The UtilityService contains useful method calls that can be used in many places. This service will grow over time to support new functionality as it comes available.
Import
The UtilityService should be imported and initialized in the component source that is responsible for displaying data from the service.
V4+ import { UtilityService } from '@clinicaloffice/clinical-office-mpage-core'; < V3 import { UtilityService } from '@clinicaloffice/clinical-office-mpage';
Initialization
Once you have imported the UtilityService, you need to inject it into your component and assign it to a variable. This is done through the constructor of your component (or the app.component.ts file). After injection has been completed all the methods shown below will be available to your component or service.
export class myComponent implements OnInit { constructor(public utility: UtilityService) { } }
Methods
asciiToHex(
asciiString: string ): string
Converts an ASCII string to its hexadecimal value. This is useful if you need to send non-textual content to CCL
for processing. The string can then be reverted to ASCII text in CCL using the CNVTHEXRAW() function.
As an example, our team built a project for a client that generated PDF documents live in the MPage which were then sent back to CCL for processing to add to the patient chart. These PDF documents required conversion to Base 64 followed by conversion to hexadecimal to prevent the contents of the PDF being corrupted due to the inclusion of both special characters in the document and UTF-8 vs ANSI content.
camelWords(
camelString: string ): string
Converts a string in camelCase format to a space separated string with the first letter of each word capitalized.
// Returns 'Name Full Formatted' const newString = this.utilityService.camelWords('nameFullFormatted');
compare(
a: any,
b: any,
isAsc: boolean = true): number
Used to compare two values together. Typically used in Angular Material Table Sorting. Returns -1 if a is less than
b, 1 if greater or the same. Optional isAsc parameter determines if ascending or descending order.
dateCompare(
a: any,
b: any,
isAsc: boolean = true): number
Used to compare two moment.js date values together. Typically used in Angular Material Table Sorting.
Returns -1 if a is less than b, 1 if greater or the same. Optional isAsc parameter determines if ascending or
descending order.
hexToAscii(
hexString: string ): string
Converts a hexadecimal string to its ASCII value. This is useful if you need to send non-textual content from CCL
to your MPage (e.g. images, HTML content). In your CCL script you would pass your content to the CNVTRAWHEX()
function and then pass the returning value back to your Angular application to be converted back to ASCII text.
inList(
testValue: any,
compareList: any[]): boolean
Tests to indicate if testValue exists in the compareList
array. Data types of both parameters must be the same to qualify as true.