Search in sources :

Example 1 with NoCoverageException

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.NoCoverageException 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;
}
Also used : NoCoverageException(org.hl7.davinci.endpoint.cdshooks.services.crd.r4.NoCoverageException) Extension(org.hl7.fhir.r4.model.Extension) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Aggregations

NoCoverageException (org.hl7.davinci.endpoint.cdshooks.services.crd.r4.NoCoverageException)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Extension (org.hl7.fhir.r4.model.Extension)1