hapi.context.getR5FhirContext¶
Signature: hapi.context.getR5FhirContext(useNarrative*)
Returns: FhirContext fhirContext - the cached FhirContext for R5
Returns the R5 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.getR5FhirContext().newJsonParser(); var hapiPatient = parser.parseResource(patientJsonString);
Note
Serializing Usage: var parser = hapi.context.getR5FhirContext().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 |
Example¶
// Get the HAPI fhir context you want (2/3/4/4b/5) etc.
var fhirContext = hapi.context.getR5FhirContext();
// 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.r5.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();