-
Notifications
You must be signed in to change notification settings - Fork 47
ATT-47: Support for concept parameter when saving/fetching attachments. #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
ec94531
347db29
968eec2
91d0158
488e206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import java.util.List; | ||
|
|
||
| import org.openmrs.Concept; | ||
| import org.openmrs.Encounter; | ||
| import org.openmrs.Patient; | ||
| import org.openmrs.Visit; | ||
|
|
@@ -60,5 +61,13 @@ public interface AttachmentsService { | |
| */ | ||
| List<Attachment> getAttachments(Patient patient, Visit visit, boolean includeVoided); | ||
|
|
||
| /** | ||
| * Get a patient's attachments that are associated with a specified concept. | ||
| * | ||
| * @param concept | ||
| * @throws APIException if non-complex obs are mistakenly returned | ||
| */ | ||
| List<Attachment> getAttachments(Patient patient, Concept concept); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my main issue, the changes to I believe this is where the existing API could be deprecated and a new one is to be introduced that caters for the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mks-d Looks like some good time is required for this one; do you think its okay to handle this in a different/followup ticket? |
||
|
|
||
| Attachment save(Attachment attachment, String reason); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| package org.openmrs.module.attachments.obs; | ||
|
|
||
| import java.awt.image.BufferedImage; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Random; | ||
|
|
||
| import javax.imageio.ImageIO; | ||
|
|
||
| import org.apache.commons.io.FilenameUtils; | ||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.commons.lang.RandomStringUtils; | ||
|
|
@@ -23,6 +28,7 @@ | |
| import org.openmrs.Patient; | ||
| import org.openmrs.Provider; | ||
| import org.openmrs.Visit; | ||
| import org.openmrs.api.ConceptService; | ||
| import org.openmrs.api.EncounterService; | ||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.module.attachments.AttachmentsActivator; | ||
|
|
@@ -257,6 +263,22 @@ public String getTestComplexObsFilePath() { | |
| * @return List of saved attachments/complex obs. | ||
| */ | ||
| public List<Obs> saveComplexObs(Encounter encounter, int count, int otherCount) throws IOException { | ||
| return saveComplexObs(encounter, null, null, count, otherCount); | ||
| } | ||
|
|
||
| /** | ||
| * Boilerplate method to save a collection of complex obs based on the encounter. | ||
| * | ||
| * @param encounter target encounter for save the complex obs. Leave null to save encounter-less | ||
| * complex obs. | ||
| * @param concept The concept that will be associated with attachment obs to be saved. | ||
| * @param otherConcept The concept that will be associated with other complex obs to be saved. | ||
| * @param count The number of the attachments/complex obs to be saved. | ||
| * @param otherCount The number of other complex obs to be saved. | ||
| * @return List of saved attachments/complex obs. | ||
| */ | ||
| public List<Obs> saveComplexObs(Encounter encounter, Concept concept, Concept otherConcept, int count, int otherCount) | ||
| throws IOException { | ||
| List<Obs> obsList = new ArrayList<>(); | ||
| byte[] randomData = new byte[20]; | ||
| Patient patient = (encounter == null) ? context.getPatientService().getPatient(2) : encounter.getPatient(); | ||
|
|
@@ -270,14 +292,14 @@ public List<Obs> saveComplexObs(Encounter encounter, int count, int otherCount) | |
| String filename = RandomStringUtils.randomAlphabetic(7) + ".ext"; | ||
| MockMultipartFile multipartRandomFile = new MockMultipartFile(FilenameUtils.getBaseName(filename), filename, | ||
| "application/octet-stream", randomData); | ||
| obsList.add(obsSaver.saveOtherAttachment(visit, patient, encounter, fileCaption, multipartRandomFile, | ||
| obsList.add(obsSaver.saveOtherAttachment(visit, patient, encounter, concept, fileCaption, multipartRandomFile, | ||
| ValueComplex.INSTRUCTIONS_DEFAULT)); | ||
| } | ||
|
|
||
| // Saves a complex obs as if they had been saved outside of Attachments | ||
| for (int i = 0; i < otherCount; i++) { | ||
| Obs obs = new Obs(); | ||
| obs.setConcept(otherConceptComplex); | ||
| obs.setConcept(otherConcept != null ? otherConcept : otherConceptComplex); | ||
| obs.setObsDatetime(new Date()); | ||
| obs.setPerson(patient); | ||
| obs.setEncounter(encounter); | ||
|
|
@@ -294,4 +316,34 @@ public List<Obs> saveComplexObs(Encounter encounter, int count, int otherCount) | |
| } | ||
| return obsList; | ||
| } | ||
|
|
||
| /** | ||
| * Factory method that constructs and persists a ComplexConcept object | ||
| * | ||
| * @return complexConcept | ||
| */ | ||
| public Concept createComplexConcept(String uuid, String name, String handler, String description) { | ||
| ConceptService conceptService = Context.getConceptService(); | ||
| ConceptComplex conceptComplex = new ConceptComplex(); | ||
| conceptComplex.setUuid(uuid); | ||
| conceptComplex.setHandler(handler); | ||
| ConceptName conceptName = new ConceptName(name, Locale.ENGLISH); | ||
| conceptComplex.setFullySpecifiedName(conceptName); | ||
| conceptComplex.setPreferredName(conceptName); | ||
| conceptComplex.setConceptClass(conceptService.getConceptClassByName("Question")); | ||
| conceptComplex.setDatatype(conceptService.getConceptDatatypeByUuid(ConceptDatatype.COMPLEX_UUID)); | ||
| conceptComplex.addDescription(new ConceptDescription(description, Locale.ENGLISH)); | ||
|
|
||
| return conceptService.saveConcept(conceptComplex); | ||
| } | ||
|
||
|
|
||
| public static byte[] loadImageResourceToByteArray(ClassLoader loader, String imageName, String contentType) | ||
| throws IOException { | ||
| InputStream inputStream = loader.getResourceAsStream(imageName); | ||
| BufferedImage img = ImageIO.read(inputStream); | ||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| ImageIO.write(img, contentType, baos); | ||
|
|
||
| return baos.toByteArray(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A detail but why is "files" plural?