RiteCare Connect

Integration Guide Beta

iFrame Customization

React Integration



  const ImportRecords = () => {
  const urlParams = new URLSearchParams(window.location.search);
  const accessToken = urlParams.get('token') || urlParams.get('accessToken') || '';
  const redirectUrl = urlParams.get('redirect-url');
  const iframeRef = useRef(null) as React.MutableRefObject<HTMLIFrameElement | null>;

  // Build the iframe URL with only required parameters
  const buildIframeUrl = () => {
    const params = new URLSearchParams();
    if (accessToken) params.set('token', accessToken);
    if (redirectUrl) params.set('redirect-url', redirectUrl);
    return ${VITE_MATCHRITE_PATIENT_APP}/import?${params.toString()};
  };

  const dynamicCustomizeUI = {
    
        'import-container': {
            styles: {
                backgroundColor: '#234e5c',
                borderRadius: '4px',
            },
        },
        'import-section': {
            'import-autocomplete': {
                label: 'Connect with Care Organization',
                placeholder: 'Connect with Care Organization...',
                styles: {
                    backgroundColor: 'white',
                    borderRadius: '4px',
                },
            },
            'import-button': {
                label: 'Import',
                styles: {
                    backgroundColor: '#176571',
                    color: 'white',
                    padding: '10px 20px',
                    borderRadius: '8px',
                },
            },
            'import-tooltip': {
                html: `Find and select a provider organization or facility that may hold an Electronic Health Record (EHR) related to your medical history.
                        <br />
                        <b>NOTE: 
                        You'll need login credentials for each provider's portal
                        <br />`,
            },
        },
        'import-dialog': {
            label: 'Connect Patient Import Record',
            cancelBtn: {
                label: 'Cancel',
                styles: {
                    backgroundColor: '#ccc',
                    color: '#000',
                },
            },
            confirmBtn: {
                label: 'Proceed',
            },
        },
    }

  // Send message after iframe loads
  useEffect(() => {
    const iframe = iframeRef.current;
    if (!iframe) return;

    const onLoad = () => {
      iframe?.contentWindow?.postMessage(
        { type: 'updateCustomization', config: dynamicCustomizeUI },
        '*',
      );
    };

    iframe.addEventListener('load', onLoad);

    return () => iframe.removeEventListener('load', onLoad);
  }, []);

  return (
    <iframe
      ref={iframeRef}
      src={buildIframeUrl()}
      className="import-iframe"
      allow="fullscreen; geolocation; microphone; camera"
      sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation-by-user-activation"
      title="Import Records"
      style={{
        width: '100%',
        height: '100vh',
        border: 'none',
      }}
    />
  );
};