Search in sources :

Example 21 with Coding

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

the class MedicationDispenseResourceProvider method getMedicationDispensesForPatientId.

@Search
public List<MedicationDispense> getMedicationDispensesForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationDispense> medicationDispenses = new ArrayList<>();
    List<MedicationDispenseDetail> medicationDispenseDetailList = medicationDispenseSearch.findMedicationDispenseForPatient(Long.parseLong(patientId));
    if (medicationDispenseDetailList != null && !medicationDispenseDetailList.isEmpty()) {
        for (MedicationDispenseDetail medicationDispenseDetail : medicationDispenseDetailList) {
            MedicationDispense medicationDispense = new MedicationDispense();
            medicationDispense.setId(String.valueOf(medicationDispenseDetail.getId()));
            medicationDispense.getMeta().setLastUpdated(medicationDispenseDetail.getLastUpdated());
            medicationDispense.getMeta().setVersionId(String.valueOf(medicationDispenseDetail.getLastUpdated().getTime()));
            switch(medicationDispenseDetail.getStatus().toLowerCase(Locale.UK)) {
                case "completed":
                    medicationDispense.setStatus(MedicationDispenseStatus.COMPLETED);
                    break;
                case "entered_in_error":
                    medicationDispense.setStatus(MedicationDispenseStatus.ENTEREDINERROR);
                    break;
                case "in_progress":
                    medicationDispense.setStatus(MedicationDispenseStatus.INPROGRESS);
                    break;
                case "on_hold":
                    medicationDispense.setStatus(MedicationDispenseStatus.ONHOLD);
                    break;
                case "stopped":
                    medicationDispense.setStatus(MedicationDispenseStatus.STOPPED);
                    break;
            }
            medicationDispense.setSubject(new Reference("Patient/" + patientId));
            medicationDispense.setAuthorizingPrescription(Collections.singletonList(new Reference("MedicationOrder/" + medicationDispenseDetail.getMedicationOrderId())));
            Medication medication = new Medication();
            Coding coding = new Coding();
            coding.setCode(String.valueOf(medicationDispenseDetail.getMedicationId()));
            coding.setDisplay(medicationDispenseDetail.getMedicationName());
            CodeableConcept codeableConcept = new CodeableConcept();
            codeableConcept.setCoding(Collections.singletonList(coding));
            medication.setCode(codeableConcept);
            medicationDispense.addDosageInstruction().setText(medicationDispenseDetail.getDosageText());
            medicationDispenses.add(medicationDispense);
        }
    }
    return medicationDispenses;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Medication(org.hl7.fhir.dstu3.model.Medication) MedicationDispenseDetail(uk.gov.hscic.model.medication.MedicationDispenseDetail) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) MedicationDispenseSearch(uk.gov.hscic.medication.dispense.MedicationDispenseSearch) Search(ca.uhn.fhir.rest.annotation.Search)

Example 22 with Coding

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

the class OrganizationResourceProvider method addAdditionalProperties.

// Adding in additional properties manually for now so we can test in the
// Test Suite
private Organization addAdditionalProperties(Organization organization) {
    Coding orgTypeCode = new Coding();
    orgTypeCode.setCode("dept");
    orgTypeCode.setDisplay("Hospital Department");
    orgTypeCode.setSystem(SystemURL.VS_CC_ORGANISATION_TYPE);
    organization.addTelecom(getValidTelecom());
    organization.addAddress(getValidAddress());
    // organization.addContact(getValidContact());
    CodeableConcept orgType = new CodeableConcept();
    orgType.addCoding(orgTypeCode);
    organization.addType(orgType);
    organization.addExtension().setUrl(SystemURL.SD_EXTENSION_CC_MAIN_LOCATION);
    return organization;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 23 with Coding

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

the class PatientResourceProvider method patientDetailsToMinimalPatient.

private Patient patientDetailsToMinimalPatient(PatientDetails patientDetails) throws FHIRException {
    Patient patient = new Patient();
    Date lastUpdated = patientDetails.getLastUpdated() == null ? new Date() : patientDetails.getLastUpdated();
    String resourceId = String.valueOf(patientDetails.getId());
    String versionId = String.valueOf(lastUpdated.getTime());
    String resourceType = patient.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    patient.setId(id);
    patient.getMeta().setVersionId(versionId);
    patient.getMeta().setLastUpdated(lastUpdated);
    patient.getMeta().addProfile(SystemURL.SD_GPC_PATIENT);
    Identifier patientNhsNumber = new Identifier().setSystem(SystemURL.ID_NHS_NUMBER).setValue(patientDetails.getNhsNumber());
    Extension extension = createCodingExtension("01", "Number present and verified", SystemURL.CS_CC_NHS_NUMBER_VERIF, SystemURL.SD_CC_EXT_NHS_NUMBER_VERIF);
    patientNhsNumber.addExtension(extension);
    patient.addIdentifier(patientNhsNumber);
    patient.setBirthDate(patientDetails.getDateOfBirth());
    String gender = patientDetails.getGender();
    if (gender != null) {
        patient.setGender(AdministrativeGender.fromCode(gender.toLowerCase(Locale.UK)));
    }
    Date registrationEndDateTime = patientDetails.getRegistrationEndDateTime();
    Date registrationStartDateTime = patientDetails.getRegistrationStartDateTime();
    Extension regDetailsExtension = new Extension(SystemURL.SD_EXTENSION_CC_REG_DETAILS);
    Period registrationPeriod = new Period().setStart(registrationStartDateTime).setEnd(registrationEndDateTime);
    Extension regPeriodExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_PERIOD, registrationPeriod);
    regDetailsExtension.addExtension(regPeriodExt);
    String registrationStatusValue = patientDetails.getRegistrationStatus();
    patient.setActive(ACTIVE_REGISTRATION_STATUS.equals(registrationStatusValue) || null == registrationStatusValue);
    String registrationTypeValue = patientDetails.getRegistrationType();
    if (registrationTypeValue != null) {
        Coding regTypeCode = new Coding();
        regTypeCode.setCode(registrationTypeValue);
        // Should always be Temporary
        regTypeCode.setDisplay("Temporary");
        regTypeCode.setSystem(SystemURL.CS_REGISTRATION_TYPE);
        CodeableConcept regTypeConcept = new CodeableConcept();
        regTypeConcept.addCoding(regTypeCode);
        Extension regTypeExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_TYPE, regTypeConcept);
        regDetailsExtension.addExtension(regTypeExt);
    }
    patient.addExtension(regDetailsExtension);
    String maritalStatus = patientDetails.getMaritalStatus();
    if (maritalStatus != null) {
        CodeableConcept marital = new CodeableConcept();
        Coding maritalCoding = new Coding();
        maritalCoding.setSystem(SystemURL.VS_CC_MARITAL_STATUS);
        maritalCoding.setCode(patientDetails.getMaritalStatus());
        maritalCoding.setDisplay("Married");
        marital.addCoding(maritalCoding);
        patient.setMaritalStatus(marital);
    }
    patient.setMultipleBirth(patientDetails.isMultipleBirth());
    if (patientDetails.isDeceased()) {
        DateTimeType decesed = new DateTimeType(patientDetails.getDeceased());
        patient.setDeceased(decesed);
    }
    return patient;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Patient(org.hl7.fhir.dstu3.model.Patient) Period(org.hl7.fhir.dstu3.model.Period) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 24 with Coding

