public async Task <IActionResult> GetDocumentStatus(string mortgageApplicationId, string documentId, CancellationToken cancellationToken) { var blob = await StorageHelper.GetBlob(_storageAccountName, "rawdocuments", $"{mortgageApplicationId.ToLower()}/{documentId}"); if (!(await blob.ExistsAsync())) { return(NotFound()); } MortgageApplicationDocument doc = new MortgageApplicationDocument(); doc.PopuplateFromBlobProperties(blob); var finalBlob = await StorageHelper.GetBlob(_storageAccountName, "parseddocuments", $"final/{mortgageApplicationId.ToLower()}/{documentId}"); if (await finalBlob.ExistsAsync()) { doc.Status = MortgageApplicationStatus.Processed; doc.HasParsedResults = true; } var markedupBlob = await StorageHelper.GetBlob(_storageAccountName, "parseddocuments", $"markedup/{mortgageApplicationId.ToLower()}/{documentId}"); if (await markedupBlob.ExistsAsync()) { doc.HasMarkedupResults = true; } return(Ok(doc)); }
public static async Task Run([BlobTrigger("rawdocuments/{name}", Connection = "Documents")] CloudBlockBlob fileBlob, [Blob("parseddocuments", Connection = "Documents")] CloudBlobContainer parsedDirectory, ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context, CancellationToken cancellationToken) { try { if (fileBlob.Metadata.ContainsKey("DocumentType")) { //skip already processed documents return; } var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); string predictionKey = config["PredictionKey"]; string predictionProjectId = config["PredictionProjectId"]; string cognativeKey = config["CognativeKey"]; double minimumPrecision = double.Parse(config["MinimalPrecision"]); string computerVisionServiceHostName = config["ComputerVisionServiceHostName"]; string customVisionServiceHostName = config["CustomVisionServiceHostName"]; string documentURLWithSAS = GetBlobSasUri(fileBlob); string tagName = await AnalyseImageAsync(documentURLWithSAS, predictionKey, predictionProjectId, minimumPrecision, customVisionServiceHostName, cancellationToken); if (!tagName.IsEmpty()) { MortgageApplicationDocument mortgageApplicationDocument = new MortgageApplicationDocument(); mortgageApplicationDocument.PopuplateFromBlobProperties(fileBlob); mortgageApplicationDocument.DateParsed = DateTimeOffset.UtcNow; var parsedResults = await ParseDocumentTextAsync(documentURLWithSAS, cognativeKey, computerVisionServiceHostName, mortgageApplicationDocument.FileName, cancellationToken); string parsedFileName = $"{tagName}/{fileBlob.Name.Trim('/')}"; CloudBlockBlob blob = parsedDirectory.GetBlockBlobReference(parsedFileName); mortgageApplicationDocument.SetBlobProperties(blob); blob.Properties.ContentType = "application/json"; await blob.UploadTextAsync(JsonConvert.SerializeObject(parsedResults)); } else { tagName = "N/A"; } fileBlob.Metadata.Add("DocumentType", tagName); await fileBlob.SetMetadataAsync(); } catch (Exception ex) { log.LogError($"Identity Document failed: {ex.ToString()}"); } }
public static async Task Run([BlobTrigger("parseddocuments/w2/{name}", Connection = "Documents")] CloudBlockBlob parsedBlob, [Blob("parseddocuments", Connection = "Documents")] CloudBlobContainer blobDirectory, [Blob("rawdocuments/{name}", FileAccess.Read)] Stream originalImage, [Blob("parseddocuments/markedup/{name}", FileAccess.ReadWrite)] CloudBlockBlob markedUpImage, ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context, CancellationToken cancellationToken) { try { MortgageApplicationDocument mortgageApplicationDocument = new MortgageApplicationDocument(); mortgageApplicationDocument.PopuplateFromBlobProperties(parsedBlob); mortgageApplicationDocument.HasParsedResults = true; mortgageApplicationDocument.DocumentType = "w2"; string jsonContents = await parsedBlob.DownloadTextAsync(); ProcessedDocument document = JsonConvert.DeserializeObject <ProcessedDocument>(jsonContents); CloudBlockBlob finalBlob = blobDirectory.GetBlockBlobReference(parsedBlob.Name.Replace("w2/", "final/")); mortgageApplicationDocument.Status = MortgageApplicationStatus.Processed; mortgageApplicationDocument.DateProcessed = DateTimeOffset.UtcNow; mortgageApplicationDocument.SetBlobProperties(finalBlob); FindDataLine(document, "SSN", "Social Security Number", mortgageApplicationDocument, "a. Employee's social security number", "social security number", "Employee's soc. sec. number", "Employee's social security number"); FindMoneyLine(document, "Wages", "Total Wages", mortgageApplicationDocument, "Wages"); FindMoneyLine(document, "FedTax", "Federal Tax Witholding", mortgageApplicationDocument, "2. Federal income tax", "Federal income tax withheld"); FindDataLine(document, "CopyType", "Copy Type", mortgageApplicationDocument, "Copy"); FindMoneyLine(document, "SocialSecurityWage", "Social Security Wage", mortgageApplicationDocument, "Social security wages"); FindMoneyLine(document, "SocialSecurityTax", "Social Security Tax", mortgageApplicationDocument, "Social security tax withheld"); FindMoneyLine(document, "MedicareWage", "Medicare Wage", mortgageApplicationDocument, "Medicare wages and tips"); FindMoneyLine(document, "MedicareTax", "Medicare Tax", mortgageApplicationDocument, "Medicare tax withheld"); FindMoneyLine(document, "SocialSecurityTips", "Social Security Tips", mortgageApplicationDocument, "Social security tips"); FindDataLine(document, "EmployerDetails", "Employer Details", mortgageApplicationDocument, "Employer's name, address, and ZIP code"); FindDataLine(document, "EmployeeDetails", "Employee Details", mortgageApplicationDocument, "Employee's first name and initial", "Last name", "Employee's name, address, and ZIP code", "Employee's name (first, middle indial, last)"); await finalBlob.UploadTextAsync(JsonConvert.SerializeObject(mortgageApplicationDocument)); await MarkupService.HighlightHits(document, originalImage, markedUpImage); } catch (Exception ex) { log.LogError(ex, "W2 Processor Failed"); } }
public async Task <ActionResult <MortgageApplication> > GetMortgageApplication(string mortgageApplicationId, CancellationToken cancellationToken) { var blobs = await StorageHelper.GetBlobs(_storageAccountName, "rawdocuments", $"{mortgageApplicationId.ToLower()}/"); MortgageApplication mortgageApplication = new MortgageApplication() { MortgageApplicationId = mortgageApplicationId, Documents = new List <MortgageApplicationDocument>() }; if (blobs.SafeAny()) { foreach (var blob in blobs) { MortgageApplicationDocument doc = new MortgageApplicationDocument(); doc.PopuplateFromBlobProperties(blob); string documentId = doc.DocumentId; CloudBlockBlob finalBlob = await StorageHelper.GetBlob(_storageAccountName, "parseddocuments", $"final/{doc.MortgageApplicationId}/{documentId}"); MortgageApplicationDocument finalDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <MortgageApplicationDocument>(await finalBlob.DownloadTextAsync()); mortgageApplication.Documents.Add(finalDoc); var markedupBlob = await StorageHelper.GetBlob(_storageAccountName, "parseddocuments", $"markedup/{mortgageApplicationId.ToLower()}/{documentId}"); finalDoc.HasParsedResults = true; if (await markedupBlob.ExistsAsync()) { finalDoc.HasMarkedupResults = true; } } } else { return(NotFound()); } return(Ok(mortgageApplication)); }