Search in sources :

Example 1 with ChPharmacyDocumentsQuery

use of org.husky.communication.ch.camel.chpharm1.requests.query.ChPharmacyDocumentsQuery in project MobileAccessGateway by i4mi.

the class Pharm5RequestConverter method operationFindMedicationListToFindMedicationListQuery.

/**
 * convert PHARM-5 request to CMPD Pharm-1
 *
 * @param searchParameter
 * @return
 */
public ChQueryRegistry operationFindMedicationListToFindMedicationListQuery(@Body Parameters searchParameter) {
    boolean getLeafClass = true;
    ChPharmacyDocumentsQuery query = null;
    boolean chPmlQuery = true;
    // we query PML except if we are explicitly adding the formatcode for
    List<Type> formatTypes = searchParameter.getParameters(Pharm5Constants.PHARM5_FORMAT);
    if (formatTypes != null && formatTypes.size() > 0) {
        for (Type format : formatTypes) {
            Coding formatCoding = (Coding) format;
            if ("urn:ch:cda-ch-emed:medication-card:2018".equals(formatCoding.getCode())) {
                chPmlQuery = false;
            }
        }
    }
    if (chPmlQuery) {
        query = new ChFindMedicationListQuery();
    } else {
        query = new ChFindMedicationCardQuery();
    }
    // status --> $XDSDocumentEntryStatus
    List<Type> statusTypes = searchParameter.getParameters(Pharm5Constants.PHARM5_STATUS);
    if (statusTypes != null) {
        List<AvailabilityStatus> availabilites = new ArrayList<AvailabilityStatus>();
        for (Type status : statusTypes) {
            String tokenValue = status.primitiveValue();
            if (tokenValue.equals("current"))
                availabilites.add(AvailabilityStatus.APPROVED);
            else if (tokenValue.equals("superseded"))
                availabilites.add(AvailabilityStatus.DEPRECATED);
        }
        query.setStatus(availabilites);
    }
    // patient or patient.identifier --> $XDSDocumentEntryPatientId
    Type patientIdentifier = searchParameter.getParameter(Pharm5Constants.PHARM5_PATIENT_IDENTIFIER);
    if (patientIdentifier != null) {
        Identifier patIdentifier = (Identifier) patientIdentifier;
        String system = patIdentifier.getSystem();
        if (system == null || !system.startsWith("urn:oid:"))
            throw new InvalidRequestException("Missing OID for patient");
        query.setPatientId(new Identifiable(patIdentifier.getValue(), new AssigningAuthority(system.substring(8))));
    }
    if (chPmlQuery) {
        Type serviceStartFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_FROM);
        if (serviceStartFrom != null) {
            ((ChFindMedicationListQuery) query).getServiceStart().setFrom(timestampFromDate(serviceStartFrom));
        }
        Type serviceStartTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_TO);
        if (serviceStartTo != null) {
            ((ChFindMedicationListQuery) query).getServiceStart().setTo(timestampFromDate(serviceStartTo));
        }
        Type serviceEndFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_FROM);
        if (serviceEndFrom != null) {
            ((ChFindMedicationListQuery) query).getServiceEnd().setFrom(timestampFromDate(serviceEndFrom));
        }
        Type serviceEndTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_TO);
        if (serviceEndTo != null) {
            ((ChFindMedicationListQuery) query).getServiceEnd().setTo(timestampFromDate(serviceEndTo));
        }
    } else {
        Type serviceStartFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_FROM);
        if (serviceStartFrom != null) {
            ((ChFindMedicationCardQuery) query).getServiceStart().setFrom(timestampFromDate(serviceStartFrom));
        }
        Type serviceStartTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_TO);
        if (serviceStartTo != null) {
            ((ChFindMedicationCardQuery) query).getServiceStart().setTo(timestampFromDate(serviceStartTo));
        }
        Type serviceEndFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_FROM);
        if (serviceEndFrom != null) {
            ((ChFindMedicationCardQuery) query).getServiceEnd().setFrom(timestampFromDate(serviceEndFrom));
        }
        Type serviceEndTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_TO);
        if (serviceEndTo != null) {
            ((ChFindMedicationCardQuery) query).getServiceEnd().setTo(timestampFromDate(serviceEndTo));
        }
    }
    formatTypes = searchParameter.getParameters(Pharm5Constants.PHARM5_FORMAT);
    if (formatTypes != null && formatTypes.size() > 0) {
        List<Code> formatCodes = new ArrayList<Code>();
        for (Type format : formatTypes) {
            Coding formatCoding = (Coding) format;
            Code formatCode = new Code();
            formatCode.setCode(formatCoding.getCode());
            String system = formatCoding.getSystem();
            if (system.startsWith("urn:oid:")) {
                system = system.substring(8);
            }
            formatCode.setSchemeName(system);
            formatCodes.add(formatCode);
        }
        query.setFormatCodes(formatCodes);
    }
    List<DocumentEntryType> documentEntryTypes = new ArrayList<DocumentEntryType>();
    documentEntryTypes.add(DocumentEntryType.ON_DEMAND);
    documentEntryTypes.add(DocumentEntryType.STABLE);
    if (chPmlQuery) {
        ((ChFindMedicationListQuery) query).setDocumentEntryTypes(documentEntryTypes);
    } else {
        ((ChFindMedicationCardQuery) query).setDocumentEntryTypes(documentEntryTypes);
    }
    final ChQueryRegistry queryRegistry = new ChQueryRegistry(query);
    queryRegistry.setReturnType((getLeafClass) ? QueryReturnType.LEAF_CLASS : QueryReturnType.OBJECT_REF);
    return queryRegistry;
}
Also used : ArrayList(java.util.ArrayList) ChQueryRegistry(org.husky.communication.ch.camel.chpharm1.requests.ChQueryRegistry) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) ChFindMedicationCardQuery(org.husky.communication.ch.camel.chpharm1.requests.query.ChFindMedicationCardQuery) Code(org.openehealth.ipf.commons.ihe.xds.core.metadata.Code) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) DocumentEntryType(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType) Type(org.hl7.fhir.r4.model.Type) DocumentEntryType(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType) QueryReturnType(org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryReturnType) ChPharmacyDocumentsQuery(org.husky.communication.ch.camel.chpharm1.requests.query.ChPharmacyDocumentsQuery) Identifier(org.hl7.fhir.r4.model.Identifier) AvailabilityStatus(org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus) Coding(org.hl7.fhir.r4.model.Coding) ChFindMedicationListQuery(org.husky.communication.ch.camel.chpharm1.requests.query.ChFindMedicationListQuery) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Aggregations

InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)1 ArrayList (java.util.ArrayList)1 Coding (org.hl7.fhir.r4.model.Coding)1 Identifier (org.hl7.fhir.r4.model.Identifier)1 Type (org.hl7.fhir.r4.model.Type)1 ChQueryRegistry (org.husky.communication.ch.camel.chpharm1.requests.ChQueryRegistry)1 ChFindMedicationCardQuery (org.husky.communication.ch.camel.chpharm1.requests.query.ChFindMedicationCardQuery)1 ChFindMedicationListQuery (org.husky.communication.ch.camel.chpharm1.requests.query.ChFindMedicationListQuery)1 ChPharmacyDocumentsQuery (org.husky.communication.ch.camel.chpharm1.requests.query.ChPharmacyDocumentsQuery)1 AssigningAuthority (org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority)1 AvailabilityStatus (org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus)1 Code (org.openehealth.ipf.commons.ihe.xds.core.metadata.Code)1 DocumentEntryType (org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType)1 Identifiable (org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable)1 QueryReturnType (org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryReturnType)1