Appointment CCL Script
The CCL source code library included with Clinical Office: MPage Edition contains a file called 1co_mpage_template.prg. This file contains the code necessary to allow creation of your own CCL scripts that work with the CustomService data service in Clinical Office.
If you open this file, you will see a great deal of documentation and helper text. At line 77, you will see a block of code checking the patient_source record structure as well as a clearPatientSource flag check.
When you run your MPage, the patient_source record structure can be used to specify which visits or patients are to be used in your custom code. Many scripts you write may never access this structure (including the one we are about to create), but it is important to know that it exists as it is very useful when chaining Clinical Office services together.
Our script will be using a different record structure which is available to all chart level MPage CCL scripts. The format of this structure is:
record chart_id ( 1 person_id = f8 ; Person Id of opened chart 1 encntr_id = f8 ; Encounter Id of opened chart 1 name_full_formatted = vc ; Name of patient 1 prsnl_id = f8 ; Prsnl Id of user opening chart 1 prsnl_name = vc ; Name of employee opening chart )We will be making using of the chart_id->person_id variable in our script to collect appointments for our patient.
- Open 1co_mpage_template.prg in Discern Visual Developer and save it as 1trn_appt_mp.prg. When prompted to rename the program to match the new file name, click the Ok button. Feel free to modify the header content to match your organization standards.
- Navigate to the section labelled "BEGIN YOUR CUSTOM CODE HERE". It should be around line 105 in the CCL script. You should see a definition for a record structure called rCustom. The rCustom record structure is where you will place all your custom script output. The current rCustom structure is simply a placeholder. If you were to compile your 1trn_appt_mp.prg script and run your 1trn_mp_appointment.prg you would no longer see any error messages and the structure of rCustom would be visible in your output.
-
Replace the rCustom declaration with the code shown below.
record rCustom ( 1 appointments[*] 2 sch_event_id = f8 2 encntr_id = f8 2 begin_dt_tm = dq8 2 duration = i4 2 appt_type = vc 2 resource = vc 2 location = vc 2 sch_state = vc )
-
Next, immediately after the rCustom definition, add the following simple appointment collection script. Be sure
to take note of how we use chart_id->person_id to match the sch_appt records to our patient.
; Collect appointments select into "nl:" from sch_appt sa, sch_event se, sch_appt sa2 plan sa where sa.person_id = chart_id->person_id and sa.role_meaning = "PATIENT" and sa.state_meaning in ("CONFIRMED", "CHECKED IN", "CHECKED OUT") and sa.version_dt_tm > sysdate and sa.active_ind = 1 and sa.end_effective_dt_tm > sysdate join se where se.sch_event_id = sa.sch_event_id and se.version_dt_tm > sysdate and se.active_ind = 1 and se.end_effective_dt_tm > sysdate join sa2 where sa2.sch_event_id = se.sch_event_id and sa2.role_meaning = "RESOURCE" and sa2.state_meaning in ("CONFIRMED", "CHECKED IN", "CHECKED OUT") and sa2.version_dt_tm > sysdate and sa2.active_ind = 1 and sa2.end_effective_dt_tm > sysdate order sa.beg_dt_tm head report nNum = 0 detail nNum = nNum + 1 stat = alterlist(rCustom->appointments, nNum) rCustom->appointments[nNum].sch_event_id = sa.sch_event_id rCustom->appointments[nNum].encntr_id = sa.encntr_id rCustom->appointments[nNum].begin_dt_tm = sa.beg_dt_tm rCustom->appointments[nNum].duration = sa.duration rCustom->appointments[nNum].appt_type = uar_get_code_display(se.appt_type_cd) rCustom->appointments[nNum].resource = uar_get_code_display(sa2.resource_cd) rCustom->appointments[nNum].location = uar_get_code_display(sa.appt_location_cd) rCustom->appointments[nNum].sch_state = uar_get_code_display(sa.sch_state_cd) with counter
-
Save and compile your script. Feel free to test your script as needed by running your test CCL script.
1trn_mp_appointment:group1 "MINE" go
We now have a CCL script that will collect the appointments for our patient. Later in this lesson we will come back to this CCL script and make modifications to display appointment details and add support for parameters such as date ranges.
If you do not wish to type in the CCL script, you can download it here.