src/components/DisplayBox/DisplayBox.js
/**
   * Take a suggestion from a CDS service based on action on from a card. Also pings the analytics endpoint (if any) of the
   * CDS service to notify that a suggestion was taken
   * @param {*} suggestion - CDS service-defined suggestion to take based on CDS Hooks specification
   * @param {*} url - CDS service endpoint URL
   */
Take a suggestion from a CDS service based on action on from a card. Also pings the analytics endpoint (if any) of the
CDS service to notify that a suggestion was taken
@param {*} suggestion - CDS service-defined suggestion to take based on CDS Hooks specification
@param {*} url - CDS service endpoint URL
Take a suggestion from a CDS service based on action on from a card . Also pings the analytics endpoint ( if any ) of the CDS service to notify that a suggestion was taken @param { * } suggestion - CDS service - defined suggestion to take based on CDS Hooks specification @param { * } url - CDS service endpoint URL
takeSuggestion(suggestion, url, buttonId, suggestionCount, cardNum, selectionBehavior) {
    if (!this.props.isDemoCard) {
      console.log("taking suggestion");
      if (selectionBehavior === 'at-most-one') {
        for (var i = 0; i < suggestionCount; i++) {
          let bId = "suggestion_button-"+cardNum+"-"+i;
          document.getElementById(bId).setAttribute("disabled", "true");
        }
      } else {
        document.getElementById(buttonId).setAttribute("disabled", "true");
      }
      if (suggestion.label) {
        if (suggestion.uuid) {
          axios({
            method: 'POST',
            url: `${url}/analytics/${suggestion.uuid}`,
            data: {},
          });
        }
        const client = FHIR.client({
          serverUrl: this.props.ehrUrl,
          tokenResponse: {
            access_token: this.props.access_token.access_token,
          },
        });
        suggestion.actions.forEach((action) => {
          if (action.type.toUpperCase() === "DELETE") {
            var uri = action.resource.resourceType + "/" + action.resource.id;
            console.log("completing suggested action DELETE: " + uri);
            client.delete(uri).then((result) => {
              console.log("suggested action DELETE result:");
              console.log(result);
            });
          } else if (action.type.toUpperCase() === "CREATE") {
            var uri = action.resource.resourceType;
            console.log("completing suggested action CREATE: " + uri);
            client.create(action.resource).then((result) => {
              console.log("suggested action CREATE result:");
              console.log(result);
              if (this.supportedRequesType(result)) {
                this.props.takeSuggestion(result);
              }
            });
          } else if (action.type.toUpperCase() === "UPDATE") {
            var uri = action.resource.resourceType + "/" + action.resource.id;
            console.log("completing suggested action UPDATE: " + uri);
            client.update(action.resource).then((result) => {
              console.log("suggested action UPDATE result:");
              console.log(result);
            });
          } else {
            console.log("WARNING: unknown action");
          }
        });
      } else {
        console.error('There was no label on this suggestion', suggestion);
      }
    }
  }
takeSuggestion ( suggestion , url , buttonId , suggestionCount , cardNum , selectionBehavior ) { if ( ! this . props . isDemoCard ) { console . log ( "taking suggestion" ) ; if ( selectionBehavior === 'at-most-one' ) { for ( var i = 0 ; i < suggestionCount ; i ++ ) { let bId = "suggestion_button-" + cardNum + "-" + i ; document . getElementById ( bId ) . setAttribute ( "disabled" , "true" ) ; } } else { document . getElementById ( buttonId ) . setAttribute ( "disabled" , "true" ) ; } if ( suggestion . label ) { if ( suggestion . uuid ) { axios ( { method : 'POST' , url : ` ${ url } ${ suggestion . uuid } ` , data : { } , } ) ; } const client = FHIR . client ( { serverUrl : this . props . ehrUrl , tokenResponse : { access_token : this . props . access_token . access_token , } , } ) ; suggestion . actions . forEach ( ( action ) => { if ( action . type . toUpperCase ( ) === "DELETE" ) { var uri = action . resource . resourceType + "/" + action . resource . id ; console . log ( "completing suggested action DELETE: " + uri ) ; client . delete ( uri ) . then ( ( result ) => { console . log ( "suggested action DELETE result:" ) ; console . log ( result ) ; } ) ; } else if ( action . type . toUpperCase ( ) === "CREATE" ) { var uri = action . resource . resourceType ; console . log ( "completing suggested action CREATE: " + uri ) ; client . create ( action . resource ) . then ( ( result ) => { console . log ( "suggested action CREATE result:" ) ; console . log ( result ) ; if ( this . supportedRequesType ( result ) ) { this . props . takeSuggestion ( result ) ; } } ) ; } else if ( action . type . toUpperCase ( ) === "UPDATE" ) { var uri = action . resource . resourceType + "/" + action . resource . id ; console . log ( "completing suggested action UPDATE: " + uri ) ; client . update ( action . resource ) . then ( ( result ) => { console . log ( "suggested action UPDATE result:" ) ; console . log ( result ) ; } ) ; } else { console . log ( "WARNING: unknown action" ) ; } } ) ; } else { console . error ( 'There was no label on this suggestion' , suggestion ) ; } } }
Take a suggestion from a CDS service based on action on from a card.
Take a suggestion from a CDS service based on action on from a card .
// disable all suggestion buttons for this card // disable this suggestion button if any are allowed // handle each action from the suggestion // call into the request builder to resubmit the CRD request with the suggested request