Skip to content

Commit

Permalink
Completed: consumePrescription, updatePrescription and deletePrescrip…
Browse files Browse the repository at this point in the history
…tion. Added: patient in showPrescription, bug fixed newPrescription
  • Loading branch information
Alex99y committed Aug 13, 2019
1 parent 23bb0f2 commit ccd05bd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
20 changes: 19 additions & 1 deletion api/controllers/services/secure-rec/prescription/delete.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fabric = require('../../../../../fabric-api/chaincodeTransactions');
const ursa = require('../../../../../crypto/keys');

module.exports = {

friendlyName: 'Secure Rec delete prescription',
Expand All @@ -14,6 +17,14 @@ module.exports = {
invalid: {
responseType: 'bad-combo',
description: 'Los parámetros proporcionados son inválidos.'
},
fabric: {
responseType: 'fabric-error',
description: 'Error Hyperledger Fabric'
},
internalError: {
responseType: 'internal-error',
description: 'Error changing password'
}
},

Expand All @@ -22,11 +33,18 @@ module.exports = {
if ( inputs.hash === undefined )
return exits.invalid();

console.log(inputs.hash);
let owner = this.req.session.auth, pubKey = await ursa.getPublicKey(owner.privateKey), result, Args;
try{
Args = [pubKey, inputs.hash];
result = await fabric.invokeTransaction('mychannel','Org1MSP','secureRec', 'deletePrescription', Args);
}catch(err){
return exits.fabric();
}

return exits.success({
success: true,
message: 'Deleted prescription',
hash: result.hash
});

}
Expand Down
37 changes: 32 additions & 5 deletions api/controllers/services/secure-rec/prescription/edit-patient.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fabric = require('../../../../../fabric-api/chaincodeTransactions');
const ursa = require('../../../../../crypto/keys');

module.exports = {

friendlyName: 'Secure Rec edit prescription patient',
Expand Down Expand Up @@ -27,22 +30,46 @@ module.exports = {
invalid: {
responseType: 'bad-combo',
description: 'Los parámetros proporcionados son inválidos.'
},
fabric: {
responseType: 'fabric-error',
description: 'Error Hyperledger Fabric'
},
internalError: {
responseType: 'internal-error',
description: 'Error changing password'
}
},

fn: async function (inputs, exits) {

if (inputs.hash === undefined || inputs.pharmacy === undefined || inputs.pharmacy === '' || inputs.selfPayment === undefined)
return exits.invalid();

console.log(inputs.hash);
console.log(inputs.pharmacy);
console.log(inputs.selfPayment);
console.log(inputs.insurance);

let owner = this.req.session.auth, pubKey = await ursa.getPublicKey(owner.privateKey);
let provider;
let result, Args;
try{
provider = await User.findOne({ emailAddress: inputs.pharmacy});
if ( inputs.selfPayment ) {
Args = [pubKey, provider.publicKey, "", inputs.hash];
}else{
let insurance = await User.findOne({ emailAddress: inputs.insurance});
Args = [pubKey, provider.publicKey, insurance.publicKey, inputs.hash];
}
}catch(err){
return exits.internalError();
}
try {
result = await fabric.invokeTransaction('mychannel','Org1MSP','secureRec', 'updatePrescription', Args);
}catch(err){
return exits.fabric();
}

return exits.success({
success: true,
message: 'Edit prescription',
hash: result.hash
});

}
Expand Down
21 changes: 19 additions & 2 deletions api/controllers/services/secure-rec/prescription/edit-provider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fabric = require('../../../../../fabric-api/chaincodeTransactions');
const ursa = require('../../../../../crypto/keys');

module.exports = {

friendlyName: 'Secure Rec edit prescription',
Expand All @@ -14,6 +17,14 @@ module.exports = {
invalid: {
responseType: 'bad-combo',
description: 'Los parámetros proporcionados son inválidos.'
},
fabric: {
responseType: 'fabric-error',
description: 'Error Hyperledger Fabric'
},
internalError: {
responseType: 'internal-error',
description: 'Error changing password'
}
},

Expand All @@ -22,11 +33,17 @@ module.exports = {
if ( inputs.hash === undefined )
return exits.invalid();

console.log(inputs.hash);

let owner = this.req.session.auth, pubKey = await ursa.getPublicKey(owner.privateKey), result, Args;
try{
Args = [pubKey, inputs.hash];
result = await fabric.invokeTransaction('mychannel','Org1MSP','secureRec', 'consumePrescription', Args);
}catch(err){
return exits.fabric();
}
return exits.success({
success: true,
message: 'Edit prescription',
hash: result.hash
});

}
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/services/secure-rec/prescription/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module.exports = {
status: result.prescriptions[i].status,
description: data.description,
doctor: doctor.emailAddress,
patient: patient.emailAddress,
insurance: insurance,
provider: provider,
ipfsHash: data.hashFile,
Expand All @@ -90,7 +91,6 @@ module.exports = {
} else if ( prescription.status === 'DELETED' ){
prescriptions.push(prescription);
}
console.log(prescription);
}
}
if (user.type == 'patient'){
Expand Down

0 comments on commit ccd05bd

Please sign in to comment.