use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED in project ab2d by CMSgov.
the class CoverageMappingCallable method call.
/**
* Execute queries against BFD and collect enrollment result into a single object.
*
* In the past there have been significant issues related to the values of the enrollment returned by BFD.
* These issues have led to adding a bunch of logs in here for most steps in the enrollment process.
*
* These logs include:
* - log each bundle received with the page number
* - listing all links to additional pages returned by BFD
* - log last page received
* - record statistics regarding potentially missing things like MBIs, beneficiary ids, distribution of reference
* years on the patient, and past reference years which are not expected.
*
* Steps
* - Set a unique id for the job as a header to BFD for monitoring purposes
* - Get the first page of enrollment results and process those results
* - Loop over the remaining pages of results and query until none are left
* - Add the results to the CoverageMapping object
* - Mark the search as completed
* - Log statistics concerning enrollment pulled
* - Remove the unique id header used for BFD
*
* @throws Exception on any failure, before the exception is thrown it will be logged
*/
@Trace(metricName = "EnrollmentRequest", dispatcher = true)
@Override
public CoverageMapping call() {
int month = coverageMapping.getPeriod().getMonth();
String contractNumber = coverageMapping.getContractNumber();
final Set<Identifiers> patientIds = new HashSet<>();
int bundleNo = 1;
try {
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}", contractNumber, this.year, month, bundleNo);
BFDClient.BFD_BULK_JOB_ID.set(coverageMapping.getJobId());
IBaseBundle bundle = getBundle(contractNumber, month, this.year);
patientIds.addAll(extractAndFilter(bundle));
String availableLinks = BundleUtils.getAvailableLinks(bundle);
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, available links {}", contractNumber, this.year, month, bundleNo, availableLinks);
if (BundleUtils.getNextLink(bundle) == null) {
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, does not have a next link", contractNumber, this.year, month, bundleNo);
}
while (BundleUtils.getNextLink(bundle) != null) {
bundleNo += 1;
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}", contractNumber, this.year, month, bundleNo);
bundle = bfdClient.requestNextBundleFromServer(version, bundle);
availableLinks = BundleUtils.getAvailableLinksPretty(bundle);
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, available links {}", contractNumber, this.year, month, bundleNo, availableLinks);
if (BundleUtils.getNextLink(bundle) == null) {
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, does not have a next link", contractNumber, this.year, month, bundleNo);
}
patientIds.addAll(extractAndFilter(bundle));
}
log.info("retrieving contract membership for ContractWorkerDto {}-{}-{}, #{} bundles received.", contractNumber, this.year, month, bundleNo);
coverageMapping.addBeneficiaries(patientIds);
log.debug("finished reading [{}] Set<Identifiers>resources", patientIds.size());
coverageMapping.completed();
return coverageMapping;
} catch (Exception e) {
log.error("Unable to get patient information for " + contractNumber + " for month " + month + " and year " + this.year, e);
coverageMapping.failed();
throw e;
} finally {
int total = patientIds.size() + missingReferenceYear + missingBeneId + pastReferenceYear;
log.info("Search {}-{}-{} found {} distribution of reference years over a total of {} benes", contractNumber, this.year, month, referenceYears, total);
log.info("Search {}-{}-{} discarded {} entries missing a reference year out of {}", contractNumber, this.year, month, missingReferenceYear, total);
log.info("Search {}-{}-{} discarded {} entries with a reference year in the past out of {}", contractNumber, this.year, month, pastReferenceYear, total);
log.info("Search {}-{}-{} discarded {} entries missing a beneficiary identifier out of {}", contractNumber, this.year, month, missingBeneId, total);
log.info("Search {}-{}-{} found {} entries missing a current mbi out of {}", contractNumber, this.year, month, missingCurrentMbi, total);
log.info("Search {}-{}-{} found {} entries with a historical mbi out of {}", contractNumber, this.year, month, hasHistoricalMbi, total);
completed.set(true);
BFDClient.BFD_BULK_JOB_ID.remove();
}
}
use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED in project Gravity-SDOH-Exchange-RI by FHIR.
the class OurTaskPollingService method updateTasks.
@Scheduled(fixedDelayString = "${scheduling.task-polling-delay-millis}")
public void updateTasks() {
log.info("Updating tasks from our tasks...");
Bundle tasksBundle = openCpClient.search().forResource(Task.class).revInclude(Task.INCLUDE_BASED_ON).include(Task.INCLUDE_FOCUS.setRecurse(true)).and(Task.INTENT.exactly().code(Task.TaskIntent.ORDER.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(TaskStatus.FAILED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(TaskStatus.REJECTED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(TaskStatus.COMPLETED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(TaskStatus.CANCELLED.toCode())).where(Task.AUTHORED_ON.before().millis(Date.from(LocalDateTime.now().minusSeconds(10).atZone(ZoneId.systemDefault()).toInstant()))).returnBundle(Bundle.class).execute();
OurTasksPollingInfo tasksPollingInfo = new OurTasksPollingBundleExtractor().extract(tasksBundle);
// Collect all entries from every Task bundle for performance considerations.
Bundle updateBundle = new Bundle();
updateBundle.setType(Bundle.BundleType.TRANSACTION);
for (Task task : tasksPollingInfo.getTasks()) {
// Skip for now. We create our tasks automatically when we set a status to Accepted.
if (task.getStatus().equals(TaskStatus.REQUESTED) || task.getStatus().equals(TaskStatus.RECEIVED)) {
continue;
}
ServiceRequest serviceRequest = getServiceRequest(task);
try {
Task ourTask = tasksPollingInfo.getOurTask(task);
combineResult(updateBundle, getUpdateBundle(task, serviceRequest, ourTask));
} catch (OurTaskPollingUpdateException exc) {
combineResult(updateBundle, failTask(task, serviceRequest, exc.getMessage()));
}
}
// If there is at least one bundle entry - execute a transaction request.
if (updateBundle.getEntry().size() != 0) {
log.info("One or more tasks were changed. Storing updates to CP...");
openCpClient.transaction().withBundle(updateBundle).execute();
}
log.info("Task update process finished.");
}
use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED in project integration-adaptor-111 by nhsconnect.
the class EncounterMapper method mapEncounter.
public Encounter mapEncounter(POCDMT000002UK01ClinicalDocument1 clinicalDocument, List<PractitionerRole> authorPractitionerRoles, Optional<PractitionerRole> responsibleParty, Coding interaction) {
Encounter encounter = new Encounter();
encounter.setIdElement(resourceUtil.newRandomUuid());
encounter.setStatus(FINISHED);
encounter.setLocation(getLocationComponents(clinicalDocument));
encounter.setPeriod(getPeriod(clinicalDocument));
setType(encounter, interaction);
setServiceProvider(encounter, clinicalDocument);
setIdentifiers(encounter, clinicalDocument);
setSubject(encounter, clinicalDocument);
encounter.setParticipant(getEncounterParticipantComponents(clinicalDocument, authorPractitionerRoles, responsibleParty, encounter));
setAppointment(encounter, clinicalDocument);
setEncounterReasonAndType(encounter, clinicalDocument);
return encounter;
}
use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method sendFile.
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
long ms = System.currentTimeMillis();
System.out.print("Loading " + f.getName() + ".. ");
IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
Resource res = parser.parse(new FileInputStream(f));
System.out.println(" done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
if (res instanceof Bundle) {
Bundle bnd = (Bundle) res;
int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
while (cursor < bnd.getEntry().size()) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor + size); i++) {
BundleEntryComponent be = bt.addEntry();
be.setResource(bnd.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
System.out.print(f.getName() + " (" + cursor + "/" + bnd.getEntry().size() + "): ");
ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
int ncursor = cursor + size;
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
ncursor = cursor + i - 1;
break;
}
}
cursor = ncursor;
System.out.println(" .. done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms) " + SimpleDateFormat.getInstance().format(new Date()));
ini.setIntegerProperty("progress", f.getName(), cursor, null);
ini.save();
}
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
} else {
client.update(res);
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
}
}
use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method sendFile.
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
long ms = System.currentTimeMillis();
System.out.print("Loading " + f.getName() + ".. ");
IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
Resource res = parser.parse(new FileInputStream(f));
System.out.println(" done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
if (res instanceof Bundle) {
Bundle bnd = (Bundle) res;
int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
while (cursor < bnd.getEntry().size()) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor + size); i++) {
if (i >= 0 && i < bnd.getEntry().size()) {
BundleEntryComponent be = bt.addEntry();
be.setResource(bnd.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
}
System.out.print(f.getName() + " (" + cursor + "/" + bnd.getEntry().size() + "): ");
ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
int ncursor = cursor + size;
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
ncursor = cursor + i - 1;
break;
}
}
cursor = ncursor;
System.out.println(" .. done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms) " + SimpleDateFormat.getInstance().format(new Date()));
ini.setIntegerProperty("progress", f.getName(), cursor, null);
ini.save();
}
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
} else {
client.update(res);
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
}
}
Aggregations