Commit f521cdff authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'Upload-to-IPFS' into 'master'

Adding EHR content IPFS completed

See merge request !16
parents bb8b426d 4c3906f6
......@@ -4,4 +4,10 @@ DATABASE_URL="mongodb+srv://dbUser:1997Ishini%21@cluster0.lmazo.mongodb.net/rese
SERVER_PORT=4000
STELLARPUBLICKEY="GB3U2F6MWAQ43O6J4AIUQXEMTK5XQZWURC3SF4D37DPBFRY4HCZGRBLG"
STELLARSEED="SBUXCZ7F7G5Z3QK3NKM52UWVJWFSLEVVGQOCIEWEJY4DOYMYVOMUTS4B"
AESKEY="QfTjWnZr4u7x!A%D"
\ No newline at end of file
AESKEY="QfTjWnZr4u7x!A%D"
IPFSPROJECTID="2KmA9x9x9odbbz9uA00GD5ZKOnv"
IPFSAPIKEY="975ea3b06bd36d434b57a315a86287ee"
IPFSHOST="ipfs.infura.io"
IPFSPORT=5001
IPFSPROTOCOL="https"
IPFSURL="https://ipfs.io/ipfs/"
\ No newline at end of file
{
"cSpell.words": ["ipfs"]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,8 +18,11 @@
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"html-to-image": "^1.11.4",
"ipfs-infura": "^1.1.9",
"mongoose": "^6.8.0",
"node-htmlpdf": "^1.0.4",
"request": "^2.88.2",
"stellar-sdk": "^10.4.1"
},
"devDependencies": {
......@@ -27,6 +30,7 @@
"@types/crypto-js": "^4.1.1",
"@types/express": "^4.17.15",
"@types/nodemon": "^1.19.2",
"@types/request": "^2.48.8",
"dotenv": "^16.0.3",
"nodemon": "^2.0.20"
}
......
......@@ -6,6 +6,9 @@ const Patient = require("./../../model/patient/patient");
const axios = require("axios");
const StellarSDK = require("stellar-sdk");
const htmlpdf = require("node-htmlpdf");
const IPFS = require("ipfs-infura");
const fs = require("fs");
const request = require("request");
let currentHash;
let genesisHash;
let isGenesisPassed;
......@@ -259,25 +262,69 @@ router.post("/", async (req, res) => {
htmlString = htmlString + `</body></html>`;
console.log("HTML code for EHR generated");
//create the PDF document for EHR
let path = `./patientehr/` + decryptedPatientKey + `-EHR.pdf`;
let pdfOptions = {
path: path,
format: "A4",
};
htmlpdf
.create(htmlString, pdfOptions)
.then((buff) => {
console.log("PDF created");
//create the IPFS instance
const ipfs = new IPFS({
host: process.env.IPFSHOST,
port: process.env.IPFSPORT,
protocol: process.env.IPFSPROTOCOL,
projectId: process.env.IPFSPROJECTID,
projectSecret: process.env.IPFSAPIKEY,
});
//add the EHR content to IPFS and get the hash
ipfs
.add(htmlString)
.then((response) => {
let ipfsContentCID = response.toString();
//!Use this when getting EHR
// request.post(
// {
// url: "https://ipfs.infura.io:5001/api/v0/cat",
// qs: {
// arg: hash,
// },
// headers: {
// Authorization:
// "Basic " +
// Buffer.from(
// process.env.IPFSPROJECTID + ":" + process.env.IPFSAPIKEY
// ).toString("base64"),
// },
// },
// (error, response, body) => {
// if (error) {
// console.log(error);
// } else {
// //create the PDF document for EHR
// let path = `./patientehr/` + decryptedPatientKey + `-EHR.pdf`;
// let pdfOptions = {
// path: path,
// format: "A4",
// };
// htmlpdf
// .create(htmlString, pdfOptions)
// .then((buff) => {
// console.log("PDF created");
// })
// .catch((errorWhenGeneratingPDF) => {
// console.log(
// "Error when generating PDF : " + errorWhenGeneratingPDF
// );
// console.log(
// "/patient/createnft - NFT creation and sharing failed"
// );
// return res.status(500).json({
// message:
// "Error when generating PDF : " +
// errorWhenGeneratingPDF,
// });
// });
// }
// }
// );
//TODO: create NFT request
})
.catch((errorWhenGeneratingPDF) => {
console.log(
"Error when generating PDF : " + errorWhenGeneratingPDF
);
console.log("/patient/createnft - NFT creation and sharing failed");
return res.status(500).json({
message: "Error when generating PDF : " + errorWhenGeneratingPDF,
});
.catch((errorWhenAddingToIPFS) => {
console.log(errorWhenAddingToIPFS);
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment