GSoC'20: Add support for FHIR Narratives

Hi all, this is the public thread for the project “Add support for FHIR Narratives”. FHIR Narratives basically are human readable representations of FHIR resources. This project mainly involves the following:

  • Creating default FHIR Narratives for core resources (like Patient, Encounter, etc.)
  • Developing a framework to make handling of template definitions easier for the implementer, and also to support localisation of the generated narratives.
  • Implementation of search feature for FHIR resources using _text parameter.

Mentors for the project: @herbert24 @ibacher @suthagar23


Thank you @iamsr , I will be aside this.


thanks @tendomart and @iamsr


Hi, I was trying to use the Default Narrative Generator of HAPI library, for which I had to create an object of FhirContext.
But, the line FhirContext ctx = FhirContext.forDstu2(); gave me the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
	at ca.uhn.fhir.context.FhirContext.<clinit>(
	at org.openmrs.module.fhir2.FhirNarrativesGen.main(

I tried adding a dependency for org.slf4j in pom.xml but that didn’t work out. What else should I be doing to get rid of this error?

For reference, the declaration of the method forDstu2() goes as follows:

public static FhirContext forDstu2() {
    return new FhirContext(FhirVersionEnum.DSTU2);

@iamsr Could you please push the code you are working on a branch so that I can try helping you.

1 Like

Hey @sidvaish97! Actually I haven’t made much of a progress yet. I just started and creating an object of FhirContext gave me that error :confused:

@iamsr I just want to have a look on the error on my machine, probably I have been through this error but I want to be sure that it’s the same error.

It would be great if you could push your code with the error and point me to the file.

@sidvaish97 Sure! I’ve pushed it to a new branch fhir-narratives-temp. This is the direct link to the file.

1 Like

@iamsr Its working for me. Have you tried running mvn clean package ?

Have a look at the screenshot

@sidvaish97 Yeah, I hadn’t tried running mvn clean. Thanks! \

It got me rid of that error, though, now on running the compiled file, I’m getting the following error:

I guess making FhirNarrative an implementation of INarrativeGenerator could make it work, and then calling a method of this class in the main method could give me the output.

What’s your say on this? Am I going the right way?

@iamsr Oh that’s great.

Again I would ask you to push the code. I follow the hit and trial method :sweat_smile::sweat_smile:

1 Like

Oh okay. Will try it out and post updates! :slight_smile:

I made some modifications in the code, with the two main files of focus being: and

EDIT: Updated files are and

After running mvn clean package, when I try to run the file using:

java -cp ./api/target/fhir2-api-1.0.0-SNAPSHOT.jar org.openmrs.module.fhir2.FhirNarrative 

I still get the error java.lang.NoClassDefFoundError. What are the probable reasons for it?

@iamsr I guess that you are trying to test things simultaneously. But it’s better to use Mockito for testing.

Here is a test I tried

package org.openmrs.module.fhir2;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.r4.model.Patient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static;

public class FhirNarrativeGenTest {
	private FhirNarrativeGen fhirNarrativeGen;

	public void shouldPopulateResourceNarrative()
		Patient patient_res = new Patient();

		Boolean result=fhirNarrativeGen.populateResourceNarrative(FhirContext.forR4(), patient_res);



Hope this might be helpful

1 Like

Thanks @sidvaish97. Though, did this test pass for you? For me even this fails.

@iamsr The test is failing for me as well. I just wanted to give you an idea on how to test things simultaneously.

Maybe the code part is not correct

Not using Mockito, and instead declaring an object directly, and adding few dependencies worked out! Now the test passes :slight_smile: . Dunno why it wasn’t working with Mockito.

Test file:
Implementation file:
POM file: pom.xml

1 Like

@iamsr First, there’s a separate NarrativeGenerator sub-library of the HAPI FHIR API, which I would recommend using over re-inventing the wheel. To do this, add the resource to the pom.xml:


I prefer this to go after the existing resources.

Also, we shouldn’t refer to specific versions inside submodule POMs where this can be avoided. Instead, the dependency and it’s specific version should go in the root fhir2 POM. In the dependencyManagement section. This helps assure that all parts of the module are using consistent versions.

In this case, you just need to add something like this to the dependency management section after the hapi-fhir-structures-r4 part:


Hope that helps!

PS Be sure to checkout the (scant) documentation on HAPI FHIR Narratives.


Thanks a lot @ibacher!

Actually, I was just trying my hands on the Narrative Generator, which is the reason I thought of implementing it, but got an error.

Okay, will take care of the versions in the POMs.

Sure, will check it out. :slight_smile:

1 Like

@ibacher @herbert24 @suthagar23 My development goal for Coding Phase-1 is basically the creation and setting up of Default Narratives for the following resources:

  • AllergyIntolerance
  • Condition
  • DiagnosticReport
  • Encounter
  • Location
  • MedicationRequest
  • Medication
  • Observation
  • Patient
  • Person
  • Practitioner
  • RelatedPerson
  • ServiceRequest
  • Task

Could you all please review it once, so that I could proceed with creating JIRA tickets for the same.

1 Like