ATT-47: Support for concept parameter when saving/fetching attachments.#53
ATT-47: Support for concept parameter when saving/fetching attachments.#53samuelmale wants to merge 5 commits intoopenmrs:masterfrom
Conversation
| MultipartFile multipartFile, String instructions) throws IOException { | ||
|
|
||
| conceptComplex = context.getConceptComplex(ContentFamily.IMAGE); | ||
| return saveImageAttachment(visit, person, encounter, null, fileCaption, multipartFile, instructions); |
There was a problem hiding this comment.
Why deprecate it? Just keep it and make sure it invokes the new signature as such:
conceptComplex = context.getConceptComplex(ContentFamily.IMAGE);
return saveImageAttachment(visit, person, encounter, conceptComplex, fileCaption, multipartFile, instructions);|
|
||
| String fileCaption = RandomStringUtils.randomAlphabetic(12); | ||
| return obsSaver.saveImageAttachment(visit, patient, encounter, fileCaption, lastSavedMultipartImageFile, | ||
| return obsSaver.saveImageAttachment(visit, patient, encounter, null, fileCaption, lastSavedMultipartImageFile, |
There was a problem hiding this comment.
Without the deprecation this change is not necessary.
| * @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.
This is my main issue, the changes to AttachmentsService are possibly much wider than thought here.
I believe this is where the existing API could be deprecated and a new one is to be introduced that caters for the new concept argument.
There was a problem hiding this comment.
I believe this is where the existing API could be deprecated and a new one is to be introduced that caters for the new concept argument.
@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?
| public Obs saveComplexObs(Patient patient, Concept concept) throws IOException { | ||
| Obs obs = new Obs(); | ||
| byte[] randomData = new byte[20]; | ||
| obs.setConcept(concept); | ||
| obs.setObsDatetime(new Date()); | ||
| obs.setPerson(patient); | ||
|
|
||
| new Random().nextBytes(randomData); | ||
|
|
||
| String filename = RandomStringUtils.randomAlphabetic(7) + ".ext"; | ||
| MockMultipartFile multipartRandomFile = new MockMultipartFile(FilenameUtils.getBaseName(filename), filename, | ||
| "application/octet-stream", randomData); | ||
| obs.setComplexData( | ||
| complexDataHelper.build(ValueComplex.INSTRUCTIONS_DEFAULT, multipartRandomFile.getOriginalFilename(), | ||
| multipartRandomFile.getBytes(), multipartRandomFile.getContentType()).asComplexData()); | ||
|
|
||
| return context.getObsService().saveObs(obs, null); | ||
| } |
There was a problem hiding this comment.
Why didn't you make this parameterizable with a concept argument?
| 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); | ||
| } |
There was a problem hiding this comment.
Isn't there any such concept in the standard test dataset, or one of Core's datasets?
There was a problem hiding this comment.
Not to my knowledge. The standard dataset has limited complex concepts.
mks-d
left a comment
There was a problem hiding this comment.
@samuelmale any chance you could look at this?
| Concept concept = testHelper.createComplexConcept("f4fab86d-4a1d-4245-8aa2-19f49b5ab07a", "Random files", | ||
| DefaultAttachmentHandler.class.getSimpleName(), "Random binary files"); |
There was a problem hiding this comment.
A detail but why is "files" plural?
ATT-47: Improved ComplexObsSaver and other APIs.
Ticket: https://issues.openmrs.org/browse/ATT-47