Search in sources :

Example 31 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project MobileAccessGateway by i4mi.

the class Iti66RequestConverter method searchParameterIti66ToFindSubmissionSetsQuery.

/**
 * convert ITI-66 request to ITI-18 request
 * @param searchParameter
 * @return
 */
public QueryRegistry searchParameterIti66ToFindSubmissionSetsQuery(@Body Iti66SearchParameters searchParameter) {
    boolean getLeafClass = true;
    Query searchQuery = null;
    if (searchParameter.getIdentifier() != null || searchParameter.get_id() != null) {
        final GetSubmissionSetAndContentsQuery query = new GetSubmissionSetAndContentsQuery();
        if (searchParameter.getIdentifier() != null) {
            String val = searchParameter.getIdentifier().getValue();
            if (val.startsWith("urn:oid:")) {
                query.setUniqueId(val.substring("urn:oid:".length()));
            } else if (val.startsWith("urn:uuid:")) {
                query.setUuid(val.substring("urn:uuid:".length()));
            }
        } else {
            query.setUuid(searchParameter.get_id().getValue());
        }
        searchQuery = query;
    } else {
        final FindSubmissionSetsQuery query = new FindSubmissionSetsQuery();
        if (searchParameter.getCode() != null && !searchParameter.getCode().getValue().equals("submissionset")) {
            throw new InvalidRequestException("Only search for submissionsets supported.");
        }
        // patient or patient.identifier -> $XDSSubmissionSetPatientId
        TokenParam tokenIdentifier = searchParameter.getPatientIdentifier();
        if (tokenIdentifier != null) {
            String system = getScheme(tokenIdentifier.getSystem());
            if (system == null)
                throw new InvalidRequestException("Missing OID for patient");
            /*if (system.startsWith("urn:oid:")) {
	                 system = system.substring(8);
	             }*/
            query.setPatientId(new Identifiable(tokenIdentifier.getValue(), new AssigningAuthority(system)));
        }
        ReferenceParam patientRef = searchParameter.getPatientReference();
        if (patientRef != null) {
            Identifiable id = transformReference(patientRef.getValue());
            query.setPatientId(id);
        }
        // created Note 1 -> $XDSSubmissionSetSubmissionTimeFrom
        // created Note 2 -> $XDSSubmissionSetSubmissionTimeTo
        DateRangeParam createdRange = searchParameter.getDate();
        if (createdRange != null) {
            DateParam creationTimeFrom = createdRange.getLowerBound();
            DateParam creationTimeTo = createdRange.getUpperBound();
            query.getSubmissionTime().setFrom(timestampFromDateParam(creationTimeFrom));
            query.getSubmissionTime().setTo(timestampFromDateParam(creationTimeTo));
        }
        // TODO author.given / author.family -> $XDSSubmissionSetAuthorPerson
        StringParam authorGivenName = searchParameter.getSourceGiven();
        StringParam authorFamilyName = searchParameter.getSourceFamily();
        if (authorGivenName != null || authorFamilyName != null) {
            String author = (authorGivenName != null ? authorGivenName.getValue() : "%") + " " + (authorFamilyName != null ? authorFamilyName.getValue() : "%");
            query.setAuthorPerson(author);
        }
        // type -> $XDSSubmissionSetContentType
        TokenOrListParam types = searchParameter.getDesignationType();
        query.setContentTypeCodes(codesFromTokens(types));
        // source -> $XDSSubmissionSetSourceId
        TokenOrListParam sources = searchParameter.getSourceId();
        query.setSourceIds(urisFromTokens(sources));
        // status -> $XDSSubmissionSetStatus
        TokenOrListParam status = searchParameter.getStatus();
        if (status != null) {
            List<AvailabilityStatus> availabilites = new ArrayList<AvailabilityStatus>();
            for (TokenParam statusToken : status.getValuesAsQueryTokens()) {
                String tokenValue = statusToken.getValue();
                if (tokenValue.equals("current"))
                    availabilites.add(AvailabilityStatus.APPROVED);
                else if (tokenValue.equals("superseded"))
                    availabilites.add(AvailabilityStatus.DEPRECATED);
            }
            query.setStatus(availabilites);
        }
        searchQuery = query;
    }
    final QueryRegistry queryRegistry = new QueryRegistry(searchQuery);
    queryRegistry.setReturnType((getLeafClass) ? QueryReturnType.LEAF_CLASS : QueryReturnType.OBJECT_REF);
    return queryRegistry;
}
Also used : GetSubmissionSetAndContentsQuery(org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetSubmissionSetAndContentsQuery) Query(org.openehealth.ipf.commons.ihe.xds.core.requests.query.Query) FindSubmissionSetsQuery(org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindSubmissionSetsQuery) QueryRegistry(org.openehealth.ipf.commons.ihe.xds.core.requests.QueryRegistry) ArrayList(java.util.ArrayList) FindSubmissionSetsQuery(org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindSubmissionSetsQuery) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) AvailabilityStatus(org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus) TokenParam(ca.uhn.fhir.rest.param.TokenParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) StringParam(ca.uhn.fhir.rest.param.StringParam) GetSubmissionSetAndContentsQuery(org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetSubmissionSetAndContentsQuery) DateParam(ca.uhn.fhir.rest.param.DateParam)

Aggregations

DateParam (ca.uhn.fhir.rest.param.DateParam)31 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)24 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)21 Test (org.junit.Test)21 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)21 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)4 StringParam (ca.uhn.fhir.rest.param.StringParam)4 TokenParam (ca.uhn.fhir.rest.param.TokenParam)4 ArrayList (java.util.ArrayList)4 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)3 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)3 Test (org.junit.jupiter.api.Test)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)2 DateOrListParam (ca.uhn.fhir.rest.param.DateOrListParam)2 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)2 Date (java.util.Date)2 List (java.util.List)2