@@ -2,17 +2,6 @@ const _ = require('lodash');
2
2
const logger = require ( './logger' ) ;
3
3
const { getBundleEntriesByResourceType, getBundleResourcesByType } = require ( './fhirUtils' ) ;
4
4
5
-
6
- function getConditionsFromContext ( mrn , context ) {
7
- logger . debug ( 'Getting conditions from context' ) ;
8
- const conditionsInContext = getBundleResourcesByType ( context , 'Condition' , { } , false ) ;
9
- if ( _ . isEmpty ( conditionsInContext ) ) {
10
- throw Error ( 'Could not find conditions in context; ensure that a ConditionExtractor is used earlier in your extraction configuration' ) ;
11
- }
12
- logger . debug ( 'Condition resources found in context.' ) ;
13
- return conditionsInContext ;
14
- }
15
-
16
5
function getPatientFromContext ( mrn , context ) {
17
6
logger . debug ( 'Getting patient from context' ) ;
18
7
const patientInContext = getBundleResourcesByType ( context , 'Patient' , { } , true ) ;
@@ -23,14 +12,34 @@ function getPatientFromContext(mrn, context) {
23
12
return patientInContext ;
24
13
}
25
14
26
- function getConditionEntriesFromContext ( mrn , context ) {
15
+ /**
16
+ * Parses context for Condition entries, which themselves contain resources
17
+ * @param {Object } context - Context object consisting of a FHIR Bundle
18
+ * @return {Array } All the conditions entries found in context
19
+ */
20
+ function getConditionEntriesFromContext ( context ) {
27
21
logger . debug ( 'Getting conditions from context' ) ;
28
- const conditionsInContext = getBundleEntriesByResourceType ( context , 'Condition' , { } , false ) ;
29
- if ( conditionsInContext . length === 0 ) {
22
+ const conditionEntriesInContext = getBundleEntriesByResourceType ( context , 'Condition' , { } , false ) ;
23
+ if ( conditionEntriesInContext . length === 0 ) {
30
24
throw Error ( 'Could not find any conditions in context; ensure that a ConditionExtractor is used earlier in your extraction configuration' ) ;
31
25
}
32
- logger . debug ( `Condition resources found in context. Found ${ conditionsInContext . length } condition resources.` ) ;
33
- return conditionsInContext ;
26
+ logger . debug ( `Condition resources found in context. Found ${ conditionEntriesInContext . length } condition resources.` ) ;
27
+ return conditionEntriesInContext ;
28
+ }
29
+
30
+ /**
31
+ * Parses context for Condition resources
32
+ * @param {Object } context - Context object consisting of a FHIR Bundle
33
+ * @return {Array } All the conditions resources found in context
34
+ */
35
+ function getConditionsFromContext ( context ) {
36
+ logger . debug ( 'Getting conditions from context' ) ;
37
+ const conditionsResourcesInContext = getBundleResourcesByType ( context , 'Condition' , { } , false ) ;
38
+ if ( _ . isEmpty ( conditionsResourcesInContext ) ) {
39
+ throw Error ( 'Could not find conditions in context; ensure that a ConditionExtractor is used earlier in your extraction configuration' ) ;
40
+ }
41
+ logger . debug ( 'Condition resources found in context.' ) ;
42
+ return conditionsResourcesInContext ;
34
43
}
35
44
36
45
/**
0 commit comments