@@ -2,7 +2,7 @@ import { Observation } from "@fhir-typescript/r4b-core/dist/fhir/Observation";
22import { snomed , loinc } from "./tonometry-to-fhir.ts" ;
33
44import { ObservationStatusCodes } from "@fhir-typescript/r4b-core/dist/fhirValueSets/ObservationStatusCodes" ;
5- import { Bundle , BundleEntry , DiagnosticReport } from "@fhir-typescript/r4b-core/dist/fhir" ;
5+ import { Bundle , BundleEntry , DiagnosticReport , Reference } from "@fhir-typescript/r4b-core/dist/fhir" ;
66import { AnteriorChamberData , SUNCells , SUNFlare } from "./anterior-chamber-data.ts" ;
77
88const SUNFlare2Fhir = {
@@ -27,6 +27,7 @@ const SUNCells2Fhir = {
2727export function anteriorChamber2Fhir ( data : AnteriorChamberData ) : Bundle [ ] {
2828 let cellsLeft = new Observation ( {
2929 resourceType : "Observation" ,
30+ id : "cells-left" ,
3031 status : ObservationStatusCodes . Final ,
3132 category : [
3233 { coding : [ { system : "http://terminology.hl7.org/CodeSystem/observation-category" , code : "exam" } ] } ,
@@ -45,6 +46,7 @@ export function anteriorChamber2Fhir(data: AnteriorChamberData): Bundle[] {
4546
4647 let flareLeft = new Observation ( {
4748 resourceType : "Observation" ,
49+ id : "flare-left" ,
4850 status : ObservationStatusCodes . Final ,
4951 category : [
5052 { coding : [ { system : "http://terminology.hl7.org/CodeSystem/observation-category" , code : "exam" } ] } ,
@@ -69,11 +71,16 @@ export function anteriorChamber2Fhir(data: AnteriorChamberData): Bundle[] {
6971
7072 // add optional note for left eye if present
7173 if ( ! ! data . leftEye . note ) {
72- left . entry . push ( new BundleEntry ( { resource : getDiagnosticReport ( data . recordedDate , data . leftEye . note ) } ) ) ;
74+ left . entry . push (
75+ new BundleEntry ( {
76+ resource : getDiagnosticReport ( data . recordedDate , data . leftEye . note , [ cellsLeft , flareLeft ] ) ,
77+ } )
78+ ) ;
7379 }
7480
7581 let cellsRight = new Observation ( {
7682 resourceType : "Observation" ,
83+ id : "cells-right" ,
7784 status : ObservationStatusCodes . Final ,
7885 category : [
7986 { coding : [ { system : "http://terminology.hl7.org/CodeSystem/observation-category" , code : "exam" } ] } ,
@@ -92,6 +99,7 @@ export function anteriorChamber2Fhir(data: AnteriorChamberData): Bundle[] {
9299
93100 let flareRight = new Observation ( {
94101 resourceType : "Observation" ,
102+ id : "flare-right" ,
95103 status : ObservationStatusCodes . Final ,
96104 category : [
97105 { coding : [ { system : "http://terminology.hl7.org/CodeSystem/observation-category" , code : "exam" } ] } ,
@@ -116,13 +124,17 @@ export function anteriorChamber2Fhir(data: AnteriorChamberData): Bundle[] {
116124
117125 // add optional note for right eye if present
118126 if ( ! ! data . rightEye . note ) {
119- right . entry . push ( new BundleEntry ( { resource : getDiagnosticReport ( data . recordedDate , data . rightEye . note ) } ) ) ;
127+ right . entry . push (
128+ new BundleEntry ( {
129+ resource : getDiagnosticReport ( data . recordedDate , data . rightEye . note , [ cellsRight , flareRight ] ) ,
130+ } )
131+ ) ;
120132 }
121133
122134 return [ left , right ] ;
123135}
124136
125- export function getDiagnosticReport ( date : string , note : string ) {
137+ export function getDiagnosticReport ( date : string , note : string , results : Observation [ ] ) {
126138 return new DiagnosticReport ( {
127139 resourceType : "DiagnosticReport" ,
128140 status : ObservationStatusCodes . Final ,
@@ -136,5 +148,6 @@ export function getDiagnosticReport(date: string, note: string) {
136148 } ,
137149 effectiveDateTime : new Date ( date ) . toISOString ( ) ,
138150 conclusion : note ,
151+ result : results . map ( ( r ) => new Reference ( { reference : `Observation/${ r . id } ` } ) ) ,
139152 } ) ;
140153}
0 commit comments