make last updated dynamic from summary api endpoint (#499)

This commit is contained in:
David Radcliffe 2024-08-11 05:55:51 -04:00 committed by GitHub
parent c5d7717cbd
commit 01caa24719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 32 additions and 9 deletions

View File

@ -7,7 +7,7 @@
<div class="media"> <div class="media">
<div class="media-body"> <div class="media-body">
<label>Last Updated</label> <label>Last Updated</label>
<h6>Oct 10, 2018</h6> <h6>{{lastUpdated ? (lastUpdated | date:'MMM d, yyyy') : ''}}</h6>
</div><!-- media-body --> </div><!-- media-body -->
</div><!-- media --> </div><!-- media -->
<div *ngIf="primaryCare" class="media"> <div *ngIf="primaryCare" class="media">

View File

@ -11,7 +11,7 @@ describe('ReportHeaderComponent', () => {
let mockedFastenApiService let mockedFastenApiService
beforeEach(async () => { beforeEach(async () => {
mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources']) mockedFastenApiService = jasmine.createSpyObj('FastenApiService', ['getResources', 'getSummary'])
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [ RouterTestingModule ], imports: [ RouterTestingModule ],
@ -23,6 +23,7 @@ describe('ReportHeaderComponent', () => {
}) })
.compileComponents(); .compileComponents();
mockedFastenApiService.getResources.and.returnValue(of({})); mockedFastenApiService.getResources.and.returnValue(of({}));
mockedFastenApiService.getSummary.and.returnValue(of({sources: []}));
fixture = TestBed.createComponent(ReportHeaderComponent); fixture = TestBed.createComponent(ReportHeaderComponent);
component = fixture.componentInstance; component = fixture.componentInstance;

View File

@ -3,6 +3,7 @@ import {ResourceFhir} from '../../models/fasten/resource_fhir';
import {FastenApiService} from '../../services/fasten-api.service'; import {FastenApiService} from '../../services/fasten-api.service';
import * as fhirpath from 'fhirpath'; import * as fhirpath from 'fhirpath';
import {PractitionerModel} from '../../../lib/models/resources/practitioner-model'; import {PractitionerModel} from '../../../lib/models/resources/practitioner-model';
import {Summary} from '../../../app/models/fasten/summary';
@Component({ @Component({
selector: 'report-header', selector: 'report-header',
@ -12,14 +13,22 @@ import {PractitionerModel} from '../../../lib/models/resources/practitioner-mode
export class ReportHeaderComponent implements OnInit { export class ReportHeaderComponent implements OnInit {
patient: ResourceFhir = null patient: ResourceFhir = null
primaryCare: PractitionerModel = null primaryCare: PractitionerModel = null
lastUpdated: Date = null
@Input() reportHeaderTitle: string = "" @Input() reportHeaderTitle: string = ""
@Input() reportHeaderSubTitle: string = "Organized by condition and encounters" @Input() reportHeaderSubTitle: string = "Organized by condition and encounters"
constructor( constructor(
private fastenApi: FastenApiService, private fastenApi: FastenApiService,
) { } ) { }
ngOnInit(): void { 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.fastenApi.getResources("Patient").subscribe(results => {
this.patient = results[0] this.patient = results[0]
if(!this.patient) return if(!this.patient) return

View File

@ -11,7 +11,7 @@
<div class="media"> <div class="media">
<div class="media-body"> <div class="media-body">
<label>Last Updated</label> <label>Last Updated</label>
<h6>Oct 10, 2018</h6> <h6>{{lastUpdated ? (lastUpdated | date:'MMM d, yyyy') : ''}}</h6>
</div><!-- media-body --> </div><!-- media-body -->
</div><!-- media --> </div><!-- media -->
<div class="media"> <div class="media">

View File

@ -9,7 +9,7 @@ import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
import {GridstackComponent, NgGridStackOptions} from '../../components/gridstack/gridstack.component'; import {GridstackComponent, NgGridStackOptions} from '../../components/gridstack/gridstack.component';
import {DashboardConfig} from '../../models/widget/dashboard-config'; import {DashboardConfig} from '../../models/widget/dashboard-config';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {Summary} from '../../models/fasten/summary';
// unique ids sets for each item for correct ngFor updating // unique ids sets for each item for correct ngFor updating
//TODO: fix this //TODO: fix this
@ -23,6 +23,8 @@ let ids = 1;
export class DashboardComponent implements OnInit { export class DashboardComponent implements OnInit {
loading: boolean = false loading: boolean = false
lastUpdated: Date = null
sources: Source[] = [] sources: Source[] = []
encounterCount: number = 0 encounterCount: number = 0
recordsCount: number = 0 recordsCount: number = 0
@ -50,6 +52,15 @@ export class DashboardComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.loading = true 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([ forkJoin([
this.fastenApi.getDashboards(), this.fastenApi.getDashboards(),

View File

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

View File

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

View File

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