use of org.hl7.fhir.r4.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.");
}
use of org.hl7.fhir.r4.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.");
}
use of org.hl7.fhir.r4.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");
}
use of org.hl7.fhir.r4.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");
}
use of org.hl7.fhir.r4.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);
}
}
}
}
Aggregations