src/main/java/ch/bfh/ti/i4mi/mag/mhd/iti66/Iti66ResponseConverter.java
/**
	 * convert ITI-18 query response to ITI-66 response bundle
	 */
convert ITI-18 query response to ITI-66 response bundle
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);
                    System.out.println("PUT="+documentManifest.getId());
                    list.add(documentManifest);
                    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");
                    }
                    LocalizedString comments = submissionSet.getComments();
                    if (comments!=null) {
                    	documentManifest.addNote().setText(comments.getValue());                    	
                    }
                    if (submissionSet.getUniqueId()!=null) {
                        documentManifest.addIdentifier((new Identifier().setUse(IdentifierUse.USUAL).setSystem("urn:ietf:rfc:3986").setValue("urn:oid:"+submissionSet.getUniqueId())));
                    }
                    if (submissionSet.getEntryUuid()!=null) {
                        documentManifest.addIdentifier((new Identifier().setUse(IdentifierUse.OFFICIAL).setSystem("urn:ietf:rfc:3986").setValue(asUuid(submissionSet.getEntryUuid()))));
                    }
                    if (AvailabilityStatus.APPROVED.equals(submissionSet.getAvailabilityStatus())) {
                        documentManifest.setStatus(ListResource.ListStatus.CURRENT);
                    }
                    documentManifest.setMode(ListMode.WORKING);
                    if (submissionSet.getContentTypeCode()!=null) {
                        documentManifest
                          .addExtension()
                          .setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType")
                          .setValue(transform(submissionSet.getContentTypeCode()));
                    }
                    if (submissionSet.getPatientId()!=null) {
                    	Identifiable patient = submissionSet.getPatientId();                    	
                    	documentManifest.setSubject(transformPatient(patient));
                    }
                    if (submissionSet.getSubmissionTime()!=null) {
                        documentManifest.setDate(Date.from(submissionSet.getSubmissionTime().getDateTime().toInstant()));
                    }
                    if (submissionSet.getAuthors() != null) {
                    	for (Author author : submissionSet.getAuthors()) {
                    		documentManifest.setSource(transformAuthor(author));
                    	}
                    }
                    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) {                    		
                    	}                    	
                    }
                    if (submissionSet.getSourceId()!=null) {
                        documentManifest
                          .addExtension()
                          .setUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId")
                          .setValue(new Identifier().setValue("urn:oid:"+submissionSet.getSourceId()));
                    }
                    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;
    }
@ 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 ) ; System . out . println ( "PUT=" + documentManifest . getId ( ) ) ; list . add ( documentManifest ) ; 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" ) ; } LocalizedString comments = submissionSet . getComments ( ) ; if ( comments != null ) { documentManifest . addNote ( ) . setText ( comments . getValue ( ) ) ; } if ( submissionSet . getUniqueId ( ) != null ) { documentManifest . addIdentifier ( ( new Identifier ( ) . setUse ( IdentifierUse . USUAL ) . setSystem ( "urn:ietf:rfc:3986" ) . setValue ( "urn:oid:" + submissionSet . getUniqueId ( ) ) ) ) ; } if ( submissionSet . getEntryUuid ( ) != null ) { documentManifest . addIdentifier ( ( new Identifier ( ) . setUse ( IdentifierUse . OFFICIAL ) . setSystem ( "urn:ietf:rfc:3986" ) . setValue ( asUuid ( submissionSet . getEntryUuid ( ) ) ) ) ) ; } if ( AvailabilityStatus . APPROVED . equals ( submissionSet . getAvailabilityStatus ( ) ) ) { documentManifest . setStatus ( ListResource . ListStatus . CURRENT ) ; } documentManifest . setMode ( ListMode . WORKING ) ; if ( submissionSet . getContentTypeCode ( ) != null ) { documentManifest . addExtension ( ) . setUrl ( "http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType" ) . setValue ( transform ( submissionSet . getContentTypeCode ( ) ) ) ; } if ( submissionSet . getPatientId ( ) != null ) { Identifiable patient = submissionSet . getPatientId ( ) ; documentManifest . setSubject ( transformPatient ( patient ) ) ; } if ( submissionSet . getSubmissionTime ( ) != null ) { documentManifest . setDate ( Date . from ( submissionSet . getSubmissionTime ( ) . getDateTime ( ) . toInstant ( ) ) ) ; } if ( submissionSet . getAuthors ( ) != null ) { for ( Author author : submissionSet . getAuthors ( ) ) { documentManifest . setSource ( transformAuthor ( author ) ) ; } } 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 ) { } } if ( submissionSet . getSourceId ( ) != null ) { documentManifest . addExtension ( ) . setUrl ( "http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId" ) . setValue ( new Identifier ( ) . setValue ( "urn:oid:" + submissionSet . getSourceId ( ) ) ) ; } 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 ; }
convert ITI-18 query response to ITI-66 response bundle
convert ITI - 18 query response to ITI - 66 response bundle
// limitedMetadata -> meta.profile canonical [0..*]        // comment -> text Narrative [0..1] // uniqueId -> masterIdentifier Identifier [0..1] [1..1] // entryUUID -> identifier Identifier [0..*] // availabilityStatus -> status code {DocumentReferenceStatus} [1..1] //   approved -> status=current Other status values are allowed but are not defined in this mapping to XDS. // contentTypeCode -> type CodeableConcept [0..1] // patientId -> subject Reference(Patient| Practitioner| Group| Device) [0..1], Reference(Patient) // submissionTime -> created dateTime [0..1] // authorInstitution, authorPerson, authorRole, authorSpeciality, authorTelecommunication -> author Reference(Practitioner| PractitionerRole| Organization| Device| Patient| RelatedPerson) [0..*] // intendedRecipient -> recipient Reference(Patient| Practitioner| PractitionerRole| RelatedPerson| Organization) [0..*] // May be a patient, related person or practitioner // sourceId -> source uri [0..1] [1..1] // title -> description string [0..1]