GSoC'20: Add support for FHIR Narratives

Tags: #<Tag:0x00007fa3ed4bd8e8> #<Tag:0x00007fa3ed4bd820> #<Tag:0x00007fa3ed4bd730>

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

3 Likes

Thank you @iamsr , I will be aside this.

3 Likes

thanks @tendomart and @iamsr

2 Likes

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>(FhirContext.java:80)
	at org.openmrs.module.fhir2.FhirNarrativesGen.main(FhirNarrativesGen.java:21)

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: FhirNarrative.java and FhirNarrativeGen.java.

EDIT: Updated files are FhirNarrativeGenServiceImpl.java and FhirNarrativeGenServiceImplTest.java

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 org.hamcrest.Matchers.is;

@RunWith(MockitoJUnitRunner.class)
public class FhirNarrativeGenTest {
	@Mock
	private FhirNarrativeGen fhirNarrativeGen;

	@Test
	public void shouldPopulateResourceNarrative()
	{
		Patient patient_res = new Patient();
		patient_res.addIdentifier().setSystem("something").setValue("0001");
		patient_res.addName().setFamily("test_family").addGiven("test_name");

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

		assertThat(result,is(true));
	}

}

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: FhirNarrativeGeneratorTest.java
Implementation file: FhirNarrativeGenerator.java
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:

<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-narrativegenerator</artifactId>
</dependency>

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:

<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-narrativegenerator</artifactId>
	<version>${hapifhirVersion}</version>
</dependency>

Hope that helps!

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

2 Likes

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