import React from 'react';
import PropTypes from 'prop-types';
import ViewerRetrieveStudyData from '../connectedComponents/ViewerRetrieveStudyData.js';

function IHEInvokeImageDisplay({ match }) {
  const requestType = match.params.query.requestType;
  let studyInstanceUids;
  //let patientUids;
  let displayStudyList = false;

  if (requestType === 'STUDY') {
    studyInstanceUids = match.params.query.studyUID.split(';');
  } else if (requestType === 'STUDYBASE64') {
    const uids = this.params.query.studyUID;
    const decodedData = window.atob(uids);
    studyInstanceUids = decodedData.split(';');
  } else if (requestType === 'PATIENT') {
    //patientUidspatientUids = this.params.query.patientID.split(';');
    displayStudyList = true;
  } else {
    displayStudyList = true;
  }

  if (displayStudyList) {
    return ''; //<StudyList patientUids={patientUids}/>);
  }

  return <ViewerRetrieveStudyData studyInstanceUids={studyInstanceUids} />;
}

IHEInvokeImageDisplay.propTypes = {
  match: PropTypes.shape({
    params: PropTypes.shape({
      query: PropTypes.shape({
        requestType: PropTypes.string.isRequired,
        studyUID: PropTypes.string,
        patientID: PropTypes.string,
      }),
    }),
  }),
};

export default IHEInvokeImageDisplay;

@@ -63,16 +63,112 @@
 %0Aimport 
+%7B withRouter %7D from 'react-router-dom';%0Aimport queryString from 'query-string';%0Aimport Connected
 ViewerRe
@@ -212,16 +212,25 @@
 ponents/
+Connected
 ViewerRe
@@ -264,301 +264,568 @@
 ion 
-IHEInvokeImageDisplay(%7B match %7D) %7B%0A  const requestType = match.params.query.requestType;%0A  let studyInstanceUids;%0A  //let patientUids;%0A  let displayStudyList = false;%0A%0A  if (requestType === 'STUDY') %7B%0A    studyInstanceUids = match.params.query.studyUID.split(';');%0A  %7D else if (requestType ===
+decodeStudyUids(studyUids) %7B%0A  const decodedData = window.atob(studyUids);%0A%0A  return decodedData.split(';');%0A%7D%0A%0Afunction getQueryParameters(location) %7B%0A  if (location) %7B%0A    return queryString.parse(location.search);%0A  %7D%0A%0A  return %7B%7D;%0A%7D%0A%0Afunction IHEInvokeImageDisplay(%7B location %7D) %7B%0A  const %7B%0A    // patientID,%0A    requestType,%0A    studyUID,%0A  %7D = getQueryParameters(location);%0A%0A  switch (requestType) %7B%0A    case 'STUDY':%0A      return (%0A        %3CConnectedViewerRetrieveStudyData%0A          studyInstanceUids=%7BstudyUID.split(';')%7D%0A        /%3E%0A      );%0A%0A    case
  'ST
@@ -838,100 +838,73 @@
 E64'
-) %7B
+:
 %0A    
-const uids = this.params.query.studyUID;%0A    const decodedData = window.atob(uids);%0A
+  return (%0A        %3CConnectedViewerRetrieveStudyData%0A      
     
@@ -924,63 +924,66 @@
 Uids
- = 
+=%7B
 decode
-dData.split(';');%0A  %7D else if (requestType ===
+StudyUids(studyUID)%7D%0A        /%3E%0A      );%0A%0A    case
  'PA
@@ -992,194 +992,113 @@
 ENT'
-) %7B
+:
 %0A    
-//patientUidspatientUids = this.params.query.patientID.split(';');%0A    displayStudyList = true;%0A  %7D else %7B%0A    displayStudyList = true;%0A  %7D%0A%0A  if (displayStudyList) %7B%0A   
+  // TODO: connect this to the StudyList when we have the filter parameters set up%0A      //
  return 
 ''; 
@@ -1097,14 +1097,8 @@
 urn 
-''; //
 %3CStu
@@ -1128,23 +1128,31 @@
 ient
-Uids%7D
+ID.split(';')%7D 
 /%3E
-)
 ;%0A  
-%7D%0A%0A
+  
   re
@@ -1160,74 +1160,170 @@
 urn 
-%3CViewerRetrieveStudyData studyInstanceUids=%7BstudyInstanceUids%7D /%3E;
+'';%0A%0A    default:%0A      // TODO: Figure out what to do here, this won't work because StudyList expects studies%0A      // return %3CStudyList /%3E;%0A      return '';%0A  %7D
 %0A%7D%0A%0A
@@ -1364,13 +1364,16 @@
 %7B%0A  
-match
+location
 : Pr
@@ -1396,84 +1396,14 @@
     
-params: PropTypes.shape(%7B%0A      query: PropTypes.shape(%7B%0A        requestType
+search
 : Pr
@@ -1416,16 +1416,22 @@
 s.string
+,%0A  %7D)
 .isRequi
@@ -1439,105 +1439,8 @@
 ed,%0A
-        studyUID: PropTypes.string,%0A        patientID: PropTypes.string,%0A      %7D),%0A    %7D),%0A  %7D),%0A
 %7D;%0A%0A
@@ -1454,16 +1454,27 @@
 default 
+withRouter(
 IHEInvok
@@ -1486,10 +1486,11 @@
 eDisplay
+)
 ;%0A

Fix the props to access query parameters per API spec