Search in sources :

Example 6 with FINISHED

use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskPollingService method demoRunQRThroughStructureMap.

/*
  A TEST polling service, implemented during January 2022 Connectathon, that automatically runs questionnaireResponse
  resources through a StructureMap. If any exception occurs - just ignore it.
   */
public void demoRunQRThroughStructureMap() {
    log.info("Looking for TOP 3 Patient QuestionnaireResponse resources without derived Observations...");
    // TODO use repository instead
    Bundle tasksBundle = openEhrClient.search().forResource(QuestionnaireResponse.class).where(new StringClientParam(Constants.PARAM_PROFILE).matches().value(SDOHProfiles.QUESTIONNAIRE_RESPONSE)).revInclude(Observation.INCLUDE_DERIVED_FROM.setRecurse(false)).sort().descending(QuestionnaireResponse.AUTHORED).count(3).returnBundle(Bundle.class).execute();
    List<QuestionnaireResponse> responses = FhirUtil.getFromBundle(tasksBundle, QuestionnaireResponse.class, Bundle.SearchEntryMode.MATCH);
    Set<String> derivedFrom = FhirUtil.getFromBundle(tasksBundle, Observation.class, Bundle.SearchEntryMode.INCLUDE).stream().map(o -> o.getDerivedFromFirstRep().getReferenceElement().getIdPart()).collect(Collectors.toSet());
    if (responses.size() != derivedFrom.size()) {
        log.info("Found " + (responses.size() - derivedFrom.size()) + " QuestionnaireResponse resources without observations.");
        List<QuestionnaireResponse> newResponses = responses.stream().filter(qr -> !derivedFrom.contains(qr.getIdElement().getIdPart())).collect(Collectors.toList());
        for (QuestionnaireResponse nr : newResponses) {
            log.info("Converting QuestionnaireResponse with id: " + nr.getIdElement().getIdPart());
            try {
                // TODO move parser logic within the convert service. Use resources instead
                JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
                Map<String, Object> result = convertService.convert((JSONObject) parser.parse(fhirContext.newJsonParser().encodeResourceToString(nr)));
                Bundle bundle = (Bundle) fhirContext.newJsonParser().parseResource(new JSONObject(result).toJSONString());
                bundle.getEntry().forEach(e -> e.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.POST).setUrl(e.getResource().getClass().getSimpleName())));
                openEhrClient.transaction().withBundle(bundle).execute();
            } catch (Exception exc) {
                // Just ignore this specific resource and go to the next one
                log.warn(exc.getMessage(), exc);
            }
        }
    }
    log.info("QuestionnaireResponse update process finished.");
}
Also used : Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Endpoint(org.hl7.fhir.r4.model.Endpoint) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Set(java.util.Set) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Organization(org.hl7.fhir.r4.model.Organization) Slf4j(lombok.extern.slf4j.Slf4j) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) List(java.util.List) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) JSONObject(net.minidev.json.JSONObject) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) JSONObject(net.minidev.json.JSONObject) Observation(org.hl7.fhir.r4.model.Observation) JSONParser(net.minidev.json.parser.JSONParser) JSONObject(net.minidev.json.JSONObject)

Example 7 with FINISHED

use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskPollingService method processTasks.

