@@ -2,14 +2,19 @@ const _ = require('lodash');
2
2
const logger = require ( './logger' ) ;
3
3
const { getBundleEntriesByResourceType, getBundleResourcesByType } = require ( './fhirUtils' ) ;
4
4
5
+ /**
6
+ * Parses context a Patient resource
7
+ * @param {Object } context - Context object consisting of a FHIR Bundle
8
+ * @return {Object } The first Patient resource found in the bundle
9
+ */
5
10
function getPatientFromContext ( mrn , context ) {
6
11
logger . debug ( 'Getting patient from context' ) ;
7
- const patientInContext = getBundleResourcesByType ( context , 'Patient' , { } , true ) ;
8
- if ( ! patientInContext ) {
12
+ const patientResourceInContext = getBundleResourcesByType ( context , 'Patient' , { } , true ) ;
13
+ if ( ! patientResourceInContext ) {
9
14
throw Error ( 'Could not find a patient in context; ensure that a PatientExtractor is used earlier in your extraction configuration' ) ;
10
15
}
11
16
logger . debug ( 'Patient resource found in context.' ) ;
12
- return patientInContext ;
17
+ return patientResourceInContext ;
13
18
}
14
19
15
20
/**
@@ -49,12 +54,12 @@ function getConditionsFromContext(context) {
49
54
*/
50
55
function getEncountersFromContext ( context ) {
51
56
logger . debug ( 'Getting encounter resources from context' ) ;
52
- const encountersInContext = getBundleResourcesByType ( context , 'Encounter' ) ;
53
- if ( encountersInContext . length === 0 ) {
57
+ const encounterResourcesInContext = getBundleResourcesByType ( context , 'Encounter' ) ;
58
+ if ( encounterResourcesInContext . length === 0 ) {
54
59
throw Error ( 'Could not find any encounter resources in context; ensure that an EncounterExtractor is used earlier in your extraction configuration' ) ;
55
60
}
56
- logger . debug ( `Condition resources found in context. Found ${ encountersInContext . length } condition resources.` ) ;
57
- return encountersInContext ;
61
+ logger . debug ( `Condition resources found in context. Found ${ encounterResourcesInContext . length } condition resources.` ) ;
62
+ return encounterResourcesInContext ;
58
63
}
59
64
60
65
module . exports = {
0 commit comments