hapi.context.getDSTU3FhirContext¶
Signature: hapi.context.getDSTU3FhirContext(useNarrative*, useUSCoreProfile*)
Returns: FhirContext fhirContext - the cached FhirContext for DSTU3
Returns the DSTU3 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.getDSTU3FhirContext().newJsonParser(); var hapiPatient = parser.parseResource(patientJsonString);
Note
Serializing Usage: var parser = hapi.context.getDSTU3FhirContext().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¶
// Make sure you've installed the hapi plugin
// Get the HAPI FHIR context for DSTU3
var fhirContext = hapi.context.getDSTU3FhirContext();
// JSON representation of a Patient resource
var patientJson = '' +
'{' +
' "resourceType": "Patient",' +
' "id": "example",' +
' "name": [' +
' {' +
' "family": "Doe",' +
' "given": ["John"]' +
' }' +
' ],' +
' "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(patientJson);
// Extract the patient's name
var humanName = patient.getName().get(0); // Get the first name in the list
var givenNames = humanName.getGiven(); // Get the list of given names
var familyName = humanName.getFamily(); // Get the family name
// Combine given names into a single string
var fullName = givenNames.toArray().join(' ') + ' ' + familyName;