Search in sources :

Example 71 with SearchParameter

use of org.hl7.fhir.r5.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method fetchResourceWithException.

@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, CanonicalResource source) throws FHIRException {
    if (uri == null) {
        return null;
    }
    if (class_ == StructureDefinition.class) {
        uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
    }
    synchronized (lock) {
        if (uri.contains("|")) {
            version = uri.substring(uri.lastIndexOf("|") + 1);
            uri = uri.substring(0, uri.lastIndexOf("|"));
        }
        if (uri.contains("#")) {
            uri = uri.substring(0, uri.indexOf("#"));
        }
        if (class_ == Resource.class || class_ == null) {
            if (structures.has(uri)) {
                return (T) structures.get(uri, version);
            }
            if (guides.has(uri)) {
                return (T) guides.get(uri, version);
            }
            if (capstmts.has(uri)) {
                return (T) capstmts.get(uri, version);
            }
            if (measures.has(uri)) {
                return (T) measures.get(uri, version);
            }
            if (libraries.has(uri)) {
                return (T) libraries.get(uri, version);
            }
            if (valueSets.has(uri)) {
                return (T) valueSets.get(uri, version);
            }
            if (codeSystems.has(uri)) {
                return (T) codeSystems.get(uri, version);
            }
            if (operations.has(uri)) {
                return (T) operations.get(uri, version);
            }
            if (searchParameters.has(uri)) {
                return (T) searchParameters.get(uri, version);
            }
            if (plans.has(uri)) {
                return (T) plans.get(uri, version);
            }
            if (maps.has(uri)) {
                return (T) maps.get(uri, version);
            }
            if (transforms.has(uri)) {
                return (T) transforms.get(uri, version);
            }
            if (questionnaires.has(uri)) {
                return (T) questionnaires.get(uri, version);
            }
            if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
                return null;
            }
            // it might be a special URL.
            if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
                // findTxValueSet(uri);
                Resource res = null;
                if (res != null) {
                    return (T) res;
                }
            }
            for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
                for (ResourceProxy r : rt.values()) {
                    if (uri.equals(r.getUrl())) {
                        if (version == null || version == r.getResource().getMeta().getVersionId()) {
                            return (T) r.getResource();
                        }
                    }
                }
            }
            return null;
        } else if (class_ == ImplementationGuide.class) {
            return (T) guides.get(uri, version);
        } else if (class_ == CapabilityStatement.class) {
            return (T) capstmts.get(uri, version);
        } else if (class_ == Measure.class) {
            return (T) measures.get(uri, version);
        } else if (class_ == Library.class) {
            return (T) libraries.get(uri, version);
        } else if (class_ == StructureDefinition.class) {
            return (T) structures.get(uri, version);
        } else if (class_ == StructureMap.class) {
            return (T) transforms.get(uri, version);
        } else if (class_ == ValueSet.class) {
            return (T) valueSets.get(uri, version);
        } else if (class_ == CodeSystem.class) {
            return (T) codeSystems.get(uri, version);
        } else if (class_ == ConceptMap.class) {
            return (T) maps.get(uri, version);
        } else if (class_ == PlanDefinition.class) {
            return (T) plans.get(uri, version);
        } else if (class_ == OperationDefinition.class) {
            OperationDefinition od = operations.get(uri, version);
            return (T) od;
        } else if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        } else if (class_ == SearchParameter.class) {
            SearchParameter res = searchParameters.get(uri, version);
            return (T) res;
        }
        if (class_ == CodeSystem.class && codeSystems.has(uri)) {
            return (T) codeSystems.get(uri, version);
        }
        if (class_ == ValueSet.class && valueSets.has(uri)) {
            return (T) valueSets.get(uri, version);
        }
        if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        }
        if (supportedCodeSystems.contains(uri)) {
            return null;
        }
        throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) CanonicalResourceProxy(org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Measure(org.hl7.fhir.r5.model.Measure) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) ValueSet(org.hl7.fhir.r5.model.ValueSet) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition)

