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 structuredCclCallParamobjects, or simplestringandnumbertypes.opts: An optional object containing the following options:pollInterval: The interval in milliseconds to poll the server for a response. The default value isundefinedand 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 themockJSONoption. 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 to418before the request is complete.result: astringvalue representing the result of the response. This will beunknownuntil the request iscomplete. The full set of values that can be returned are:im a teapot- corresponds to a418status code and is used when attempting to query the server outside of the PowerChart environment without targeting mock data.internal server exception- corresponds to a500status code.invalid state- corresponds to a409status code.memory error- corresponds to a493status code.method not allowed- corresponds to a405status code.non-fatal error- corresponds to a492status code.success- corresponds to a200status 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: astringrepresenting the ready state of the underlyingXMLCclRequest. This will beuninitializeduntil the request is initialized. The full set of potential status values are:uninitialized- corresponds to a0status code.loading- corresponds to a1status code.loaded- corresponds to a2status code.interactive- corresponds to a3status code.complete- corresponds to a4status code.
details: astringvalue 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: anObjectwhich represenets the response data from the CCL call. This will beundefineduntil the request is complete. When using TypeScript this object will be of typeT.__request: The underlyingXMLCclRequestobject. 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 structuredCclCallParamobjects, or simplestringandnumbertypes.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 themockJSONoption. 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 to418before the request is complete.result: astringvalue representing the result of the response. This will beunknownuntil the request iscomplete. The full set of values that can be returned are:im a teapot- corresponds to a418status code and is used when attempting to query the server outside of the PowerChart environment without targeting mock data.internal server exception- corresponds to a500status code.invalid state- corresponds to a409status code.memory error- corresponds to a493status code.method not allowed- corresponds to a405status code.non-fatal error- corresponds to a492status code.success- corresponds to a200status 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: astringrepresenting the ready state of the underlyingXMLCclRequest. This will beuninitializeduntil the request is initialized. The full set of potential status values are:uninitialized- corresponds to a0status code.loading- corresponds to a1status code.loaded- corresponds to a2status code.interactive- corresponds to a3status code.complete- corresponds to a4status code.
details: astringvalue 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: anObjectwhich represenets the response data from the CCL call. This will beundefineduntil the request is complete. When using TypeScript this object will be of typeT.__request: The underlyingXMLCclRequestobject. 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-requestChoosing 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.