hapi.context.getR4bFhirContext¶
Signature: hapi.context.getR4bFhirContext(useNarrative*, useUSCoreProfile*)
Returns: FhirContext fhirContext - the cached FhirContext for R4b
Returns the R4b FhirContext for parsing and serializing HAPI resources.
This threadsafe instance is cached, and therefore optimized for use within QIE.
Note
Parsing Usage: var parser = hapi.context.getR4bFhirContext().newJsonParser(); var hapiPatient = parser.parseResource(patientJsonString);
Note
Serializing Usage: var parser = hapi.context.getR4bFhirContext().newJsonParser(); var patientJsonString = parser.encodeResourceToString(hapiPatient);
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| Boolean | useNarrative* | (optional) if true, includes a narrative text based on the resource | false |
| Boolean | useUSCoreProfile* | (optional) if true, includes USCoreProfile extensions | false |
Example¶
// Get the HAPI fhir context you want (2/3/4b) etc.
var fhirContext = hapi.context.getR4bFhirContext();
// now you can do things with fhirContext
var patientJson = '' +
'{' +
' "resourceType": "Patient",' +
' "id": "example",' +
' "name": [' +
' {' +
' "family": "Doe",' +
' "given": ["John","Jaques"]' +
' }' +
' ],' +
' "gender": "male",' +
' "birthDate": "1980-01-01"' +
'}';
// Use the context to create a parser
var jsonParser = fhirContext.newJsonParser();
// Parse the JSON string into a Patient object
var patient = jsonParser.parseResource(org.hl7.fhir.r4b.model.Patient, patientJson);
// Extract the patient's name
var humanName = patient.name.get(0); // Get the first name in the list
var fullName = humanName.getGiven() + ' ' + humanName.getFamily();