Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.96 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8.  
  9. <div id="gridDiv" style="height:800px;width:100%;" class="ag-theme-balham"></div>
  10.  
  11. <script src="/static/js/ag-grid-enterprise.min.js"></script>
  12.  
  13. <script>
  14.  
  15.  
  16. // License function -> used in production.
  17. var license_key = "";
  18.  
  19. async function license() {
  20. license_key = await ReportApp.utils.getAgGridLicense();
  21. agGrid.LicenseManager.setLicenseKey(license_key);
  22. return license_key;
  23. }
  24.  
  25. // license();
  26.  
  27. // Need to handle child samples data
  28. function samplesChildTable(sample_key, sample_value, row,wf, tech) {
  29.  
  30. if (Object.getOwnPropertyNames(row).length === 0){
  31. row['Relation'] = 'N/A'
  32. row["STR Result"] = 'N/A'
  33. row["QC"] = 'N/A'
  34. row["Interpretation"] = 'N/A'
  35. row["NGS Result"] = 'N/A'
  36. row["Sample #"] = 'N/A'
  37. row['Parent ID'] = 'N/A'
  38. row["Sample ID"] = sample_value[0]["sample_name"]
  39. }
  40.  
  41. if (wf === "Data Analysis"){
  42. for (var i = 0; i < sample_value.length; i++) {
  43. if (sample_value[i]["tag_name"] !== null ) {
  44. if (sample_value[i]["tag_name"].includes('chr_result') && sample_value[i]["value"] !== null){
  45. let raw = sample_value[i]["value"].split(':');
  46. if (raw.length === 1){
  47. row['NGS Result'] = 'Euploid'
  48. }
  49.  
  50. else {
  51. row['NGS Result'] = raw[1]
  52. }
  53.  
  54. }
  55. if (sample_value[i]["tag_name"].includes('illumina_qc_result' && sample_value[i]["value"] !== null)) {
  56. row["QC"] = sample_value[i]["value"];
  57. }
  58. if (sample_value[i]["tag_name"].includes('chr_interpretation') || sample_value[i]["tag_name"].includes('res_interpretation') && sample_value[i]["value"] !== null) {
  59. row["Interpretation"] = sample_value[i]["value"];
  60. }
  61. if (sample_value[i]["tag_name"].includes('embryo_number') && sample_value[i]["value"] !== null){
  62. row["Sample #"] = sample_value[i]["value"]
  63. }
  64. }
  65.  
  66. if (sample_value[i]['resource_var_name']==='Parent ID' && sample_value[i]["value"] !== null){
  67. row["Parent ID"] = sample_value[i]["value"]
  68. }
  69. }
  70. }
  71.  
  72. if (wf === "Identifiler"){
  73. for (var i = 0; i < sample_value.length; i++) {
  74. if (sample_value[i]["tag_name"] !== null ) {
  75.  
  76. if (sample_value[i]["tag_name"].includes('dna_relation')){
  77. row["Relation"] = sample_value[i]["value"];
  78. }
  79. if (sample_value[i]["tag_name"].includes('str_result')) {
  80. row["STR Result"] = sample_value[i]["value"];
  81. }
  82. }
  83. }
  84. }
  85.  
  86. if (wf === 'Collect and Extract Buccal Swab'){
  87. for (var i = 0; i < sample_value.length; i++) {
  88. if (sample_value[i]["tag_name"] !== null ) {
  89.  
  90. if (sample_value[i]["tag_name"].includes('dna_relation')){
  91. row["Relation"] = sample_value[i]["value"];
  92. }
  93. }
  94. if (sample_value[i]['resource_var_name']==='Parent ID'){
  95. row["Parent ID"] = sample_value[i]["value"]
  96. }
  97. }
  98. }
  99.  
  100. if (wf === "Veriseq NGS"){
  101. for (var i = 0; i < sample_value.length; i++) {
  102. if (sample_value[i]["tag_name"] !== null ) {
  103.  
  104. if (sample_value[i]["tag_name"].includes('embryo_number')){
  105. row["Sample #"] = sample_value[i]["value"]
  106. }
  107. }
  108.  
  109. if (sample_value[i]['resource_var_name']==='Sample Number'){
  110. row["Sample #"] = sample_value[i]["value"]
  111. }
  112.  
  113. if (sample_value[i]['resource_var_name']==='Parent ID'){
  114. row["Parent ID"] = sample_value[i]["value"]
  115. }
  116. }
  117. }
  118.  
  119.  
  120. if (wf === "Extract DNA"){
  121. for (var i = 0; i < sample_value.length; i++) {
  122. if (sample_value[i]['resource_var_name']==='Sample Number'){
  123. row["Sample #"] = sample_value[i]["value"]
  124. }
  125.  
  126. if (sample_value[i]['resource_var_name']==='Parent ID'){
  127. row["Parent ID"] = sample_value[i]["value"]
  128. }
  129. }
  130. }
  131.  
  132. const child_sample_row = row;
  133. return child_sample_row;
  134. }
  135.  
  136. async function hexPayload(payload) {
  137. //function from MDN docs for getting hex of hash of text
  138. const msgUint8 = new TextEncoder().encode(payload); // encode as (utf-8) Uint8Array
  139. const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
  140. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  141. const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
  142. return hashHex;
  143. }
  144.  
  145. function groupDuplicates(propertyName, data) {
  146. var grouped = {};
  147.  
  148. data.map(function(item) {
  149. var itemPropertyName = item[propertyName];
  150.  
  151. if (itemPropertyName in grouped) {
  152. grouped[itemPropertyName].push(item)
  153. }
  154. else {
  155. grouped[itemPropertyName] = [];
  156. grouped[itemPropertyName].push(item)
  157. }
  158. });
  159. return grouped
  160. }
  161.  
  162. try {
  163. ReportApp.utils.registerRefreshCallback(run);
  164. ReportApp.utils.registerPrintCallback(print);
  165. } catch(e) {
  166. console.error(e);
  167. }
  168.  
  169. run();
  170.  
  171. function run() {
  172. ReportApp.utils.getApiQueryResults("patient_summary", { name: "POC Chain"}, onSuccess, function onError (error) {
  173. console.error(error)
  174. });
  175. }
  176.  
  177. function print() {
  178. ReportApp.utils.print('printDiv');
  179. }
  180.  
  181.  
  182. function onSuccess(data) {
  183.  
  184. const key = "L7_Informatics_Enterprise_Science_Platform_3Devs_5OEM_8_August_2019__MTU2NTIxODgwMDAwMA==02c676ec74743c60bbd1471e0c9fed9f";
  185. agGrid.LicenseManager.setLicenseKey(key);
  186. let rowData = [];
  187.  
  188. let dateParams = {
  189. // provide comparator function
  190. comparator: function (filterLocalDateAtMidnight, cellValue) {
  191. var dateAsString = cellValue;
  192. if (dateAsString == null) return 0;
  193.  
  194. // In the example application, dates are stored as dd/mm/yyyy
  195. // We create a Date object for comparison against the filter date
  196. var dateParts = dateAsString.split("/");
  197. var day = Number(dateParts[2]);
  198. var month = Number(dateParts[1]) - 1;
  199. var year = Number(dateParts[0]);
  200. var cellDate = new Date(day, month, year);
  201.  
  202. // Now that both parameters are Date objects, we can compare
  203. if (cellDate < filterLocalDateAtMidnight) {
  204. return -1;
  205. } else if (cellDate > filterLocalDateAtMidnight) {
  206. return 1;
  207. } else {
  208. return 0;
  209. }
  210. }
  211. }
  212.  
  213. // Gradalis defined columns they would like to see.
  214. let columnDefs = [
  215. {headerName: 'pat_id', field: 'pat_id', hide: true},
  216. {headerName: "Patient ID", field: "Patient ID", filter: 'agTextColumnFilter', cellRenderer: 'agGroupCellRenderer', pinned: 'left'},
  217. {headerName: "Patient Last Name", field: "Last Name", filter: 'agTextColumnFilter'},
  218. {headerName: "Patient First Name", field: "First Name", filter: 'agTextColumnFilter'},
  219. {headerName: "Chart Number", field: "Chart Number", filter: 'agTextColumnFilter'},
  220. {headerName: "Patient DOB", field: "DOB", filter: 'agDateColumnFilter', filterParams: dateParams},
  221. {headerName: "Patient Gender", field: "Patient Gender"},
  222. {headerName: "Partner Last Name", field: "Partner Last Name", filter: 'agTextColumnFilter'},
  223. {headerName: "Partner First Name", field: "Partner First Name", filter: 'agTextColumnFilter'},
  224. {headerName: "Partner DOB", field: "Partner DOB", filter: 'agDateColumnFilter', filterParams: dateParams},
  225. {headerName: "Partner Gender", field: "Partner Gender"},
  226. {headerName: "Partner Chart Number", field: "Partner Chart Number", filter: 'agTextColumnFilter'},
  227. {headerName: "Partner Comments", field: "Partner Comments", editable: true},
  228. {headerName: "Date Received", field: "Date Received", filter: 'agDateColumnFilter', filterParams: dateParams},
  229. {headerName: "GA by Date", field: "GA by Dates", filter: 'agDateColumnFilter', filterParams: dateParams},
  230. {headerName: "GA by Size", field: "GA by Size"},
  231. {headerName: "Method of Conception", field: "Method of Conception"},
  232. {headerName: "Comments & Special Requests", field: "Comments & Special Requests", editable: true},
  233. {headerName: "# Controls", field: "# Controls", editable: true, type: "numericColumn"},
  234. {headerName: "# of Tested Samples", field: "# of Tested Samples", editable: true},
  235. {headerName: "Referring Physician", field: "MD"},
  236. {headerName: "Technician", field: 'Technician',editable: true},
  237. {headerName: "Analysed by", field: "Analysed by", editable: true},
  238. {headerName: "Approved by", field: 'Approved by', editable: true},
  239. {headerName: "Workflow Chain", field: "Workflow Chain"},
  240. {headerName: "Generate Report", field: "Generate Report", cellRenderer: reportCellRendererFunc, pinned: 'right'},
  241. {
  242. headerName: "Download",
  243. field: "Download",
  244. cellRenderer: function(params) {
  245. if (params.value && params.value.url) {
  246. return '<a href="' + params.value.url + '" target="_blank">' + params.value.name + '</a>'
  247. }
  248. /* if (){
  249.  
  250. }*/
  251. //var storage = localStorage.getItem(params.node.id)
  252. //if (storage !== null){
  253. // let link = JSON.parse(storage)
  254.  
  255. // return '<a href="' + link.url + '" target="_blank">' + link.name + '</a>'
  256. //}
  257. return ' '
  258. }
  259. },
  260. ];
  261.  
  262. // let the grid know which columns and what data to use
  263. var gridOptions = {
  264.  
  265. columnDefs: columnDefs,
  266. enableFilter: true,
  267. masterDetail: true,
  268. filter: true,
  269. enableCellChangeFlash: true,
  270. getRowNodeId: function(data) { return data['pat_id']; },
  271. detailCellRendererParams: {
  272. detailGridOptions: {
  273. enableFilter: true,
  274. filter: true,
  275. columnDefs: [
  276. {headerName: "Sample #", field: "Sample #"},
  277. {headerName: "Sample ID", field: "Sample ID"},
  278. {headerName: "STR Result", field: 'STR Result'},
  279. {headerName: "NGS Result", field: "NGS Result"},
  280. {headerName: "Relation", field: 'Relation'},
  281. {headerName: "QC", field: "QC"},
  282. {headerName: "Interpretation", field: "Interpretation", editable: true},
  283. {headerName: "Include in Report", field: 'Include in Report', pinned: 'right',
  284. cellRenderer: function(params) {
  285. var input = document.createElement('input');
  286. input.type="checkbox";
  287. input.addEventListener('click', function (event) {
  288. params.value= !params.value;
  289. params.node.data.fieldName = params.value;
  290. gridOptions.api.refreshCells()
  291. });
  292. return input;
  293. }},
  294. ],
  295. onFirstDataRendered(params) {
  296. params.api.sizeColumnsToFit();
  297. }
  298. },
  299. getDetailRowData: function (params) {
  300. params.successCallback(params.data.Samples);
  301. },
  302. },
  303. onFirstDataRendered(params) {
  304. params.api.sizeColumnsToFit();
  305. }
  306. };
  307.  
  308. // lookup the container we want the Grid to use
  309. var gridDiv = document.querySelector('#gridDiv');
  310.  
  311. // create the grid passing in the div to use together with the columns & data we want to use
  312. new agGrid.Grid(gridDiv, gridOptions);
  313.  
  314. // Get Grouped Experiments
  315. const getGroupedChainExperiments = groupDuplicates('chain_uuid', data.results);
  316. var dna_dict = {}
  317. for (const [chain_key, chain_value] of Object.entries(getGroupedChainExperiments)) {
  318.  
  319. // Initialize the row as an object
  320. var row = {};
  321.  
  322. // Child Table data to be held.
  323. row["Samples"] = [];
  324. row["Patient ID"] = chain_value[0]['sample_name'];
  325. let row_storage = new Object()
  326. row["Workflow Chain"] = "POC Chain"
  327. let pat_uuid = chain_value[0]['sample_uuid']
  328.  
  329. const getsGroupedExperiments = groupDuplicates('workflow_definition_name', chain_value);
  330.  
  331. let patient_headers = ["Last Name", "First Name", "Chart Number", "DOB",
  332. "Partner Last Name", "Partner First Name", "Partner DOB", "MD", "Patient Gender", "Partner Gender", "Partner Chart Number", "Partner Comments", "Date Received", "GA by Dates", "GA by Size", "Method of Conception", "Comments & Special Requests"]
  333. for (const [workflow_key, workflow_value] of Object.entries(getsGroupedExperiments)) {
  334. if (workflow_key.includes("Receive POC Request")) {
  335. let getGroupedProtocols = groupDuplicates('protocol_name', workflow_value);
  336. for (const [protocol_key, protocol_value] of Object.entries(getGroupedProtocols)) {
  337. // Initialize the row as an object
  338. if (protocol_key === "Receive POC Request") {
  339. Object.values(protocol_value).find((item) => {
  340. if (patient_headers.includes(item.resource_var_name)) {
  341. if (item.value !== null) {
  342. row[item.resource_var_name] = item.value
  343. }
  344. }
  345.  
  346. })
  347. }
  348.  
  349. }
  350. }
  351.  
  352. row["# Controls"] = "N/A";
  353.  
  354. let patient = row['Patient ID'];
  355. let pcn = row['Partner Chart Number'];
  356. let pln = row['Partner Last Name'];
  357. let pfn = row['Partner First Name'];
  358. let ln_fn = pln + ' ' + pfn;
  359.  
  360. $.ajax({
  361. method: "GET",
  362. url: '/api/samples/' + pat_uuid,
  363. async: true,
  364. success: function(data){
  365. let meta = data[0].meta
  366. if (meta.reports.POC.ln_fn){
  367. row['Download'] ='<a href="' + meta.reports.POC.ln_fn.url[length(meta.reports.POC.ln_fn.url.length-1)] + '" target="_blank">' + 'Download Report' + '</a>'
  368. }
  369.  
  370. },
  371. error: function (error) {
  372. console.error(error);
  373. //ReportApp.utils.showNotification(error, 'error')
  374. }
  375.  
  376. })
  377.  
  378. row['pat_id'] = pat_uuid.concat(' ', pcn, ' ',ln_fn, ' POC');
  379.  
  380. if (workflow_key.includes("Create Fetus")){
  381. let getGroupedProtocols = groupDuplicates('protocol_name', workflow_value);
  382. let fetus_dict = getGroupedProtocols['Create Sub-samples']
  383. let ss_dict = {}
  384. let getGroupedSS = groupDuplicates('sample_uuid', fetus_dict)
  385. for (const [sample_key, sample_values] of Object.entries(getGroupedSS)){
  386. Object.values(sample_values).find((item) => {
  387. if (sample_key in ss_dict){
  388. if (item.resource_var_name === "Relation"){
  389. ss_dict[sample_key]['Relation'] = item.value
  390. }
  391. if (item.resource_var_name === "Fetus ID"){
  392. ss_dict[sample_key]['Fetus ID'] = item.value
  393. }
  394. }
  395. else {
  396. if (item.resource_var_name === "Relation"){
  397. ss_dict[sample_key] = {}
  398. ss_dict[sample_key]['Relation'] = item.value
  399. }
  400. if (item.resource_var_name === "Fetus ID"){
  401. ss_dict[sample_key] = {}
  402. ss_dict[sample_key]['Fetus ID'] = item.value
  403. }
  404. }
  405. })
  406. }
  407. }
  408.  
  409. if (workflow_key.includes("Veriseq NGS")){
  410. let getGroupedProtocols = groupDuplicates('protocol_name', workflow_value);
  411. let ngs_dict = getGroupedProtocols['NGS Testing List']
  412. let getGroupedDNA = groupDuplicates('sample_uuid', ngs_dict)
  413. for (const [sample_key, sample_values] of Object.entries(getGroupedDNA)){
  414. Object.values(sample_values).find((item) => {
  415. if (sample_key in dna_dict){
  416. if (item.tag_name==='seq_tech' && item.value !== null){
  417. row["Technician"] = item.value
  418. }
  419. if (item.resource_var_name === "Sample Number"){
  420. dna_dict[sample_key]['Sample_Number'] = item.value
  421. }
  422. }
  423. else {
  424. if (item.resource_var_name === "Sample Number"){
  425. dna_dict[sample_key] = {}
  426. dna_dict[sample_key]['Sample Number'] = item.value
  427. }
  428. }
  429. })
  430. }
  431. }
  432.  
  433. if (workflow_key.includes("Extract DNA")){
  434. let getGroupedProtocols = groupDuplicates('protocol_name', workflow_value);
  435. let ex_dict = getGroupedProtocols['Extract gDNA']
  436. let getGroupedEx = groupDuplicates('sample_uuid', ex_dict)
  437. for (const [sample_key, sample_values] of Object.entries(getGroupedDNA)){
  438. Object.values(sample_values).find((item) => {
  439. if (sample_key in dna_dict){
  440. if (item.resource_var_name === "Parent ID"){
  441. dna_dict[sample_key]['Parent ID'] = item.value
  442. }
  443. }
  444. else {
  445. if (item.resource_var_name === "Parent ID"){
  446. dna_dict[sample_key] = {}
  447. dna_dict[sample_key]['Parent ID'] = item.value
  448. }
  449. }
  450. })
  451. }
  452. }
  453.  
  454.  
  455.  
  456. const getsGroupedSamples = groupDuplicates("sample_uuid", workflow_value);
  457.  
  458.  
  459. for (const [sample_key, sample_value] of Object.entries(getsGroupedSamples)) {
  460. if (sample_value[0]['sample_name'].includes("PAT")){
  461. continue
  462. }
  463.  
  464. const workflows_tag_values = ['Data Analysis', 'Identifiler', 'Collect and Extract Buccal Swab', 'Veriseq NGS', 'Extract DNA'];
  465.  
  466. if (workflows_tag_values.includes(sample_value[0]["workflow_definition_name"])) {
  467.  
  468. if (sample_key in row_storage){
  469. row_storage[sample_key] = samplesChildTable(sample_key, sample_value, row_storage[sample_key], sample_value[0]['workflow_definition_name'])
  470.  
  471. }
  472. else {
  473. let row_dict = new Object()
  474. row_storage[sample_key] = samplesChildTable(sample_key,sample_value, row_dict, sample_value[0]['workflow_definition_name'])
  475. }
  476.  
  477. }
  478. }
  479.  
  480. }
  481.  
  482. for (let [s_key, s_values] of Object.entries(row_storage)){
  483. if (dna_dict[s_values['Parent ID']]){
  484. row_storage[s_key]['Sample #'] = dna_dict[s_values['Parent ID']]['Sample Number']
  485. }
  486. row['Samples'].push(s_values)
  487. }
  488.  
  489. rowData.push(row);
  490. }
  491. gridOptions.api.setRowData(rowData);
  492.  
  493. // Cell Renderers
  494. function reportCellRendererFunc() {}
  495.  
  496. // Handle the the gui element inside of the cell
  497. reportCellRendererFunc.prototype.getGui = function() {
  498. return this.eGui;resource
  499. };
  500.  
  501. // Report Cell Renderer for generating reports
  502. reportCellRendererFunc.prototype.init = function(params) {
  503. this.eGui = document.createElement('div');
  504. this.eGui.innerHTML = '<button class="generate-button">Generate</button>';
  505. this.eButton = this.eGui.querySelector('.generate-button');
  506. this.eventListener = function() {
  507. reportClicked(params.node.data, params.node.rowIndex, this);
  508. this.setAttribute("style", "color: #ffffff;\n" +
  509. " border-color: #0e76ba;\n" +
  510. " background-color: lightgrey;font-size: 13px;\n" +
  511. " font-weight: 600;\n" +
  512. " min-width: 0;\n" +
  513. " min-height: 26px;\n" +
  514. " border-radius: 2px;\n" +
  515. " cursor: pointer;\n" +
  516. " display: inline-flex;\n" +
  517. " border: 1px solid;\n" +
  518. " vertical-align: middle;" )
  519. };
  520. this.eButton.addEventListener('click', this.eventListener);
  521. this.eButton.setAttribute("style", "color: #ffffff;\n" +
  522. " border-color: #0e76ba;\n" +
  523. " background-color: #0e76ba;font-size: 13px;\n" +
  524. " font-weight: 600;\n" +
  525. " min-width: 0;\n" +
  526. " min-height: 26px;\n" +
  527. " border-radius: 2px;\n" +
  528. " cursor: pointer;\n" +
  529. " display: inline-flex;\n" +
  530. " border: 1px solid;\n" +
  531. " vertical-align: middle;" )
  532. };
  533.  
  534. function reportClicked(params,rowIndex, button) {
  535. var pipelineName = 'POC%20Report';
  536. let url = '/api/pipelines?name=' + pipelineName;
  537. let generateButtonElements = document.getElementsByClassName('generate-button');
  538. for (var i = 0; i < generateButtonElements.length; i ++) {
  539. generateButtonElements[i].disabled = true
  540. }
  541. ReportApp.utils.startSpinner();
  542. ReportApp.utils.get(
  543. url,
  544. "",
  545. function (json) {
  546. var sample_selection = params.Samples //gridOptions.api.getModel().rowsToDisplay[0].data.Samples;
  547. var sample_list = [];
  548. var sample_number = [];
  549. var str_results = [];
  550. var ngs_results = [];
  551. var relations = [];
  552. var qc_results = [];
  553. var interpretations = [];
  554. for (var i = 0; i < sample_selection.length; i++ ) {
  555. if (sample_selection[i]["fieldName"] === true) {
  556. sample_number.push((sample_selection[i]["Sample #"]))
  557. str_results.push((sample_selection[i]["STR Result"]))
  558. ngs_results.push((sample_selection[i]["NGS Result"]))
  559. relations.push((sample_selection[i]["Relation"]))
  560. qc_results.push((sample_selection[i]["QC"]))
  561. sample_list.push(sample_selection[i]["Sample ID"])
  562. interpretations.push((sample_selection[i]["Interpretation"]))
  563. }
  564.  
  565. }
  566.  
  567. if (sample_number.length === 0) {
  568. window.reportInteractionApi.toast("No samples selected!", "Please select at least one sample to generate a report.")
  569. return;
  570. }
  571.  
  572. var payload = {};
  573.  
  574. payload["samples"] = sample_list;
  575. payload["sample_number"] = sample_number;
  576. payload["str_results"] = str_results;
  577. payload["ngs_results"] = ngs_results;
  578. payload["relations"] = relations;
  579. payload["qc_results"] = qc_results;
  580. payload["interpretations"] = interpretations;
  581. payload["last_name"] = params['Last Name'];
  582. payload["first_name"] = params['First Name'];
  583. payload["chart_number"] = params['Chart Number'];
  584. payload["patient_id"] = params['Patient ID'];
  585. payload["report_wfc"] = params['Workflow Chain'];
  586. payload["partner_last_name"] = params['Partner Last Name'];
  587. payload["partner_first_name"] = params['Partner First Name'];
  588. payload["patient_dob"] = params['DOB'];
  589. payload["partner_dob"] = params['Partner DOB'];
  590. payload["patient_gender"] = params['Patient Gender'];
  591. payload["partner_gender"] = params['Partner Gender'];
  592. payload["partner_comments"] = params['Partner Comments'];
  593. payload["partner_chart_number"] = params['Partner Chart Number'];
  594. payload["poc_receiving_date"] = params['Date Received'];
  595. payload["poc_ga_by_size"] = params['GA by Size'];
  596. payload["poc_ga_by_date"] = params['GA by Dates'];
  597. payload["method_of_conception"] = params['Method of Conception'];
  598. payload["poc_special_requests"] = params['Comments & Special Requests'];
  599. payload["tested"] = params["# of Tested Samples"];
  600. payload["controls"] = params['# Controls'];
  601. payload["tech"] = params['Technician'];
  602. payload["analyzer"] = params['Analysed by'];
  603. payload["approver"] = params['Approved by'];
  604. payload["referring_physician"] = params['MD'];
  605.  
  606. var payload_hex= hexPayload(payload);
  607.  
  608. payload_hex.then(function(value){
  609. var hex = value;
  610. })
  611.  
  612. url = '/api/pipeline_instances';
  613. let data = {
  614. 'pipeline': json[0]['uuid'],
  615. 'instances': true,
  616. "env": {"samples": JSON.stringify(payload)},
  617. };
  618.  
  619.  
  620.  
  621. var rowNode = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
  622. var sample_url = '/api/samples/' + params[pat_id].split(' ')[0];
  623. var partner = params[pat_id].split(' ')[1] + ' ' params[pat_id].split(' ')[2];
  624.  
  625.  
  626. if (params['Download']){
  627. $.ajax({
  628. method: "GET",
  629. url: sample_url
  630. async: true,
  631. success: function(data){
  632. let meta = data[0].meta;
  633.  
  634. hexes = meta.reports.POC.partner.hex;
  635. urls = meta.reports.POC.partner.url;
  636.  
  637. if (hex.includes(hexes)){
  638. hex_index = hexes.findIndex(_hex)
  639. old_report = urls[hex_index]
  640.  
  641. var link = {
  642. 'name': 'Download Report',
  643. 'url': old_report
  644. }
  645.  
  646. rowNode.setDataValue('Download', link);
  647.  
  648. };
  649.  
  650. $.ajax({
  651. method: "POST",
  652. url: url,
  653. contentType:"application/json; charset=utf-8",
  654. dataType: "json",
  655. data: JSON.stringify(data), //posting the pipeline uuid
  656. success: function (data) {
  657.  
  658. monitorPipeline(data[0].uuid, rowIndex, button, sample_url, partner, hex);
  659. },
  660. error: function (error) {
  661. console.error(error);
  662. ReportApp.utils.showNotification(error, 'error')
  663. },
  664. processData: false
  665. });
  666.  
  667. },
  668. error: function (error) {
  669. console.error(error);
  670. //ReportApp.utils.showNotification(error, 'error')
  671. }
  672.  
  673. });
  674.  
  675. };
  676.  
  677. $.ajax({
  678. method: "POST",
  679. url: url,
  680. contentType:"application/json; charset=utf-8",
  681. dataType: "json",
  682. data: JSON.stringify(data), //posting the pipeline uuid
  683. success: function (data) {
  684.  
  685. monitorPipeline(data[0].uuid, rowIndex, button, sample_url, partner, hex);
  686. },
  687. error: function (error) {
  688. console.error(error);
  689. ReportApp.utils.showNotification(error, 'error')
  690. },
  691. processData: false
  692. });
  693.  
  694. },
  695. function (error) {
  696. console.error(error)
  697. ReportApp.utils.showNotification(error, 'error')
  698. }
  699. )
  700. }
  701.  
  702. function monitorPipeline(uuid, rowIndex, button, sample_url, partner, new_hex) {
  703. monitorInterval = setInterval(function() {
  704. ReportApp.utils.get(
  705. '/api/pipeline_instances/' + uuid,
  706. {},
  707. function(json) {
  708. if (json.state === 'done'){
  709. clearInterval(monitorInterval);
  710. var task_uuid = json.steps[0]['uuid'];
  711. $.ajax({
  712. url: '/api/task_instances/' + task_uuid,
  713. type: 'GET',
  714. success: function(data) {
  715. var task_files = data['task_files'];
  716.  
  717. for (var i = 0; i < task_files.length; i++) {
  718. if (task_files[i]['taskfile_name'] === 'poc-report') {
  719. var file_uuid = task_files[i]['uuid']
  720. }
  721. }
  722. //var url = '/api/files/' + file_uuid + '/export' //add in var
  723. var link = {
  724. 'name': 'Download Report',
  725. 'url': '/api/files/' + file_uuid + '/export'
  726. }
  727. console.log(new_hex);
  728. console.log(link.url);
  729. /* $.ajax({
  730. method: "POST",
  731. url: sample_url,
  732. //contentType:"application/json; charset=utf-8",
  733. async: true,
  734. //dataType: "json",
  735. //data: JSON.stringify(data),
  736. success: function (data) {
  737. meta = data[0].meta;
  738. //meta.reports.POC.partner.hex.push(hex);
  739. //meta.reports.POC.partner.url.push(link.url);
  740. },
  741. error: function (error) {
  742. console.error(error);
  743. ReportApp.utils.showNotification(error, 'error')
  744. },
  745. processData: false
  746. });*/
  747. //var rowNode = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
  748. rowNode.setDataValue('Download', link);
  749. ReportApp.utils.stopSpinner();
  750. button.setAttribute("style", "color: #ffffff;\n" +
  751. " border-color: #0e76ba;\n" +
  752. " background-color: #0e76ba;font-size: 13px;\n" +
  753. " font-weight: 600;\n" +
  754. " min-width: 0;\n" +
  755. " min-height: 26px;\n" +
  756. " border-radius: 2px;\n" +
  757. " cursor: pointer;\n" +
  758. " display: inline-flex;\n" +
  759. " border: 1px solid;\n" +
  760. " vertical-align: middle;" );
  761. let generateButtonElements = document.getElementsByClassName('generate-button');
  762. for (var j = 0; j < generateButtonElements.length; j++) {
  763. generateButtonElements[j].disabled = false;
  764. };
  765. },
  766. error: function(error) {
  767. window.reportInteractionApi.toast({
  768. status: 'error',
  769. title: 'Report Error',
  770. description: 'Error Generating Report'
  771. });
  772. console.log(error)
  773. }
  774. })
  775.  
  776. } else if (json.state === 'failed') {
  777. clearInterval(monitorInterval);
  778. window.reportInteractionApi.toast({
  779. status: 'error',
  780. title: 'Report Error',
  781. description: 'Error Generating Report'
  782. });
  783. console.log(error)
  784. }
  785.  
  786. },
  787. function (error) {
  788. clearInterval(monitorInterval);
  789. var rowNode = gridOptions.api.getRowNode(row);
  790. var rowData = rowNode.data;
  791. window.reportInteractionApi.toast({
  792. status: 'error',
  793. title: 'Report Error',
  794. description: 'Error Generating Report'
  795. });
  796. })
  797. }, 1000);
  798. }
  799.  
  800. gridOptions.api.redrawRows()
  801. }
  802.  
  803.  
  804.  
  805. </script>
  806.  
  807. </body>
  808. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement