1
+ const _ = require ( 'lodash' ) ;
1
2
const logger = require ( './logger' ) ;
2
3
const { getBundleEntriesByResourceType, getBundleResourcesByType } = require ( './fhirUtils' ) ;
3
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
+ */
4
10
function getPatientFromContext ( mrn , context ) {
5
11
logger . debug ( 'Getting patient from context' ) ;
6
- const patientInContext = getBundleResourcesByType ( context , 'Patient' , { } , true ) ;
7
- if ( ! patientInContext ) {
12
+ const patientResourceInContext = getBundleResourcesByType ( context , 'Patient' , { } , true ) ;
13
+ if ( ! patientResourceInContext ) {
8
14
throw Error ( 'Could not find a patient in context; ensure that a PatientExtractor is used earlier in your extraction configuration' ) ;
9
15
}
10
16
logger . debug ( 'Patient resource found in context.' ) ;
11
- return patientInContext ;
17
+ return patientResourceInContext ;
12
18
}
13
19
14
- function getConditionEntriesFromContext ( mrn , context ) {
15
- logger . debug ( 'Getting conditions from context' ) ;
16
- const conditionsInContext = getBundleEntriesByResourceType ( context , 'Condition' , { } , false ) ;
17
- if ( conditionsInContext . length === 0 ) {
20
+ /**
21
+ * Parses context for Condition entries, which themselves contain resources
22
+ * @param {Object } context - Context object consisting of a FHIR Bundle
23
+ * @return {Array } All the conditions entries found in context
24
+ */
25
+ function getConditionEntriesFromContext ( context ) {
26
+ logger . debug ( 'Getting condition entries from context' ) ;
27
+ const conditionEntriesInContext = getBundleEntriesByResourceType ( context , 'Condition' , { } , false ) ;
28
+ if ( conditionEntriesInContext . length === 0 ) {
29
+ throw Error ( 'Could not find any conditions in context; ensure that a ConditionExtractor is used earlier in your extraction configuration' ) ;
30
+ }
31
+ logger . debug ( `Condition entries found in context. Found ${ conditionEntriesInContext . length } condition resources.` ) ;
32
+ return conditionEntriesInContext ;
33
+ }
34
+
35
+ /**
36
+ * Parses context for Condition resources
37
+ * @param {Object } context - Context object consisting of a FHIR Bundle
38
+ * @return {Array } All the conditions resources found in context
39
+ */
40
+ function getConditionsFromContext ( context ) {
41
+ logger . debug ( 'Getting condition resources from context' ) ;
42
+ const conditionsResourcesInContext = getBundleResourcesByType ( context , 'Condition' , { } , false ) ;
43
+ if ( _ . isEmpty ( conditionsResourcesInContext ) ) {
18
44
throw Error ( 'Could not find any conditions in context; ensure that a ConditionExtractor is used earlier in your extraction configuration' ) ;
19
45
}
20
- logger . debug ( `Condition resources found in context. Found ${ conditionsInContext . length } condition resources.` ) ;
21
- return conditionsInContext ;
46
+ logger . debug ( `Condition resources found in context. Found ${ conditionsResourcesInContext . length } condition resources.` ) ;
47
+ return conditionsResourcesInContext ;
22
48
}
23
49
24
50
/**
@@ -28,16 +54,17 @@ function getConditionEntriesFromContext(mrn, context) {
28
54
*/
29
55
function getEncountersFromContext ( context ) {
30
56
logger . debug ( 'Getting encounter resources from context' ) ;
31
- const encountersInContext = getBundleResourcesByType ( context , 'Encounter' ) ;
32
- if ( encountersInContext . length === 0 ) {
57
+ const encounterResourcesInContext = getBundleResourcesByType ( context , 'Encounter' ) ;
58
+ if ( encounterResourcesInContext . length === 0 ) {
33
59
throw Error ( 'Could not find any encounter resources in context; ensure that an EncounterExtractor is used earlier in your extraction configuration' ) ;
34
60
}
35
- logger . debug ( `Condition resources found in context. Found ${ encountersInContext . length } condition resources.` ) ;
36
- return encountersInContext ;
61
+ logger . debug ( `Condition resources found in context. Found ${ encounterResourcesInContext . length } condition resources.` ) ;
62
+ return encounterResourcesInContext ;
37
63
}
38
64
39
65
module . exports = {
40
66
getConditionEntriesFromContext,
67
+ getConditionsFromContext,
41
68
getEncountersFromContext,
42
69
getPatientFromContext,
43
70
} ;
0 commit comments