Skip to content

Commit

Permalink
#9 - Updated the UI that allows us to test the parsing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
koen-ongena-imec committed Nov 7, 2022
1 parent a91c5d3 commit 2ed6dab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ nvm use
npm install
npm run dev
```

The website is available on `http://localhost:8080/`, the API on `http://localhost:8080/`
1 change: 1 addition & 0 deletions src/handlers/complianceReportPdfHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@ const complianceReportPdfHandler = genericPdfHandler(parseComplianceReport);

module.exports = {
complianceReportPdfHandler,
parseComplianceReport,
};
21 changes: 19 additions & 2 deletions src/handlers/homeViewHandler.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
const { parseDiagnosticReportPdfFile } = require('./diagnosticReportPdfHandler');
const { parseComplianceReport } = require('./complianceReportPdfHandler');

function chooseParser(typeOfReport) {
switch (typeOfReport) {
case 'complianceReport':
return parseComplianceReport;
case 'diagnosticReport':
default:
return parseDiagnosticReportPdfFile;
}
}

const post = (req, res) => {
if (!req.files) {
res.status(400);
} else {
const { pdf } = req.files;
parseDiagnosticReportPdfFile(pdf).then((data) => {
res.status(200).render('index', { values: data, filename: pdf.name });
const { typeOfReport } = req.body;
const parser = chooseParser(typeOfReport);
parser(pdf).then((data) => {
if (data) {
res.status(200).render('index', { values: data, filename: pdf.name });
} else {
res.status(500).render('index', { error: 'Something went wrong. Are you sure this is a valid PDF of the specified type?' });
}
}).catch(() => {
res.status(500).render('index', { error: 'Something went wrong. Are you sure this is a valid PDF?' });
});
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { diagnosticReportPdfHandler } = require('./handlers/diagnosticReportPdfHa
const homeViewHandler = require('./handlers/homeViewHandler');
const morganMiddleware = require('./tools/morgan');
const logger = require('./tools/logger');
const pdfHandler = require('./handlers/pdfHandler');

/** *****************
* Express setup
Expand Down
36 changes: 32 additions & 4 deletions src/views/index.handlebars
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
<div class="container">
{{#if error }}
<div class="alert alert-danger show" role="alert">
{{error}}
</div>
<div class="alert alert-danger show" role="alert">
{{error}}
</div>
{{/if}}

<h2>Diagnostic report</h2>

<form action="/" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="formFile" class="form-label">Resmed PDF file:</label>
<label for="formFile" class="form-label">Type of file:</label>
</div>

<div class="mb-3">
<div class="radio">
<label>
<input type="radio" name="typeOfReport" id="typeOfReport1" value="diagnosticReport" checked>
Diagnostic
report
</label>
</div>
<div class="radio">
<label class="radio">
<input type="radio" name="typeOfReport" id="typeOfReport2" value="complianceReport"> Compliance
report
</label>
</div>
</div>

<div class="mb-3">
<label for="formFile" class="form-label">PDF file:</label>
<input required class="form-control" type="file" id="pdf" name="pdf">
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
{{#if error }}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
Something went wrong while parsing {{ filename }}: {{error}}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{{/if }}
{{#if values.length }}
<hr>

Expand Down

0 comments on commit 2ed6dab

Please sign in to comment.