Search in sources :

Example 11 with CodeableConcept

use of org.hl7.fhir.r4.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class AppointmentValidation method validateParticipantType.

/**
 * This method is effectively disabled since we dont check against value sets
 * This was experimental code that never worked correctly.
 * @param participantType
 * @return
 */
public Boolean validateParticipantType(CodeableConcept participantType) {
    Boolean hasCode = !participantType.isEmpty();
    Coding code = participantType.getCodingFirstRep();
    Boolean isValid = !hasCode;
    if (hasCode) {
        // isValid = valueSetValidator.validateCode(code);
        isValid = true;
        if (!isValid) {
            throwUnprocessableEntity422_InvalidResourceException(MessageFormat.format("Invalid Participant Type Code. Code: {0} [Display: {1}, System:{2}]", code.getCode(), code.getDisplay(), code.getSystem()));
        }
    }
    return isValid;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding)

Example 12 with CodeableConcept

use of org.hl7.fhir.r4.model.CodeableConcept in project bunsen by cerner.

the class ValueSetUdfsTest method codeable.

private static CodeableConcept codeable(String system, String value) {
    CodeableConcept concept = new CodeableConcept();
    concept.addCoding().setSystem(system).setCode(value);
    return concept;
}
Also used : CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 13 with CodeableConcept

use of org.hl7.fhir.r4.model.CodeableConcept 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)

Example 14 with CodeableConcept

use of org.hl7.fhir.r4.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class MedicationStatementResourceProvider method getMedicationStatementResource.

public MedicationStatement getMedicationStatementResource(MedicationStatementDetail statementDetail) {
    MedicationStatement medicationStatement = new MedicationStatement();
    medicationStatement.setId(statementDetail.getId().toString());
    List<Identifier> identifiers = new ArrayList<>();
    Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(statementDetail.getGuid());
    identifiers.add(identifier);
    medicationStatement.setIdentifier(identifiers);
    medicationStatement.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_STATEMENT));
    medicationStatement.addExtension(new Extension(SystemURL.SD_CC_EXT_MEDICATION_STATEMENT_LAST_ISSUE, new DateTimeType(statementDetail.getLastIssueDate(), TemporalPrecisionEnum.DAY)));
    if (statementDetail.getMedicationRequestPlanId() != null) {
        medicationStatement.addBasedOn(new Reference(new IdType("MedicationRequest", statementDetail.getMedicationRequestPlanId())));
    }
    try {
        medicationStatement.setStatus(MedicationStatementStatus.fromCode(statementDetail.getStatusCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    if (statementDetail.getMedicationId() != null) {
        medicationStatement.setMedication(new Reference(new IdType("Medication", statementDetail.getMedicationId())));
    }
    medicationStatement.setEffective(new Period().setStart(statementDetail.getStartDate()).setEnd(statementDetail.getEndDate()));
    medicationStatement.setDateAsserted(statementDetail.getDateAsserted());
    if (statementDetail.getPatientId() != null)
        medicationStatement.setSubject(new Reference(new IdType("Patient", statementDetail.getPatientId())));
    try {
        medicationStatement.setTaken(statementDetail.getTakenCode() != null ? MedicationStatementTaken.fromCode(statementDetail.getTakenCode()) : MedicationStatementTaken.UNK);
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    setReasonCodes(medicationStatement, statementDetail);
    setNotes(medicationStatement, statementDetail);
    String dosageText = statementDetail.getDosageText();
    medicationStatement.addDosage(new Dosage().setText(dosageText == null || dosageText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageText).setPatientInstruction(statementDetail.getDosagePatientInstruction()));
    String prescribingAgency = statementDetail.getPrescribingAgency();
    if (prescribingAgency != null && !prescribingAgency.trim().isEmpty()) {
        String prescribingAgencyDisplay = "";
        if (prescribingAgency.equalsIgnoreCase("prescribed-at-gp-practice")) {
            prescribingAgencyDisplay = "Prescribed at GP practice";
        } else if (prescribingAgency.equalsIgnoreCase("prescribed-by-another-organisation")) {
            prescribingAgencyDisplay = "Prescribed by another organisation";
        }
        Coding coding = new Coding(SystemURL.CS_CC_PRESCRIBING_AGENCY_STU3, prescribingAgency, prescribingAgencyDisplay);
        CodeableConcept codeableConcept = new CodeableConcept().addCoding(coding);
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_PRESCRIBING_AGENCY, codeableConcept));
    }
    // #281 1.2.5 add dosageLastChanged
    Date dosageLastChanged = statementDetail.getDosageLastChanged();
    if (dosageLastChanged != null) {
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_DOSAGE_LAST_CHANGED, new DateTimeType(dosageLastChanged)));
    }
    return medicationStatement;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) Date(java.util.Date)

Example 15 with CodeableConcept

use of org.hl7.fhir.r4.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method addWarningIssue.

/**
 * see
 * https://gpconnect-1-2-4.netlify.com/accessrecord_structured_development_version_compatibility.html
 * add an issue to the OperationOutcome to be returned in a successful
 * response bundle this is for forward compatibility as specified in 1.2.4
 *
 * @param param
 * @param paramPart
 * @param issueType
 * @param details lower level details to be added to the text element
 */
private void addWarningIssue(ParametersParameterComponent param, ParametersParameterComponent paramPart, IssueType issueType, String details) {
    if (operationOutcome == null) {
        createOperationOutcome();
    }
    OperationOutcomeIssueComponent issue = new OperationOutcomeIssueComponent();
    issue.setSeverity(OperationOutcome.IssueSeverity.WARNING);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setSystem(VS_GPC_ERROR_WARNING_CODE);
    switch(issueType) {
        case NOTSUPPORTED:
            issue.setCode(issueType);
            coding.setCode(SystemCode.NOT_IMPLEMENTED);
            coding.setDisplay("Not implemented");
            break;
        case REQUIRED:
            issue.setCode(issueType);
            coding.setCode(SystemCode.PARAMETER_NOT_FOUND);
            coding.setDisplay("Parameter not found");
            break;
        case INVALID:
            issue.setCode(issueType);
            coding.setCode(SystemCode.INVALID_PARAMETER);
            coding.setDisplay("Invalid Parameter");
            break;
    }
    codeableConcept.addCoding(coding);
    issue.setDetails(codeableConcept);
    String locus = paramPart != null ? "." + paramPart.getName() : "";
    issue.setDiagnostics(param.getName() + locus);
    if (details == null) {
        // mod to remove more informative text which was off spec
        codeableConcept.setText(param.getName() + locus + " is an unrecognised parameter");
    } else {
        codeableConcept.setText(details);
    }
    operationOutcome.addIssue(issue);
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)

Aggregations

CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)16 Coding (org.hl7.fhir.dstu3.model.Coding)12 Reference (org.hl7.fhir.dstu3.model.Reference)8 IdType (org.hl7.fhir.dstu3.model.IdType)5 ArrayList (java.util.ArrayList)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 Date (java.util.Date)3 Period (org.hl7.fhir.dstu3.model.Period)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Outcome (org.monarchinitiative.loinc2hpocore.codesystems.Outcome)3 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)3 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)2 ContactDetail (org.hl7.fhir.dstu3.model.ContactDetail)2 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)2 HumanName (org.hl7.fhir.dstu3.model.HumanName)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 Location (org.hl7.fhir.dstu3.model.Location)2 Narrative (org.hl7.fhir.dstu3.model.Narrative)2 OperationOutcomeIssueComponent (org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)2