generated from PackagrIO/goweb-template
-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
report-medical-history-condition.component.ts
180 lines (152 loc) · 6.57 KB
/
report-medical-history-condition.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import {Component, Input, OnInit} from '@angular/core';
import {ResourceFhir} from '../../models/fasten/resource_fhir';
import {CareTeamModel} from '../../../lib/models/resources/care-team-model';
import {PractitionerModel} from '../../../lib/models/resources/practitioner-model';
import {EncounterModel} from '../../../lib/models/resources/encounter-model';
import {fhirModelFactory} from '../../../lib/models/factory';
import {fhirVersions, ResourceType} from '../../../lib/models/constants';
import {MedicationModel} from '../../../lib/models/resources/medication-model';
import {ProcedureModel} from '../../../lib/models/resources/procedure-model';
import {DeviceModel} from '../../../lib/models/resources/device-model';
import {DiagnosticReportModel} from '../../../lib/models/resources/diagnostic-report-model';
import {FastenDisplayModel} from '../../../lib/models/fasten/fasten-display-model';
import * as _ from "lodash";
import {ConditionModel} from '../../../lib/models/resources/condition-model';
import {CodingModel} from '../../../lib/models/datatypes/coding-model';
@Component({
selector: 'app-report-medical-history-condition',
templateUrl: './report-medical-history-condition.component.html',
styleUrls: ['./report-medical-history-condition.component.scss']
})
export class ReportMedicalHistoryConditionComponent implements OnInit {
/*
* conditionGroup is either a Condition or Composite object
*
* Condition
├─ related_resources
│ ├─ Encounter1
│ │ ├─ Location
│ ├─ Encounter2
│ │ ├─ Observation
│ ├─ Observation
│ ├─ Location
*
* or
* Composite
├─ related_resources
│ ├─ Condition2
│ ├─ Condition
│ │ ├─ related_resources
│ │ │ ├─ Encounter1
│ │ │ │ ├─ Location
│ │ │ ├─ Encounter2
│ │ │ │ ├─ Observation
│ │ │ ├─ Observation
│ │ │ ├─ Location
*
* */
@Input() conditionGroup: ResourceFhir
conditionDisplayModel: Partial<ConditionModel>
//lookup table for all resources
resourcesLookup: {[name:string]: FastenDisplayModel} = {}
involvedInCare: {displayName: string, role?: string, email?: string}[] = []
encounters: EncounterModel[] = []
// medications: {[encounterResourceId: string]: MedicationModel[]} = {}
// procedures: {[encounterResourceId: string]: ProcedureModel[]} = {}
// diagnosticReports: {[encounterResourceId: string]: DiagnosticReportModel[]} = {}
// device: {[encounterResourceId: string]: DeviceModel[]} = {}
constructor() { }
ngOnInit(): void {
if(!this.conditionGroup){
return
}
//add resources to the lookup table, ensure uniqueness.
this.conditionDisplayModel = this.recExtractResources(this.conditionGroup)
let involvedInCareMap: {[resource_id: string]: {displayName: string, role?: string, email?: string}} = {}
//loop though all resources, process display data
for(let resourceId in this.resourcesLookup){
let resource = this.resourcesLookup[resourceId]
switch(resource.source_resource_type){
case ResourceType.CareTeam:
for(let participant of (resource as CareTeamModel).participants){
let id = participant.reference.reference || participant.display
involvedInCareMap[id] = _.mergeWith(
{},
involvedInCareMap[id],
{
displayName: participant.display,
role: participant.role
},
)
}
break
case ResourceType.Practitioner:
let practitionerModel = resource as PractitionerModel
let id = `${resource.source_resource_type}/${resource.source_resource_id}`
let telecomEmails =_.find(practitionerModel.telecom, {"system": "email"})
let email = _.get(telecomEmails, '[0].value')
let qualification = _.find(practitionerModel.qualification, {"system": "http://nucc.org/provider-taxonomy"}) as CodingModel
involvedInCareMap[id] = _.mergeWith(
{},
involvedInCareMap[id],
{
displayName: practitionerModel.name?.family && practitionerModel.name?.given ? `${practitionerModel.name?.family }, ${practitionerModel.name?.given}` : practitionerModel.name?.text,
role: qualification?.display || practitionerModel.name?.prefix || practitionerModel.name?.suffix,
email: email,
},
)
break
case ResourceType.Encounter:
this.encounters.push(resource as EncounterModel);
(resource as EncounterModel).participant.map((participant) => {
let id = participant.reference.reference
involvedInCareMap[id] = _.mergeWith(
{},
involvedInCareMap[id],
{
displayName: participant.display,
role: participant.role,
},
)
})
break
}
}
console.log("GENERATED INVOLVED IN CARE MAP", involvedInCareMap)
for(let resourceId in involvedInCareMap){
this.involvedInCare.push(involvedInCareMap[resourceId])
}
}
/*
This function flattens all resources
*/
recExtractResources(resource: ResourceFhir): FastenDisplayModel{
let resourceId = this.genResourceId(resource)
let resourceDisplayModel: FastenDisplayModel = this.resourcesLookup[resourceId]
//ensure display model is populated
if(!resourceDisplayModel){
try{
resourceDisplayModel = fhirModelFactory(resource?.source_resource_type as ResourceType, resource)
this.resourcesLookup[resourceId] = resourceDisplayModel
}catch(e){
console.error(e) //failed to parse a model
return null
}
}
if(!resource.related_resources){
return resourceDisplayModel
} else {
for(let relatedResource of resource.related_resources){
resourceDisplayModel.related_resources[relatedResource.source_resource_type] = resourceDisplayModel.related_resources[relatedResource.source_resource_type] || []
let relatedResourceDisplayModel = this.recExtractResources(relatedResource)
if(relatedResourceDisplayModel){
resourceDisplayModel.related_resources[relatedResource.source_resource_type].push(relatedResourceDisplayModel)
}
}
}
return resourceDisplayModel
}
genResourceId(relatedResource: ResourceFhir): string {
return `/source/${relatedResource?.source_id}/resource/${relatedResource?.source_resource_type}/${relatedResource?.source_resource_id}`
}
}