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 ?
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.
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 ,
Do i need to create a separate method in TestHelper ? or
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.
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 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:
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.
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.
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 ?