generated from PackagrIO/goweb-template
-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support displaying non-numerical observation results (#453)
* Add new datatype models and specs * Update datatypes/coding-model * Add new factories and update observation-r4-factory * Update observation model to use new datatypes * Add new observation-visualization and observation-table components * Update observation-bar-chart * Update observation and report-labs-observation components * Forgot to switch to observation-visualization; add test and update test imports to fix errors
- Loading branch information
1 parent
1bcf4aa
commit 6264415
Showing
45 changed files
with
1,463 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...nd/src/app/components/fhir-card/common/observation-table/observation-table.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="table-responsive"> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th *ngFor="let header of headers"> | ||
{{header}} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let row of rows"> | ||
<td *ngFor="let data of row"> | ||
{{data}} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> |
3 changes: 3 additions & 0 deletions
3
...nd/src/app/components/fhir-card/common/observation-table/observation-table.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tbody tr td:first-child { | ||
font-weight: bold; | ||
} |
51 changes: 51 additions & 0 deletions
51
...src/app/components/fhir-card/common/observation-table/observation-table.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ObservationTableComponent } from './observation-table.component'; | ||
import { ObservationModel } from 'src/lib/models/resources/observation-model'; | ||
import { observationR4Factory } from 'src/lib/fixtures/factories/r4/resources/observation-r4-factory'; | ||
import { fhirVersions } from 'src/lib/models/constants'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('ObservationTableComponent', () => { | ||
let component: ObservationTableComponent; | ||
let fixture: ComponentFixture<ObservationTableComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ ObservationTableComponent ] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ObservationTableComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
fixture.detectChanges(); | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should display reference range column if any observations have a reference range', () => { | ||
component.observations = [ | ||
new ObservationModel(observationR4Factory.valueQuantity().build(), fhirVersions.R4), | ||
new ObservationModel(observationR4Factory.valueCodeableConcept().build(), fhirVersions.R4), | ||
new ObservationModel(observationR4Factory.valueString().referenceRange().build(), fhirVersions.R4), | ||
] | ||
fixture.detectChanges(); | ||
|
||
expect(component.headers).toEqual(['Date', 'Result', 'Reference Range']); | ||
expect(fixture.debugElement.queryAll(By.css('th')).length).toEqual(3); | ||
}); | ||
|
||
|
||
it('should not display reference range column if no observations have a reference range', () => { | ||
component.observations = [ | ||
new ObservationModel(observationR4Factory.valueQuantity().build(), fhirVersions.R4), | ||
new ObservationModel(observationR4Factory.valueCodeableConcept().build(), fhirVersions.R4), | ||
new ObservationModel(observationR4Factory.valueString().build(), fhirVersions.R4), | ||
] | ||
fixture.detectChanges(); | ||
|
||
expect(component.headers).toEqual(['Date', 'Result']); | ||
expect(fixture.debugElement.queryAll(By.css('th')).length).toEqual(2); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
...tend/src/app/components/fhir-card/common/observation-table/observation-table.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { ObservationModel } from '../../../../../lib/models/resources/observation-model'; | ||
import { CommonModule, formatDate } from '@angular/common'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'observation-table', | ||
imports: [ CommonModule ], | ||
templateUrl: './observation-table.component.html', | ||
styleUrls: ['./observation-table.component.scss'] | ||
}) | ||
export class ObservationTableComponent implements OnInit { | ||
@Input() observations: ObservationModel[] | ||
|
||
headers: string[] = [] | ||
rows: string[][] = [] | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
if(!this.observations || !this.observations[0]) { | ||
return; | ||
} | ||
|
||
let displayRange = this.rangeExists(this.observations); | ||
|
||
if (displayRange) { | ||
this.headers = ['Date', 'Result', 'Reference Range']; | ||
this.rows = this.observations.map((observation) => { | ||
return [this.formatDate(observation.effective_date), observation.value_model?.display(), observation.reference_range?.display()]; | ||
}); | ||
} else { | ||
this.headers = ['Date', 'Result']; | ||
this.rows = this.observations.map((observation) => { | ||
return [this.formatDate(observation.effective_date), observation.value_model?.display()]; | ||
}); | ||
} | ||
} | ||
|
||
private rangeExists(observations: ObservationModel[]): boolean { | ||
return observations.some((observation) => { return observation.reference_range?.hasValue() }) | ||
} | ||
|
||
private formatDate(date: string | number | Date): string { | ||
if (date) { | ||
return formatDate(date, "mediumDate", "en-US", undefined); | ||
} else { | ||
return 'Unknown date'; | ||
} | ||
} | ||
} |
Oops, something went wrong.