use of org.hl7.fhir.r5.model.IdType in project gpconnect-demonstrator by nhsconnect.
the class MedicationRequestResourceProvider method getMedicationRequestFromDetail.
private MedicationRequest getMedicationRequestFromDetail(MedicationRequestDetail requestDetail) {
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setId(requestDetail.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(requestDetail.getGuid());
identifiers.add(identifier);
medicationRequest.setIdentifier(identifiers);
medicationRequest.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_REQUEST));
setBasedOnReferences(medicationRequest, requestDetail);
if (requestDetail.getPrescriptionTypeCode().contains("repeat")) {
medicationRequest.setGroupIdentifier(new Identifier().setValue(requestDetail.getGroupIdentifier()));
}
try {
medicationRequest.setStatus(MedicationRequestStatus.fromCode(requestDetail.getStatusCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
try {
medicationRequest.setIntent(MedicationRequestIntent.fromCode(requestDetail.getIntentCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
if (requestDetail.getMedicationId() != null) {
medicationRequest.setMedication(new Reference(new IdType("Medication", requestDetail.getMedicationId())));
}
if (requestDetail.getPatientId() != null) {
medicationRequest.setSubject(new Reference(new IdType("Patient", requestDetail.getPatientId())));
}
if (requestDetail.getAuthorisingPractitionerId() != null) {
medicationRequest.setRecorder(new Reference(new IdType("Practitioner", requestDetail.getAuthorisingPractitionerId())));
}
if (requestDetail.getPriorMedicationRequestId() != null) {
medicationRequest.setPriorPrescription(new Reference(new IdType("MedicationRequest", requestDetail.getPriorMedicationRequestId())));
}
medicationRequest.setAuthoredOn(requestDetail.getAuthoredOn());
medicationRequest.setDispenseRequest(getDispenseRequestComponent(requestDetail));
// medicationRequest.setRequester(getRequesterComponent(requestDetail)); //TODO - spec needs to clarify whether this should be populated or not
setReasonCodes(medicationRequest, requestDetail);
setNotes(medicationRequest, requestDetail);
if (medicationRequest.getIntent() != MedicationRequestIntent.ORDER) {
setRepeatInformation(medicationRequest, requestDetail);
}
setPrescriptionType(medicationRequest, requestDetail);
setStatusReason(medicationRequest, requestDetail);
String dosageInstructionText = requestDetail.getDosageText();
medicationRequest.addDosageInstruction(new Dosage().setText(dosageInstructionText == null || dosageInstructionText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageInstructionText).setPatientInstruction(requestDetail.getDosageInstructions()));
return medicationRequest;
}
use of org.hl7.fhir.r5.model.IdType in project gpconnect-demonstrator by nhsconnect.
the class OrganizationResourceProvider method convertOrganizatonDetailsListToOrganizationList.
private List<Organization> convertOrganizatonDetailsListToOrganizationList(List<OrganizationDetails> organizationDetails) {
Map<Long, Organization> map = new HashMap<>();
for (OrganizationDetails organizationDetail : organizationDetails) {
// Changed key to be logical id rather than ods code since can have > 1 org per ods code
// for 1.2.2
Long mapKey = organizationDetail.getId();
if (map.containsKey(mapKey)) {
continue;
}
Identifier identifier = new Identifier().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(organizationDetail.getOrgCode());
Organization organization = new Organization().setName(organizationDetail.getOrgName()).addIdentifier(identifier);
String resourceId = String.valueOf(organizationDetail.getId());
String versionId = String.valueOf(organizationDetail.getLastUpdated().getTime());
String resourceType = organization.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
organization.setId(id);
organization.getMeta().setVersionId(versionId);
organization.getMeta().setLastUpdated(organizationDetail.getLastUpdated());
organization.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
organization = addAdditionalProperties(organization);
map.put(mapKey, organization);
}
return new ArrayList<>(map.values());
}
use of org.hl7.fhir.r5.model.IdType in project gpconnect-demonstrator by nhsconnect.
the class SlotResourceProvider method slotDetailToSlotResourceConverter.
private Slot slotDetailToSlotResourceConverter(SlotDetail slotDetail) {
Slot slot = new Slot();
Date lastUpdated = slotDetail.getLastUpdated() == null ? new Date() : slotDetail.getLastUpdated();
String resourceId = String.valueOf(slotDetail.getId());
String versionId = String.valueOf(lastUpdated.getTime());
IdType id = new IdType(resourceId);
slot.setId(id);
slot.getMeta().setVersionId(versionId);
slot.getMeta().addProfile(SystemURL.SD_GPC_SLOT);
slot.setSchedule(new Reference("Schedule/" + slotDetail.getScheduleReference()));
slot.setStart(slotDetail.getStartDateTime());
slot.setEnd(slotDetail.getEndDateTime());
// #218 Date time formats
slot.getStartElement().setPrecision(TemporalPrecisionEnum.SECOND);
slot.getEndElement().setPrecision(TemporalPrecisionEnum.SECOND);
switch(slotDetail.getFreeBusyType().toLowerCase(Locale.UK)) {
case "free":
slot.setStatus(SlotStatus.FREE);
break;
default:
slot.setStatus(SlotStatus.BUSY);
break;
}
String deliveryChannelCode = slotDetail.getDeliveryChannelCode();
ArrayList<Extension> al = new ArrayList<>();
if (deliveryChannelCode != null && !deliveryChannelCode.trim().isEmpty()) {
Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeType(deliveryChannelCode));
al.add(deliveryChannelExtension);
}
slot.setExtension(al);
// 1.2.7 add slot type description as service type
slot.addServiceType(new CodeableConcept().setText(slotDetail.getTypeDisply()));
return slot;
}
use of org.hl7.fhir.r5.model.IdType in project gpconnect-demonstrator by nhsconnect.
the class SlotResourceProvider method getSlotById.
@Read()
public Slot getSlotById(@IdParam IdType slotId) {
SlotDetail slotDetail = slotSearch.findSlotByID(slotId.getIdPartAsLong());
if (slotDetail == null) {
OperationOutcome operationalOutcome = new OperationOutcome();
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No slot details found for ID: " + slotId.getIdPart());
throw new InternalErrorException("No slot details found for ID: " + slotId.getIdPart(), operationalOutcome);
}
return slotDetailToSlotResourceConverter(slotDetail);
}
use of org.hl7.fhir.r5.model.IdType in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProvider method read.
/**
* Adds support for the FHIR "read" operation, for {@link Patient}s. The {@link Read} annotation
* indicates that this method supports the read operation.
*
* <p>Read operations take a single parameter annotated with {@link IdParam}, and should return a
* single resource instance.
*
* @param patientId The read operation takes one parameter, which must be of type {@link IdType}
* and must be annotated with the {@link IdParam} annotation.
* @param requestDetails a {@link RequestDetails} containing the details of the request URL, used
* to parse out pagination values
* @return Returns a resource matching the specified {@link IdDt}, or <code>null</code> if none
* exists.
*/
@Read(version = false)
@Trace
public Patient read(@IdParam IdType patientId, RequestDetails requestDetails) {
if (patientId == null)
throw new IllegalArgumentException();
if (patientId.getVersionIdPartAsLong() != null)
throw new IllegalArgumentException();
String beneIdText = patientId.getIdPart();
if (beneIdText == null || beneIdText.trim().isEmpty())
throw new IllegalArgumentException();
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
Operation operation = new Operation(Operation.Endpoint.V1_PATIENT);
operation.setOption("by", "id");
// there is another method with exclude list: requestHeader.getNVPairs(<excludeHeaders>)
requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
operation.publishOperationName();
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Beneficiary> criteria = builder.createQuery(Beneficiary.class);
Root<Beneficiary> root = criteria.from(Beneficiary.class);
root.fetch(Beneficiary_.skippedRifRecords, JoinType.LEFT);
if (requestHeader.isHICNinIncludeIdentifiers())
root.fetch(Beneficiary_.beneficiaryHistories, JoinType.LEFT);
if (requestHeader.isMBIinIncludeIdentifiers())
root.fetch(Beneficiary_.medicareBeneficiaryIdHistories, JoinType.LEFT);
criteria.select(root);
criteria.where(builder.equal(root.get(Beneficiary_.beneficiaryId), beneIdText));
Beneficiary beneficiary = null;
Long beneByIdQueryNanoSeconds = null;
Timer.Context timerBeneQuery = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_by_id")).time();
try {
beneficiary = entityManager.createQuery(criteria).getSingleResult();
} catch (NoResultException e) {
throw new ResourceNotFoundException(patientId);
} finally {
beneByIdQueryNanoSeconds = timerBeneQuery.stop();
TransformerUtils.recordQueryInMdc(String.format("bene_by_id.include_%s", String.join("_", (List<String>) requestHeader.getValue(HEADER_NAME_INCLUDE_IDENTIFIERS))), beneByIdQueryNanoSeconds, beneficiary == null ? 0 : 1);
}
// Null out the unhashed HICNs if we're not supposed to be returning them
if (!requestHeader.isHICNinIncludeIdentifiers()) {
beneficiary.setHicnUnhashed(Optional.empty());
}
// Null out the unhashed MBIs if we're not supposed to be returning
if (!requestHeader.isMBIinIncludeIdentifiers()) {
beneficiary.setMedicareBeneficiaryId(Optional.empty());
}
// Add bene_id to MDC logs
TransformerUtils.logBeneIdToMdc(Arrays.asList(beneIdText));
Patient patient = BeneficiaryTransformer.transform(metricRegistry, beneficiary, requestHeader);
return patient;
}
Aggregations