Search in sources :

Example 11 with IdType

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;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 12 with IdType

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());
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Identifier(org.hl7.fhir.dstu3.model.Identifier) HashMap(java.util.HashMap) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ArrayList(java.util.ArrayList) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 13 with IdType

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;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) CodeType(org.hl7.fhir.dstu3.model.CodeType) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 14 with IdType

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);
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail) Read(ca.uhn.fhir.rest.annotation.Read)

Example 15 with IdType

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Patient(org.hl7.fhir.dstu3.model.Patient) Operation(gov.cms.bfd.server.war.Operation) NoResultException(javax.persistence.NoResultException) Timer(com.codahale.metrics.Timer) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Read(ca.uhn.fhir.rest.annotation.Read) Trace(com.newrelic.api.agent.Trace)

Aggregations

Test (org.junit.Test)240 IdType (org.hl7.fhir.r4.model.IdType)224 IdType (org.hl7.fhir.dstu3.model.IdType)206 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)87 Test (org.junit.jupiter.api.Test)68 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)50 Date (java.util.Date)44 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)43 Bundle (org.hl7.fhir.r4.model.Bundle)40 ArrayList (java.util.ArrayList)38 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)36 Coding (org.hl7.fhir.r4.model.Coding)34 Resource (org.hl7.fhir.r4.model.Resource)33 Provenance (org.hl7.fhir.r4.model.Provenance)32 Reference (org.hl7.fhir.dstu3.model.Reference)30 FHIRException (org.hl7.fhir.exceptions.FHIRException)30 List (java.util.List)27 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)27 Bundle (org.hl7.fhir.dstu3.model.Bundle)25 StringType (org.hl7.fhir.r4.model.StringType)25