Author: Travis Nesbit, MD (@geekmdtravis)
Environment | CI | Publish |
---|---|---|
Production | ||
Development | — |
A useful React hook written in TypeScript which wraps the XMLCclRequest
exposed as a native function
to the Microsoft Edge Chromium Browser in the Cerner Discern environment (e.g. PowerChart). Of note, this hook is only intended for use within the Cerner Discern environment and it will not work in other environments. Additionally, while it might work in other browsers like Microsoft Internet Explorer, it is untested in t hem and is only currently being developed for compatibility with the Microsoft Edge Chromium Browser.
function App() {
const { data, loading, errors } = useCcl<UserData>('00_GET_USER_DATA', [123]);
return (
<div>
<h2>Example Response</h1>
{loading && <p>Fetching data...</p>}
{data && (
<pre>
<code>{JSON.stringify(data, null, 2)}</code>
</pre>
)}
{errors.length > 0 && (
<>
<h2>Errors:</h2>
<ul>
{errors.map((error, i) => (
<li key={i}>{error}</li>
))}
</ul>
</>
)}
</div>
);
}
export default App;
prg
: The CCL program to call.params
: An array of parameters to pass to the CCL program. These can be the structuredCclCallParam
objects, or simplestring
andnumber
types.opts
: An optional object containing the following options:pollInterval
: The interval in milliseconds to poll the server for a response. The default value isundefined
and will not poll the server. A value of zero also disables polling. This is useful for scripts that might need to update the UI in regular intervals so that the information is always up-to-date.excludeMine
: Whether to exclude the current user's data from the response. Default isfalse
.mockJSON
: A string of JSON to use as a mock response. This is useful for testing the hook without needing to make a real CCL call.mode
: The mode to use for the CCL call. Default is'auto'
. This can be set to'production'
or'development'
to force the mode. When in'auto'
mode, the hook will use environment variables to determine the mode. That is, if the app is determined to be in'development'
environment the hook will attempt to load mock CCL data which should be provided by the developer as a JSON string in themockJSON
option. If the app is determined to be in'production'
environment, the hook will make a real CCL call to the server.
loading
: A boolean indicating whether the request is still loading.errors
: An array of strings containing any errors that occurred during the request.abort
: A function that can be called to abort the request.inPowerChart
: A boolean indicating whether the hook is running in the Cerner Discern environment.code
: The numeric code of the response. This defaults to418
before the request is complete.result
: astring
value representing the result of the response. This will beunknown
until the request iscomplete
. The full set of values that can be returned are:im a teapot
- corresponds to a418
status code and is used when attempting to query the server outside of the PowerChart environment without targeting mock data.internal server exception
- corresponds to a500
status code.invalid state
- corresponds to a409
status code.memory error
- corresponds to a493
status code.method not allowed
- corresponds to a405
status code.non-fatal error
- corresponds to a492
status code.success
- corresponds to a200
status code.unknown
- does not correspond to any specific status code and generally indicates the result is not yet known because the request may not have resolved or been run.
status
: astring
representing the ready state of the underlyingXMLCclRequest
. This will beuninitialized
until the request is initialized. The full set of potential status values are:uninitialized
- corresponds to a0
status code.loading
- corresponds to a1
status code.loaded
- corresponds to a2
status code.interactive
- corresponds to a3
status code.complete
- corresponds to a4
status code.
details
: astring
value which represents the full status text (response in string form) of the response. This will be an empty string until the request is complete.data
: anObject
which represenets the response data from the CCL call. This will beundefined
until the request is complete. When using TypeScript this object will be of typeT
.__request
: The underlyingXMLCclRequest
object. This is exposed for advanced users who may need to interact with the request object directly.
function App() {
const [fetch, abort, { callback, data, loading, errors }] = useCclLazy<UserData>('00_GET_USER_DATA', [123]);
return (
<div>
<h2>Example Response</h1>
{loading && <p>Fetching data...</p>}
{data && (
<pre>
<code>{JSON.stringify(data, null, 2)}</code>
</pre>
)}
{errors.length > 0 && (
<>
<h2>Errors:</h2>
<ul>
{errors.map((error, i) => (
<li key={i}>{error}</li>
))}
</ul>
</>
)}
<button onClick={fetch}>Fetch Data</button>
<button onClick={abort}>Abort Request</button>
</div>
);
}
export default App;
prg
: The CCL program to call.params
: An array of parameters to pass to the CCL program. These can be the structuredCclCallParam
objects, or simplestring
andnumber
types.opts
: An optional object containing the following options:excludeMine
: Whether to exclude the current user's data from the response. Default isfalse
.mockJSON
: A string of JSON to use as a mock response. This is useful for testing the hook without needing to make a real CCL call.mode
: The mode to use for the CCL call. Default is'auto'
. This can be set to'production'
or'development'
to force the mode. When in'auto'
mode, the hook will use environment variables to determine the mode. That is, if the app is determined to be in'development'
environment the hook will attempt to load mock CCL data which should be provided by the developer as a JSON string in themockJSON
option. If the app is determined to be in'production'
environment, the hook will make a real CCL call to the server.
Returns an Array
with three elements as part of the thook:
fetch
: A function that can be called to fetch the data from the server.abort
: A function that can be called to abort the request.response
: An object containing the following properties:loading
: A boolean indicating whether the request is still loading.errors
: An array of strings containing any errors that occurred during the request.abort
: A function that can be called to abort the request.inPowerChart
: A boolean indicating whether the hook is running in the Cerner Discern environment.code
: The numeric code of the response. This defaults to418
before the request is complete.result
: astring
value representing the result of the response. This will beunknown
until the request iscomplete
. The full set of values that can be returned are:im a teapot
- corresponds to a418
status code and is used when attempting to query the server outside of the PowerChart environment without targeting mock data.internal server exception
- corresponds to a500
status code.invalid state
- corresponds to a409
status code.memory error
- corresponds to a493
status code.method not allowed
- corresponds to a405
status code.non-fatal error
- corresponds to a492
status code.success
- corresponds to a200
status code.unknown
- does not correspond to any specific status code and generally indicates the result is not yet known because the request may not have resolved or been run.
status
: astring
representing the ready state of the underlyingXMLCclRequest
. This will beuninitialized
until the request is initialized. The full set of potential status values are:uninitialized
- corresponds to a0
status code.loading
- corresponds to a1
status code.loaded
- corresponds to a2
status code.interactive
- corresponds to a3
status code.complete
- corresponds to a4
status code.
details
: astring
value which represents the full status text (response in string form) of the response. This will be an empty string until the request is complete.data
: anObject
which represenets the response data from the CCL call. This will beundefined
until the request is complete. When using TypeScript this object will be of typeT
.__request
: The underlyingXMLCclRequest
object. This is exposed for advanced users who may need to interact with the request object directly.
This project uses the easy-ccl-request
package to handle the CCL requests. Because this package is commonly used , it was included here as a peer dependency. This means that you will need to install easy-ccl-request
in your project in order to use this hook. You can install it by running the following command:
npm install easy-ccl-request
Choosing to make this dependency a peer dependency that react-hook-useccl
will use your project's version of the easy-ccl-request
. This was done to minimize version conflicts and incompatabilities. This package, react-hook-useccl
, is actively developed to work with versions identified in the peerDependencies
section of the package.json file of this project.