use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method validateNames.
private void validateNames(Patient patient) {
List<HumanName> names = patient.getName();
if (names.size() < 1) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("The patient must have at least one Name."), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<HumanName> activeOfficialNames = names.stream().filter(nm -> IsActiveName(nm)).filter(nm -> NameUse.OFFICIAL.equals(nm.getUse())).collect(Collectors.toList());
if (activeOfficialNames.size() != 1) {
InvalidRequestException exception = new InvalidRequestException("The patient must have one Active Name with a Use of OFFICIAL");
throw OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<String> officialFamilyNames = new ArrayList<>();
for (HumanName humanName : activeOfficialNames) {
if (humanName.getFamily() != null) {
officialFamilyNames.add(humanName.getFamily());
}
}
validateNameCount(officialFamilyNames, "family");
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromInterpretation method getHPOforObservation.
@Override
public HpoTermId4LoincTest getHPOforObservation() throws UnsupportedCodingSystemException, AmbiguousResultsFoundException, AnnotationNotFoundException, UnrecognizedCodeException {
// here we use a map to store the results: since there could be more than one interpretation coding system,
// we try them all and store the results in a map <external code, result in internal code>
Map<Code, Code> results = new HashMap<>();
// get the annotation class for this loinc code
UniversalLoinc2HPOAnnotation annotationForLoinc = annotationMap.get(this.loincId);
if (annotationForLoinc == null)
throw new AnnotationNotFoundException();
// all interpretation codes in different coding systems. Expect one in most cases.
Set<Code> interpretationCodes = getInterpretationCodes();
interpretationCodes.stream().filter(p -> CodeSystemConvertor.getCodeContainer().getCodeSystemMap().containsKey(p.getSystem())).forEach(p -> {
Code internalCode = null;
try {
internalCode = CodeSystemConvertor.convertToInternalCode(p);
results.put(p, internalCode);
} catch (InternalCodeNotFoundException e) {
e.printStackTrace();
}
});
List<Code> distinct = results.values().stream().distinct().collect(Collectors.toList());
if (distinct.size() == 1) {
HpoTermId4LoincTest hpoTermId4LoincTest = annotationForLoinc.loincInterpretationToHPO(distinct.get(0));
if (hpoTermId4LoincTest == null)
throw new UnrecognizedCodeException();
return hpoTermId4LoincTest;
} else {
throw new AmbiguousResultsFoundException();
}
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.
/**
* fhir resource Appointment to AppointmentDetail
*
* @param appointment Resource
* @return populated AppointmentDetail
*/
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " characters");
}
AppointmentDetail appointmentDetail = new AppointmentDetail();
Long id = appointment.getIdElement().getIdPartAsLong();
appointmentDetail.setId(id);
appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
if (cnlExtension != null && !cnlExtension.isEmpty()) {
IBaseDatatype value = cnlExtension.get(0).getValue();
if (null == value) {
throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
}
appointmentDetail.setCancellationReason(value.toString());
}
appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
appointmentDetail.setPriority(appointment.getPriority());
appointmentDetail.setStartDateTime(appointment.getStart());
appointmentDetail.setEndDateTime(appointment.getEnd());
List<Long> slotIds = new ArrayList<>();
for (Reference slotReference : appointment.getSlot()) {
// #200 check slots for absolute references
checkReferenceIsRelative(slotReference.getReference());
try {
String here = slotReference.getReference().substring("Slot/".length());
Long slotId = new Long(here);
slotIds.add(slotId);
} catch (NumberFormatException ex) {
throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
}
}
appointmentDetail.setSlotIds(slotIds);
if (appointmentValidation.appointmentCommentTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
}
appointmentDetail.setComment(appointment.getComment());
appointmentDetail.setDescription(appointment.getDescription());
for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
if (participant.getActor() != null) {
String participantReference = participant.getActor().getReference();
String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
Long actorId;
if (actorIdString.equals("null")) {
actorId = null;
} else {
actorId = Long.valueOf(actorIdString);
}
if (participantReference.contains("Patient/")) {
appointmentDetail.setPatientId(actorId);
} else if (participantReference.contains("Practitioner/")) {
appointmentDetail.setPractitionerId(actorId);
} else if (participantReference.contains("Location/")) {
appointmentDetail.setLocationId(actorId);
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
}
}
if (appointment.getCreated() != null) {
Date created = appointment.getCreated();
appointmentDetail.setCreated(created);
}
// #200 check extensions for absolute references
List<Extension> extensions = appointment.getExtension();
for (Extension extension : extensions) {
try {
Reference reference = (Reference) extension.getValue();
if (reference != null) {
checkReferenceIsRelative(reference.getReference());
}
} catch (ClassCastException ex) {
}
}
List<Resource> contained = appointment.getContained();
if (contained != null && !contained.isEmpty()) {
Resource org = contained.get(0);
Organization bookingOrgRes = (Organization) org;
BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
bookingOrgDetail.setName(bookingOrgRes.getName());
// #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
while (iter.hasNext()) {
ContactPoint thisTelecom = iter.next();
if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
telecom = thisTelecom;
break;
}
}
bookingOrgDetail.setTelephone(telecom.getValue());
bookingOrgDetail.setSystem(telecom.getSystem().toString());
if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
bookingOrgDetail.setUsetype(telecom.getUse().toString());
}
if (!bookingOrgRes.getIdentifier().isEmpty()) {
bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
// check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
if (system != null && !system.trim().isEmpty()) {
if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
}
}
bookingOrgDetail.setAppointmentDetail(appointmentDetail);
appointmentDetail.setBookingOrganization(bookingOrgDetail);
// 1.2.7
appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
}
return appointmentDetail;
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project gpconnect-demonstrator by nhsconnect.
the class PopulateSlotBundle method addOrganisation.
/**
* Add OrganizationResource to Bundle
*
* @param organization OrganizationDetails object to add to bundle
* @param bundle Bundle Resource to add organisation to
*/
private void addOrganisation(OrganizationDetails organization, Bundle bundle) {
BundleEntryComponent organizationEntry = new BundleEntryComponent();
Long organizationId = organization.getId();
OrganizationDetails organizationDetails = organizationSearch.findOrganizationDetails(organizationId);
Organization organizationResource = organizationResourceProvider.convertOrganizationDetailsToOrganization(organizationDetails);
organizationEntry.setResource(organizationResource);
// #202 use full urls
// #215 full url removed completely
// organizationEntry.setFullUrl(serverBaseUrl + "Organization/" + organization.getId());
bundle.addEntry(organizationEntry);
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use 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;
}
Aggregations