use of org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet in project ipf by oehf.
the class RegisterDocumentSetBuilderTest method basicBuilder.
@Test
public void basicBuilder() throws GSSException {
Identifiable patientID = new Identifiable("id3", new Oid("1.3"));
SubmissionSet submissionSet = SampleData.createSubmissionSet(patientID);
submissionSet.setEntryUuid(null);
submissionSet.setUniqueId(null);
DocumentEntry document = SampleData.createDocumentEntry(patientID);
document.setEntryUuid(null);
document.setUniqueId(null);
RegisterDocumentSet registerDocuments = RegisterDocumentSet.builderWith(submissionSet).withDocument(document).build();
assertEquals(0, registerDocuments.getAssociations().size());
assertNull(submissionSet.getEntryUuid());
assertEquals(1, registerDocuments.getDocumentEntries().size());
}
use of org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet in project MobileAccessGateway by i4mi.
the class Iti66ResponseConverter method translateToFhir.
/**
* convert ITI-18 query response to ITI-66 response bundle
*/
@Override
public List<ListResource> translateToFhir(QueryResponse input, Map<String, Object> parameters) {
ArrayList<ListResource> list = new ArrayList<ListResource>();
if (input != null && Status.SUCCESS.equals(input.getStatus())) {
Map<String, ListResource> targetList = new HashMap<String, ListResource>();
if (input.getSubmissionSets() != null) {
for (SubmissionSet submissionSet : input.getSubmissionSets()) {
ListResource documentManifest = new ListResource();
documentManifest.setId(noUuidPrefix(submissionSet.getEntryUuid()));
documentManifest.setCode(new CodeableConcept(new Coding("http://profiles.ihe.net/ITI/MHD/CodeSystem/MHDlistTypes", "submissionset", "Submission Set")));
targetList.put(documentManifest.getId(), documentManifest);
list.add(documentManifest);
// limitedMetadata -> meta.profile canonical [0..*]
if (submissionSet.isLimitedMetadata()) {
documentManifest.getMeta().addProfile("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Minimal.SubmissionSet");
} else {
documentManifest.getMeta().addProfile("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.SubmissionSet");
}
// comment -> text Narrative [0..1]
LocalizedString comments = submissionSet.getComments();
if (comments != null) {
documentManifest.addNote().setText(comments.getValue());
}
// uniqueId -> masterIdentifier Identifier [0..1] [1..1]
if (submissionSet.getUniqueId() != null) {
documentManifest.addIdentifier((new Identifier().setUse(IdentifierUse.USUAL).setSystem("urn:ietf:rfc:3986").setValue("urn:oid:" + submissionSet.getUniqueId())));
}
// entryUUID -> identifier Identifier [0..*]
if (submissionSet.getEntryUuid() != null) {
documentManifest.addIdentifier((new Identifier().setUse(IdentifierUse.OFFICIAL).setSystem("urn:ietf:rfc:3986").setValue(asUuid(submissionSet.getEntryUuid()))));
}
// approved -> status=current Other status values are allowed but are not defined in this mapping to XDS.
if (AvailabilityStatus.APPROVED.equals(submissionSet.getAvailabilityStatus())) {
documentManifest.setStatus(ListResource.ListStatus.CURRENT);
}
documentManifest.setMode(ListMode.WORKING);
// contentTypeCode -> type CodeableConcept [0..1]
if (submissionSet.getContentTypeCode() != null) {
documentManifest.addExtension().setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType").setValue(transform(submissionSet.getContentTypeCode()));
}
// patientId -> subject Reference(Patient| Practitioner| Group| Device) [0..1], Reference(Patient)
if (submissionSet.getPatientId() != null) {
Identifiable patient = submissionSet.getPatientId();
documentManifest.setSubject(transformPatient(patient));
}
// submissionTime -> created dateTime [0..1]
if (submissionSet.getSubmissionTime() != null) {
documentManifest.setDate(Date.from(submissionSet.getSubmissionTime().getDateTime().toInstant()));
}
// authorInstitution, authorPerson, authorRole, authorSpeciality, authorTelecommunication -> author Reference(Practitioner| PractitionerRole| Organization| Device| Patient| RelatedPerson) [0..*]
if (submissionSet.getAuthors() != null) {
for (Author author : submissionSet.getAuthors()) {
documentManifest.setSource(transformAuthor(author));
}
}
// intendedRecipient -> recipient Reference(Patient| Practitioner| PractitionerRole| RelatedPerson| Organization) [0..*]
List<Recipient> recipients = submissionSet.getIntendedRecipients();
for (Recipient recipient : recipients) {
Organization org = recipient.getOrganization();
Person person = recipient.getPerson();
ContactPoint contact = transform(recipient.getTelecom());
var organization = transform(org);
Practitioner practitioner = transformPractitioner(person);
if (organization != null && practitioner == null) {
if (contact != null)
organization.addTelecom(contact);
documentManifest.addExtension().setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-intendedRecipient").setValue(new Reference().setResource(organization));
} else if (organization != null && practitioner != null) {
PractitionerRole role = new PractitionerRole();
role.setPractitioner((Reference) new Reference().setResource(practitioner));
role.setOrganization((Reference) new Reference().setResource(organization));
if (contact != null)
role.addTelecom(contact);
documentManifest.addExtension().setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-intendedRecipient").setValue(new Reference().setResource(role));
} else if (organization == null && practitioner != null) {
// May be a patient, related person or practitioner
}
}
// sourceId -> source uri [0..1] [1..1]
if (submissionSet.getSourceId() != null) {
documentManifest.addExtension().setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId").setValue(new Identifier().setValue("urn:oid:" + submissionSet.getSourceId()));
}
// title -> description string [0..1]
LocalizedString title = submissionSet.getTitle();
if (title != null) {
documentManifest.setTitle(title.getValue());
}
}
}
if (input.getAssociations() != null) {
for (Association ass : input.getAssociations()) {
AssociationType tt = ass.getAssociationType();
String source = ass.getSourceUuid();
String target = ass.getTargetUuid();
if (tt == AssociationType.HAS_MEMBER) {
ListResource s = targetList.get(noUuidPrefix(source));
if (s != null) {
s.addEntry().setItem(new Reference().setReference("DocumentReference/" + noUuidPrefix(target)));
}
}
}
}
} else {
processError(input);
}
return list;
}
use of org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet in project ipf by oehf.
the class RegisterDocumentSetBuilderTest method supportiveBuilder.
@Test
public void supportiveBuilder() throws GSSException {
Identifiable patientID = new Identifiable("id3", new Oid("1.3"));
SubmissionSet submissionSet = SampleData.createSubmissionSet(patientID);
submissionSet.setEntryUuid(null);
submissionSet.setUniqueId(null);
submissionSet.setSubmissionTime((String) null);
DocumentEntry document = SampleData.createDocumentEntry(patientID);
document.setEntryUuid(null);
document.setUniqueId(null);
Folder folder1 = SampleData.createFolder(patientID);
folder1.setEntryUuid(null);
folder1.setUniqueId(null);
Folder folder2 = SampleData.createFolder(patientID);
folder2.setEntryUuid("lol");
folder2.setUniqueId("2.999.2.3.4");
RegisterDocumentSet registerDocuments = RegisterDocumentSet.supportiveBuilderWith(submissionSet).withDocument(document).withFolders(List.of(folder1, folder2)).build();
assertEquals(3, registerDocuments.getAssociations().size(), "Expecting 3 Association to be created");
assertEquals(2, registerDocuments.getFolders().size());
assertEquals(1, registerDocuments.getDocumentEntries().size());
assertNotNull(submissionSet.getEntryUuid());
assertNotNull(submissionSet.getSubmissionTime());
assertNotNull(folder1.getEntryUuid());
assertNotNull(document.getEntryUuid());
assertNotNull(submissionSet.getUniqueId());
assertNotNull(folder1.getUniqueId());
assertNotNull(document.getUniqueId());
assertEquals("lol", folder2.getEntryUuid());
assertEquals("2.999.2.3.4", folder2.getUniqueId());
}
use of org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet in project MobileAccessGateway by i4mi.
the class Iti65RequestConverter method convert.
/**
* convert ITI-65 to ITI-41 request
* @param requestBundle
* @return
*/
public ProvideAndRegisterDocumentSet convert(@Body Bundle requestBundle) {
SubmissionSet submissionSet = new SubmissionSet();
ProvideAndRegisterDocumentSetBuilder builder = new ProvideAndRegisterDocumentSetBuilder(true, submissionSet);
// create mapping fullUrl -> resource for each resource in bundle
Map<String, Resource> resources = new HashMap<String, Resource>();
ListResource manifestNeu = null;
for (Bundle.BundleEntryComponent requestEntry : requestBundle.getEntry()) {
Resource resource = requestEntry.getResource();
/*if (resource instanceof DocumentManifest) {
manifest = (DocumentManifest) resource;
} else*/
if (resource instanceof DocumentReference) {
resources.put(requestEntry.getFullUrl(), resource);
} else if (resource instanceof ListResource) {
manifestNeu = (ListResource) resource;
// resources.put(requestEntry.getFullUrl(), resource);
} else if (resource instanceof Binary) {
resources.put(requestEntry.getFullUrl(), resource);
} else {
throw new IllegalArgumentException(resource + " is not allowed here");
}
}
/*if (manifest != null) {
processDocumentManifest(manifest, submissionSet);
} else {*/
processDocumentManifest(manifestNeu, submissionSet);
// set limited metadata
for (CanonicalType profile : requestBundle.getMeta().getProfile()) {
if ("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Provide_Comprehensive_DocumentBundle".equals(profile.getValue())) {
submissionSet.setLimitedMetadata(false);
} else if ("http://ihe.net/fhir/StructureDefinition/IHE_MHD_Provide_Minimal_DocumentBundle".equals(profile.getValue())) {
submissionSet.setLimitedMetadata(true);
} else if ("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.ProvideBundle".equals(profile.getValue())) {
submissionSet.setLimitedMetadata(false);
} else if ("http://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Minimal.ProvideBundle".equals(profile.getValue())) {
submissionSet.setLimitedMetadata(true);
}
}
// process all resources referenced in DocumentManifest.content
for (ListEntryComponent listEntry : manifestNeu.getEntry()) {
Reference content = listEntry.getItem();
String refTarget = content.getReference();
Resource resource = resources.get(refTarget);
if (resource instanceof DocumentReference) {
DocumentReference documentReference = (DocumentReference) resource;
Document doc = new Document();
DocumentEntry entry = new DocumentEntry();
processDocumentReference(documentReference, entry);
doc.setDocumentEntry(entry);
entry.setRepositoryUniqueId(config.getRepositoryUniqueId());
// create associations
for (DocumentReferenceRelatesToComponent relatesTo : documentReference.getRelatesTo()) {
Reference target = relatesTo.getTarget();
DocumentRelationshipType code = relatesTo.getCode();
Association association = new Association();
switch(code) {
case REPLACES:
association.setAssociationType(AssociationType.REPLACE);
break;
case TRANSFORMS:
association.setAssociationType(AssociationType.TRANSFORM);
break;
case SIGNS:
association.setAssociationType(AssociationType.SIGNS);
break;
case APPENDS:
association.setAssociationType(AssociationType.APPEND);
break;
default:
}
association.setSourceUuid(entry.getEntryUuid());
association.setTargetUuid(transformUriFromReference(target));
builder.withAssociation(association);
}
// get binary content from attachment.data or from referenced Binary resource
Attachment attachment = documentReference.getContentFirstRep().getAttachment();
if (attachment.hasData()) {
doc.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment.getData(), attachment.getContentType())));
byte[] decoded = attachment.getData();
entry.setSize((long) decoded.length);
entry.setHash(SHAsum(decoded));
} else if (attachment.hasUrl()) {
String contentURL = attachment.getUrl();
Resource binaryContent = resources.get(contentURL);
if (binaryContent instanceof Binary) {
String contentType = attachment.getContentType();
Binary binary = (Binary) binaryContent;
if (binary.hasContentType() && !binary.getContentType().equals(contentType))
throw new InvalidRequestException("ContentType in Binary and in DocumentReference must match");
doc.setDataHandler(new DataHandler(new ByteArrayDataSource(binary.getData(), contentType)));
byte[] decoded = binary.getData();
entry.setSize((long) decoded.length);
entry.setHash(SHAsum(decoded));
Identifier masterIdentifier = documentReference.getMasterIdentifier();
binary.setUserData("masterIdentifier", noPrefix(masterIdentifier.getValue()));
}
}
builder.withDocument(doc);
}
}
return builder.build();
}
Aggregations