Skip to content

Commit

Permalink
make last updated dynamic from summary api endpoint (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwradcliffe authored Aug 11, 2024
1 parent c5d7717 commit 01caa24
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2 class="az-dashboard-title">{{reportHeaderTitle}}</h2>
<div class="media">
<div class="media-body">
<label>Last Updated</label>
<h6>Oct 10, 2018</h6>
<h6>{{lastUpdated ? (lastUpdated | date:'MMM d, yyyy') : ''}}</h6>
</div><!-- media-body -->
</div><!-- media -->
<div *ngIf="primaryCare" class="media">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ReportHeaderComponent', () => {
let mockedFastenApiService

beforeEach(async () => {
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources'])
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'getSummary'])

await TestBed.configureTestingModule({
imports: [ RouterTestingModule ],
Expand All @@ -23,6 +23,7 @@ describe('ReportHeaderComponent', () => {
})
.compileComponents();
mockedFastenApiService.getResources.and.returnValue(of({}));
mockedFastenApiService.getSummary.and.returnValue(of({sources: []}));

fixture = TestBed.createComponent(ReportHeaderComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ResourceFhir} from '../../models/fasten/resource_fhir';
import {FastenApiService} from '../../services/fasten-api.service';
import * as fhirpath from 'fhirpath';
import {PractitionerModel} from '../../../lib/models/resources/practitioner-model';
import {Summary} from '../../../app/models/fasten/summary';

@Component({
selector: 'report-header',
Expand All @@ -12,14 +13,22 @@ import {PractitionerModel} from '../../../lib/models/resources/practitioner-mode
export class ReportHeaderComponent implements OnInit {
patient: ResourceFhir = null
primaryCare: PractitionerModel = null
lastUpdated: Date = null
@Input() reportHeaderTitle: string = ""
@Input() reportHeaderSubTitle: string = "Organized by condition and encounters"

constructor(
private fastenApi: FastenApiService,
) { }

ngOnInit(): void {
this.fastenApi.getSummary().subscribe((summary: Summary) => {
if (summary.sources && summary.sources.length > 0) {
this.lastUpdated = summary.sources.reduce((latest, source) => {
const sourceDate = new Date(source.updated_at);
return sourceDate > latest ? sourceDate : latest;
}, new Date(0));
}
})
this.fastenApi.getResources("Patient").subscribe(results => {
this.patient = results[0]
if(!this.patient) return
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/pages/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="az-dashboard-title">Welcome back!</h2>
<div class="media">
<div class="media-body">
<label>Last Updated</label>
<h6>Oct 10, 2018</h6>
<h6>{{lastUpdated ? (lastUpdated | date:'MMM d, yyyy') : ''}}</h6>
</div><!-- media-body -->
</div><!-- media -->
<div class="media">
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
import {GridstackComponent, NgGridStackOptions} from '../../components/gridstack/gridstack.component';
import {DashboardConfig} from '../../models/widget/dashboard-config';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';

import {Summary} from '../../models/fasten/summary';

// unique ids sets for each item for correct ngFor updating
//TODO: fix this
Expand All @@ -23,6 +23,8 @@ let ids = 1;
export class DashboardComponent implements OnInit {
loading: boolean = false

lastUpdated: Date = null

sources: Source[] = []
encounterCount: number = 0
recordsCount: number = 0
Expand Down Expand Up @@ -50,6 +52,15 @@ export class DashboardComponent implements OnInit {
ngOnInit() {
this.loading = true

this.fastenApi.getSummary().subscribe((summary: Summary) => {
if (summary.sources && summary.sources.length > 0) {
this.lastUpdated = summary.sources.reduce((latest, source) => {
const sourceDate = new Date(source.updated_at);
return sourceDate > latest ? sourceDate : latest;
}, new Date(0));
}
})


forkJoin([
this.fastenApi.getDashboards(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('MedicalHistoryComponent', () => {

beforeEach(async () => {

mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'getResourceGraph'])
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'getResourceGraph', 'getSummary'])
await TestBed.configureTestingModule({
declarations: [ MedicalHistoryComponent, ReportHeaderComponent ],
imports: [ RouterTestingModule ],
Expand All @@ -26,6 +26,7 @@ describe('MedicalHistoryComponent', () => {
.compileComponents();
mockedFastenApiService.getResourceGraph.and.returnValue(of({"Condition":[],"Encounter":[]}));
mockedFastenApiService.getResources.and.returnValue(of([]));
mockedFastenApiService.getSummary.and.returnValue(of({sources: []}));

fixture = TestBed.createComponent(MedicalHistoryComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('PatientProfileComponent', () => {
let mockedFastenApiService

beforeEach(async () => {
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources'])
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'getSummary'])
await TestBed.configureTestingModule({
declarations: [ PatientProfileComponent, ReportHeaderComponent ],
imports: [PipesModule, RouterTestingModule],
Expand All @@ -24,7 +24,7 @@ describe('PatientProfileComponent', () => {
})
.compileComponents();
mockedFastenApiService.getResources.and.returnValue(of([{}]));

mockedFastenApiService.getSummary.and.returnValue(of({sources: []}));
fixture = TestBed.createComponent(PatientProfileComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ReportLabsComponent', () => {

beforeEach(async () => {

mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'queryResources'])
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'queryResources', 'getSummary'])
await TestBed.configureTestingModule({
declarations: [ ReportLabsComponent, ReportHeaderComponent ],
imports: [RouterTestingModule, LoadingSpinnerComponent, RouterTestingModule],
Expand All @@ -26,6 +26,7 @@ describe('ReportLabsComponent', () => {
.compileComponents();
mockedFastenApiService.getResources.and.returnValue(of([]));
mockedFastenApiService.queryResources.and.returnValue(of([]));
mockedFastenApiService.getSummary.and.returnValue(of({sources: []}));

fixture = TestBed.createComponent(ReportLabsComponent);
component = fixture.componentInstance;
Expand Down

0 comments on commit 01caa24

Please sign in to comment.