/**
 *  Defines an object with a function that returns a mock FHIR context, and also
 *  a structure of mock FHIR data.
 */ const fhirMock = { param fhirVersion param weightQuantity param resources mockFHIRContext : function ( fhirVersion , weightQuantity , resources ) { if ( ! weightQuantity ) { weightQuantity = { "value" : 95 , "unit" : "kg" , "system" : "http://unitsofmeasure.org" , "code" : "kg" } ; } return { getFhirVersion : function ( ) { return Promise . resolve ( fhirVersion ) ; } , request : function ( relativeURL ) { let rtnData , md ; if ( relativeURL . startsWith ( 'ValueSet' ) ) { if ( md = relativeURL . match ( /ValueSet\/([^/]+)\/\$expand/ ) ) { let vsID = md [ 1 ] ; rtnData = resources . ValueSet [ vsID ] ; } } return new Promise ( ( resolve , reject ) => { setTimeout ( function ( ) { if ( rtnData ) resolve ( rtnData ) ; else reject ( 'Not found' ) ; } ) ; } ) ; } , patient : { id : 5 , read : function ( ) { return new Promise ( ( resolve , reject ) => { setTimeout ( function ( ) { resolve ( { resourceType : "Patient" , name : [ { family : "Smith" , given : [ "John" , "Adam" ] } ] , birthDate : "1990-12-10" , gender : "male" } ) ; } ) ; } ) ; } , request : function ( relativeURL ) { let url = new URL ( relativeURL , 'https://example.com' ) ; let params = url . searchParams ; var entry = { "resource" : { "status" : "final" , "effectiveDateTime" : "2016-06-29T19:14:57-04:00" , "issued" : "2016-06-29T19:14:57-04:00" , } } ; let entries = [ ] ; switch ( params . get ( 'code' ) ) { case 'http://loinc.org|29463-7' : entry . resource . code = { "coding" : [ { "system" : "http://loinc.org" , "code" : "29463-7" , "display" : "Body Weight" } ] , "text" : "Body Weight" } ; entries . push ( entry ) ; entry = JSON . parse ( JSON . stringify ( entry ) ) ; entry . effectiveDateTime = "2015-06-29T19:14:57-04:00" ; entry . resource . valueQuantity = weightQuantity ; entries . push ( entry ) ; break ; case 'http://loinc.org|44250-9' : entry . resource . code = { "coding" : [ { "system" : "http://loinc.org" , "code" : "44250-9" , "display" : "Little interest or pleasure in doing things?" } ] , "text" : "Little interest or pleasure in doing things?" } ; entry . resource . valueCodeableConcept = { "coding" : [ { "system" : "http://loinc.org" , "code" : "LA6568-5" , "display" : "Not at all" } ] , "text" : "Not at all" } ; entries . push ( entry ) ; break ; case 'http://example.org|example,http://loinc.org|29463-7' : entry . resource . code = { "coding" : [ { "system" : "http://example.org" , "code" : "example" , "display" : "Example" } ] , "text" : "Example" } ; entry . resource . valueQuantity = weightQuantity ; entry . resource . valueQuantity . value = 96 ; entry . resource . effectiveDateTime = "2020-06-29T19:14:57-04:00" ; entry . resource . issued = "2020-06-29T19:14:57-04:00" ; entries . push ( entry ) ; entry = JSON . parse ( JSON . stringify ( entry ) ) ; entry . resource . valueQuantity . value = 95 ; entry . resource . effectiveDateTime = "2016-06-29T19:14:57-04:00" ; entry . resource . issued = "2016-06-29T19:14:57-04:00" ; entries . push ( entry ) ; break ; default : entry = null ; break ; } return { then : function ( callback ) { var data = { "resourceType" : "Bundle" , "type" : "searchset" , } ; if ( entries . length ) data . entry = entries ; setTimeout ( function ( ) { callback ( data ) ; } ) ; } } ; } } } ; } , mockData : { ValueSet : { } } } ; let vsID = 'language-preference-type' ; fhirMock . mockData . ValueSet [ vsID ] = require ( '../../../../src/test-data/e2e/R4/ValueSet/' + vsID + '.json' ) ; module . exports = fhirMock ;