GSoC'20: Add support for FHIR Narratives

Tags: #<Tag:0x00007fe6dbd49ad0> #<Tag:0x00007fe6dbd499e0> #<Tag:0x00007fe6dbd498f0>

looked through this and also requested other people to look through added a comment on the pr thanks

1 Like

Now that all the tasks for Coding Phase-1 have been wrapped up with this PR, these are the initial objectives for Coding Phase-2.

Overall Objective: Developing a framework to support user defined custom narratives.

Initial Approach:

  • The framework would be implemented as a class in FHIR module’s OMOD.
  • There would be a separate custom narratives properties file for the custom narratives template assignment.
  • The framework would handle setting up of the custom narrative template for the resource in the custom narratives properties file, using helper methods.
  • There would be a check for custom narratives in the initialize() method of FhirRestServlet and the properties file will be provided to the narrative generator accordingly.
  • Apart from this, there will be tests to check for errors in the user defined templates.

Looking forward to feedback/suggestions.

cc: @ibacher @herbert24 @suthagar23

Hi! I’ve come up with something like this for updating the customNarratives.properties file. It gives a rough idea of the approach I’m following:

public void addToPropertiesFile(String resourceName, String templateLocation) throws IOException {
	Properties customProperties = new Properties();
	try {
		customProperties.load(new FileInputStream(getCustomNarrativesPropFile()));
	}
	finally {
		Map<String, String> propertiesMap = getProperties(resourceName, templateLocation);
		propertiesMap.forEach(customProperties::put);
		customProperties.store(new FileOutputStream(getCustomNarrativesPropFile()), null);
	}
}

protected File getCustomNarrativesPropFile() {
	return new File(OpenmrsUtil.getDirectoryInApplicationDataDirectory(FhirConstants.CUSTOM_NARRATIVES_FOLDER_NAME),
	        FhirConstants.CUSTOM_NARRATIVES_PROPERTY_FILE_NAME);
}
	
protected Map<String, String> getProperties(String resourceClass, String templateResourceClasspath {
	Map<String, String> propertiesMap = new HashMap<String, String>();
	propertiesMap.put(String.join(".", resourceClass.toLowerCase(), "resourceType"), resourceClass);
	propertiesMap.put(String.join(".", resourceClass.toLowerCase(), "narrative"), templateResourceClasspath);
	return propertiesMap;
}
  • If a properties file is not present, it creates one in the subdirectory customNarratives of OpenMRS Application Data Directory.
  • The addToPropertiesFile() method takes in the resource class and template location and assigns the template for the resource narrative.
  • In case there already is an entry for that resource, it will automatically update it with the new resource narrative template.
  • Also, I’m thinking of adding a method to remove the listing of a custom narrative for some resource.

Does it look fine? @ibacher @herbert24 @suthagar23

Also, since this is something that the implementer would do on choice and not every time when the FHIR module is used, should it be in a separate module?

Does any other mentor have a different approach than this cc @ibacher @suthagar23

1 Like

Updated Objectives for Coding Phase-2:

  1. Add support for custom narratives.
  2. Support relative paths prefixed with openmrs: for location of narratives and properties file. For example, the relative path openmrs:configuration/Patient.html would point to the location <OPENMRS_APPLICATION_DATA_DIRECTORY>/configuration/Patient.html .

Approach to be followed:

Support for custom narratives could be provided by giving the implementer an option to specify a properties file containing the location of narrative templates which he/she wants to override. The FHIR Module would give a higher priority to these overrides to serve the intended purpose. In order to support relative paths prefixed with openmrs: , we would need to implement our own narrative generator with the required changes in order to support openmrs: prefixed relative paths.

Please find the link for draft PR for FM2-252 below. It contains a basic working version of the modified narrative generator. If this looks fine, I’ll be working on simplification of the implementation.

cc @ibacher @herbert24 @suthagar23

Hi there!

Since we are autowiring messageSource in our message resolver, on running tests, messageSource remains null. For that, we might use @Mock annotation for the messageSource but then the messages won’t be populated in the narrative templates. So what could be done for that? Any suggestions?


Also, if I try to do something like this:

OpenMRSMessageResolver resolver = new OpenMRSMessageResolver(null);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(resolver.getClass());
OpenMRSMessageResolver app = context.getBean(resolver.getClass());
log.info(app.getMessageSource().getMessage("fhir2.title", new Object[] {}, Locale.getDefault()));

I get the following error, even if the property exists in the messages.properties file:

org.springframework.context.NoSuchMessageException: No message found under code 'fhir2.title' for locale 'en_GB'.

So where did I go wrong here?


cc @ibacher @herbert24 @suthagar23

Are you picking from message_en_GB.properties ?

No, I had placed the property in messages.properties. Isn’t it the default fallback for EN locale?

Just create a ReloadableResourceBundleMessageSource:

private ReloadableResourceBundleMessageSource messageSource;

...

@Before
public void setupMessageSource() {
    messageSource = new ReloadableResourceBundleMessageSource();
    // this is effectively what OpenMRS uses
    messageSource.addBasenames("classpath:messages")
}

Then just add this messageSource where it’s needed.

2 Likes

Oh okay! Thanks! :smiley:

Please take a look at the draft PR (link below) for FM2-280. Does it look fine?

For now I’ve just made changes to AllergyIntolerance template. I’ll make changes to the rest too if the approach looks fine.

cc @ibacher @herbert24 @suthagar23

1 Like

hello @iamsr

am experiencing a failure in org.openmrs.module.fhir2.narrative.NarrativeGeneratorTest. during maven build

Thanks

1 Like

Hi @gcliff! Thanks for raising this up.

I guess the error is occurring due to the newline issue in Windows (something similar to FM2-243).

I’ve raised a PR for the same issue. Could you please verify if the build succeeds on Windows?

2 Likes

Thanks @ibacher for that quick solution :+1:

1 Like

@iamsr works fine now , :+1:

2 Likes

Hi! Please take a look at the following PRs.

cc @ibacher @herbert24 @suthagar23

Hello everyone!

I’m super happy to share that all the main project objectives for this project have got completed. I would like to thank my wonderful mentors @ibacher, @herbert24 and @suthagar23 who always supported me throughout the project. I would also thank the entire OpenMRS community which was so supportive and was always there for help.

Here are the links to the final report and the demonstration video:

2 Likes

Congrats @iamsr

1 Like

Thanks @tendomart! :smiley: