use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project dpc-app by CMSgov.
the class JobBatchProcessor method processJobBatchPartial.
/**
* Processes a partial of a job batch. Marks the partial as completed upon processing
*
* @param aggregatorID the current aggregatorID
* @param queue the queue
* @param job the job to process
* @param patientID the current patient id to process
* @return A list of batch files {@link JobQueueBatchFile}
*/
public List<JobQueueBatchFile> processJobBatchPartial(UUID aggregatorID, IJobQueue queue, JobQueueBatch job, String patientID) {
StopWatch stopWatch = StopWatch.createStarted();
OutcomeReason failReason = null;
final Pair<Optional<List<ConsentResult>>, Optional<OperationOutcome>> consentResult = getConsent(patientID);
Flowable<Resource> flowable;
if (consentResult.getRight().isPresent()) {
flowable = Flowable.just(consentResult.getRight().get());
failReason = OutcomeReason.INTERNAL_ERROR;
} else if (isOptedOut(consentResult.getLeft())) {
failReason = OutcomeReason.CONSENT_OPTED_OUT;
flowable = Flowable.just(AggregationUtils.toOperationOutcome(OutcomeReason.CONSENT_OPTED_OUT, patientID));
} else if (isLookBackExempt(job.getOrgID())) {
logger.info("Skipping lookBack for org: {}", job.getOrgID().toString());
MDC.put(MDCConstants.IS_SMOKE_TEST_ORG, "true");
flowable = Flowable.fromIterable(job.getResourceTypes()).flatMap(r -> fetchResource(job, patientID, r, job.getSince().orElse(null)));
} else {
List<LookBackAnswer> answers = getLookBackAnswers(job, patientID);
if (passesLookBack(answers)) {
flowable = Flowable.fromIterable(job.getResourceTypes()).flatMap(r -> fetchResource(job, patientID, r, job.getSince().orElse(null)));
} else {
failReason = LookBackAnalyzer.analyze(answers);
flowable = Flowable.just(AggregationUtils.toOperationOutcome(failReason, patientID));
}
}
final var results = writeResource(job, flowable).toList().blockingGet();
queue.completePartialBatch(job, aggregatorID);
final String resourcesRequested = job.getResourceTypes().stream().map(DPCResourceType::getPath).filter(Objects::nonNull).collect(Collectors.joining(";"));
final String failReasonLabel = failReason == null ? "NA" : failReason.name();
stopWatch.stop();
logger.info("dpcMetric=DataExportResult,dataRetrieved={},failReason={},resourcesRequested={},duration={}", failReason == null, failReasonLabel, resourcesRequested, stopWatch.getTime());
return results;
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project gpconnect-demonstrator by nhsconnect.
the class MedicationDispenseResourceProvider method getMedicationDispensesForPatientId.
@Search
public List<MedicationDispense> getMedicationDispensesForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationDispense> medicationDispenses = new ArrayList<>();
List<MedicationDispenseDetail> medicationDispenseDetailList = medicationDispenseSearch.findMedicationDispenseForPatient(Long.parseLong(patientId));
if (medicationDispenseDetailList != null && !medicationDispenseDetailList.isEmpty()) {
for (MedicationDispenseDetail medicationDispenseDetail : medicationDispenseDetailList) {
MedicationDispense medicationDispense = new MedicationDispense();
medicationDispense.setId(String.valueOf(medicationDispenseDetail.getId()));
medicationDispense.getMeta().setLastUpdated(medicationDispenseDetail.getLastUpdated());
medicationDispense.getMeta().setVersionId(String.valueOf(medicationDispenseDetail.getLastUpdated().getTime()));
switch(medicationDispenseDetail.getStatus().toLowerCase(Locale.UK)) {
case "completed":
medicationDispense.setStatus(MedicationDispenseStatus.COMPLETED);
break;
case "entered_in_error":
medicationDispense.setStatus(MedicationDispenseStatus.ENTEREDINERROR);
break;
case "in_progress":
medicationDispense.setStatus(MedicationDispenseStatus.INPROGRESS);
break;
case "on_hold":
medicationDispense.setStatus(MedicationDispenseStatus.ONHOLD);
break;
case "stopped":
medicationDispense.setStatus(MedicationDispenseStatus.STOPPED);
break;
}
medicationDispense.setSubject(new Reference("Patient/" + patientId));
medicationDispense.setAuthorizingPrescription(Collections.singletonList(new Reference("MedicationOrder/" + medicationDispenseDetail.getMedicationOrderId())));
Medication medication = new Medication();
Coding coding = new Coding();
coding.setCode(String.valueOf(medicationDispenseDetail.getMedicationId()));
coding.setDisplay(medicationDispenseDetail.getMedicationName());
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.setCoding(Collections.singletonList(coding));
medication.setCode(codeableConcept);
medicationDispense.addDosageInstruction().setText(medicationDispenseDetail.getDosageText());
medicationDispenses.add(medicationDispense);
}
}
return medicationDispenses;
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project dpc-app by CMSgov.
the class JobBatchProcessorV2 method processJobBatchPartial.
/**
* Processes a partial of a job batch. Marks the partial as completed upon processing
*
* @param aggregatorID the current aggregatorID
* @param queue the queue
* @param job the job to process
* @param patientID the current patient id to process
* @return A list of batch files {@link JobQueueBatchFile}
*/
public List<JobQueueBatchFile> processJobBatchPartial(UUID aggregatorID, IJobQueue queue, JobQueueBatch job, String patientID) {
StopWatch stopWatch = StopWatch.createStarted();
OutcomeReason failReason = null;
final Pair<Optional<List<ConsentResult>>, Optional<OperationOutcome>> consentResult = getConsent(patientID);
Flowable<Resource> flowable;
if (consentResult.getRight().isPresent()) {
flowable = Flowable.just(consentResult.getRight().get());
failReason = OutcomeReason.INTERNAL_ERROR;
} else if (isOptedOut(consentResult.getLeft())) {
failReason = OutcomeReason.CONSENT_OPTED_OUT;
flowable = Flowable.just(AggregationUtils.toOperationOutcomeV2(OutcomeReason.CONSENT_OPTED_OUT, patientID));
} else {
logger.info("Skipping lookBack for V2 job: {}", job.getOrgID().toString());
flowable = Flowable.fromIterable(job.getResourceTypes()).flatMap(r -> fetchResource(job, patientID, r, job.getSince().orElse(null)));
}
final var results = writeResource(job, flowable).toList().blockingGet();
queue.completePartialBatch(job, aggregatorID);
final String resourcesRequested = job.getResourceTypes().stream().map(DPCResourceType::getPath).filter(Objects::nonNull).collect(Collectors.joining(";"));
final String failReasonLabel = failReason == null ? "NA" : failReason.name();
stopWatch.stop();
logger.info("dpcMetric=DataExportResult,dataRetrieved={},failReason={},resourcesRequested={},duration={}", failReason == null, failReasonLabel, resourcesRequested, stopWatch.getTime());
return results;
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project synthea by synthetichealth.
the class FhirR4 method procedure.
/**
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry
* @param bundle Bundle to add to
* @param encounterEntry The current Encounter entry
* @param procedure The Procedure
* @return The added Entry
*/
private static BundleEntryComponent procedure(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Procedure procedure) {
org.hl7.fhir.r4.model.Procedure procedureResource = new org.hl7.fhir.r4.model.Procedure();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure");
procedureResource.setMeta(meta);
}
procedureResource.setStatus(ProcedureStatus.COMPLETED);
procedureResource.setSubject(new Reference(personEntry.getFullUrl()));
procedureResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
if (USE_US_CORE_IG) {
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
procedureResource.setLocation(encounterResource.getLocationFirstRep().getLocation());
}
Code code = procedure.codes.get(0);
CodeableConcept procCode = mapCodeToCodeableConcept(code, SNOMED_URI);
procedureResource.setCode(procCode);
if (procedure.stop != 0L) {
Date startDate = new Date(procedure.start);
Date endDate = new Date(procedure.stop);
procedureResource.setPerformed(new Period().setStart(startDate).setEnd(endDate));
} else {
procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
}
if (!procedure.reasons.isEmpty()) {
// Only one element in list
Code reason = procedure.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
procedureResource.addReasonReference().setReference(entry.getFullUrl()).setDisplay(reason.display);
}
}
}
}
if (USE_SHR_EXTENSIONS) {
procedureResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-procedure-ProcedurePerformed"));
// required fields for this profile are action-PerformedContext-extension,
// status, code, subject, performed[x]
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
procedureResource.addExtension(performedContext);
}
BundleEntryComponent procedureEntry = newEntry(rand, bundle, procedureResource);
procedure.fullUrl = procedureEntry.getFullUrl();
return procedureEntry;
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project synthea by synthetichealth.
the class FhirR4 method medicationRequest.
/**
* Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
*
* @param person The person being prescribed medication
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the Medication to
* @param encounterEntry Current Encounter entry
* @param medication The Medication
* @return The added Entry
*/
private static BundleEntryComponent medicationRequest(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
MedicationRequest medicationResource = new MedicationRequest();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest");
medicationResource.setMeta(meta);
} else if (USE_SHR_EXTENSIONS) {
medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
Extension requestedContext = new Extension();
requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
medicationResource.addExtension(requestedContext);
}
medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
medicationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
Code code = medication.codes.get(0);
String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
if (USE_US_CORE_IG && medication.administration) {
// Occasionally, rather than use medication codes, we want to use a Medication
// Resource. We only want to do this when we use US Core, to make sure we
// sometimes produce a resource for the us-core-medication profile, and the
// 'administration' flag is an arbitrary way to decide without flipping a coin.
org.hl7.fhir.r4.model.Medication drugResource = new org.hl7.fhir.r4.model.Medication();
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");
drugResource.setMeta(meta);
drugResource.setCode(mapCodeToCodeableConcept(code, system));
drugResource.setStatus(MedicationStatus.ACTIVE);
BundleEntryComponent drugEntry = newEntry(person, bundle, drugResource);
medicationResource.setMedication(new Reference(drugEntry.getFullUrl()));
}
medicationResource.setAuthoredOn(new Date(medication.start));
medicationResource.setIntent(MedicationRequestIntent.ORDER);
org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
medicationResource.setRequester(encounter.getParticipantFirstRep().getIndividual());
if (medication.stop != 0L) {
medicationResource.setStatus(MedicationRequestStatus.STOPPED);
} else {
medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
}
if (!medication.reasons.isEmpty()) {
// Only one element in list
Code reason = medication.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
medicationResource.addReasonReference().setReference(entry.getFullUrl());
}
}
}
}
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
Dosage dosage = new Dosage();
dosage.setSequence(1);
// as_needed is true if present
dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
if (rxInfo.has("as_needed")) {
dosage.setText("Take as needed.");
}
// as_needed is false
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
Timing timing = new Timing();
TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
timing.setRepeat(timingRepeatComponent);
dosage.setTiming(timing);
Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
DosageDoseAndRateComponent dosageDetails = new DosageDoseAndRateComponent();
dosageDetails.setType(new CodeableConcept().addCoding(new Coding().setCode(DoseRateType.ORDERED.toCode()).setSystem(DoseRateType.ORDERED.getSystem()).setDisplay(DoseRateType.ORDERED.getDisplay())));
dosageDetails.setDose(dose);
List<DosageDoseAndRateComponent> details = new ArrayList<DosageDoseAndRateComponent>();
details.add(dosageDetails);
dosage.setDoseAndRate(details);
if (rxInfo.has("instructions")) {
String text = "";
for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
JsonObject instruction = instructionElement.getAsJsonObject();
Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
text += instructionCode.display + "\n";
dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
}
dosage.setText(text);
}
}
List<Dosage> dosageInstruction = new ArrayList<Dosage>();
dosageInstruction.add(dosage);
medicationResource.setDosageInstruction(dosageInstruction);
}
BundleEntryComponent medicationEntry = newEntry(person, bundle, medicationResource);
// create new claim for medication
medicationClaim(person, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
// Create new administration for medication, if needed
if (medication.administration) {
medicationAdministration(person, personEntry, bundle, encounterEntry, medication, medicationResource);
}
return medicationEntry;
}
Aggregations