diff --git a/docs/energy_bill_fra_v1.md b/docs/energy_bill_fra_v1.md index 18def7f6c..675b537c8 100644 --- a/docs/energy_bill_fra_v1.md +++ b/docs/energy_bill_fra_v1.md @@ -39,18 +39,18 @@ apiResponse.then((resp) => { ######## Document ######## -:Mindee ID: 17f0ccef-e3fe-4a28-838d-d704489d6ce7 +:Mindee ID: ff1f2ca8-4d29-44d8-a564-599a982a4ef7 :Filename: default_sample.pdf Inference ######### -:Product: mindee/energy_bill_fra v1.0 -:Rotation applied: No +:Product: mindee/energy_bill_fra v1.2 +:Rotation applied: Yes Prediction ========== -:Invoice Number: 10123590373 -:Contract ID: 1234567890 +:Invoice Number: 1234567890 +:Contract ID: 9876543210 :Delivery Point: 98765432109876 :Invoice Date: 2021-01-29 :Due Date: 2021-02-15 @@ -58,11 +58,11 @@ Prediction :Total Taxes: 238.82 :Total Amount: 1479.85 :Energy Supplier: - :Address: TSA 12345, 12345 DEMOCITY CEDEX, 75001 PARIS + :Address: TSA 12345, 12345 DEMOCITY CEDEX :Name: EDF :Energy Consumer: - :Address: 12 AVENUE DES RÊVES, RDC A 123 COUR FAUSSE A, 75000 PARIS - :Name: John Doe + :Address: 123 RUE DE L'IMAGINAIRE, 75001 PARIS + :Name: JOHN DOE :Subscription: +--------------------------------------+------------+------------+----------+-----------+------------+ | Description | End Date | Start Date | Tax Rate | Total | Unit Price | @@ -70,27 +70,27 @@ Prediction | Abonnement électricité | 2021-02-28 | 2021-01-01 | 5.50 | 59.00 | 29.50 | +--------------------------------------+------------+------------+----------+-----------+------------+ :Energy Usage: - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Description | End Date | Start Date | Tax Rate | Total | Unit Price | - +======================================+============+============+==========+===========+============+ - | Consommation (HT) | 2021-01-27 | 2020-11-28 | 20.00 | 898.43 | 10.47 | - +--------------------------------------+------------+------------+----------+-----------+------------+ + +-------------+--------------------------------------+------------+------------+----------+-----------+-----------------+------------+ + | Consumption | Description | End Date | Start Date | Tax Rate | Total | Unit of Measure | Unit Price | + +=============+======================================+============+============+==========+===========+=================+============+ + | 8581.00 | Consommation électricité | 2021-01-27 | 2020-11-28 | 20.00 | 898.43 | kWh | 0.1047 | + +-------------+--------------------------------------+------------+------------+----------+-----------+-----------------+------------+ :Taxes and Contributions: +--------------------------------------+------------+------------+----------+-----------+------------+ | Description | End Date | Start Date | Tax Rate | Total | Unit Price | +======================================+============+============+==========+===========+============+ - | Contribution au Service Public de... | 2021-01-27 | 2020-11-28 | 20.00 | 193.07 | 2.25 | + | Contribution au Service Public de... | 2021-01-27 | 2020-11-28 | 20.00 | 193.07 | 0.0225 | +--------------------------------------+------------+------------+----------+-----------+------------+ - | Départementale sur la Conso Final... | 2020-12-31 | 2020-11-28 | 20.00 | 13.98 | 0.3315 | + | Taxe Départementale sur la Conso ... | 2021-01-27 | 2020-11-28 | 20.00 | 13.98 | 0.003315 | +--------------------------------------+------------+------------+----------+-----------+------------+ - | Communale sur la Conso Finale Ele... | 2021-01-27 | 2021-01-01 | 20.00 | 28.56 | 0.6545 | + | Taxe Communale sur la Conso Final... | 2021-01-27 | 2020-11-28 | 20.00 | 28.56 | 0.006545 | +--------------------------------------+------------+------------+----------+-----------+------------+ - | Contribution Tarifaire d'Achemine... | 2020-12-31 | 2020-11-28 | 20.00 | 27.96 | 0.663 | + | Taxe Communale sur la Conso Final... | 2021-01-27 | 2020-11-28 | 20.00 | 27.96 | 0.00663 | +--------------------------------------+------------+------------+----------+-----------+------------+ :Meter Details: :Meter Number: 620 :Meter Type: electricity - :Unit of Measure: kWh + :Unit of Power: 36kVA ``` # Field Types diff --git a/docs/expense_receipts_v5.md b/docs/expense_receipts_v5.md index 10144de03..71fcc18ab 100644 --- a/docs/expense_receipts_v5.md +++ b/docs/expense_receipts_v5.md @@ -232,6 +232,9 @@ The following fields are extracted for Receipt V5: - 'gasoline' - 'telecom' - 'miscellaneous' + - 'software' + - 'shopping' + - 'energy' ```js console.log(result.document.inference.prediction.category.value); @@ -287,6 +290,15 @@ console.log(result.document.inference.prediction.receiptNumber.value); - 'train' - 'restaurant' - 'shopping' + - 'other' + - 'groceries' + - 'cultural' + - 'electronics' + - 'office_supplies' + - 'micromobility' + - 'car_rental' + - 'public' + - 'delivery' - null ```js diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md index 00cc9d83f..c3549303c 100644 --- a/docs/financial_document_v1.md +++ b/docs/financial_document_v1.md @@ -65,12 +65,12 @@ apiResponse.then((resp) => { ######## Document ######## -:Mindee ID: a80ac0ee-26f6-4e2e-988a-960b240d5ba7 +:Mindee ID: 6dd26385-719b-4527-bf6f-87d9da619de5 :Filename: default_sample.jpg Inference ######### -:Product: mindee/financial_document v1.11 +:Product: mindee/financial_document v1.14 :Rotation applied: Yes Prediction @@ -106,6 +106,7 @@ Prediction :Shipping Address: 2019 Redbud Drive New York, NY 10011 :Billing Address: 4312 Wood Road New York, NY 10031 :Document Type: INVOICE +:Document Type Extended: INVOICE :Purchase Subcategory: :Purchase Category: miscellaneous :Total Tax: 9.75 @@ -158,6 +159,7 @@ Page 0 :Shipping Address: 2019 Redbud Drive New York, NY 10011 :Billing Address: 4312 Wood Road New York, NY 10031 :Document Type: INVOICE +:Document Type Extended: INVOICE :Purchase Subcategory: :Purchase Category: miscellaneous :Total Tax: 9.75 @@ -196,6 +198,21 @@ A typical `Field` object will have the following attributes: Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **streetNumber** (`string`): String representation of the street number. Can be `null`. +* **streetName** (`string`): Name of the street. Can be `null`. +* **poBox** (`string`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`string`): Address complement. Can be `null`. +* **city** (`string`): City name. Can be `null`. +* **postalCode** (`string`): String representation of the postal code. Can be `null`. +* **state** (`string`): State name. Can be `null`. +* **country** (`string`): Country name. Can be `null`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + + ### Amount Field The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). @@ -269,14 +286,14 @@ A `FinancialDocumentV1LineItem` implements the following attributes: The following fields are extracted for Financial Document V1: ## Billing Address -**billingAddress** ([StringField](#string-field)): The customer's address used for billing. +**billingAddress** : The customer's address used for billing. ```js console.log(result.document.inference.prediction.billingAddress.value); ``` ## Purchase Category -**category** ([ClassificationField](#classification-field)): The purchase category, only for receipts. +**category** ([ClassificationField](#classification-field)): The purchase category. #### Possible values include: - 'toll' @@ -287,13 +304,16 @@ console.log(result.document.inference.prediction.billingAddress.value); - 'gasoline' - 'telecom' - 'miscellaneous' + - 'software' + - 'shopping' + - 'energy' ```js console.log(result.document.inference.prediction.category.value); ``` ## Customer Address -**customerAddress** ([StringField](#string-field)): The address of the customer. +**customerAddress** : The address of the customer. ```js console.log(result.document.inference.prediction.customerAddress.value); @@ -428,14 +448,14 @@ for (const referenceNumbersElem of result.document.inference.prediction.referenc ``` ## Shipping Address -**shippingAddress** ([StringField](#string-field)): The customer's address used for shipping. +**shippingAddress** : The customer's address used for shipping. ```js console.log(result.document.inference.prediction.shippingAddress.value); ``` ## Purchase Subcategory -**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory for transport and food, only for receipts. +**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory for transport, food and shooping. #### Possible values include: - 'plane' @@ -443,6 +463,15 @@ console.log(result.document.inference.prediction.shippingAddress.value); - 'train' - 'restaurant' - 'shopping' + - 'other' + - 'groceries' + - 'cultural' + - 'electronics' + - 'office_supplies' + - 'micromobility' + - 'car_rental' + - 'public' + - 'delivery' - null ```js @@ -450,7 +479,7 @@ console.log(result.document.inference.prediction.subcategory.value); ``` ## Supplier Address -**supplierAddress** ([StringField](#string-field)): The address of the supplier or merchant. +**supplierAddress** : The address of the supplier or merchant. ```js console.log(result.document.inference.prediction.supplierAddress.value); diff --git a/docs/ind_passport_v1.md b/docs/ind_passport_v1.md index a942e5e8a..2babfc971 100644 --- a/docs/ind_passport_v1.md +++ b/docs/ind_passport_v1.md @@ -44,7 +44,7 @@ Document Inference ######### -:Product: mindee/ind_passport v1.0 +:Product: mindee/ind_passport v1.2 :Rotation applied: Yes Prediction @@ -67,10 +67,10 @@ Prediction :Name of Mother: :Old Passport Date of Issue: :Old Passport Number: +:Old Passport Place of Issue: :Address Line 1: :Address Line 2: :Address Line 3: -:Old Passport Place of Issue: :File Number: ``` diff --git a/docs/invoices_v4.md b/docs/invoices_v4.md index 1ee2c0765..bdf269e5a 100644 --- a/docs/invoices_v4.md +++ b/docs/invoices_v4.md @@ -65,12 +65,12 @@ apiResponse.then((resp) => { ######## Document ######## -:Mindee ID: b55db8f9-ae3b-4f05-b2f1-ec0ced5e5b70 +:Mindee ID: 744748d5-9051-461c-b70c-bbf81f5ff943 :Filename: default_sample.jpg Inference ######### -:Product: mindee/invoices v4.9 +:Product: mindee/invoices v4.11 :Rotation applied: Yes Prediction @@ -105,6 +105,9 @@ Prediction :Shipping Address: :Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada :Document Type: INVOICE +:Document Type Extended: INVOICE +:Purchase Subcategory: +:Purchase Category: miscellaneous :Line Items: +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | @@ -151,6 +154,9 @@ Page 0 :Shipping Address: :Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada :Document Type: INVOICE +:Document Type Extended: INVOICE +:Purchase Subcategory: +:Purchase Category: miscellaneous :Line Items: +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | @@ -184,6 +190,21 @@ A typical `Field` object will have the following attributes: Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **streetNumber** (`string`): String representation of the street number. Can be `null`. +* **streetName** (`string`): Name of the street. Can be `null`. +* **poBox** (`string`): String representation of the PO Box number. Can be `null`. +* **addressComplement** (`string`): Address complement. Can be `null`. +* **city** (`string`): City name. Can be `null`. +* **postalCode** (`string`): String representation of the postal code. Can be `null`. +* **state** (`string`): State name. Can be `null`. +* **country** (`string`): Country name. Can be `null`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + + ### Amount Field The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). @@ -257,14 +278,33 @@ A `InvoiceV4LineItem` implements the following attributes: The following fields are extracted for Invoice V4: ## Billing Address -**billingAddress** ([StringField](#string-field)): The customer billing address. +**billingAddress** : The customer billing address. ```js console.log(result.document.inference.prediction.billingAddress.value); ``` +## Purchase Category +**category** ([ClassificationField](#classification-field)): The purchase category. + +#### Possible values include: + - 'toll' + - 'food' + - 'parking' + - 'transport' + - 'accommodation' + - 'telecom' + - 'miscellaneous' + - 'software' + - 'shopping' + - 'energy' + +```js +console.log(result.document.inference.prediction.category.value); +``` + ## Customer Address -**customerAddress** ([StringField](#string-field)): The address of the customer. +**customerAddress** : The address of the customer. ```js console.log(result.document.inference.prediction.customerAddress.value); @@ -383,14 +423,38 @@ for (const referenceNumbersElem of result.document.inference.prediction.referenc ``` ## Shipping Address -**shippingAddress** ([StringField](#string-field)): Customer's delivery address. +**shippingAddress** : Customer's delivery address. ```js console.log(result.document.inference.prediction.shippingAddress.value); ``` +## Purchase Subcategory +**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory for transport, food and shopping. + +#### Possible values include: + - 'plane' + - 'taxi' + - 'train' + - 'restaurant' + - 'shopping' + - 'other' + - 'groceries' + - 'cultural' + - 'electronics' + - 'office_supplies' + - 'micromobility' + - 'car_rental' + - 'public' + - 'delivery' + - null + +```js +console.log(result.document.inference.prediction.subcategory.value); +``` + ## Supplier Address -**supplierAddress** ([StringField](#string-field)): The address of the supplier or merchant. +**supplierAddress** : The address of the supplier or merchant. ```js console.log(result.document.inference.prediction.supplierAddress.value); diff --git a/docs/us_healthcare_cards_v1.md b/docs/us_healthcare_cards_v1.md index 702486dda..254a480e1 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/us_healthcare_cards_v1.md @@ -39,17 +39,18 @@ apiResponse.then((resp) => { ######## Document ######## -:Mindee ID: 0ced9f49-00c0-4a1d-8221-4a1538813a95 +:Mindee ID: 5e917fc8-5c13-42b2-967f-954f4eed9959 :Filename: default_sample.jpg Inference ######### -:Product: mindee/us_healthcare_cards v1.0 -:Rotation applied: No +:Product: mindee/us_healthcare_cards v1.3 +:Rotation applied: Yes Prediction ========== :Company Name: UnitedHealthcare +:Plan Name: Choice Plus :Member Name: SUBSCRIBER SMITH :Member ID: 123456789 :Issuer 80840: @@ -60,21 +61,22 @@ Prediction :Group Number: 98765 :Payer ID: 87726 :RX BIN: 610279 +:RX ID: :RX GRP: UHEALTH :RX PCN: 9999 -:copays: - +--------------+--------------+ - | Service Fees | Service Name | - +==============+==============+ - | 20.00 | office visit | - +--------------+--------------+ - | 300.00 | emergency | - +--------------+--------------+ - | 75.00 | urgent care | - +--------------+--------------+ - | 30.00 | specialist | - +--------------+--------------+ -:Enrollment Date: 2023-09-13 +:Copays: + +--------------+----------------------+ + | Service Fees | Service Name | + +==============+======================+ + | 20.00 | office_visit | + +--------------+----------------------+ + | 300.00 | emergency_room | + +--------------+----------------------+ + | 75.00 | urgent_care | + +--------------+----------------------+ + | 30.00 | specialist | + +--------------+----------------------+ +:Enrollment Date: ``` # Field Types @@ -108,13 +110,13 @@ The text field `StringField` only has one constraint: its **value** is a `string ## Specific Fields Fields which are specific to this product; they are not used in any other product. -### copays Field -Is a fixed amount for a covered service. +### Copays Field +Copayments for covered services. A `HealthcareCardV1Copay` implements the following attributes: -* `serviceFees` (number): The price of service. -* `serviceName` (string): The name of service of the copay. +* `serviceFees` (number): The price of the service. +* `serviceName` (string): The name of the service. #### Possible values include: - primary_care @@ -135,8 +137,8 @@ The following fields are extracted for Healthcare Card V1: console.log(result.document.inference.prediction.companyName.value); ``` -## copays -**copays** ([HealthcareCardV1Copay](#copays-field)[]): Is a fixed amount for a covered service. +## Copays +**copays** ([HealthcareCardV1Copay](#copays-field)[]): Copayments for covered services. ```js for (const copaysElem of result.document.inference.prediction.copays) { @@ -195,6 +197,13 @@ console.log(result.document.inference.prediction.memberName.value); console.log(result.document.inference.prediction.payerId.value); ``` +## Plan Name +**planName** ([StringField](#string-field)): The name of the healthcare plan. + +```js +console.log(result.document.inference.prediction.planName.value); +``` + ## RX BIN **rxBin** ([StringField](#string-field)): The BIN number for prescription drug coverage. diff --git a/docs/us_mail_v3.md b/docs/us_mail_v3.md index 4f6694169..c9d05fe1b 100644 --- a/docs/us_mail_v3.md +++ b/docs/us_mail_v3.md @@ -6,7 +6,7 @@ parentDoc: 609809574212d40077a040f1 --- The Node.js OCR SDK supports the [US Mail API](https://platform.mindee.com/mindee/us_mail). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg) can be used for testing purposes. ![US Mail sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg?raw=true) # Quick-Start @@ -33,39 +33,6 @@ apiResponse.then((resp) => { console.log(resp.document.toString()); }); ``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: f9c36f59-977d-4ddc-9f2d-31c294c456ac -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/us_mail v3.0 -:Rotation applied: Yes - -Prediction -========== -:Sender Name: company zed -:Sender Address: - :City: Dallas - :Complete Address: 54321 Elm Street, Dallas, Texas 54321 - :Postal Code: 54321 - :State: TX - :Street: 54321 Elm Street -:Recipient Names: Jane Doe -:Recipient Addresses: - +-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+ - | City | Complete Address | Is Address Change | Postal Code | Private Mailbox Number | State | Street | Unit | - +=================+=====================================+===================+=============+========================+=======+===========================+=================+ - | Detroit | 1234 Market Street PMB 4321, Det... | False | 12345 | 4321 | MI | 1234 Market Street | | - +-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+ -:Return to Sender: False -``` - # Field Types ## Standard Fields These fields are generic and used in several products. diff --git a/src/parsing/common/document.ts b/src/parsing/common/document.ts index 29590c88d..d7a28bb4b 100644 --- a/src/parsing/common/document.ts +++ b/src/parsing/common/document.ts @@ -79,6 +79,7 @@ ${this.inference?.toString()}`; private injectFullTextOcr(rawPrediction: StringDict) { if ( rawPrediction["inference"]["pages"].length < 1 || + !("extras" in rawPrediction["inference"]["pages"][0]) || rawPrediction["inference"]["pages"][0]["extras"].length < 1 || !("full_text_ocr" in rawPrediction["inference"]["pages"][0]["extras"]) || !rawPrediction["inference"]["pages"][0]["extras"]["full_text_ocr"] || diff --git a/src/parsing/standard/addressField.ts b/src/parsing/standard/addressField.ts new file mode 100644 index 000000000..f8b4901d8 --- /dev/null +++ b/src/parsing/standard/addressField.ts @@ -0,0 +1,60 @@ +import { StringField, FieldConstructor } from "./text"; + +/** + * A field containing a detailed address value broken down into components + * (street number, city, postal code, …) while still exposing the full + * address string through {@link StringField.value}. + */ +export class AddressField extends StringField { + /** Street number. */ + streetNumber?: string; + /** Street name. */ + streetName?: string; + /** PO-box number. */ + poBox?: string; + /** Additional address complement. */ + addressComplement?: string; + /** City or locality. */ + city?: string; + /** Postal / ZIP code. */ + postalCode?: string; + /** State, province or region. */ + state?: string; + /** Country. */ + country?: string; + + constructor({ + prediction = {}, + valueKey = "value", + reconstructed = false, + pageId, + }: FieldConstructor) { + super({ prediction, valueKey, reconstructed, pageId }); + + // Populate the sub-components if they exist in the prediction object + if (prediction["street_number"]) { + this.streetNumber = prediction["street_number"] as string; + } + if (prediction["street_name"]) { + this.streetName = prediction["street_name"] as string; + } + if (prediction["po_box"]) { + this.poBox = prediction["po_box"] as string; + } + if (prediction["address_complement"]) { + this.addressComplement = prediction["address_complement"] as string; + } + if (prediction["city"]) { + this.city = prediction["city"] as string; + } + if (prediction["postal_code"]) { + this.postalCode = prediction["postal_code"] as string; + } + if (prediction["state"]) { + this.state = prediction["state"] as string; + } + if (prediction["country"]) { + this.country = prediction["country"] as string; + } + } +} diff --git a/src/parsing/standard/index.ts b/src/parsing/standard/index.ts index 6d87501b7..a04b929d1 100644 --- a/src/parsing/standard/index.ts +++ b/src/parsing/standard/index.ts @@ -1,13 +1,14 @@ -export { ClassificationField } from "./classification"; -export { Taxes, TaxField } from "./tax"; -export { PaymentDetailsField } from "./paymentDetails"; -export { BooleanField } from "./boolean"; -export { LocaleField } from "./locale"; +export { AddressField } from "./addressField"; export { AmountField } from "./amount"; -export { DateField } from "./date"; export { BaseField, BaseFieldConstructor } from "./base"; -export { Word } from "./word"; +export { BooleanField } from "./boolean"; +export { ClassificationField } from "./classification"; export { CompanyRegistrationField } from "./companyRegistration"; -export { PositionField } from "./position"; -export { StringField } from "./text"; +export { DateField } from "./date"; +export { LocaleField } from "./locale"; export { Field } from "./field"; +export { Taxes, TaxField } from "./tax"; +export { StringField } from "./text"; +export { PaymentDetailsField } from "./paymentDetails"; +export { PositionField } from "./position"; +export { Word } from "./word"; diff --git a/src/product/financialDocument/financialDocumentV1Document.ts b/src/product/financialDocument/financialDocumentV1Document.ts index 279cd0e6d..d9e0a78b9 100644 --- a/src/product/financialDocument/financialDocumentV1Document.ts +++ b/src/product/financialDocument/financialDocumentV1Document.ts @@ -5,6 +5,7 @@ import { } from "../../parsing/common"; import { FinancialDocumentV1LineItem } from "./financialDocumentV1LineItem"; import { + AddressField, AmountField, ClassificationField, CompanyRegistrationField, @@ -16,15 +17,15 @@ import { } from "../../parsing/standard"; /** - * Financial Document API version 1.12 document data. + * Financial Document API version 1.14 document data. */ export class FinancialDocumentV1Document implements Prediction { /** The customer's address used for billing. */ - billingAddress: StringField; - /** The purchase category, only for receipts. */ + billingAddress: AddressField; + /** The purchase category. */ category: ClassificationField; /** The address of the customer. */ - customerAddress: StringField; + customerAddress: AddressField; /** List of company registration numbers associated to the customer. */ customerCompanyRegistrations: CompanyRegistrationField[] = []; /** The customer account number or identifier from the supplier. */ @@ -59,11 +60,11 @@ export class FinancialDocumentV1Document implements Prediction { /** List of Reference numbers, including PO number, only if the document is an invoice. */ referenceNumbers: StringField[] = []; /** The customer's address used for shipping. */ - shippingAddress: StringField; - /** The purchase subcategory for transport and food, only for receipts. */ + shippingAddress: AddressField; + /** The purchase subcategory for transport, food and shooping. */ subcategory: ClassificationField; /** The address of the supplier or merchant. */ - supplierAddress: StringField; + supplierAddress: AddressField; /** List of company registration numbers associated to the supplier. */ supplierCompanyRegistrations: CompanyRegistrationField[] = []; /** The email of the supplier or merchant. */ @@ -90,14 +91,14 @@ export class FinancialDocumentV1Document implements Prediction { totalTax: AmountField; constructor(rawPrediction: StringDict, pageId?: number) { - this.billingAddress = new StringField({ + this.billingAddress = new AddressField({ prediction: rawPrediction["billing_address"], pageId: pageId, }); this.category = new ClassificationField({ prediction: rawPrediction["category"], }); - this.customerAddress = new StringField({ + this.customerAddress = new AddressField({ prediction: rawPrediction["customer_address"], pageId: pageId, }); @@ -176,14 +177,14 @@ export class FinancialDocumentV1Document implements Prediction { }) ) ); - this.shippingAddress = new StringField({ + this.shippingAddress = new AddressField({ prediction: rawPrediction["shipping_address"], pageId: pageId, }); this.subcategory = new ClassificationField({ prediction: rawPrediction["subcategory"], }); - this.supplierAddress = new StringField({ + this.supplierAddress = new AddressField({ prediction: rawPrediction["supplier_address"], pageId: pageId, }); diff --git a/src/product/ind/indianPassport/indianPassportV1Document.ts b/src/product/ind/indianPassport/indianPassportV1Document.ts index fef066334..c71ac7a60 100644 --- a/src/product/ind/indianPassport/indianPassportV1Document.ts +++ b/src/product/ind/indianPassport/indianPassportV1Document.ts @@ -175,10 +175,10 @@ export class IndianPassportV1Document implements Prediction { :Name of Mother: ${this.nameOfMother} :Old Passport Date of Issue: ${this.oldPassportDateOfIssue} :Old Passport Number: ${this.oldPassportNumber} +:Old Passport Place of Issue: ${this.oldPassportPlaceOfIssue} :Address Line 1: ${this.address1} :Address Line 2: ${this.address2} :Address Line 3: ${this.address3} -:Old Passport Place of Issue: ${this.oldPassportPlaceOfIssue} :File Number: ${this.fileNumber}`.trimEnd(); return cleanOutString(outStr); } diff --git a/src/product/internationalId/internationalIdV2Document.ts b/src/product/internationalId/internationalIdV2Document.ts index 9ceb7c5f4..4cb541e6b 100644 --- a/src/product/internationalId/internationalIdV2Document.ts +++ b/src/product/internationalId/internationalIdV2Document.ts @@ -10,7 +10,7 @@ import { } from "../../parsing/standard"; /** - * International ID API version 2.1 document data. + * International ID API version 2.2 document data. */ export class InternationalIdV2Document implements Prediction { /** The physical address of the document holder. */ diff --git a/src/product/invoice/invoiceV4Document.ts b/src/product/invoice/invoiceV4Document.ts index c75fba9ef..745a703d1 100644 --- a/src/product/invoice/invoiceV4Document.ts +++ b/src/product/invoice/invoiceV4Document.ts @@ -5,6 +5,7 @@ import { } from "../../parsing/common"; import { InvoiceV4LineItem } from "./invoiceV4LineItem"; import { + AddressField, AmountField, ClassificationField, CompanyRegistrationField, @@ -16,13 +17,15 @@ import { } from "../../parsing/standard"; /** - * Invoice API version 4.10 document data. + * Invoice API version 4.11 document data. */ export class InvoiceV4Document implements Prediction { /** The customer billing address. */ - billingAddress: StringField; + billingAddress: AddressField; + /** The purchase category. */ + category: ClassificationField; /** The address of the customer. */ - customerAddress: StringField; + customerAddress: AddressField; /** List of company registration numbers associated to the customer. */ customerCompanyRegistrations: CompanyRegistrationField[] = []; /** The customer account number or identifier from the supplier. */ @@ -50,9 +53,11 @@ export class InvoiceV4Document implements Prediction { /** List of all reference numbers on the invoice, including the purchase order number. */ referenceNumbers: StringField[] = []; /** Customer's delivery address. */ - shippingAddress: StringField; + shippingAddress: AddressField; + /** The purchase subcategory for transport, food and shopping. */ + subcategory: ClassificationField; /** The address of the supplier or merchant. */ - supplierAddress: StringField; + supplierAddress: AddressField; /** List of company registration numbers associated to the supplier. */ supplierCompanyRegistrations: CompanyRegistrationField[] = []; /** The email address of the supplier or merchant. */ @@ -75,11 +80,14 @@ export class InvoiceV4Document implements Prediction { totalTax: AmountField; constructor(rawPrediction: StringDict, pageId?: number) { - this.billingAddress = new StringField({ + this.billingAddress = new AddressField({ prediction: rawPrediction["billing_address"], pageId: pageId, }); - this.customerAddress = new StringField({ + this.category = new ClassificationField({ + prediction: rawPrediction["category"], + }); + this.customerAddress = new AddressField({ prediction: rawPrediction["customer_address"], pageId: pageId, }); @@ -150,11 +158,14 @@ export class InvoiceV4Document implements Prediction { }) ) ); - this.shippingAddress = new StringField({ + this.shippingAddress = new AddressField({ prediction: rawPrediction["shipping_address"], pageId: pageId, }); - this.supplierAddress = new StringField({ + this.subcategory = new ClassificationField({ + prediction: rawPrediction["subcategory"], + }); + this.supplierAddress = new AddressField({ prediction: rawPrediction["supplier_address"], pageId: pageId, }); @@ -263,6 +274,8 @@ export class InvoiceV4Document implements Prediction { :Billing Address: ${this.billingAddress} :Document Type: ${this.documentType} :Document Type Extended: ${this.documentTypeExtended} +:Purchase Subcategory: ${this.subcategory} +:Purchase Category: ${this.category} :Line Items: ${lineItemsSummary}`.trimEnd(); return cleanOutString(outStr); } diff --git a/src/product/invoiceSplitter/invoiceSplitterV1Document.ts b/src/product/invoiceSplitter/invoiceSplitterV1Document.ts index 165dfa294..fdc50e948 100644 --- a/src/product/invoiceSplitter/invoiceSplitterV1Document.ts +++ b/src/product/invoiceSplitter/invoiceSplitterV1Document.ts @@ -7,7 +7,7 @@ import { InvoiceSplitterV1InvoicePageGroup } from "./invoiceSplitterV1InvoicePag /** - * Invoice Splitter API version 1.2 document data. + * Invoice Splitter API version 1.4 document data. */ export class InvoiceSplitterV1Document implements Prediction { /** List of page groups. Each group represents a single invoice within a multi-invoice document. */ diff --git a/src/product/receipt/receiptV5Document.ts b/src/product/receipt/receiptV5Document.ts index d8e7fdf8f..40fca42eb 100644 --- a/src/product/receipt/receiptV5Document.ts +++ b/src/product/receipt/receiptV5Document.ts @@ -15,7 +15,7 @@ import { } from "../../parsing/standard"; /** - * Receipt API version 5.3 document data. + * Receipt API version 5.4 document data. */ export class ReceiptV5Document implements Prediction { /** The purchase category of the receipt. */ diff --git a/src/product/us/healthcareCard/healthcareCardV1Copay.ts b/src/product/us/healthcareCard/healthcareCardV1Copay.ts index be3f65e42..ffb487e7a 100644 --- a/src/product/us/healthcareCard/healthcareCardV1Copay.ts +++ b/src/product/us/healthcareCard/healthcareCardV1Copay.ts @@ -3,12 +3,12 @@ import { StringDict } from "../../../parsing/common"; import { Polygon } from "../../../geometry"; /** - * Is a fixed amount for a covered service. + * Copayments for covered services. */ export class HealthcareCardV1Copay { - /** The price of service. */ + /** The price of the service. */ serviceFees: number | null; - /** The name of service of the copay. */ + /** The name of the service. */ serviceName: string | null; /** Confidence score */ confidence: number = 0.0; diff --git a/src/product/us/healthcareCard/healthcareCardV1Document.ts b/src/product/us/healthcareCard/healthcareCardV1Document.ts index 470b5a707..919a8cd55 100644 --- a/src/product/us/healthcareCard/healthcareCardV1Document.ts +++ b/src/product/us/healthcareCard/healthcareCardV1Document.ts @@ -7,12 +7,12 @@ import { HealthcareCardV1Copay } from "./healthcareCardV1Copay"; import { DateField, StringField } from "../../../parsing/standard"; /** - * Healthcare Card API version 1.2 document data. + * Healthcare Card API version 1.3 document data. */ export class HealthcareCardV1Document implements Prediction { /** The name of the company that provides the healthcare plan. */ companyName: StringField; - /** Is a fixed amount for a covered service. */ + /** Copayments for covered services. */ copays: HealthcareCardV1Copay[] = []; /** The list of dependents covered by the healthcare plan. */ dependents: StringField[] = []; @@ -28,6 +28,8 @@ export class HealthcareCardV1Document implements Prediction { memberName: StringField; /** The unique identifier for the payer in the healthcare system. */ payerId: StringField; + /** The name of the healthcare plan. */ + planName: StringField; /** The BIN number for prescription drug coverage. */ rxBin: StringField; /** The group number for prescription drug coverage. */ @@ -86,6 +88,10 @@ export class HealthcareCardV1Document implements Prediction { prediction: rawPrediction["payer_id"], pageId: pageId, }); + this.planName = new StringField({ + prediction: rawPrediction["plan_name"], + pageId: pageId, + }); this.rxBin = new StringField({ prediction: rawPrediction["rx_bin"], pageId: pageId, @@ -122,6 +128,7 @@ export class HealthcareCardV1Document implements Prediction { ).join(""); } const outStr = `:Company Name: ${this.companyName} +:Plan Name: ${this.planName} :Member Name: ${this.memberName} :Member ID: ${this.memberId} :Issuer 80840: ${this.issuer80840} @@ -132,7 +139,7 @@ export class HealthcareCardV1Document implements Prediction { :RX ID: ${this.rxId} :RX GRP: ${this.rxGrp} :RX PCN: ${this.rxPcn} -:copays: ${copaysSummary} +:Copays: ${copaysSummary} :Enrollment Date: ${this.enrollmentDate}`.trimEnd(); return cleanOutString(outStr); } diff --git a/tests/api/response.spec.ts b/tests/api/response.spec.ts index 72fafb0d2..c8683d487 100644 --- a/tests/api/response.spec.ts +++ b/tests/api/response.spec.ts @@ -29,8 +29,8 @@ describe("Synchronous API predict response", () => { const httpResponse = JSON.parse(jsonData.toString()); const response = new PredictResponse(InvoiceV4, httpResponse); expect(response.document.inference.prediction).to.not.be.undefined; - expect(response.document.inference.pages.length).to.be.equals(2); - expect(response.document.nPages).to.be.equals(2); + expect(response.document.inference.pages.length).to.be.equals(1); + expect(response.document.nPages).to.be.equals(1); response.document.inference.pages.forEach((page, idx) => { expect(page.id).to.be.equals(idx); expect(page.toString()).to.not.be.undefined; diff --git a/tests/data b/tests/data index f8afbc409..e48b26e52 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit f8afbc409adada51d6bbd9bea9128a727ff2c8e6 +Subproject commit e48b26e5250cbbab9d3ee6c66c0eb85b667a4bb8 diff --git a/tests/inputs/localResponse.spec.ts b/tests/inputs/localResponse.spec.ts index 6dce7e2bd..ad400644b 100644 --- a/tests/inputs/localResponse.spec.ts +++ b/tests/inputs/localResponse.spec.ts @@ -2,12 +2,12 @@ import { LocalResponse } from "../../src"; import * as fs from "node:fs/promises"; import { expect } from "chai"; import { Client, PredictResponse, AsyncPredictResponse } from "../../src"; -import { InternationalIdV2, InvoiceV4 } from "../../src/product"; +import { InternationalIdV2, InvoiceV4, MultiReceiptsDetectorV1 } from "../../src/product"; const signature: string = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; const filePath: string = "tests/data/async/get_completed_empty.json"; -const invoicePath: string = "tests/data/products/invoices/response_v4/complete.json"; +const multiReceiptsDetectorPath: string = "tests/data/products/multi_receipts_detector/response_v1/complete.json"; const failedPath: string = "tests/data/async/get_failed_job_error.json"; const internationalIdPath: string = "tests/data/products/international_id/response_v2/complete.json"; @@ -44,11 +44,11 @@ describe("A valid local response", () => { }); it("should load into a sync prediction.", async () => { - const fileObj = await fs.readFile(invoicePath, { encoding: "utf-8" }); + const fileObj = await fs.readFile(multiReceiptsDetectorPath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); await localResponse.init(); const dummyClient = new Client({ apiKey: "dummy-key" }); - const prediction = await dummyClient.loadPrediction(InvoiceV4, localResponse); + const prediction = await dummyClient.loadPrediction(MultiReceiptsDetectorV1, localResponse); expect(prediction).to.be.an.instanceof(PredictResponse); expect(JSON.stringify(prediction.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); diff --git a/tests/product/ind/indianPassport/indianPassportV1.spec.ts b/tests/product/ind/indianPassport/indianPassportV1.spec.ts index 6056fc991..d8cffa939 100644 --- a/tests/product/ind/indianPassport/indianPassportV1.spec.ts +++ b/tests/product/ind/indianPassport/indianPassportV1.spec.ts @@ -33,10 +33,10 @@ describe("IndianPassportV1 Object initialization", async () => { expect(docPrediction.nameOfMother.value).to.be.undefined; expect(docPrediction.oldPassportDateOfIssue.value).to.be.undefined; expect(docPrediction.oldPassportNumber.value).to.be.undefined; + expect(docPrediction.oldPassportPlaceOfIssue.value).to.be.undefined; expect(docPrediction.address1.value).to.be.undefined; expect(docPrediction.address2.value).to.be.undefined; expect(docPrediction.address3.value).to.be.undefined; - expect(docPrediction.oldPassportPlaceOfIssue.value).to.be.undefined; expect(docPrediction.fileNumber.value).to.be.undefined; }); diff --git a/tests/product/us/healthcareCard/healthcareCardV1.spec.ts b/tests/product/us/healthcareCard/healthcareCardV1.spec.ts index 170c3368f..7e6976865 100644 --- a/tests/product/us/healthcareCard/healthcareCardV1.spec.ts +++ b/tests/product/us/healthcareCard/healthcareCardV1.spec.ts @@ -18,6 +18,7 @@ describe("HealthcareCardV1 Object initialization", async () => { const doc = new mindee.Document(mindee.product.us.HealthcareCardV1, response.document); const docPrediction = doc.inference.prediction; expect(docPrediction.companyName.value).to.be.undefined; + expect(docPrediction.planName.value).to.be.undefined; expect(docPrediction.memberName.value).to.be.undefined; expect(docPrediction.memberId.value).to.be.undefined; expect(docPrediction.issuer80840.value).to.be.undefined;