Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 16
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 16
22_23-J 16
Commits
61032c9c
Commit
61032c9c
authored
Jan 04, 2023
by
Kiridena I.T.K_IT19981840
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'practitioner-acceptance-route' into 'master'
practitioner acceptance completed See merge request
!12
parents
03678947
6139d91b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
219 additions
and
0 deletions
+219
-0
ExpressBackend/route/practitioner-routes/acceptance-route.js
ExpressBackend/route/practitioner-routes/acceptance-route.js
+216
-0
ExpressBackend/server.js
ExpressBackend/server.js
+3
-0
No files found.
ExpressBackend/route/practitioner-routes/acceptance-route.js
0 → 100644
View file @
61032c9c
const
express
=
require
(
"
express
"
);
const
router
=
express
.
Router
();
const
DecryptWithServerKey
=
require
(
"
./../../services/decryptionservice
"
);
const
StellarSDK
=
require
(
"
stellar-sdk
"
);
const
PractitionerPatientCount
=
require
(
"
./../../model/practitioner/practitioner-patient
"
);
const
Requests
=
require
(
"
./../../model/patient/request
"
);
router
.
post
(
"
/
"
,
async
(
req
,
res
)
=>
{
//Get the payload
const
decryptedPatientKey
=
req
.
body
.
patient
;
const
decryptedPractitionerKey
=
req
.
body
.
practitionerkey
;
const
decryptedPractitionerSeed
=
req
.
body
.
practitionerseed
;
const
decryptedStatus
=
req
.
body
.
status
;
let
timestamp
;
//check the condition
if
(
decryptedStatus
===
"
Accepted
"
)
{
//load user account
const
userSourceKeyPair
=
StellarSDK
.
Keypair
.
fromSecret
(
decryptedPractitionerSeed
);
const
userPublicKey
=
userSourceKeyPair
.
publicKey
();
const
server
=
new
StellarSDK
.
Server
(
process
.
env
.
STELLARTESTNET
);
const
account
=
await
server
.
loadAccount
(
userPublicKey
);
const
fee
=
await
server
.
fetchBaseFee
();
timestamp
=
new
Date
().
toString
();
//build the transaction
const
genesisTransaction
=
new
StellarSDK
.
TransactionBuilder
(
account
,
{
fee
,
networkPassphrase
:
StellarSDK
.
Networks
.
TESTNET
,
})
.
addMemo
(
StellarSDK
.
Memo
.
text
(
"
Genesis
"
))
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
User
"
,
value
:
decryptedPatientKey
,
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Practitioner
"
,
value
:
decryptedPractitionerKey
,
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Timestamp
"
,
value
:
timestamp
,
})
)
.
setTimeout
(
30
)
.
build
();
//sign the transaction
genesisTransaction
.
sign
(
userSourceKeyPair
);
try
{
//send the transaction
const
genesisTransactionResult
=
await
server
.
submitTransaction
(
genesisTransaction
);
console
.
log
(
"
Genesis transaction added to blockchain : HASH :
"
,
genesisTransactionResult
.
hash
);
console
.
log
(
"
View account creation transaction at : https://horizon-testnet.stellar.org/transactions/
"
+
genesisTransactionResult
.
hash
);
//create insert object
const
insertObject
=
new
PractitionerPatientCount
({
practitionerpubkey
:
decryptedPractitionerKey
,
patientpubkey
:
decryptedPatientKey
,
genesishash
:
genesisTransactionResult
.
hash
,
currenthash
:
genesisTransactionResult
.
hash
,
currentcounter
:
1
,
});
try
{
//save the object in database
const
saveInCollection
=
await
insertObject
.
save
();
console
.
log
(
"
Genesis transaction saved in the database:
"
+
saveInCollection
);
try
{
///update the request record in database
const
updateRequestCollection
=
await
Requests
.
updateOne
(
{
practitioner
:
decryptedPractitionerKey
,
patient
:
decryptedPatientKey
,
},
{
status
:
decryptedStatus
}
);
if
(
!
updateRequestCollection
)
{
console
.
log
(
"
Failed to update the request :
"
+
updateRequestCollection
);
console
.
log
(
"
/practitioner/request - adding practitioner acceptance failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Failed to update the request :
"
+
updateRequestCollection
,
});
}
else
{
console
.
log
(
"
Practitioner acceptance updated in the database:
"
+
updateRequestCollection
);
console
.
log
(
"
/practitioner/request - adding practitioner acceptance success
"
);
return
res
.
status
(
200
).
json
({
message
:
"
Practitioner acceptance updated in the database:
"
+
updateRequestCollection
,
});
}
}
catch
(
errorWhenUpdatingRequestCollection
)
{
console
.
log
(
"
Error when updating request collection in database :
"
+
errorWhenUpdatingRequestCollection
);
res
.
status
(
500
).
json
({
message
:
"
Error when updating request collection in database :
"
+
errorWhenUpdatingRequestCollection
,
});
}
}
catch
(
errorWhenSavingDetailsInDatabase
)
{
console
.
log
(
"
Error sending genesis transaction details to database :
"
+
errorWhenSavingDetailsInDatabase
);
res
.
status
(
500
).
json
({
message
:
"
Error sending genesis transaction details to database :
"
+
errorWhenSavingDetailsInDatabase
,
});
console
.
log
(
"
/practitioner/request - adding practitioner acceptance failed
"
);
}
}
catch
(
errorWhenSendingGenericTransaction
)
{
console
.
log
(
"
Error sending genesis transaction to blockchain :
"
+
errorWhenSendingGenericTransaction
);
res
.
status
(
500
).
json
({
message
:
"
Error sending genesis transaction to blockchain :
"
+
errorWhenSendingGenericTransaction
,
});
console
.
log
(
"
/practitioner/request - adding practitioner acceptance failed
"
);
}
}
else
if
(
decryptedStatus
===
"
Rejected
"
)
{
//update the status
try
{
///update the request record in database
const
updateRequestCollection
=
await
Requests
.
updateOne
(
{
practitioner
:
decryptedPractitionerKey
,
patient
:
decryptedPatientKey
,
},
{
status
:
decryptedStatus
}
);
if
(
!
updateRequestCollection
)
{
console
.
log
(
"
Failed to update the request :
"
+
updateRequestCollection
);
console
.
log
(
"
/practitioner/request - adding practitioner acceptance failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Failed to update the request :
"
+
updateRequestCollection
,
});
}
else
{
console
.
log
(
"
Practitioner acceptance updated in the database:
"
+
updateRequestCollection
);
console
.
log
(
"
/practitioner/request - adding practitioner acceptance success
"
);
return
res
.
status
(
200
).
json
({
message
:
"
Practitioner acceptance updated in the database:
"
+
updateRequestCollection
,
});
}
}
catch
(
errorWhenUpdatingRequestCollection
)
{
console
.
log
(
"
Error when updating request collection in database :
"
+
errorWhenUpdatingRequestCollection
);
res
.
status
(
500
).
json
({
message
:
"
Error when updating request collection in database :
"
+
errorWhenUpdatingRequestCollection
,
});
}
}
else
{
console
.
log
(
"
Incorrect status :
"
,
decryptedStatus
);
console
.
log
(
"
/practitioner/request - adding practitioner acceptance failed
"
);
return
res
.
status
(
400
).
json
({
message
:
"
Incorrect status :
"
+
decryptedStatus
,
});
}
});
module
.
exports
=
router
;
ExpressBackend/server.js
View file @
61032c9c
...
...
@@ -36,6 +36,9 @@ app.use("/practitioner/register", practitionerRegister);
const
practitionerRecords
=
require
(
"
./route/practitioner-routes/records-route
"
);
app
.
use
(
"
/practitioner/records
"
,
practitionerRecords
);
const
practitionerAcceptance
=
require
(
"
./route/practitioner-routes/acceptance-route
"
);
app
.
use
(
"
/practitioner/request
"
,
practitionerAcceptance
);
app
.
listen
(
process
.
env
.
SERVER_PORT
,
()
=>
console
.
log
(
"
Server started on port
"
+
process
.
env
.
SERVER_PORT
)
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment