Skip to content

Commit

Permalink
completed service implementation, mirrored to AppointmentBookService.…
Browse files Browse the repository at this point in the history
… Added the endpoint to CdsHooksController
  • Loading branch information
salahlantana committed Sep 18, 2024
1 parent 634bbe8 commit 06008e9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,69 @@
package org.hl7.davinci.endpoint.cdshooks.services.crd.r4;

import org.cdshooks.Hook;
import org.hl7.davinci.PrefetchTemplateElement;
import org.hl7.davinci.RequestIncompleteException;
import org.hl7.davinci.endpoint.cdshooks.services.crd.CdsService;
import org.hl7.davinci.endpoint.components.CardBuilder;
import org.hl7.davinci.endpoint.components.QueryBatchRequest;
import org.hl7.davinci.endpoint.files.FileStore;
import org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult;
import org.hl7.davinci.r4.FhirComponents;
import org.hl7.davinci.r4.crdhook.ConfigurationOption;
import org.hl7.davinci.r4.crdhook.CrdPrefetch;
import org.hl7.davinci.r4.crdhook.DiscoveryExtension;
import org.hl7.davinci.r4.crdhook.appointmentbook.CrdExtensionConfigurationOptions;
import org.hl7.davinci.r4.crdhook.appointmentbook.CrdPrefetchTemplateElements;
import org.hl7.davinci.r4.crdhook.encounterstart.EncounterStartRequest;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.opencds.cqf.cql.engine.execution.Context;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component("r4_EncounterStartService")
public class EncounterStartService extends CdsService<EncounterStartRequest> {

public static final String ID = "encounter-start-crd";
public static final String TITLE = "encounter-start Coverage Requirements Discovery";
public static final Hook HOOK = Hook.APPOINTMENT_BOOK;
public static final String DESCRIPTION =
"Get information regarding the coverage requirements for encounters";
public static final List<PrefetchTemplateElement> PREFETCH_ELEMENTS = Arrays.asList(
CrdPrefetchTemplateElements.COVERAGE_REQUEST_BUNDLE,
CrdPrefetchTemplateElements.PATIENT,
CrdPrefetchTemplateElements.ENCOUNTER_BUNDLE);
public static final FhirComponents FHIRCOMPONENTS = new FhirComponents();
public static final List<ConfigurationOption> CONFIGURATION_OPTIONS = Arrays.asList(
CrdExtensionConfigurationOptions.COVERAGE,
CrdExtensionConfigurationOptions.MAX_CARDS
);
public static final DiscoveryExtension EXTENSION = new DiscoveryExtension(CONFIGURATION_OPTIONS);

public EncounterStartService() { super(ID, HOOK, TITLE, DESCRIPTION, PREFETCH_ELEMENTS, FHIRCOMPONENTS, EXTENSION);}

@Override
public List<CoverageRequirementRuleResult> createCqlExecutionContexts(EncounterStartRequest request, FileStore fileStore, String baseUrl) throws RequestIncompleteException {
return null;
// List<String> selections = Arrays.asList(request.getContext().getSelections());
List<String> selections = null;

FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl, selections);
CrdPrefetch prefetch = request.getPrefetch();
//It should be safe to cast these as Bundles as any OperationOutcome's found in the prefetch that could not get resolved would have thrown an exception
List<CoverageRequirementRuleResult> results = fhirBundleProcessor.getResults();

if (results.isEmpty()) {
throw RequestIncompleteException.NoSupportedBundlesFound();
}
return results;
}

@Override
protected CardBuilder.CqlResultsForCard executeCqlAndGetRelevantResults(Context context, String topic) {
return null;
CardBuilder.CqlResultsForCard cardResult = new CardBuilder.CqlResultsForCard();
cardResult.setRequest((IBaseResource)context);
return cardResult;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import org.cdshooks.CdsResponse;
import org.hl7.davinci.endpoint.Utils;
import org.hl7.davinci.endpoint.cdshooks.services.crd.CdsServiceInformation;
import org.hl7.davinci.endpoint.cdshooks.services.crd.r4.AppointmentBookService;
import org.hl7.davinci.endpoint.cdshooks.services.crd.r4.OrderSelectService;
import org.hl7.davinci.endpoint.cdshooks.services.crd.r4.OrderSignService;
import org.hl7.davinci.endpoint.cdshooks.services.crd.r4.OrderDispatchService;
import org.hl7.davinci.endpoint.cdshooks.services.crd.r4.*;
import org.hl7.davinci.r4.crdhook.CrdPrefetch;
import org.hl7.davinci.r4.crdhook.appointmentbook.AppointmentBookRequest;
import org.hl7.davinci.r4.crdhook.encounterstart.EncounterStartRequest;
import org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest;
import org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest;
import org.hl7.davinci.r4.crdhook.orderdispatch.OrderDispatchRequest;
Expand All @@ -36,7 +34,7 @@ public class CdsHooksController {
@Autowired private OrderSignService orderSignService;
@Autowired private AppointmentBookService appointmentBookService;
@Autowired private OrderDispatchService orderDispatchService;
@Autowired private Enc
@Autowired private EncounterStartService encounterStartService;

/**
* The FHIR r4 services discovery endpoint.
Expand Down Expand Up @@ -104,13 +102,20 @@ public CdsResponse handleAppointmentBook(@Valid @RequestBody AppointmentBookRequ
}

@CrossOrigin
@PostMapping(value = FHIR_RELEASE + URL_BASE + "/" + )
@PostMapping(value = FHIR_RELEASE + URL_BASE + "/" + EncounterStartService.ID,
consumes = "application/json;charset=UTF-8")
public CdsResponse handleEncounterStart(@Valid @RequestBody EncounterStartRequest request, final HttpServletRequest httpServletRequest) {
logger.info("r4/handleEncounterStart");
if (request.getPrefetch() == null) {
request.setPrefetch(new CrdPrefetch());
}
return encounterStartService.handleRequest(request, Utils.getApplicationBaseUrl(httpServletRequest));
}



/**
* The coverage requirement discovery endpoint for the appointment-book hook.
* @param request An appointment-book triggered cds request
* @return The card response
*/
@CrossOrigin
Expand Down

0 comments on commit 06008e9

Please sign in to comment.