Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from regulaforensics/develop
Browse files Browse the repository at this point in the history
Authenticity
  • Loading branch information
aliaksandr-drozd authored Feb 14, 2024
2 parents 2ae9246 + 57afeeb commit 9d0c119
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.21",
"version": "0.0.22",
"author": "Regula Forensics, Inc.",
"name": "@regulaforensics/document-reader-recipes",
"description": "Document Reader Recipes",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
import {
AuthenticityCheckListContainer,
AuthenticityFibersTypeCheckResult,
AuthenticityIdentCheckResult,
AuthenticityPhotoIdentCheckResult,
AuthenticitySecurityFeatureCheckResult,
eAuthenticity,
eCheckDiagnose,
eCheckResult,
eResultType,
eSecurityFeatureType,
ProcessResponse
} from '@regulaforensics/document-reader-typings'

import { RAuthenticityCheckListItem, RAuthenticityImageCheckListItem } from './models'
import {
RAuthenticityBarcodeCheckListItem,
RAuthenticityCheckListItem,
RAuthenticityImageCheckListItem,
RAuthenticityIpiCheckListItem
} from './models'


export const getAuthenticityCheckList = (input: ProcessResponse): RAuthenticityCheckListItem[] => {
const containers = AuthenticityCheckListContainer.fromProcessResponse(input, false)
const result: RAuthenticityCheckListItem[] = []

containers.forEach((container) => {
const isComparison = [eResultType.FINGER_PRINT_COMPARISON, eResultType.PORTRAIT_COMPARISON]
.includes(container.result_type)

const list = container.AuthenticityCheckList.List
const current = RAuthenticityCheckListItem.fromPlain({
page: container.page_idx || 1,
images: []
images: [],
ipi: [],
barcode: [],
})

list.forEach((item) => {
/*
if (AuthenticityFibersTypeCheckResult.isBelongs(item)) {
item.List.forEach((subItem) => {
})
}
*/

if (AuthenticityIdentCheckResult.isBelongs(item)) {
item.List.forEach((subItem) => {
Expand All @@ -47,21 +53,37 @@ export const getAuthenticityCheckList = (input: ProcessResponse): RAuthenticityC
})
}

/*if (AuthenticityOCRSecurityTextCheckResult.isBelongs(item)) {
/*
if (AuthenticityOCRSecurityTextCheckResult.isBelongs(item)) {
item.List.forEach((subItem) => {
})
}*/
}
*/

if (AuthenticityPhotoIdentCheckResult.isBelongs(item)) {
item.List.forEach((subItem) => {

if (subItem.Type === eAuthenticity.IPI) {
if (subItem.ResultImages?.Images?.length) {
current.ipi.push(RAuthenticityIpiCheckListItem.fromPlain({
checkResult: subItem.ElementResult || eCheckResult.WAS_NOT_DONE,
diagnose: subItem.ElementDiagnose || eCheckDiagnose.UNKNOWN,
image: subItem.ResultImages.Images[0].image,
}))
}
}
})
}

if (AuthenticitySecurityFeatureCheckResult.isBelongs(item)) {
item.List.forEach((subItem) => {

if (subItem.Type === eAuthenticity.BARCODE_FORMAT_CHECK) {
current.barcode.push(RAuthenticityBarcodeCheckListItem.fromPlain({
checkResult: subItem.ElementResult || eCheckResult.WAS_NOT_DONE,
diagnose: subItem.ElementDiagnose || eCheckDiagnose.UNKNOWN,
feature: subItem.ElementType || eSecurityFeatureType.BLANK,
}))
}
})
}

Expand All @@ -70,5 +92,5 @@ export const getAuthenticityCheckList = (input: ProcessResponse): RAuthenticityC
result.push(current)
})

return result.filter((item) => item.images.length > 0)
return result.filter((item) => item.images.length > 0 || item.ipi.length > 0 || item.barcode.length > 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { plainToClass, Type } from 'class-transformer'
import { IsDefined, IsInt, ValidateNested, validateSync, ValidationError } from 'class-validator'

import { AllowPrimitives } from '@/types'
import { iRAuthenticityImageCheckListItem, RAuthenticityImageCheckListItem } from './children'
import {
iRAuthenticityBarcodeCheckListItem,
iRAuthenticityImageCheckListItem,
iRAuthenticityIpiCheckListItem, RAuthenticityBarcodeCheckListItem,
RAuthenticityImageCheckListItem,
RAuthenticityIpiCheckListItem
} from './children'


/**
Expand All @@ -20,6 +26,18 @@ export interface iRAuthenticityCheckListItem {
* @type {iRAuthenticityImageCheckListItem[]}
*/
images: iRAuthenticityImageCheckListItem[]

/**
* IPI
* @type {iRAuthenticityIpiCheckListItem[]}
*/
ipi: iRAuthenticityIpiCheckListItem[]

/**
* Barcode
* @type {iRAuthenticityBarcodeCheckListItem[]}
*/
barcode: iRAuthenticityBarcodeCheckListItem[]
}

/**
Expand All @@ -43,6 +61,24 @@ export class RAuthenticityCheckListItem implements iRAuthenticityCheckListItem {
@Type(() => RAuthenticityImageCheckListItem)
images: RAuthenticityImageCheckListItem[]

/**
* IPI
* @type {RAuthenticityIpiCheckListItem[]}
*/
@IsDefined()
@ValidateNested({ each: true })
@Type(() => RAuthenticityIpiCheckListItem)
ipi: RAuthenticityIpiCheckListItem[]

/**
* Barcode
* @type {RAuthenticityBarcodeCheckListItem[]}
*/
@IsDefined()
@ValidateNested({ each: true })
@Type(() => RAuthenticityBarcodeCheckListItem)
barcode: RAuthenticityBarcodeCheckListItem[]

/**
* Create instance of RAuthenticityCheckListItem from plain object
* @param {AllowPrimitives<iRAuthenticityCheckListItem>} input - plain object
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IsDefined, IsEnum } from 'class-validator'

import { eCheckDiagnose, eCheckResult, eSecurityFeatureType } from '@regulaforensics/document-reader-typings'
import { plainToClass } from 'class-transformer'


/**
* Authenticity Barcode check list item
*/
export interface iRAuthenticityBarcodeCheckListItem {
/**
* Feature type
* @type {string}
*/
feature: eSecurityFeatureType

/**
* Element with which errors are checked
* @type {eCheckDiagnose}
*/
diagnose: eCheckDiagnose

/**
* Overall checking result
* @type {eCheckResult}
*/
checkResult: eCheckResult
}

/**
* Authenticity Barcode check list item
*/
export class RAuthenticityBarcodeCheckListItem implements iRAuthenticityBarcodeCheckListItem {
/**
* Feature type
* @type {string}
*/
@IsDefined()
@IsEnum(eSecurityFeatureType)
feature: eSecurityFeatureType

/**
* Element with which errors are checked
* @type {eCheckDiagnose}
*/
@IsDefined()
@IsEnum(eCheckDiagnose)
diagnose: eCheckDiagnose

/**
* Overall checking result
* @type {eCheckResult}
*/
@IsDefined()
@IsEnum(eCheckResult)
checkResult: eCheckResult

/**
* Create instance of RAuthenticityBarcodeCheckListItem from plain object
* @param {iRAuthenticityBarcodeCheckListItem} input - plain object
* @returns {RAuthenticityBarcodeCheckListItem}
*/
static fromPlain = (input: iRAuthenticityBarcodeCheckListItem): RAuthenticityBarcodeCheckListItem =>
plainToClass(RAuthenticityBarcodeCheckListItem, input)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './authenticity-barcode-check-list-item.model'
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface iRAuthenticityImageCheckListItem {
}

/**
* Authenticity image check list item
* Authenticity image check list item
*/
export class RAuthenticityImageCheckListItem implements iRAuthenticityImageCheckListItem {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IsDefined, IsEnum, IsString } from 'class-validator'

import { eCheckDiagnose, eCheckResult } from '@regulaforensics/document-reader-typings'
import { plainToClass } from 'class-transformer'


/**
* Authenticity IPI check list item
*/
export interface iRAuthenticityIpiCheckListItem {
/**
* Located image fragment
* @type {string}
*/
image: string

/**
* Element with which errors are checked
* @type {eCheckDiagnose}
*/
diagnose: eCheckDiagnose

/**
* Overall checking result
* @type {eCheckResult}
*/
checkResult: eCheckResult
}

/**
* Authenticity IPI check list item
*/
export class RAuthenticityIpiCheckListItem implements iRAuthenticityIpiCheckListItem {
/**
* Located image fragment
* @type {string}
*/
@IsDefined()
@IsString()
image: string

/**
* Element with which errors are checked
* @type {eCheckDiagnose}
*/
@IsDefined()
@IsEnum(eCheckDiagnose)
diagnose: eCheckDiagnose

/**
* Overall checking result
* @type {eCheckResult}
*/
@IsDefined()
@IsEnum(eCheckResult)
checkResult: eCheckResult

/**
* Create instance of RAuthenticityIpiCheckListItem from plain object
* @param {iRAuthenticityIpiCheckListItem} input - plain object
* @returns {RAuthenticityIpiCheckListItem}
*/
static fromPlain = (input: iRAuthenticityIpiCheckListItem): RAuthenticityIpiCheckListItem =>
plainToClass(RAuthenticityIpiCheckListItem, input)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './authenticity-ipi-check-list-item.model'
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './authenticity-barcode-check-list-item'
export * from './authenticity-image-check-list-item'
export * from './authenticity-ipi-check-list-item'
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import { RDocumentIdentification } from './models'
* @param {ProcessResponse} input
* @param {false} allowDefault
* @param {string|undefined} defaultDocumentName
* @returns {RDocumentIdentification}
* @returns {RDocumentIdentification|undefined}
*/
export function getDocumentIdentification(
input: ProcessResponse,
allowDefault?: false,
defaultDocumentName?: string
): RDocumentIdentification;
): RDocumentIdentification | undefined;

/**
* Returns document identification from process response
* @param {ProcessResponse} input
* @param {true} allowDefault
* @param {string|undefined} defaultDocumentName
* @returns {RDocumentIdentification | undefined}
* @returns {RDocumentIdentification}
*/
export function getDocumentIdentification(
input: ProcessResponse,
allowDefault?: true,
defaultDocumentName?: string
): RDocumentIdentification | undefined;
): RDocumentIdentification;

/**
* Returns document identification from process response
Expand Down

0 comments on commit 9d0c119

Please sign in to comment.