Search in sources :

Example 6 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier in project gpconnect-demonstrator by nhsconnect.

the class ScheduleResourceProvider method scheduleDetailToScheduleResourceConverter.

private Schedule scheduleDetailToScheduleResourceConverter(ScheduleDetail scheduleDetail) {
    Schedule schedule = new Schedule();
    String resourceId = String.valueOf(scheduleDetail.getId());
    String versionId = String.valueOf(scheduleDetail.getLastUpdated().getTime());
    String resourceType = schedule.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    schedule.setId(id);
    schedule.getMeta().setVersionId(versionId);
    schedule.getMeta().setLastUpdated(scheduleDetail.getLastUpdated());
    if (scheduleDetail.getPractitionerId() != null) {
        schedule.addActor(new Reference("Practitioner/" + scheduleDetail.getPractitionerId()));
    }
    if (scheduleDetail.getPractitionerRoleCode() != null) {
        Coding roleCoding = new Coding(SystemURL.VS_GPC_PRACTITIONER_ROLE, scheduleDetail.getPractitionerRoleCode(), scheduleDetail.getPractitionerRoleDisplay());
        Extension practitionerRoleExtension = new Extension(SystemURL.SD_EXTENSION_GPC_PRACTITIONER_ROLE, new CodeableConcept().addCoding(roleCoding));
        schedule.addExtension(practitionerRoleExtension);
    }
    // # 194
    // Identifier identifier = new Identifier();
    // identifier.setSystem(SystemURL.ID_GPC_SCHEDULE_IDENTIFIER);
    // identifier.setValue(scheduleDetail.getIdentifier());
    // schedule.addIdentifier(identifier);
    Coding coding = new Coding().setSystem(SystemURL.HL7_VS_C80_PRACTICE_CODES).setCode(scheduleDetail.getTypeCode()).setDisplay(scheduleDetail.getTypeDescription());
    CodeableConcept codableConcept = new CodeableConcept().addCoding(coding);
    codableConcept.setText(scheduleDetail.getTypeDescription());
    schedule.addActor(new Reference("Location/" + scheduleDetail.getLocationId()));
    Period period = new Period();
    period.setStart(scheduleDetail.getStartDateTime());
    period.setEnd(scheduleDetail.getEndDateTime());
    schedule.setPlanningHorizon(period);
    // 1.2.7 remove comment
    // schedule.setComment(scheduleDetail.getComment());
    // 1.2.7 add schedule type description as service category
    schedule.setServiceCategory(new CodeableConcept().setText(scheduleDetail.getTypeDescription()));
    return schedule;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) Schedule(org.hl7.fhir.dstu3.model.Schedule) Period(org.hl7.fhir.dstu3.model.Period) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 7 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier 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 8 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier 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 9 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier in project loinc2hpo by monarch-initiative.

the class FhirResourceRetriever method retrievePatientFromServer.

/**
 * Retrieve a patient from the reference field of an observation
 * @param subject
 * @return
 */
public static Patient retrievePatientFromServer(Reference subject) throws SubjectNotFoundException, AmbiguousSubjectException {
    List<Patient> patients = new ArrayList<>();
    if (subject.hasReference()) {
        String ref = subject.getReference();
        if (!ref.startsWith(BASEURL) && ref.startsWith("Patient")) {
            ref = BASEURL + "/" + ref;
        }
        Bundle patientBundle = client.search().byUrl(ref).returnBundle(Bundle.class).execute();
        while (true) {
            patientBundle.getEntry().forEach(p -> patients.add((Patient) p.getResource()));
            if (patientBundle.getLink(IBaseBundle.LINK_NEXT) != null) {
                patientBundle = client.loadPage().next(patientBundle).execute();
            } else {
                break;
            }
        }
    } else if (subject.hasIdentifier()) {
        Identifier identifier = subject.getIdentifier();
    // TODO: find patient through the identifier
    }
    if (patients.size() == 1) {
        return patients.iterator().next();
    } else if (patients.isEmpty()) {
        throw new SubjectNotFoundException("Expect one subject, but found none");
    } else {
        throw new AmbiguousSubjectException("Except one subject, but found multiple");
    }
}
Also used : SubjectNotFoundException(org.monarchinitiative.loinc2hpo.exception.SubjectNotFoundException) AmbiguousSubjectException(org.monarchinitiative.loinc2hpo.exception.AmbiguousSubjectException) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList)

