From 29949bbb9e9fcef319f06ec7ee1be636544d83f7 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 23 Oct 2023 10:33:08 -0700 Subject: [PATCH] update instructions. --- .../resource-creator.component.html | 30 +++++++---- .../resource-creator.component.ts | 52 ++++++++++++++++--- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/pages/resource-creator/resource-creator.component.html b/frontend/src/app/pages/resource-creator/resource-creator.component.html index d42149d78..81f689ff5 100644 --- a/frontend/src/app/pages/resource-creator/resource-creator.component.html +++ b/frontend/src/app/pages/resource-creator/resource-creator.component.html @@ -2,14 +2,13 @@
- Components - Forms - Form Elements + Create Record + Condition
-

Create a Record

+

Condition Wizard

-
+
-

While Fasten Health is designed to pull your health records automatically from your healthcare institutions, in some cases you may be unable to do so due to various limitations:

+ +

Fasten Health is meant to automatically retrieve your health records from your healthcare providers. However, you might face limitations in these situations:

    -
  • Your healthcare institution is unsupported
  • -
  • Your records are too old and no longer exist in the system
  • -
  • You have additional information you'd like to associate with your medical condition (Imaging Results, Notes, etc)
  • +
  • Your healthcare provider isn't supported.
  • +
  • Your records are too old and no longer available in the system.
  • +
  • You want to include extra information related to your medical condition, like imaging results or notes.
-

In such cases, you can use this form to manually add records to Fasten.

+

If any of these apply to you, you can use this form to manually input your records into Fasten.

- +

A condition is a disease, illness, or injury that needs to be managed over time. A condition may be a comorbidity (a co-occurring condition), or it may be a main diagnosis.

@@ -465,6 +465,14 @@
Notes & Attachments
+
+
+
    +
  • {{error.controlName}} {{error.errorName}} {{error.errorValue}}
  • +
+
+
+ diff --git a/frontend/src/app/pages/resource-creator/resource-creator.component.ts b/frontend/src/app/pages/resource-creator/resource-creator.component.ts index b7a3d487e..48ba5fc85 100644 --- a/frontend/src/app/pages/resource-creator/resource-creator.component.ts +++ b/frontend/src/app/pages/resource-creator/resource-creator.component.ts @@ -1,5 +1,5 @@ import {Component, Input, OnInit} from '@angular/core'; -import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@angular/forms'; +import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms'; import { ModalDismissReasons, NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { ResourceCreateAttachment, @@ -27,6 +27,12 @@ export enum ContactType { ContactTypeManual = 'manual', } +interface FormValidationErrors { + controlName: string; + errorName: string; + errorValue: any; +} + @Component({ selector: 'app-resource-creator', templateUrl: './resource-creator.component.html', @@ -36,6 +42,7 @@ export class ResourceCreatorComponent implements OnInit { debugMode = false; collapsePanel: {[name: string]: boolean} = {} + public errors: FormValidationErrors[] = []; @Input() form!: FormGroup; get isValid() { return true; } @@ -80,8 +87,42 @@ export class ResourceCreatorComponent implements OnInit { this.resetOrganizationForm() // this.resetPractitionerForm() + + this.form.valueChanges.subscribe(() => { + this.errors = []; + this.calculateErrors(this.form); + }); } + calculateErrors(form: FormGroup | FormArray) { + Object.keys(form.controls).forEach(field => { + const control = form.get(field); + if (control instanceof FormGroup || control instanceof FormArray) { + this.errors = this.errors.concat(this.calculateErrors(control)); + return; + } + + const controlErrors: ValidationErrors = control.errors; + if (controlErrors !== null) { + Object.keys(controlErrors).forEach(keyError => { + console.log("Found Error", field, keyError, controlErrors[keyError], controlErrors); + this.errors.push({ + controlName: field, + errorName: keyError, + errorValue: controlErrors[keyError] + }); + }); + } + }); + + // This removes duplicates + this.errors = this.errors.filter((error, index, self) => self.findIndex(t => { + return t.controlName === error.controlName && t.errorName === error.errorName; + }) === index); + return this.errors; + } + + get medications(): FormArray { return this.form.controls["medications"] as FormArray; } @@ -216,16 +257,15 @@ export class ResourceCreatorComponent implements OnInit { let bundle = GenerateR4Bundle(this.form.getRawValue()); let bundleJsonStr = JSON.stringify(bundle); - let bundleBlob = new Blob([bundleJsonStr], { type: 'application/json' }); - let bundleFile = new File([ bundleBlob ], 'bundle.json'); + let bundleBlob = new Blob([bundleJsonStr], {type: 'application/json'}); + let bundleFile = new File([bundleBlob], 'bundle.json'); this.fastenApi.createManualSource(bundleFile).subscribe((resp) => { console.log(resp) this.router.navigate(['/medical-history']) }) - + } else { + this.calculateErrors(this.form); } - - } //Modal Helpers