use of org.hl7.davinci.FhirComponentsT in project CRD by HL7-DaVinci.
the class CardBuilder method createSuggestionWithNote.
public static Suggestion createSuggestionWithNote(Card card, IBaseResource request, FhirComponentsT fhirComponents, String label, String description, boolean isRecommended, CoverageGuidance coverageGuidance) {
Date now = new Date();
Suggestion requestWithNoteSuggestion = new Suggestion();
requestWithNoteSuggestion.setLabel(label);
requestWithNoteSuggestion.setIsRecommended(isRecommended);
List<Action> actionList = new ArrayList<>();
// build the Annotation
Annotation annotation = new Annotation();
StringType author = new StringType();
author.setValue(card.getSource().getLabel());
annotation.setAuthor(author);
String text = card.getSummary() + ": " + card.getDetail();
annotation.setText(text);
// set the date and time to now
annotation.setTime(now);
IBaseResource resource = FhirRequestProcessor.addNoteToRequest(request, annotation);
try {
// build the Extension with the coverage information
Extension extension = new Extension();
extension.setUrl("http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information");
Extension coverageInfo = new Extension();
coverageInfo.setUrl("coverageInfo").setValue(coverageGuidance.getCoding());
extension.addExtension(coverageInfo);
Extension coverageExtension = new Extension();
Reference coverageReference = new Reference();
// TODO: get the coverage from the prefetch and pass it into here instead of retrieving it from the request
coverageReference.setReference(FhirRequestProcessor.getCoverageFromRequest(request).getReference());
coverageExtension.setUrl("coverage").setValue(coverageReference);
extension.addExtension(coverageExtension);
Extension date = new Extension();
date.setUrl("date").setValue(new DateType().setValue(now));
extension.addExtension(date);
Extension identifier = new Extension();
String id = UUID.randomUUID().toString();
identifier.setUrl("identifier").setValue(new StringType(id));
extension.addExtension(identifier);
resource = FhirRequestProcessor.addExtensionToRequest(resource, extension);
} catch (NoCoverageException e) {
logger.warn("No Coverage, discrete coverage extension will not be included: " + e.getMessage());
}
Action updateAction = new Action(fhirComponents);
updateAction.setType(Action.TypeEnum.update);
updateAction.setDescription(description);
updateAction.setResource(resource);
actionList.add(updateAction);
requestWithNoteSuggestion.setActions(actionList);
return requestWithNoteSuggestion;
}
use of org.hl7.davinci.FhirComponentsT in project CRD by HL7-DaVinci.
the class FhirRequestProcessor method executeFhirQuery.
/**
* Execute a Fhir query with the given query body and query url.
* @param queryBody
* @param queryUrl
* @param cdsRequest
* @param fhirComponents
* @param httpMethod
* @return
*/
public static IBaseResource executeFhirQuery(String queryBody, String queryUrl, CdsRequest<?, ?> cdsRequest, FhirComponentsT fhirComponents, HttpMethod httpMethod) {
if (cdsRequest.getFhirServer() == null) {
throw new FatalRequestIncompleteException("Attempted to perform a Query Batch Request, but no fhir " + "server provided.");
}
// Remove the trailing '/' if there is one.
String fhirBase = cdsRequest.getFhirServer();
if (fhirBase != null && fhirBase.endsWith("/")) {
fhirBase = fhirBase.substring(0, fhirBase.length() - 1);
}
String fullUrl = fhirBase + "/" + queryUrl;
// TODO: Once our provider fhir server is up, switch the fetch to use the hapi client instead
// cdsRequest.getOauth();
// FhirContext ctx = FhirContext.forR4();
// BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(oauth.get("access_token"));
// IGenericClient client = ctx.newRestfulGenericClient(server);
// client.registerInterceptor(authInterceptor);
// return client;
// IGenericClient client = ctx.newRestfulGenericClient(serverBase);
// return client.search().byUrl(query).encodedJson().returnBundle(Bundle.class).execute();
String token = null;
if (cdsRequest.getFhirAuthorization() != null) {
token = cdsRequest.getFhirAuthorization().getAccessToken();
}
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
if (!queryBody.isEmpty()) {
headers.setContentType(MediaType.APPLICATION_JSON);
}
if (token != null) {
headers.set("Authorization", "Bearer " + token);
}
HttpEntity<String> entity = new HttpEntity<>(queryBody, headers);
try {
logger.info("Fetching: " + fullUrl);
// Request source: https://www.hl7.org/fhir/http.html#transaction
ResponseEntity<String> response = restTemplate.exchange(fullUrl, httpMethod, entity, String.class);
logger.info("Fetched: " + response.getBody());
return fhirComponents.getJsonParser().parseResource(response.getBody());
} catch (RestClientException e) {
logger.warn("Unable to make the fetch request", e);
return null;
}
}
use of org.hl7.davinci.FhirComponentsT in project CRD by HL7-DaVinci.
the class CardBuilder method priorAuthCard.
public static Card priorAuthCard(CqlResultsForCard cqlResults, IBaseResource request, FhirComponentsT fhirComponents, String priorAuthId, String patientId, String payerId, String providerId, String applicationFhirPath, FhirResourceRepository fhirResourceRepository) {
logger.info("Build Prior Auth Card");
Card card = transform(CardTypes.PRIOR_AUTH, cqlResults, false);
// create the ClaimResponse
ClaimResponse claimResponse = Utilities.createClaimResponse(priorAuthId, patientId, payerId, providerId, applicationFhirPath);
// build the FhirResource and save to the database
FhirResource fhirResource = new FhirResource();
fhirResource.setFhirVersion(fhirComponents.getFhirVersion().toString()).setResourceType(claimResponse.fhirType()).setData(fhirComponents.getJsonParser().encodeResourceToString(claimResponse));
fhirResource.setId(claimResponse.getId());
fhirResource.setName(claimResponse.getId());
FhirResource newFhirResource = fhirResourceRepository.save(fhirResource);
logger.info("stored: " + newFhirResource.getFhirVersion() + "/" + newFhirResource.getResourceType() + "/" + newFhirResource.getId());
// create the reference to the ClaimResponse
Reference claimResponseReference = new Reference();
claimResponseReference.setReference("ClaimResponse/" + claimResponse.getId());
// add SupportingInfo to the Request
IBaseResource outputRequest = FhirRequestProcessor.addSupportingInfoToRequest(request, claimResponseReference);
// add suggestion with ClaimResponse
Suggestion suggestionWithClaimResponse = createSuggestionWithResource(outputRequest, claimResponse, fhirComponents, "Store the prior authorization in the EHR", true);
card.addSuggestionsItem(suggestionWithClaimResponse);
// add suggestion with annotation
Suggestion suggestionWithAnnotation = createSuggestionWithNote(card, outputRequest, fhirComponents, "Store prior authorization as an annotation to the order", "Add authorization to record", false, CoverageGuidance.PRIOR_AUTH);
card.addSuggestionsItem(suggestionWithAnnotation);
card.setSelectionBehavior(Card.SelectionBehaviorEnum.AT_MOST_ONE);
return card;
}
Aggregations