Jump to content

How to display Generated PDF link conditionally


Recommended Posts

Hi. I have a datapage that will allow users to create a PDF treatment sheet for patients enrolled on cancer studies. There are multiple studies and each treatment sheets looks quite different, so I have created unique treatment sheets in Caspio's document templates.

image.thumb.png.e41d11f3309f67df4797c19db9869acd.png

 

The datapage that is a tabular report that filters data based on my pre-defined criteria. I allow inline insert at the top as a means for users to add records. All records in the results are ALWAYS associate with one study. 

When the user completes the fields in the inline insert, a record is generated. I would like the results in this record to show the Generated PDF link for the appropriate study.

I cannot figure out how to do this. Since the generated pdf link doesn't show up as a field, I cannot use a calculated field to show the PDF that I want.

So I tried creating all of the links to the PDFs...

image.png.6dcdf35b4e658dd66378692a0dea6978.png

 

Below I passed a study parameter [@studyid] so the only records displayed are for the one particular study. But all tx sheets column's are there I cannot figure out how to hide the columns conditionally.

image.png.e075bf4a5c7909f86049f93209e3a6ef.png

 

What I would like to do is pass a parameter [@studyid] and have that study's tx sheet be the only thing displayed. One treatments sheet template for each record.

Any guidance would be truly appreciated. 

 

 

image.png

Link to comment
Share on other sites

Hello @kcastagnaro

Assuming there are 5 studies and there is a correlation between studyid and generate PDF column, you can do the following:

1. Hide all PDF column by default using CSS:

 

<style>

tr > th:nth-child(5), tr > td:nth-child(5) {
display: none;
}
tr > th:nth-child(6), tr > td:nth-child(6) {
display: none;
}
tr > th:nth-child(7), tr > td:nth-child(7) {
display: none;
}
tr > th:nth-child(8), tr > td:nth-child(8) {
display: none;
}
tr > th:nth-child(9), tr > td:nth-child(9) {
display: none;
}

</style>

Where numbers 5-9 represent the order position of PDF columns in a tabular report

2. With JavaScript, show only 1 column that corresponds to the value of passed studyid parameter:
 

<script>
if (typeof DataPageReadyHandler == 'undefined') {

const studyColumnDependencies = [{
columnPosition: 5, // position of PDF column for study with UZ5U2HTP ID
studyID:  'UZ5U2HTP' 
}, {
columnPosition: 6, // position of PDF column for study with 84DMNK2T ID
studyID:  '84DMNK2T'
}, {
columnPosition: 7, // position of PDF column for study with MVDIF4JM ID
studyID:  'MVDIF4JM'
}, {
columnPosition: 8, // position of PDF column for study with 7PA40M6B ID
studyID:  '7PA40M6B'
}, {
columnPosition: 9, // position of PDF column for study with A361MWHP ID
studyID:  'A361MWHP'
}]


const getPositionOfCurrentStudyColumn = () => {
let studyID = '[@studyid]'
if(studyID=='') {return -1}
let position = -1
for (let i=0;i<studyColumnDependencies.length; i++) {
if (studyColumnDependencies[i].studyID == studyID) {
position = studyColumnDependencies[i].columnPosition
break}}
return position
}

const DataPageReadyHandler = () => {
let currentStudyColumn = getPositionOfCurrentStudyColumn()
if (currentStudyColumn == -1) {return}
document.querySelectorAll(`tr th:nth-child(${currentStudyColumn}), tr td:nth-child(${currentStudyColumn})`).forEach(cell=>{
cell.style = 'display: table-cell;'
})
}
document.addEventListener('DataPageReady', DataPageReadyHandler)
}
</script>


Customize the studyColumnDependencies array to map studyIDs with corresponding PDF column positions.

Here is a DP example: 

https://c7eku786.caspio.com/dp/7f80b00097f5e5b8b46b4b0d95db?studyid=A361MWHP

You can change the value of studyid parameter to the one of mentioned in studyColumnDependencies array above to see that different generate PDF columns will be displayed based on the studyid
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...