use of org.hl7.fhir.r4b.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));
}
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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());
}
Aggregations