use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project loinc2hpo by monarch-initiative.
the class CodeSystemInternal method init.
@Override
protected void init() {
final Coding BELOWNORMAL = new Coding(INTERNALSYSTEM, "L", "below normal range");
final Coding NORMAL = new Coding(INTERNALSYSTEM, "N", "within normal range");
final Coding ABOVENORMAL = new Coding(INTERNALSYSTEM, "H", "above normal range");
final Coding ABSENCE = new Coding(INTERNALSYSTEM, "NP", "not present");
final Coding PRESENCE = new Coding(INTERNALSYSTEM, "P", "present");
final Coding UNKNOWN = new Coding(INTERNALSYSTEM, "unknown", "unknown");
codes.put(BELOWNORMAL.getCode(), BELOWNORMAL);
codes.put(NORMAL.getCode(), NORMAL);
codes.put(ABOVENORMAL.getCode(), ABOVENORMAL);
codes.put(ABSENCE.getCode(), ABSENCE);
codes.put(PRESENCE.getCode(), PRESENCE);
codes.put(UNKNOWN.getCode(), UNKNOWN);
}
use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method updateAppointment.
/**
* amend or cancel an existing appointment
*
* @param appointmentId
* @param appointment Resource
* @param theRequest required to access the interaction id
* @return MethodOutcome
*/
@Update
public MethodOutcome updateAppointment(@IdParam IdType appointmentId, @ResourceParam Appointment appointment, HttpServletRequest theRequest) {
MethodOutcome methodOutcome = new MethodOutcome();
OperationOutcome operationalOutcome = new OperationOutcome();
AppointmentDetail appointmentDetail = appointmentResourceConverterToAppointmentDetail(appointment);
Meta meta = appointment.getMeta();
final List<UriType> profiles = meta.getProfile();
// #203 validations
VC.execute(new VC[] { new VC(() -> profiles.isEmpty(), () -> "Meta element must be present in Appointment"), new VC(() -> !profiles.get(0).getValue().equalsIgnoreCase(SD_GPC_APPOINTMENT), // what to do if > 1 meta profile element?
() -> "Meta.profile " + profiles.get(0).getValue() + " is not equal to " + SD_GPC_APPOINTMENT), // #203
new VC(() -> !appointment.getReason().isEmpty(), () -> "Appointment reason shouldn't be provided!"), new VC(() -> !appointment.getSpecialty().isEmpty(), () -> "Appointment speciality shouldn't be provided!"), // new VC(() -> !appointment.getServiceType().isEmpty(), () -> "Appointment service type shouldn't be provided!"),
new VC(() -> !appointment.getAppointmentType().isEmpty(), () -> "Appointment type shouldn't be provided!"), new VC(() -> !appointment.getIndication().isEmpty(), () -> "Appointment indication shouldn't be provided!"), new VC(() -> !appointment.getSupportingInformation().isEmpty(), () -> "Appointment supporting information shouldn't be provided!"), new VC(() -> !appointment.getIncomingReferral().isEmpty(), () -> "Appointment incoming referral shouldn't be provided!") });
// URL ID and Resource ID must be the same
if (!Objects.equals(appointmentId.getIdPartAsLong(), appointmentDetail.getId())) {
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("Id in URL (" + appointmentId.getIdPart() + ") should match Id in Resource (" + appointmentDetail.getId() + ")");
methodOutcome.setOperationOutcome(operationalOutcome);
return methodOutcome;
}
// Make sure there is an existing appointment to be amended
AppointmentDetail oldAppointmentDetail = appointmentSearch.findAppointmentByID(appointmentId.getIdPartAsLong());
if (oldAppointmentDetail == null) {
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No appointment details found for ID: " + appointmentId.getIdPart());
methodOutcome.setOperationOutcome(operationalOutcome);
return methodOutcome;
}
// 1.2.7 set the old service type and service category for comparison with incoming update/cancel content values
SlotDetail slotDetail1 = slotSearch.findSlotByID(oldAppointmentDetail.getSlotIds().get(0));
oldAppointmentDetail.setServiceType(slotDetail1.getTypeDisply());
ScheduleDetail scheduleDetail = scheduleSearch.findScheduleByID(slotDetail1.getScheduleReference());
oldAppointmentDetail.setServiceCategory(scheduleDetail.getTypeDescription());
String oldAppointmentVersionId = String.valueOf(oldAppointmentDetail.getLastUpdated().getTime());
String newAppointmentVersionId = appointmentId.getVersionIdPart();
if (newAppointmentVersionId != null && !newAppointmentVersionId.equalsIgnoreCase(oldAppointmentVersionId)) {
throw new ResourceVersionConflictException("The specified version (" + newAppointmentVersionId + ") did not match the current resource version (" + oldAppointmentVersionId + ")");
}
// check for absolute reference #200
Iterator<AppointmentParticipantComponent> iter = appointment.getParticipant().iterator();
while (iter.hasNext()) {
AppointmentParticipantComponent participant = iter.next();
if (participant.getActor() != null) {
checkReferenceIsRelative(participant.getActor().getReference());
}
}
String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
// Determine if it is a cancel or an amend. This was previously a check for the presence of a cancellation reason
// but that is not sufficient. We can sefely assume that the interaction id is populated at this point.
AppointmentOperation appointmentOperation = null;
final AppointmentDetail fAppointmentDetail = appointmentDetail;
switch(interactionId) {
case REST_CANCEL_APPOINTMENT:
appointmentOperation = AppointmentOperation.CANCEL;
// added at 1.2.2
VC.execute(new VC[] { new VC(() -> appointment.getStatus() != AppointmentStatus.CANCELLED, () -> "Status must be \"cancelled\""), // #203
new VC(() -> isInThePast(fAppointmentDetail.getStartDateTime()), () -> "The cancellation start date cannot be in the past"), new VC(() -> fAppointmentDetail.getCancellationReason() == null, () -> "The cancellation reason must be provided"), // no point in this since fhir forbids empty elements
new VC(() -> fAppointmentDetail.getCancellationReason().isEmpty(), () -> "The cancellation reason can not be blank") });
validateAppointmentExtensions(appointment, profiles, appointmentOperation);
// #172
String appointmentType = appointment.getAppointmentType().getText();
if (appointmentType != null) {
throwUnprocessableEntity422_InvalidResourceException("The appointment type cannot be updated on a cancellation");
}
// This is a Cancellation - so copy across fields which can be
// altered
List cancelComparisonResult = compareAppointmentsForInvalidProperty(AppointmentOperation.CANCEL, oldAppointmentDetail, appointmentDetail);
if (cancelComparisonResult.size() > 0) {
throwUnprocessableEntity422_InvalidResourceException("Invalid Appointment property has been amended (cancellation) " + cancelComparisonResult);
}
oldAppointmentDetail.setCancellationReason(appointmentDetail.getCancellationReason());
String oldStatus = oldAppointmentDetail.getStatus();
appointmentDetail = oldAppointmentDetail;
appointmentDetail.setStatus("cancelled");
if (!"cancelled".equalsIgnoreCase(oldStatus)) {
for (Long slotId : appointmentDetail.getSlotIds()) {
SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
// slotDetail.setAppointmentId(null);
slotDetail.setFreeBusyType("FREE");
slotDetail.setLastUpdated(new Date());
slotStore.saveSlot(slotDetail);
}
}
break;
case REST_UPDATE_APPOINTMENT:
appointmentOperation = AppointmentOperation.AMEND;
VC.execute(new VC[] { new VC(() -> appointment.getStatus() != AppointmentStatus.BOOKED, () -> "Status must be \"booked\""), // this subsumes #161 which only inhibited amendment of the cancellation reason in an amend
new VC(() -> fAppointmentDetail.getCancellationReason() != null, () -> "Cannot amend cancellation reason in appointment amend"), // added at 1.2.2
new VC(() -> isInThePast(fAppointmentDetail.getStartDateTime()), () -> "The appointment amend start date cannot be in the past") });
List amendComparisonResult = compareAppointmentsForInvalidProperty(AppointmentOperation.AMEND, oldAppointmentDetail, appointmentDetail);
if (amendComparisonResult.size() > 0) {
throwUnprocessableEntity422_InvalidResourceException("Invalid Appointment property has been amended " + amendComparisonResult);
}
validateAppointmentExtensions(appointment, profiles, appointmentOperation);
// This is an Amend
oldAppointmentDetail.setComment(appointmentDetail.getComment());
oldAppointmentDetail.setDescription(appointmentDetail.getDescription());
appointmentDetail = oldAppointmentDetail;
break;
default:
System.err.println("AppointmentResourceProvider.updateAppointment Unhandled interaction id " + interactionId);
}
// we'll get the delivery channel from the slot
String deliveryChannel = null;
String practitionerRoleCode = null;
String practitionerRoleDisplay = null;
ScheduleDetail schedule = null;
// Common to both Update and cancel
// slots valid?
List<SlotDetail> slots = new ArrayList<>();
for (Long slotId : appointmentDetail.getSlotIds()) {
SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
if (slotDetail == null) {
throwUnprocessableEntity422_InvalidResourceException("Slot resource reference is not a valid resource");
}
if (deliveryChannel == null) {
deliveryChannel = slotDetail.getDeliveryChannelCode();
}
if (schedule == null) {
// load the schedule so we can get the Practitioner ID
schedule = scheduleSearch.findScheduleByID(slotDetail.getScheduleReference());
}
if (practitionerRoleDisplay == null) {
practitionerRoleDisplay = schedule.getPractitionerRoleDisplay();
practitionerRoleCode = schedule.getPractitionerRoleCode();
}
slots.add(slotDetail);
}
validateUpdateExtensions(deliveryChannel, practitionerRoleDisplay, practitionerRoleCode, appointment.getExtension());
// dates valid?
// #203
Date firstSlotStart = slots.get(0).getStartDateTime();
Date lastSlotEnd = slots.get(slots.size() - 1).getEndDateTime();
// need to insert a colon in the timezone string
String firstSlotStartStr = TIMESTAMP_FORMAT.format(firstSlotStart).replaceFirst("([0-9]{2})([0-9]{2})$", "$1:$2");
String lastSlotEndStr = TIMESTAMP_FORMAT.format(lastSlotEnd).replaceFirst("([0-9]{2})([0-9]{2})$", "$1:$2");
VC.execute(new VC[] { new VC(() -> appointment.getStart().compareTo(firstSlotStart) != 0, () -> String.format("Start date '%s' must match start date of first slot '%s'", appointment.getStart(), firstSlotStart)), new VC(() -> appointment.getEnd().compareTo(lastSlotEnd) != 0, () -> String.format("End date '%s' must match end date of last slot '%s'", appointment.getEnd(), lastSlotEnd)), // #218 strings should match exactly
new VC(() -> !appointment.getStartElement().getValueAsString().equals(firstSlotStartStr), () -> String.format("Start date '%s' must lexically match start date of first slot '%s'", appointment.getStartElement().getValueAsString(), firstSlotStartStr)), new VC(() -> !appointment.getEndElement().getValueAsString().equals(lastSlotEndStr), () -> String.format("End date '%s' must lexically match end date of last slot '%s'", appointment.getEndElement().getValueAsString(), lastSlotEndStr)), new VC(() -> appointment.getSlot().size() != slots.size(), () -> String.format("Slot count mismatch %d provided appointment has %d", appointment.getSlot().size(), slots.size())) });
// check the slots match
HashSet<String> hs = new HashSet<>();
for (SlotDetail slotDetail : slots) {
hs.add("Slot/" + slotDetail.getId());
}
for (Reference reference : appointment.getSlot()) {
if (!hs.contains(reference.getReference())) {
throwUnprocessableEntity422_InvalidResourceException(String.format("Provided slot id %s does not exist in booked appointment", reference.getReference()));
}
}
// Update version and
appointmentDetail.setLastUpdated(new Date());
// lastUpdated timestamp
appointmentDetail = appointmentStore.saveAppointment(appointmentDetail, slots);
methodOutcome.setId(new IdDt("Appointment", appointmentDetail.getId()));
methodOutcome.setResource(appointmentDetailToAppointmentResourceConverter(appointmentDetail));
return methodOutcome;
}
use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project gpconnect-demonstrator by nhsconnect.
the class GpConnectServerCapabilityStatementProvider method getServerConformance.
@Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
final boolean FROM_JSON = true;
CapabilityStatement capabilityStatement = null;
if (!FROM_JSON) {
// Get the automatically generated statement
capabilityStatement = super.getServerConformance(theRequest);
// added at 1.2.2 force overwrite the default entries which are not correct
for (CapabilityStatement.CapabilityStatementRestComponent st : capabilityStatement.getRest()) {
for (CapabilityStatement.CapabilityStatementRestOperationComponent operation : st.getOperation()) {
String opPlusDollar = "$" + operation.getName();
switch(opPlusDollar) {
case REGISTER_PATIENT_OPERATION_NAME:
operation.getDefinition().setReference(OD_GPC_REGISTER_PATIENT);
break;
case GET_STRUCTURED_RECORD_OPERATION_NAME:
operation.getDefinition().setReference(OD_GPC_GET_STRUCTURED_RECORD);
break;
}
}
}
} else {
try {
// 1.2.6 #316
String interactionId = theRequest.getHeader(SSP_INTERACTIONID);
String capabilityFile = null;
switch(interactionId) {
case REST_READ_STRUCTURED_METADATA:
capabilityFile = "structured_capability.json";
break;
default:
capabilityFile = "capability.json";
}
// read a json capability file
String capabilityJson = new String(Files.readAllBytes(Paths.get(FhirRequestGenericIntercepter.getConfigPath() + "/" + capabilityFile)));
FhirContext ctx = FhirContext.forDstu3();
capabilityStatement = (CapabilityStatement) ctx.newJsonParser().parseResource(capabilityJson);
} catch (IOException ex) {
return null;
}
}
// And add additional required information
capabilityStatement.setVersion(SystemVariable.VERSION);
capabilityStatement.setDescription("This server implements the GP Connect API version " + SystemVariable.VERSION);
capabilityStatement.setName("GP Connect");
capabilityStatement.setCopyright("Copyright NHS Digital 2018");
capabilityStatement.getSoftware().setReleaseDate(Date.valueOf(LocalDate.parse("2017-09-27")));
return capabilityStatement;
}
use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addCareTeamPractitioner.
/**
* Ensures that the specified {@link ExplanationOfBenefit} has the specified {@link
* CareTeamComponent}, and links the specified {@link ItemComponent} to that {@link
* CareTeamComponent} (via {@link ItemComponent#addCareTeamLinkId(int)}).
*
* @param eob the {@link ExplanationOfBenefit} that the {@link CareTeamComponent} should be part
* of
* @param eobItem the {@link ItemComponent} that should be linked to the {@link CareTeamComponent}
* @param practitionerIdSystem the {@link Identifier#getSystem()} of the practitioner to reference
* in {@link CareTeamComponent#getProvider()}
* @param practitionerIdValue the {@link Identifier#getValue()} of the practitioner to reference
* in {@link CareTeamComponent#getProvider()}
* @param careTeamRole the {@link ClaimCareteamrole} to use for the {@link
* CareTeamComponent#getRole()}
* @return the {@link CareTeamComponent} that was created/linked
*/
static CareTeamComponent addCareTeamPractitioner(ExplanationOfBenefit eob, ItemComponent eobItem, String practitionerIdSystem, String practitionerIdValue, ClaimCareteamrole careTeamRole) {
// Try to find a matching pre-existing entry.
CareTeamComponent careTeamEntry = eob.getCareTeam().stream().filter(ctc -> ctc.getProvider().hasIdentifier()).filter(ctc -> practitionerIdSystem.equals(ctc.getProvider().getIdentifier().getSystem()) && practitionerIdValue.equals(ctc.getProvider().getIdentifier().getValue())).filter(ctc -> ctc.hasRole()).filter(ctc -> careTeamRole.toCode().equals(ctc.getRole().getCodingFirstRep().getCode()) && careTeamRole.getSystem().equals(ctc.getRole().getCodingFirstRep().getSystem())).findAny().orElse(null);
// If no match was found, add one to the EOB.
if (careTeamEntry == null) {
careTeamEntry = eob.addCareTeam();
careTeamEntry.setSequence(eob.getCareTeam().size() + 1);
careTeamEntry.setProvider(createIdentifierReference(practitionerIdSystem, practitionerIdValue));
CodeableConcept careTeamRoleConcept = createCodeableConcept(ClaimCareteamrole.OTHER.getSystem(), careTeamRole.toCode());
careTeamRoleConcept.getCodingFirstRep().setDisplay(careTeamRole.getDisplay());
careTeamEntry.setRole(careTeamRoleConcept);
}
// care team entry is at eob level so no need to create item link id
if (eobItem == null) {
return careTeamEntry;
}
// Link the EOB.item to the care team entry (if it isn't already).
final int careTeamEntrySequence = careTeamEntry.getSequence();
if (eobItem.getCareTeamLinkId().stream().noneMatch(id -> id.getValue() == careTeamEntrySequence)) {
eobItem.addCareTeamLinkId(careTeamEntrySequence);
}
return careTeamEntry;
}
use of org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProvider method findClaimTypeByPatient.
/**
* @param claimType the {@link ClaimType} to find
* @param patientId the {@link Beneficiary#getBeneficiaryId()} to filter by
* @param lastUpdated the update time to filter by
* @return the matching claim/event entities
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Trace
private <T> List<T> findClaimTypeByPatient(ClaimType claimType, String patientId, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery criteria = builder.createQuery((Class) claimType.getEntityClass());
Root root = criteria.from(claimType.getEntityClass());
claimType.getEntityLazyAttributes().stream().forEach(a -> root.fetch(a));
criteria.select(root).distinct(true);
// Search for a beneficiary's records. Use lastUpdated if present
Predicate wherePredicate = builder.equal(root.get(claimType.getEntityBeneficiaryIdAttribute()), patientId);
if (lastUpdated != null && !lastUpdated.isEmpty()) {
Predicate predicate = QueryUtils.createLastUpdatedPredicate(builder, root, lastUpdated);
wherePredicate = builder.and(wherePredicate, predicate);
}
criteria.where(wherePredicate);
List<T> claimEntities = null;
Long eobsByBeneIdQueryNanoSeconds = null;
Timer.Context timerEobQuery = metricRegistry.timer(MetricRegistry.name(metricRegistry.getClass().getSimpleName(), "query", "eobs_by_bene_id", claimType.name().toLowerCase())).time();
try {
claimEntities = entityManager.createQuery(criteria).getResultList();
} finally {
eobsByBeneIdQueryNanoSeconds = timerEobQuery.stop();
TransformerUtils.recordQueryInMdc(String.format("eobs_by_bene_id.%s", claimType.name().toLowerCase()), eobsByBeneIdQueryNanoSeconds, claimEntities == null ? 0 : claimEntities.size());
}
if (claimEntities != null && serviceDate != null && !serviceDate.isEmpty()) {
final Instant lowerBound = serviceDate.getLowerBoundAsInstant() != null ? serviceDate.getLowerBoundAsInstant().toInstant() : null;
final Instant upperBound = serviceDate.getUpperBoundAsInstant() != null ? serviceDate.getUpperBoundAsInstant().toInstant() : null;
final java.util.function.Predicate<LocalDate> lowerBoundCheck = lowerBound == null ? (date) -> true : (date) -> compareLocalDate(date, lowerBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getLowerBound().getPrefix());
final java.util.function.Predicate<LocalDate> upperBoundCheck = upperBound == null ? (date) -> true : (date) -> compareLocalDate(date, upperBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getUpperBound().getPrefix());
return claimEntities.stream().filter(entity -> lowerBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity)) && upperBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity))).collect(Collectors.toList());
}
return claimEntities;
}
Aggregations