use of org.hl7.fhir.r4.model.Device in project CRD by HL7-DaVinci.
the class PrefetchHydrator method hydrate.
/**
* Attempt to hydrate missing prefetch elements, note that this modifies the request object.
*/
public void hydrate() {
Object crdResponse = cdsRequest.getPrefetch();
for (PrefetchTemplateElement prefetchElement : cdsService.getPrefetchElements()) {
String prefetchKey = prefetchElement.getKey();
// check if the prefetch has already been populated with that key
Boolean alreadyIncluded = false;
try {
alreadyIncluded = (PropertyUtils.getProperty(crdResponse, prefetchKey) != null);
} catch (Exception e) {
throw new RuntimeException("System error: Mismatch in prefetch keys between the " + "CrdPrefetch and the key templates set in the service.", e);
}
if (!alreadyIncluded) {
// check if the bundle actually has element
String prefetchQuery = cdsService.prefetch.get(prefetchKey);
String hydratedPrefetchQuery = hydratePrefetchQuery(prefetchQuery);
// e.g. this could be a query template for a medication order but we have a device request
if (hydratedPrefetchQuery != null) {
if (cdsRequest.getFhirServer() == null) {
throw new FatalRequestIncompleteException("Attempting to fill the prefetch, but no fhir " + "server provided. Either provide a full prefetch or provide a fhir server.");
}
try {
PropertyUtils.setProperty(crdResponse, prefetchKey, prefetchElement.getReturnType().cast(FhirRequestProcessor.executeFhirQueryUrl(hydratedPrefetchQuery, cdsRequest, fhirComponents, HttpMethod.GET)));
} catch (Exception e) {
logger.warn("Failed to fill prefetch for key: " + prefetchKey, e);
}
}
}
}
}
use of org.hl7.fhir.r4.model.Device in project CRD by HL7-DaVinci.
the class CoverageRequirementsDiscoveryOperationHardCodedResponse method coverageRequirementsDiscovery.
/**
* Submits the CRD request.
* @param request the request to be submitted
* @param endpoint the endpoint to submit the request to
* @param requestQualification what kind of request it is
* @return the parameters returned from the server
*/
@Operation(name = "$coverage-requirements-discovery", idempotent = true)
public Parameters coverageRequirementsDiscovery(@OperationParam(name = "request") Parameters.ParametersParameterComponent request, @OperationParam(name = "endpoint") Endpoint endpoint, @OperationParam(name = "requestQualification") CodeableConcept requestQualification) {
logger.debug("coverageRequirementsDiscovery: start");
Parameters retVal = new Parameters();
CoverageEligibilityRequest eligibilityRequest = null;
Patient patient = null;
Coverage coverage = null;
Practitioner provider = null;
Organization insurer = null;
Location facility = null;
// supportingInformation
// serviceInformation
// grab the list of parameters
List<Parameters.ParametersParameterComponent> paramList = request.getPart();
// pull each of the parameters from the list
for (Parameters.ParametersParameterComponent part : paramList) {
System.out.println(part.getName());
switch(part.getName()) {
case "eligibilityrequest":
logger.debug("CRD: got eligibilityrequest");
eligibilityRequest = (CoverageEligibilityRequest) part.getResource();
break;
case "patient":
logger.debug("CRD: got patient");
patient = (Patient) part.getResource();
break;
case "coverage":
logger.debug("CRD: got coverage");
coverage = (Coverage) part.getResource();
break;
case "provider":
logger.debug("CRD: got provider");
provider = (Practitioner) part.getResource();
break;
case "insurer":
logger.debug("CRD: got insurer");
insurer = (Organization) part.getResource();
break;
case "facility":
logger.debug("CRD: got facility");
facility = (Location) part.getResource();
break;
case "patientContext":
ResourceType patientContextType = part.getResource().getResourceType();
switch(patientContextType) {
case Condition:
logger.debug("CRD: got request.patientContext of type Condition");
break;
case Device:
logger.debug("CRD: got request.patientContext of type Device");
break;
case Procedure:
logger.debug("CRD: got request.patientContext of type Procedure");
break;
case MedicationStatement:
logger.debug("CRD: got request.patientContext of type MedicationStatement");
break;
case HealthcareService:
logger.debug("CRD: got request.patientContext of type HealthcareService");
break;
default:
logger.warn("Warning: unexpected request.patientContext type");
break;
}
break;
case "serviceInformationReference":
ResourceType serviceInformationReferenceType = part.getResource().getResourceType();
switch(serviceInformationReferenceType) {
case Procedure:
logger.debug("CRD: got request.serviceInformationReferenceType of type Procedure");
break;
case HealthcareService:
logger.debug("CRD: got request.serviceInformationReferenceType " + "of type HealthcareService");
break;
case ServiceRequest:
logger.debug("CRD: got request.serviceInformationReferenceType " + "of type ServiceRequest");
break;
case MedicationRequest:
logger.debug("CRD: got request.serviceInformationReferenceType " + "of type MedicationRequest");
break;
case Medication:
logger.debug("CRD: got request.serviceInformationReferenceType of type Medication");
break;
case Device:
logger.debug("CRD: got request.serviceInformationReferenceType of type Device");
break;
case DeviceRequest:
logger.debug("CRD: got request.serviceInformationReferenceType " + "of type DeviceRequest");
break;
default:
logger.warn("Warning: unexpected request.serviceInformationReferenceType type");
break;
}
break;
default:
logger.warn("Warning: unexpected parameter part: " + part.getName());
break;
}
}
// Note: if nothing is set in the reference (even if it was created) it will be null
if (nullCheck(eligibilityRequest, "eligibilityrequest") || nullCheck(patient, "patient") || nullCheck(coverage, "coverage") || nullCheck(provider, "provider") || nullCheck(insurer, "insurer")) {
logger.error("ERROR: required information missing!");
return retVal;
}
// print out the patient name
assert patient != null;
if (patient.hasName()) {
logger.debug("CRD: Patient Name: " + patient.getName().get(0).getText());
} else {
logger.debug("CRD: No Patient Name provided");
}
// start building the response
CoverageEligibilityResponse eligibilityResponse = new CoverageEligibilityResponse();
eligibilityResponse.setDisposition("this is a test");
Endpoint finalEndPoint = new Endpoint();
finalEndPoint.setAddress("http://www.mitre.org");
Parameters.ParametersParameterComponent response = retVal.addParameter();
response.setName("response");
response.addPart().setName("eligibilityresponse").setResource(eligibilityResponse);
response.addPart().setName("requestProvider").setResource(provider);
response.addPart().setName("request").setResource(eligibilityRequest);
response.addPart().setName("insurer").setResource(insurer);
response.addPart().setName("coverage").setResource(coverage);
// add a few service resources to the parameters
Procedure procedure = new Procedure();
procedure.setId("procedure-1");
Device device = new Device();
device.setModelNumber("LMNOP678");
response.addPart().setName("service").setResource(procedure);
response.addPart().setName("service").setResource(device);
if (finalEndPoint != null) {
response.addPart().setName("endPoint").setResource(finalEndPoint);
}
logger.debug("coverageRequirementsDiscovery: end");
return retVal;
}
use of org.hl7.fhir.r4.model.Device in project MobileAccessGateway by i4mi.
the class Iti65RequestConverter method processDocumentReference.
/**
* ITI-65: process DocumentReference resource from Bundle
* @param reference
* @param entry
*/
public void processDocumentReference(DocumentReference reference, DocumentEntry entry) {
if (reference.getIdElement() != null) {
entry.setEntryUuid(reference.getIdElement().getIdPart());
} else {
entry.assignEntryUuid();
reference.setId(entry.getEntryUuid());
}
Identifier masterIdentifier = reference.getMasterIdentifier();
entry.setUniqueId(noPrefix(masterIdentifier.getValue()));
// limitedMetadata -> meta.profile canonical [0..*]
// No action
// availabilityStatus -> status code {DocumentReferenceStatus} [1..1]
// approved -> status=current
// deprecated -> status=superseded
// Other status values are allowed but are not defined in this mapping to XDS.
DocumentReferenceStatus status = reference.getStatus();
switch(status) {
case CURRENT:
entry.setAvailabilityStatus(AvailabilityStatus.APPROVED);
break;
case SUPERSEDED:
entry.setAvailabilityStatus(AvailabilityStatus.DEPRECATED);
break;
default:
throw new InvalidRequestException("Unknown document status");
}
// contentTypeCode -> type CodeableConcept [0..1]
CodeableConcept type = reference.getType();
entry.setTypeCode(transform(type));
// classCode -> category CodeableConcept [0..*]
List<CodeableConcept> category = reference.getCategory();
entry.setClassCode(transform(category));
// patientId -> subject Reference(Patient| Practitioner| Group| Device) [0..1],
Reference subject = reference.getSubject();
entry.setPatientId(transformReferenceToIdentifiable(subject, reference));
// creationTime -> date instant [0..1]
entry.setCreationTime(timestampFromDate(reference.getDateElement()));
// PractitionerRole| Organization| Device| Patient| RelatedPerson) [0..*]
for (Reference authorRef : reference.getAuthor()) {
entry.getAuthors().add(transformAuthor(authorRef, reference.getContained(), null));
}
if (reference.hasAuthenticator()) {
Reference authenticatorRef = reference.getAuthenticator();
Resource authenticator = findResource(authenticatorRef, reference.getContained());
if (authenticator instanceof Practitioner) {
entry.setLegalAuthenticator(transform((Practitioner) authenticator));
} else if (authenticator instanceof PractitionerRole) {
Practitioner practitioner = (Practitioner) findResource(((PractitionerRole) authenticator).getPractitioner(), reference.getContained());
if (practitioner != null)
entry.setLegalAuthenticator(transform(practitioner));
} else
throw new InvalidRequestException("No authenticator of type Organization supported.");
}
// title -> description string [0..1]
String title = reference.getDescription();
if (title != null)
entry.setTitle(localizedString(title));
// confidentialityCode -> securityLabel CodeableConcept [0..*] Note: This
// is NOT the DocumentReference.meta, as that holds the meta tags for the
// DocumentReference itself.
List<CodeableConcept> securityLabels = reference.getSecurityLabel();
transformCodeableConcepts(securityLabels, entry.getConfidentialityCodes());
// mimeType -> content.attachment.contentType [1..1] code [0..1]
DocumentReferenceContentComponent content = reference.getContentFirstRep();
if (content == null)
throw new InvalidRequestException("Missing content field in DocumentReference");
Attachment attachment = content.getAttachment();
if (attachment == null)
throw new InvalidRequestException("Missing attachment field in DocumentReference");
entry.setMimeType(attachment.getContentType());
// languageCode -> content.attachment.language code [0..1]
entry.setLanguageCode(attachment.getLanguage());
// size -> content.attachment.size integer [0..1] The size is calculated
if (attachment.hasSize())
entry.setSize((long) attachment.getSize());
// on the data prior to base64 encoding, if the data is base64 encoded.
// hash -> content.attachment.hash string [0..1]
byte[] hash = attachment.getHash();
if (hash != null)
entry.setHash(Hex.encodeHexString(hash));
// comments -> content.attachment.title string [0..1]
String comments = attachment.getTitle();
if (comments != null)
entry.setComments(localizedString(comments));
// creationTime -> content.attachment.creation dateTime [0..1]
if (attachment.hasCreation()) {
if (entry.getCreationTime() == null)
entry.setCreationTime(timestampFromDate(attachment.getCreationElement()));
else if (!timestampFromDate(attachment.getCreationElement()).equals(entry.getCreationTime()))
throw new InvalidRequestException("DocumentReference.date does not match attachment.creation element");
}
// formatCode -> content.format Coding [0..1]
Coding coding = content.getFormat();
entry.setFormatCode(transform(coding));
DocumentReferenceContextComponent context = reference.getContext();
// Instead: referenceIdList -> related.identifier
for (Reference ref : context.getRelated()) {
Identifiable refId = transformReferenceToIdentifiable(ref, reference);
if (refId != null) {
ReferenceId referenceId = new ReferenceId();
referenceId.setAssigningAuthority(new CXiAssigningAuthority(null, refId.getAssigningAuthority().getUniversalId(), refId.getAssigningAuthority().getUniversalIdType()));
referenceId.setId(refId.getId());
entry.getReferenceIdList().add(referenceId);
}
}
// Currently not mapped
/*for (Reference encounterRef : context.getEncounter()) {
ReferenceId referenceId = new ReferenceId();
Identifiable id = transformReferenceToIdentifiable(encounterRef, reference);
if (id != null) {
referenceId.setIdTypeCode(ReferenceId.ID_TYPE_ENCOUNTER_ID);
referenceId.setId(id.getId());
//referenceId.setAssigningAuthority(new CXiAid.getAssigningAuthority().getUniversalId());
entry.getReferenceIdList().add(referenceId );
}*/
// eventCodeList -> context.event CodeableConcept [0..*]
List<CodeableConcept> events = context.getEvent();
transformCodeableConcepts(events, entry.getEventCodeList());
// serviceStartTime serviceStopTime -> context.period Period [0..1]
Period period = context.getPeriod();
if (period != null) {
entry.setServiceStartTime(timestampFromDate(period.getStartElement()));
entry.setServiceStopTime(timestampFromDate(period.getEndElement()));
}
// healthcareFacilityTypeCode -> context.facilityType CodeableConcept
// [0..1]
entry.setHealthcareFacilityTypeCode(transformCodeableConcept(context.getFacilityType()));
// practiceSettingCode -> context.practiceSetting CodeableConcept [0..1]
entry.setPracticeSettingCode(transformCodeableConcept(context.getPracticeSetting()));
Extension originalRole = reference.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
if (originalRole != null) {
if (originalRole.getValue() instanceof Coding) {
Coding value = (Coding) originalRole.getValue();
String system = noPrefix(value.getSystem());
String code = value.getCode();
entry.setExtraMetadata(Collections.singletonMap("urn:e-health-suisse:2020:originalProviderRole", Collections.singletonList(code + "^^^&" + system + "&ISO")));
}
}
Extension deletionStatus = reference.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-deletionstatus");
if (deletionStatus != null) {
if (deletionStatus.getValue() instanceof Coding) {
Coding value = (Coding) deletionStatus.getValue();
String code = value.getCode();
entry.setExtraMetadata(Collections.singletonMap("urn:e-health-suisse:2019:deletionStatus", Collections.singletonList("urn:e-health-suisse:2019:deletionStatus:" + code)));
}
}
// Patient.identifier.use element set to ‘usual’.
if (context.hasSourcePatientInfo()) {
entry.setSourcePatientId(transformReferenceToIdentifiable(context.getSourcePatientInfo(), reference));
entry.setSourcePatientInfo(transformReferenceToPatientInfo(context.getSourcePatientInfo(), reference));
}
}
Aggregations