GSCoC 2018 / 'Attachments enhancements'

Is there a way to directly get the TestHelper class ( inside the /api ) for the AttachmentServiceTest class inside the /api-2.0.

Or may I create a new testHelper class inside the /api-2.0 and extend with the above mentioned TestHelper class and add the additional methods required for the /api-2.0 ?

Ah ok I understand the problem.

Just add this dependency to api-2.0/pom.xml:

<dependency>
  <groupId>${project.parent.groupId}</groupId>
  <artifactId>${project.parent.artifactId}-api</artifactId>
  <version>${project.parent.version}</version>
  <classifier>tests</classifier>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

This will expose api’s test classes to the test scope of api-2.0, and in particular the much wanted TestHelper. It is to be noted that api’s test-jar is already being built, see here.

More on all this here ā€˜How to create a jar containing test classes’.

1 Like

Thank you very much for your help . I will get rid of the additional TestHelper.:slight_smile:

Hi @mksd,

Inside the AttachmentServiceTest class @dileka used

Assert.assertArrayEquals(expectedAttachments.stream().map(Attachment::getUuid).collect(Collectors.toList()).toArray(),actualAttachments.stream().map(Attachment::getUuid).collect(Collectors.toList()).toArray()); method

Instead of that can i use Assert.assertEquals(expectedAttachments.size(), actualAttachments.size()); ( Because sometimes Array values can be in different orders.)

Comparing the sizes is nowhere near as good as verifying that the contents match.

A correct design would be to ensure that the API returns attachments in an order that is anticipated. Such as ā€˜most recent first’, and then arrange the expected array so that is respects that order ahead of the comparison.

Thank you for your suggestions. I updated the PR. It is only focus on

saveComplexObs(Encounter encounter, int count, int otherCount) method. And i add additional parameter ( allComplexRelatedToAttach , I just put this name .if it is not relevent please suggest a new name ) for method which can config the Complex obs creation for used non-attachment concepts and attachment concepts.

@mksd , For testing the fetch attachment based on the visit ,

  1. Do i need to create a separate method in TestHelper ? or
  2. Can I used the methods create for encounters saveComplexObs(Encounter encounter, int count, int otherCount) ? ( So like you mentioned earlier we can get all the encounters for particular visit and using above method we can fetch all the attachments )

I would not add yet another method to TestHelper, I would just have a test setup that is a bit longer/more complex and that takes care of populating - say - two or three encounters of a given visit with saveComplexObs(Encounter, int, int), with a slightly different configuration for each encounter.

1 Like

Hi , @mksd I updated the PR. Please review and give me your feedback. :slight_smile:

I just did.

I also would like you to write an exhaustive Javadoc for the API, so on the interface AttachmentsService (not AttachmentsServiceImpl). That’s where other developers will go to find the documentation as to what this API exactly does.

Also I just finally had a look at the implementation, so AttachmentsServiceImpl, and it’s great! Reusability :slight_smile: Very good.

Now here is what we’ve got, for a given patient:

  • a method that can return attachments of a given encounter ;
  • a method that can return attachments of a given visit ;
  • a method that can return attachments of all encounters.

There is a fourth category of attachments that are not associated with any encounters (and hence any visits either). We need a way to fetch those as well, let’s introduce:

List<Attachment> getIsolatedAttachments(Patient patient, boolean includeRetired);

(We might rename it, I’m not sure yet about the best terminology here.)

1 Like

Thank you for your feed backs. I will start to work with above mentioned tasks. :slight_smile:

Hi @mksd ,

I updated the PR with changes you mentioned. And can you give me a example about how to write a java doc for APIs in OpenMRS ( Is there any specific standard in OpenMRS.? )

Mmm, maybe have a look at this. Nothing specific to OpenMRS though, just enough information for an outsider to understand what an API is about:

  • A (short) description of what the method does.
  • A short description for each argument (using @param).
  • A short description of what is returned (using @return).

Note that most IDEs (at least Eclipse and most likely IntelliJ) will pre-generate everything for you as soon as you type ā€˜slash star star ENTER’, so /** + ENTER.

1 Like

@mksd I added the Javadoc for the API and update the PR. :slight_smile:

Just commented on your two last commits.

Thanks for the Javadoc, in the end we will keep it simpler than what you submitted. In general the OpenMRS code base is poorly Javadoc’d, so we won’t go over the top here. But believe me that sometimes you will pull your hair because the original developer didn’t take the necessary 3 min of his life to tell others what some API method is doing exactly.

For instance in the context of OpenMRS, when fetching data, a Patient parameter is quite obvious. So that’s a case where there is no need to detail why it’s there… etc.

Hi @mksd,

I was little bit stuck with getIsolatedAttachments(…) unit test implementation. I tried to create Attachments without configure any encounter and visit.

	// setup
	Patient patient = ps.getPatient(2);
	Concept concept = context.getConceptComplex(AttachmentsConstants.ContentFamily.OTHER);
	List<Attachment> expectedAttachments = new ArrayList<>();
	
	
	//
	for (int i = 0; i < 2; i++) {
		Obs obs = new Obs();
		obs.setConcept(concept);
		obs.setObsDatetime(new Date());
		obs.setPerson(patient);
		obs.setValueText("Some text value for a test obs.");
		obs = os.saveObs(obs, null);
		expectedAttachments.add(new Attachment(obs));
	}

But there was an error Configuration required: attachments.defaultConceptComplexUuid. I can’t find a way to solve this. Is there any other way to create obs without configuring encounter or visit ?

Hi @mksd

I solved the problem by using different approach and update the PR. Please review and give me your suggestions. :slight_smile:

Thanks @ridmal, I just reviewed.

Thank you for you suggestions and modifications. I add those modifications and update the PR. :slight_smile: