Skip to content

Commit

Permalink
Add resource param to FhirCodeService (#241)
Browse files Browse the repository at this point in the history
* Added resource param to FhirCodeService

* bump version to 3.4.1
  • Loading branch information
semicolin authored Mar 25, 2024
1 parent 161e9b6 commit ee224c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion libs/ngx-charts-on-fhir/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elimuinformatics/ngx-charts-on-fhir",
"version": "3.4.0",
"version": "3.4.1",
"description": "Charts-on-FHIR: A data visualization library for SMART-on-FHIR healthcare applications",
"license": "Apache-2.0",
"homepage": "https://elimuinformatics.github.io/charts-on-fhir",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { CodeableConcept, Coding } from 'fhir/r4';
import { CodeableConcept, Coding, FhirResource } from 'fhir/r4';

/**
* A service for getting the display name of a FHIR `CodableConcept`.
Expand All @@ -11,7 +11,7 @@ import { CodeableConcept, Coding } from 'fhir/r4';
* ```ts
* @Injectable({ providedIn: 'root' })
* export class CustomFhirCodeService extends FhirCodeService {
* getName(code: CodeableConcept): string {
* getName(code: CodeableConcept, resource?: FhirResource): string {
* const customCodings = [
* {
* system: 'http://loinc.org',
Expand Down Expand Up @@ -42,7 +42,7 @@ import { CodeableConcept, Coding } from 'fhir/r4';
*/
@Injectable({ providedIn: 'root' })
export class FhirCodeService {
getName(code: CodeableConcept): string {
getName(code: CodeableConcept, resource?: FhirResource): string {
return code.text ?? '';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Inject } from '@angular/core';
import { ScaleOptions, Chart } from 'chart.js';
import { MedicationRequest } from 'fhir/r4';
import { FhirResource, MedicationRequest } from 'fhir/r4';
import { merge } from 'lodash-es';
import { DataLayer, TimelineChartType, TimelineDataPoint } from '../../data-layer/data-layer';
import { Mapper } from '../multi-mapper.service';
Expand All @@ -15,7 +15,7 @@ export type SimpleMedication = {
};
authoredOn: string;
} & MedicationRequest;
export function isMedication(resource: MedicationRequest): resource is SimpleMedication {
export function isMedication(resource: FhirResource): resource is SimpleMedication {
return !!(resource.resourceType === 'MedicationRequest' && resource.authoredOn && resource.medicationCodeableConcept?.text);
}

Expand All @@ -35,7 +35,7 @@ export class SimpleMedicationMapper implements Mapper<SimpleMedication> {
canMap = isMedication;
map(resource: SimpleMedication): DataLayer<TimelineChartType, MedicationDataPoint[]> {
const authoredOn = new Date(resource.authoredOn).getTime();
const codeName = this.codeService.getName(resource?.medicationCodeableConcept);
const codeName = this.codeService.getName(resource?.medicationCodeableConcept, resource);
return {
name: 'Prescribed Medications',
category: ['medication'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class ComponentObservationMapper implements Mapper<ComponentObservation>
) {}
canMap = isComponentObservation;
map(resource: ComponentObservation, overrideLayerName?: string): DataLayer {
const codeName = this.codeService.getName(resource.code);
const codeName = this.codeService.getName(resource.code, resource);
const layerName = overrideLayerName ?? codeName;
return {
name: layerName,
category: resource.category?.flatMap((c) => c.coding?.map((coding) => coding.display)).filter(isDefined),
datasets: resource.component.map((component) => ({
label: this.codeService.getName(component.code) + getMeasurementSettingSuffix(resource),
label: this.codeService.getName(component.code, resource) + getMeasurementSettingSuffix(resource),
yAxisID: layerName,
data: [
{
Expand All @@ -70,10 +70,13 @@ export class ComponentObservationMapper implements Mapper<ComponentObservation>
},
],
chartsOnFhir: {
group: this.codeService.getName(component.code),
group: this.codeService.getName(component.code, resource),
colorPalette: isHomeMeasurement(resource) ? 'light' : 'dark',
tags: [isHomeMeasurement(resource) ? 'Home' : 'Clinic'],
referenceRangeAnnotation: this.referenceRangeService.getAnnotationLabel(component.referenceRange?.[0], this.codeService.getName(component.code)),
referenceRangeAnnotation: this.referenceRangeService.getAnnotationLabel(
component.referenceRange?.[0],
this.codeService.getName(component.code, resource)
),
},
})),
scale: merge({}, this.linearScaleOptions, {
Expand All @@ -84,7 +87,7 @@ export class ComponentObservationMapper implements Mapper<ComponentObservation>
annotations: resource.component
.flatMap((component) =>
component.referenceRange?.map((range) =>
this.referenceRangeService.createReferenceRangeAnnotation(range, this.codeService.getName(component.code), layerName)
this.referenceRangeService.createReferenceRangeAnnotation(range, this.codeService.getName(component.code, resource), layerName)
)
)
.filter(isDefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SimpleObservationMapper implements Mapper<SimpleObservation> {
) {}
canMap = isSimpleObservation;
map(resource: SimpleObservation, overrideLayerName?: string): DataLayer {
const codeName = this.codeService.getName(resource.code);
const codeName = this.codeService.getName(resource.code, resource);
const layerName = overrideLayerName ?? codeName;
return {
name: layerName,
Expand Down

0 comments on commit ee224c9

Please sign in to comment.