Example 72 with SearchParameter

use of org.hl7.fhir.r5.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method loadFromPackageInt.

public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws IOException, FHIRException {
    int t = 0;
    if (progress) {
        System.out.println("Load Package " + pi.name() + "#" + pi.version());
    }
    if (loadedPackages.contains(pi.id() + "#" + pi.version())) {
        return 0;
    }
    loadedPackages.add(pi.id() + "#" + pi.version());
    if ((types == null || types.length == 0) && loader != null) {
        types = loader.getTypes();
    }
    if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad()) {
        // can't lazy load R2 because of valueset/codesystem implementation
        if (types.length == 0) {
            types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
        }
        for (String s : pi.listResources(types)) {
            try {
                loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
                t++;
            } catch (Exception e) {
                throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
            }
        }
    } else {
        if (types.length == 0) {
            types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" };
        }
        for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
            if (!pri.getFilename().contains("ig-r4")) {
                try {
                    registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
                    t++;
                } catch (FHIRException e) {
                    throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
                }
            }
        }
    }
    for (String s : pi.list("other")) {
        binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
    }
    if (version == null) {
        version = pi.version();
    }
    return t;
}
Also used : PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 73 with SearchParameter

use of org.hl7.fhir.r5.model.SearchParameter in project MobileAccessGateway by i4mi.

the class Pharm5RequestConverter method operationFindMedicationListToFindMedicationListQuery.

/**
 * convert PHARM-5 request to CMPD Pharm-1
 *
 * @param searchParameter
 * @return
 */
public QueryRegistry operationFindMedicationListToFindMedicationListQuery(@Body Parameters searchParameter) {
    boolean getLeafClass = true;
    FindMedicationListQuery query = new FindMedicationListQuery();
    // 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))));
    }
    // patient or patient.identifier --> $XDSDocumentEntryPatientId
    Type serviceStartFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_FROM);
    if (serviceStartFrom != null) {
        query.getServiceStart().setFrom(timestampFromDate(serviceStartFrom));
    }
    Type serviceStartTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_START_TO);
    if (serviceStartTo != null) {
        query.getServiceStart().setTo(timestampFromDate(serviceStartTo));
    }
    Type serviceEndFrom = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_FROM);
    if (serviceEndFrom != null) {
        query.getServiceEnd().setFrom(timestampFromDate(serviceEndFrom));
    }
    Type serviceEndTo = searchParameter.getParameter(Pharm5Constants.PHARM5_SERVICE_END_TO);
    if (serviceEndTo != null) {
        query.getServiceEnd().setTo(timestampFromDate(serviceEndTo));
    }
    List<Type> 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);
    query.setDocumentEntryTypes(documentEntryTypes);
    final QueryRegistry queryRegistry = new QueryRegistry(query);
    queryRegistry.setReturnType((getLeafClass) ? QueryReturnType.LEAF_CLASS : QueryReturnType.OBJECT_REF);
    return queryRegistry;
}
Also used : QueryRegistry(org.openehealth.ipf.commons.ihe.xds.core.requests.QueryRegistry) FindMedicationListQuery(org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindMedicationListQuery) ArrayList(java.util.ArrayList) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) 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) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) QueryReturnType(org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryReturnType) Identifier(org.hl7.fhir.r4.model.Identifier) AvailabilityStatus(org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus) Coding(org.hl7.fhir.r4.model.Coding) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Aggregations

SearchParameter (org.hl7.fhir.r5.model.SearchParameter)32 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ArrayList (java.util.ArrayList)12 File (java.io.File)9 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 SearchParameter (org.hl7.fhir.r4b.model.SearchParameter)9 CodeType (org.hl7.fhir.r5.model.CodeType)9 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)5 Example (org.hl7.fhir.definitions.model.Example)5 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)4