Search in sources :

Example 71 with SearchParameter

use of org.hl7.fhir.r4.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.r4.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.r4.model.SearchParameter 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)

Example 74 with SearchParameter

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

the class Iti67RequestUpdateConverter method convertDocumentReferenceToDocumentEntry.

/**
 * ITI-67 Response to ITI-57 request converter
 *
 * @param searchParameter
 * @return
 */
public SubmitObjectsRequest convertDocumentReferenceToDocumentEntry(@Body DocumentReference documentReference) {
    SubmissionSet submissionSet = new SubmissionSet();
    submissionSet.setSubmissionTime(new Timestamp(ZonedDateTime.now(), Timestamp.Precision.SECOND));
    Extension source = documentReference.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId");
    if (source != null && source.getValue() instanceof Identifier) {
        submissionSet.setSourceId(noPrefix(((Identifier) source.getValue()).getValue()));
    }
    Extension designationType = documentReference.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType");
    if (designationType != null && designationType.getValue() instanceof CodeableConcept) {
        submissionSet.setContentTypeCode(transformCodeableConcept((CodeableConcept) designationType.getValue()));
    }
    Extension authorRoleExt = documentReference.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
    if (authorRoleExt != null) {
        Identifiable identifiable = null;
        if (authorRoleExt != null) {
            Coding coding = authorRoleExt.castToCoding(authorRoleExt.getValue());
            if (coding != null) {
                identifiable = new Identifiable(coding.getCode(), new AssigningAuthority(noPrefix(coding.getSystem())));
            }
        }
        submissionSet.setAuthor(transformAuthor(null, null, identifiable));
    }
    // TODO should be
    RegisterDocumentSetBuilder builder = new RegisterDocumentSetBuilder(true, submissionSet);
    // true?
    DocumentEntry entry = new DocumentEntry();
    processDocumentReference(documentReference, entry);
    entry.setLogicalUuid(new URN(UUID.randomUUID()).toString());
    submissionSet.setPatientId(entry.getPatientId());
    submissionSet.assignEntryUuid();
    builder.withDocument(entry);
    builder.withAssociation(createHasMemberAssocationWithOriginalPreviousLabel(submissionSet, entry));
    return EbXML30Converters.convert(builder.build());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) URN(org.openehealth.ipf.commons.core.URN) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) RegisterDocumentSetBuilder(org.openehealth.ipf.commons.ihe.xds.core.requests.builder.RegisterDocumentSetBuilder) SubmissionSet(org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet) DocumentEntry(org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntry) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) Timestamp(org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable)

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 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)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