use of org.hl7.fhir.r4.model.Coding in project loinc2hpo by monarch-initiative.

the class ObservationDtu3 method getOutcome.

@Override
public Optional<Outcome> getOutcome() {
    if (observation.hasInterpretation()) {
        List<String> codes = this.observation.getInterpretation().getCoding().stream().map(Coding::getCode).distinct().collect(Collectors.toList());
        if (codes.size() > 1) {
            LOGGER.error("Multiple interpretation codes returned");
            return Optional.empty();
        }
        ShortCode code = ShortCode.fromShortCode(codes.get(0));
        Outcome outcome = getOutcome(code, observation);
        return Optional.of(outcome);
    } else if (observation.hasValueCodeableConcept()) {
        return getOutcomeFromCodedValue();
    } else if (observation.hasValueQuantity()) {
        return getOutcomeFromValueQuantity();
    } else {
        LOGGER.error("Unable to handle observation {}", observation);
        return Optional.empty();
    }
}
Also used : ShortCode(org.monarchinitiative.loinc2hpocore.codesystems.ShortCode) Coding(org.hl7.fhir.dstu3.model.Coding) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome)

Example 25 with Coding

use of org.hl7.fhir.r4.model.Coding in project loinc2hpo by monarch-initiative.

the class ObservationDtu3 method getOutcomeFromCodedValue.

Optional<Outcome> getOutcomeFromCodedValue() {
    CodeableConcept codeableConcept = this.observation.getValueCodeableConcept();
    if (codeableConcept == null) {
        // should never happen
        LOGGER.error("Codable concept null in getOutcomeFromCodedValue");
    }
    List<Coding> codings = codeableConcept != null ? codeableConcept.getCoding() : List.of();
    for (Coding coding : codings) {
        String code = coding.getCode();
        String system = coding.getSystem();
        String display = coding.getDisplay();
        String outcomeString = code + ":" + system + ":" + display;
        Outcome outcome = Outcome.nominal(outcomeString);
        return Optional.of(outcome);
    }
    return Optional.empty();
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) Outcome(org.monarchinitiative.loinc2hpocore.codesystems.Outcome) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Aggregations

Coding (org.hl7.fhir.dstu3.model.Coding)16 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)13 IdType (org.hl7.fhir.dstu3.model.IdType)5 Reference (org.hl7.fhir.dstu3.model.Reference)5 Extension (org.hl7.fhir.dstu3.model.Extension)4 Outcome (org.monarchinitiative.loinc2hpocore.codesystems.Outcome)4 Identifier (org.hl7.fhir.dstu3.model.Identifier)3 Location (org.hl7.fhir.dstu3.model.Location)3 Period (org.hl7.fhir.dstu3.model.Period)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Search (ca.uhn.fhir.rest.annotation.Search)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Collectors (java.util.stream.Collectors)2 HumanName (org.hl7.fhir.dstu3.model.HumanName)2 OperationOutcomeIssueComponent (org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)2 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)2 Schedule (org.hl7.fhir.dstu3.model.Schedule)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1