public IActionResult PatientRecords() { ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); if (HttpContext.Session.GetString(Globals.currentDSPriK) == null || HttpContext.Session.GetString(Globals.currentDAPriK) == null) { return(RedirectToAction("Login")); } else if (HttpContext.Session.GetString(Globals.currentPSPubK) == null || HttpContext.Session.GetString(Globals.currentPAPubK) == null) { return(RedirectToAction("PatientLookUp")); } else { Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(HttpContext.Session.GetString(Globals.currentPPHN)); var doctorSignPrivateKey = HttpContext.Session.GetString(Globals.currentDSPriK); var doctorAgreePrivateKey = HttpContext.Session.GetString(Globals.currentDAPriK); var doctorSignPublicKey = EncryptionService.getSignPublicKeyStringFromPrivate(doctorSignPrivateKey); var patientSignPublicKey = HttpContext.Session.GetString(Globals.currentPSPubK); PatientCredMetadata userMetadata = _bigChainDbService.GetMetadataFromAssetPublicKey <PatientCredMetadata>(userAsset.id, patientSignPublicKey); var prescriptionsList = _bigChainDbService.GetAllTypeRecordsFromDPublicPPublicKey <string, PrescriptionMetadata> (AssetType.Prescription, doctorSignPublicKey, patientSignPublicKey); var prescriptions = new List <PrescriptionFullData>(); foreach (var prescription in prescriptionsList) { var hashedKey = prescription.metadata.AccessList[doctorSignPublicKey]; var dataDecryptionKey = EncryptionService.getDecryptedEncryptionKey(hashedKey, doctorAgreePrivateKey); var data = EncryptionService.getDecryptedAssetData(prescription.data.Data, dataDecryptionKey); var newEntry = new PrescriptionFullData { assetData = JsonConvert.DeserializeObject <Prescription>(data), Metadata = prescription.metadata.data, transID = prescription.transID, assetID = prescription.id }; prescriptions.Add(newEntry); } var patientInfo = userAsset.data.Data; var patientOverviewViewModel = new PatientOverviewViewModel { PatientAsset = patientInfo, PatientMetadata = userMetadata, PatientAge = patientInfo.DateOfBirth.CalculateAge(), Prescriptions = prescriptions.OrderByDescending(p => p.assetData.PrescribingDate).ToList() }; return(View(patientOverviewViewModel)); } }
public IActionResult PatientRecords() { ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName); if (HttpContext.Session.GetString(Globals.currentDSPriK) == null || HttpContext.Session.GetString(Globals.currentDAPriK) == null) { return(RedirectToAction("Login")); } else if (HttpContext.Session.GetString(Globals.currentPSPubK) == null || HttpContext.Session.GetString(Globals.currentPAPubK) == null) { return(RedirectToAction("PatientLookUp")); } else { Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(HttpContext.Session.GetString(Globals.currentPPHN)); var doctorSignPrivateKey = HttpContext.Session.GetString(Globals.currentDSPriK); var doctorAgreePrivateKey = HttpContext.Session.GetString(Globals.currentDAPriK); var doctorSignPublicKey = EncryptionService.getSignPublicKeyStringFromPrivate(doctorSignPrivateKey); var patientSignPublicKey = HttpContext.Session.GetString(Globals.currentPSPubK); PatientCredMetadata userMetadata = _bigChainDbService.GetMetadataFromAssetPublicKey <PatientCredMetadata>(userAsset.id, patientSignPublicKey); var testRequisitionList = _bigChainDbService.GetAllTypeRecordsFromDPublicPPublicKey <string, double> (AssetType.TestRequisition, doctorSignPublicKey, patientSignPublicKey); Dictionary <string, string> testResults = null; if (testRequisitionList.Any()) { testResults = _bigChainDbService.GetAssociatedTestResults(testRequisitionList); } var testRequisitions = new List <TestRequisitionFullData>(); foreach (var testrequisition in testRequisitionList) { var hashedKey = testrequisition.metadata.AccessList[doctorSignPublicKey]; var dataDecryptionKey = EncryptionService.getDecryptedEncryptionKey(hashedKey, doctorAgreePrivateKey); var data = EncryptionService.getDecryptedAssetData(testrequisition.data.Data, dataDecryptionKey); var newEntry = new TestRequisitionFullData { assetData = JsonConvert.DeserializeObject <TestRequisitionAsset>(data), Metadata = testrequisition.metadata.data, assetID = testrequisition.id, transID = testrequisition.transID }; if (testResults != null && testResults.Keys.Contains(testrequisition.id)) { var decryptedResultFile = EncryptionService.getDecryptedAssetData(testResults[testrequisition.id], dataDecryptionKey); newEntry.ResultFile = JsonConvert.DeserializeObject <FileData>(decryptedResultFile); } testRequisitions.Add(newEntry); } var patientInfo = userAsset.data.Data; var patientOverviewViewModel = new PatientOverviewViewModel { PatientAsset = patientInfo, PatientMetadata = userMetadata, PatientAge = patientInfo.DateOfBirth.CalculateAge(), TestRequisitions = testRequisitions.OrderByDescending(p => p.assetData.DateOrdered).ToList() }; return(View(patientOverviewViewModel)); } }