Example 10 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier in project gpconnect-demonstrator by nhsconnect.

the class LocationResourceProvider method locationDetailsToLocation.

/**
 * convert locationDetails to fhir resource
 * @param locationDetails
 * @return Location resource
 */
private Location locationDetailsToLocation(LocationDetails locationDetails) {
    Location location = new Location();
    String resourceId = String.valueOf(locationDetails.getId());
    String versionId = String.valueOf(locationDetails.getLastUpdated().getTime());
    String resourceType = location.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    location.setId(id);
    location.getMeta().setVersionId(versionId);
    location.getMeta().setLastUpdated(locationDetails.getLastUpdated());
    location.getMeta().addProfile(SystemURL.SD_GPC_LOCATION);
    location.setName(locationDetails.getName());
    // #207 no site code
    // location.setIdentifier(Collections.singletonList(new Identifier().setSystem(SystemURL.ID_ODS_SITE_CODE).setValue(locationDetails.getSiteOdsCode())));
    // #246 remove type element
    // Coding locationCommTypeCode = new Coding();
    // locationCommTypeCode.setCode("COMM");
    // locationCommTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
    // locationCommTypeCode.setDisplay("Community Location");
    // 
    // Coding locationGachTypeCode = new Coding();
    // locationGachTypeCode.setCode("GACH");
    // locationGachTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
    // locationGachTypeCode.setDisplay("Hospitals; General Acute Care Hospital");
    // 
    // @SuppressWarnings("deprecation")
    // CodeableConcept locationType = new CodeableConcept();
    // locationType.addCoding(locationCommTypeCode);
    // locationType.addCoding(locationGachTypeCode);
    // location.setType(locationType);
    Organization orgz = FindOrganization(locationDetails.getOrgOdsCode());
    if (orgz != null) {
        Reference mngOrg = new Reference();
        mngOrg.setReference(orgz.getId());
        // #246 remove display element
        // mngOrg.setDisplay(orgz.getName());
        location.setManagingOrganization(mngOrg);
    }
    EnumSet<LocationStatus> statusList = EnumSet.allOf(LocationStatus.class);
    LocationStatus locationStatus = null;
    String status = locationDetails.getStatus();
    if (status != null) {
        for (LocationStatus statusItem : statusList) {
            if (statusItem.toCode().equalsIgnoreCase(status)) {
                locationStatus = statusItem;
                break;
            }
        }
    }
    location.setAddress(createAddress(locationDetails));
    location.setStatus(locationStatus);
    return location;
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Reference(org.hl7.fhir.dstu3.model.Reference) LocationStatus(org.hl7.fhir.dstu3.model.Location.LocationStatus) Location(org.hl7.fhir.dstu3.model.Location) IdType(org.hl7.fhir.dstu3.model.IdType)

Aggregations

IdType (org.hl7.fhir.dstu3.model.IdType)7 Identifier (org.hl7.fhir.dstu3.model.Identifier)7 ArrayList (java.util.ArrayList)5 Organization (org.hl7.fhir.dstu3.model.Organization)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)3 Period (org.hl7.fhir.dstu3.model.Period)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Search (ca.uhn.fhir.rest.annotation.Search)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)2 Location (org.hl7.fhir.dstu3.model.Location)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 IdDt (ca.uhn.fhir.model.primitive.IdDt)1 Count (ca.uhn.fhir.rest.annotation.Count)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1