Skip to content

Latest commit

 

History

History
90 lines (84 loc) · 2.36 KB

document_parser.md

File metadata and controls

90 lines (84 loc) · 2.36 KB

Folder Structure

/src
  /document-parser
    /index.ts
    /aadhaar-parser.ts
    /pan-parser.ts
    /your-parser-goes-here.ts

Interface changes

  • (Optionally) If your parser exposes new document fields

src/interfaces/SmartDocuments.ts

interface DocumentDetails {
  document_type?: string;
  identification_number?: string;
  name?: string;
  fathers_name?: string;
  date_of_birth?: string;
  gender?: string;
  address?: string;
  // Add new fields here
}

src/interfaces/DocumentParser.ts

interface DocumentDetails {
  document_type?: string;
  identification_number?: string;
  name?: string;
  fathers_name?: string;
  date_of_birth?: string;
  gender?: string;
  address?: string;
  // Add new fields here
}

Configuration changes

src/constants.ts

Constants.DOCUMENT_TYPES = {
  PAN_CARD: "PAN_CARD",
  AADHAAR_CARD: "AADHAAR_CARD"
  // // Add new document type here
};

Implementation changes

src/document-parser/index.ts

import YourParser from "./your-parser-goes-here";

// Make strategy for new document
DocumentParser[Constants.DOCUMENT_TYPES.NEW_DOCUMENT] = {
  parseDocumentDetails: YourParser.parseDocumentDetails
};

src/document-parser/your-parser-goes-here.ts

  • Your parser should expose a function called parseDocumentDetails.
  • For function contract check src/interfaces/DocumentParser.ts
  • For reference please check the source code of other parsers.
  • Read about the process from (here)
import {
  ParseDocumentDetailsRequest,
  ParseDocumentDetailsResponse
} from "../interfaces/DocumentParser";

// ******************************************************* //
// Logic for API handlers starts here                      //
// ******************************************************* //
YourParser.parseDocumentDetails = (
  params: ParseDocumentDetailsRequest
): ParseDocumentDetailsResponse => {
  ....
  ....
  ....
  return {
    is_document_valid: true,
    document_details: parsedDetails
  };
};
// ******************************************************* //
// Logic for API handlers ends here                        //
// ******************************************************* //

export default YourParser;