CustomService
The CustomService gives you the flexibility to execute your own CCL scripts from within a Clinical Office payload. Your scripts can be run before or after the normal Clinical Office tasks allowing you the flexibility to not only control output of the JSON, but also control the list of visit and person records being used by Clinical Office data services.
Import
The CustomService should be imported and initialized in the component source that is responsible for displaying data from the service. Alternatively, if you have your required payload information available, you can initialize the loading of your data in the app.component.ts source.
V4+ import { CustomService } from '@clinicaloffice/clinical-office-mpage-core'; < V3 import { CustomService } from '@clinicaloffice/clinical-office-mpage';
If you plan on calling other data services in your payload you will also need to make sure they are loaded somewhere on the current page to allow loading of data into the proper objects. For example, if you call the PersonService in your payload, it needs to be implemented in your script for the data to be used.
Initialization
Once you have imported the CustomService, 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).
export class myComponent implements OnInit { constructor(public customService: CustomService) { } }
Initialization can be performed one of two ways.
-
In the ngOnInit() method of your app.component.ts or component file through a payload tag and direct
call to the mPageService executeCCL method.
ngOnInit() { this.mpage.executeCCL({ payload: { customScript: { script: [ {name: 'ccl script name', run: 'pre', id: 'unique name', parameters: { anything you want }} ], clearPatientSource: true } } }, [this.customService.mpage.emptyPatientSource], () => { your custom callback function; }); }
-
Call the CustomService load method from the ngOnInit() method of your app.component.ts or component file.
ngOnInit() { this.customService.load({ customScript: { script: [ {name: 'ccl script name', run: 'pre', id: 'unique name', parameters: { anything you want }} ], clearPatientSource: true } } }, [this.customService.mpage.emptyPatientSource], () => { your custom callback function; }); }
Methods
clear(key: string = ''): void
Clears one or all of the custom data values from memory. If '' is passed as the key, all custom data is
removed from memory.
emptyDmInfo(): IDMInfo
Returns an empty IDmInfo object for usage in your project.
executeDmInfoAction(id: string,
action: string = 'r',
data: IDmInfo[],
callback: any = undefined): void
Executes a read/write/delete action on the DM_INFO table. Please see the
DMInfo Details
documentation for usage instructions.
executeDmInfoActions([{id: string,
action: string = 'r',
data: IDmInfo[]}],
callback: any = undefined): void
Plural version of executeDMInfoAction where you can issue multiple DMInfoActions in the same call.
get(key:string): any
Returns the content created by your custom CCL script as a JavaScript object where key is equal to the name of the
unique id you passed in your payload. If you passed an empty string to the "id" field in your payload, no
data will be returned to your MPage.
isLoaded(key:string): boolean
Returns a boolean true or false indicating if the custom service has loaded and stored data under the key name. This
is a useful method for determining if your custom script has finished running.
load(payload: any,
patientSource: any[] = [{personId: 0, encntrId: 0}],
callback: any = undefined): void
Executes custom script(s) inside payload for the provided patientSource. The payload can be
any valid payload string or default payload (see payload tab).
putLog(message: string): void
Outputs the content of the message parameter to the activity log component.
set(key:string, value: any): void
Allows you the ability to create or change the values associated with a key. This feature is especially useful
if you need to store your own custom data that is available across templates and pages.
Public Variables
The CustomService exposes the following variable that can be useful in the development of your MPages.
- custom: Map<string, any> - Map containing custom data.
CCL
For your custom CCL data service to work, you need a CCL script that is going to perform your task(s) and either update the PATIENT_SOURCE record structure or populate your MPage JSON stream.
You can use the 1co_mpage_template.prg script that was included with your CCL repository as a starting point for your custom CCL scripts. Simply save the script under your own custom name, modify or remove the rCUSTOM record structure and add your own code where indicated in the source. If you chose to remove the rCUSTOM record structure and create your own new structure, you will need to put the name of your new record structure in the call to ADD_CUSTOM_OUTPUT at the bottom of the script.
Any elements you place in your custom structure or the rCUSTOM structure will be available as a
JavaScript object in your MPage through the get(key) method. For example, if you were to run the default
template script with a custom id equal to "test" in your payload, you could access record field called
YOUR_CUSTOM_FIELD in your MPage with this.customService.get("test").yourCustomField
.
Payload
The following payload options represent all available payload values for the CustomService.
{ payload: { patientSource: [ {personId: value, encntrId: value} ], customScript: { script: [ {name: 'ccl script name', run: 'pre', id: 'unique name', parameters: { anything you want }} ], clearPatientSource: true } } }
Payload Notes
You can include multiple script tags within the customScript payload. The only requirement is that any parameters you include in your payload must have the same data types between scripts. For example, if you run two custom scripts in the same payload that have a parameter called startDate and in one script you are using a fully qualified JavaScript Date and in the second script you are using a simple string, your CCL scripts will error out and cause your MPage to fail.
The name field in your script tag needs to be the executable name of your CCL script and include the group level the script runs at. We highly recommend that all of your custom scripts run at a level of GROUP1.
Valid values for the run element are 'pre' and 'post'. Scripts identified as 'pre' will run before all other Clinical Office scripts. Scripts marked as 'post' will run at the end of the payload job.
id represents a unique name that you will give your custom data. This name is the key name that will be used by the CustomService provider when using the get(key) method. Re-using an identifier will result in the old data being replaced.
The parameters payload tag has been designed to allow you the flexibility of passing any needed parameter
data such as date ranges to your CCL script. A parameter called fromDate in your payload will be available
in CCL as PAYLOAD->CUSTOMSCRIPT->SCRIPT[nSCRIPT]->PARAMETERS.FROMDATE
.
The clearPatientSource payload tag is responsible for erasing the contents of the PATIENT_SOURCE record structure which is used by all Clinical Office scripts to identify visit and person records. Once you have cleared the patient source, you can re-populate the record structure with your CCL script. For this to have any effect, you will also need to execute some Clinical Office payload tags such as person, allergy, etc. as the patient source is only clear for the current payload run.
Interfaces
IDmInfo
interface IDmInfo { infoDomain: string; infoName: string; infoDate: Date; infoChar: string; infoNumber: number; infoLongText: string; infoDomainId: number; }