Skip to content

Commit

Permalink
Jim/bring form summary back (#137)
Browse files Browse the repository at this point in the history
* form summary from v1 api

* default vals

* split into two PRs

* split into two PRs

* base url

* defaults
  • Loading branch information
jimmoffet authored May 22, 2024
1 parent 376e3e2 commit c7f9aea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/forms/src/documents/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const addDocument = async (
if (parsedPdf) {
form = updateFormSummary(form, {
title: parsedPdf.title,
description: '',
description: parsedPdf.description,
});
form = addPatternMap(form, parsedPdf.patterns, parsedPdf.root);
const updatedForm = addFormOutput(form, {
Expand Down
21 changes: 19 additions & 2 deletions packages/forms/src/documents/pdf/parsing-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { type ParagraphPattern } from '../../patterns/paragraph';
import { type SequencePattern } from '../../patterns/sequence';
import { type CheckboxPattern } from '../../patterns/checkbox';
import { type RadioGroupPattern } from '../../patterns/radio-group';
import { type FormSummary } from '../../patterns/form-summary';

import { uint8ArrayToBase64 } from '../util';
import { type DocumentFieldMap } from '../types';
Expand Down Expand Up @@ -126,6 +127,7 @@ export type ParsedPdf = {
outputs: DocumentFieldMap; // to populate FormOutput
root: PatternId;
title: string;
description: string;
};

export const callExternalParser = async (
Expand All @@ -151,14 +153,29 @@ export const callExternalParser = async (
const json = await response.json();
const extracted: ExtractedObject = ExtractedObject.parse(json.parsed_pdf);

const rootSequence: PatternId[] = [];

const parsedPdf: ParsedPdf = {
patterns: {},
outputs: {},
root: 'root',
title: extracted.form_summary.title,
title: extracted.form_summary.title || 'Default Form Title',
description:
extracted.form_summary.description || 'Default Form Description',
};

const rootSequence: PatternId[] = [];
const formSummaryId = generatePatternId();

parsedPdf.patterns[formSummaryId] = {
type: 'form-summary',
id: formSummaryId,
data: {
title: extracted.form_summary.title || 'Default Form Title',
description:
extracted.form_summary.description || 'Default Form Description',
},
} satisfies FormSummary;
rootSequence.push(formSummaryId);

for (const element of extracted.elements) {
const randomId = generatePatternId();
Expand Down
2 changes: 2 additions & 0 deletions packages/forms/src/patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type FormConfig } from '../pattern';
import { addressConfig } from './address';
import { checkboxConfig } from './checkbox';
import { fieldsetConfig } from './fieldset';
import { formSummaryConfig } from './form-summary';
import { inputConfig } from './input';
import { paragraphConfig } from './paragraph';
import { radioGroupConfig } from './radio-group';
Expand All @@ -13,6 +14,7 @@ import { sequenceConfig } from './sequence';
// understand the usage scenarios better.
export const defaultFormConfig: FormConfig = {
patterns: {
'form-summary': formSummaryConfig,
address: addressConfig,
checkbox: checkboxConfig,
fieldset: fieldsetConfig,
Expand Down

0 comments on commit c7f9aea

Please sign in to comment.