@Scheduled(fixedDelayString = "${scheduling.task-polling-delay-millis}")
public void processTasks() {
    log.info("Checking for requested tasks from EHR...");
    Bundle searchBundle = openCpClient.search().forResource(Task.class).and(Task.STATUS.exactly().code(Task.TaskStatus.REQUESTED.toCode())).returnBundle(Bundle.class).execute();
    Bundle transactionBundle = new Bundle();
    transactionBundle.setType(Bundle.BundleType.TRANSACTION);
    FhirUtil.getFromBundle(searchBundle, Task.class).stream().map(taskProcessor::process).forEach(bundle -> transactionBundle.getEntry().addAll(bundle.getEntry()));
    if (transactionBundle.getEntry().size() > 0) {
        log.info("One or more task were received from EHR. Storing updates...");
        openCpClient.transaction().withBundle(transactionBundle).execute();
    }
    log.info("Task receiving process finished.");
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 8 with FINISHED

use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method execute.

private void execute(String base, String dest) throws IOException {
    CodeSystem cs = makeMMSCodeSystem();
    JsonObject version = fetchJson(Utilities.pathURL(base, "/icd/release/11/mms"));
    String[] p = version.get("latestRelease").getAsString().split("\\/");
    cs.setVersion(p[6]);
    JsonObject root = fetchJson(url(base, version.get("latestRelease").getAsString()));
    cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
    for (JsonElement child : root.getAsJsonArray("child")) {
        processMMSEntity(cs, base, child.getAsString(), cs.addConcept(), dest);
        System.out.println();
    }
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-mms.xml")), cs);
    makeFullVs(dest, cs);
    cs = makeEntityCodeSystem();
    root = fetchJson(Utilities.pathURL(base, "/icd/entity"));
    cs.setVersion(root.get("releaseId").getAsString());
    cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
    cs.setTitle(readString(root, "title"));
    Set<String> ids = new HashSet<>();
    for (JsonElement child : root.getAsJsonArray("child")) {
        processEntity(cs, ids, base, tail(child.getAsString()), dest);
        System.out.println();
    }
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-foundation.xml")), cs);
    makeFullVs2(dest, cs);
    System.out.println("finished");
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

Example 9 with FINISHED

use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project org.hl7.fhir.core by hapifhir.

the class DicomPackageBuilder method execute.

public void execute() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
    CodeSystem cs = buildCodeSystem();
    String fn = Utilities.path(dest, pattern.replace("{version}", version));
    Utilities.createDirectory(Utilities.getDirectoryForFile(fn));
    NPMPackageGenerator gen = new NPMPackageGenerator(fn, buildPackage());
    int i = 2;
    gen.addFile(Category.RESOURCE, "CodeSystem-" + cs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(cs));
    ValueSet vs = buildAllValueSet();
    gen.addFile(Category.RESOURCE, "ValueSet-" + vs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(vs));
    Set<String> ids = new HashSet<>();
    ids.add(vs.getId());
    for (File f : new File(Utilities.path(source, "Resources", "valuesets", "fhir", "json")).listFiles()) {
        vs = (ValueSet) JsonParser.loadFile(new FileInputStream(f));
        vs.setVersion(version);
        if (vs.getId().length() > 64) {
            vs.setId(vs.getId().substring(0, 64));
        }
        if (ids.contains(vs.getId())) {
            throw new Error("Duplicate Id (note Ids cut off at 64 char): " + vs.getId());
        }
        ids.add(vs.getId());
        gen.addFile(Category.RESOURCE, "ValueSet-" + vs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(vs));
        i++;
    }
    gen.finish();
    System.out.println("Finished - " + i + " resources");
}
Also used : NPMPackageGenerator(org.hl7.fhir.r4.utils.NPMPackageGenerator) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet) File(java.io.File) FileInputStream(java.io.FileInputStream) JsonParser(org.hl7.fhir.r4.formats.JsonParser) HashSet(java.util.HashSet)

Example 10 with FINISHED

use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project org.hl7.fhir.core by hapifhir.

the class BatchLoader method LoadDirectory.

private static void LoadDirectory(String server, String folder, int size) throws IOException, Exception {
    System.out.print("Connecting to " + server + ".. ");
    FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
    System.out.println("Done");
    IniFile ini = new IniFile(Utilities.path(folder, "batch-load-progress.ini"));
    for (File f : new File(folder).listFiles()) {
        if (f.getName().endsWith(".json") || f.getName().endsWith(".xml")) {
            if (!ini.getBooleanProperty("finished", f.getName())) {
                sendFile(client, f, size, ini);
            }
        }
    }
}
Also used : FHIRToolingClient(org.hl7.fhir.r4.utils.client.FHIRToolingClient) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile)

Aggregations

Test (org.junit.jupiter.api.Test)8 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Bundle (org.hl7.fhir.r4.model.Bundle)7 File (java.io.File)6 Date (java.util.Date)6 Order (org.junit.jupiter.api.Order)6 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)6 FileInputStream (java.io.FileInputStream)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 Reference (org.hl7.fhir.r4.model.Reference)4 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)3 HashSet (java.util.HashSet)3 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)3 Coding (org.hl7.fhir.r4.model.Coding)3 Task (org.hl7.fhir.r4.model.Task)3 ValueSet (org.hl7.fhir.r4.model.ValueSet)3 Provider (org.mitre.synthea.world.agents.Provider)3 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)3