Search in sources :

Example 16 with Patient

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

the class PatientJwtValidator method getPatientResourceBinding.

private ResourceBinding getPatientResourceBinding(IRestfulServerDefaults defaultServer) {
    ResourceBinding resourceBinding = null;
    if (defaultServer instanceof RestfulServer) {
        RestfulServer restfulServer = (RestfulServer) defaultServer;
        // if we get more than one Patient binding then return null
        resourceBinding = restfulServer.getResourceBindings().stream().filter(currentResourceBinding -> "Patient".equalsIgnoreCase(currentResourceBinding.getResourceName())).collect(Collectors.reducing((a, b) -> null)).orElse(null);
    }
    return resourceBinding;
}
Also used : BaseMethodBinding(ca.uhn.fhir.rest.server.method.BaseMethodBinding) IParameter(ca.uhn.fhir.rest.server.method.IParameter) IdDt(ca.uhn.fhir.model.primitive.IdDt) RestfulServer(ca.uhn.fhir.rest.server.RestfulServer) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ResourceBinding(ca.uhn.fhir.rest.server.ResourceBinding) Autowired(org.springframework.beans.factory.annotation.Autowired) ParameterUtil(ca.uhn.fhir.rest.param.ParameterUtil) Collectors(java.util.stream.Collectors) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) Value(org.springframework.beans.factory.annotation.Value) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) RuleBuilder(ca.uhn.fhir.rest.server.interceptor.auth.RuleBuilder) List(java.util.List) Component(org.springframework.stereotype.Component) RequestTypeEnum(ca.uhn.fhir.rest.api.RequestTypeEnum) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) PatientResourceProvider(uk.gov.hscic.patient.PatientResourceProvider) IRestfulServerDefaults(ca.uhn.fhir.rest.server.IRestfulServerDefaults) IAuthRule(ca.uhn.fhir.rest.server.interceptor.auth.IAuthRule) SystemCode(uk.gov.hscic.SystemCode) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) AuthorizationInterceptor(ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor) RestfulServer(ca.uhn.fhir.rest.server.RestfulServer) ResourceBinding(ca.uhn.fhir.rest.server.ResourceBinding)

Example 17 with Patient

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

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

the class WarningCodeExtHelper method addWarningCodeExtensions.

/**
 * confidential items are per record but the other two are global values per
 * patient
 *
 * @param warningCodes
 * @param list
 * @param patientRepository
 * @param medicationStatementRepository
 * @param structuredAllergySearch
 */
public static void addWarningCodeExtensions(Set<String> warningCodes, ListResource list, PatientRepository patientRepository, MedicationStatementRepository medicationStatementRepository, StructuredAllergySearch structuredAllergySearch) {
    String NHS = list.getSubject().getIdentifier().getValue();
    PatientEntity patientEntity = patientRepository.findByNhsNumber(NHS);
    List<MedicationStatementEntity> medicationStatements = medicationStatementRepository.findByPatientId(patientEntity.getId());
    for (MedicationStatementEntity medicationStatement : medicationStatements) {
        setFlags(medicationStatement.getWarningCode());
    }
    List<StructuredAllergyIntoleranceEntity> allergies = structuredAllergySearch.getAllergyIntollerence(NHS);
    for (StructuredAllergyIntoleranceEntity allergy : allergies) {
        setFlags(allergy.getWarningCode());
    }
    // check medication_statements for either of the global flags
    if (dataInTransit) {
        warningCodes.add(DATA_IN_TRANSIT);
    }
    if (dataAwaitingFiling) {
        warningCodes.add(DATA_AWAITING_FILING);
    }
    StringBuilder sb = new StringBuilder();
    warningCodes.forEach(warningCode -> {
        if (warningCode != null) {
            String warningCodeDisplay = "";
            Annotation annotation = new Annotation();
            switch(warningCode) {
                case CONFIDENTIAL_ITEMS:
                    warningCodeDisplay = "Confidential Items";
                    // #266
                    annotation.setText(CONFIDENTIAL_ITEMS_NOTE);
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                case DATA_IN_TRANSIT:
                    warningCodeDisplay = "Data in Transit";
                    Calendar cal = new GregorianCalendar();
                    Date now = new Date();
                    cal.setTime(now);
                    // a week before now
                    cal.add(Calendar.DAY_OF_YEAR, -7);
                    // #266
                    annotation.setText(String.format(DATA_IN_TRANSIT_NOTE, DATE_FORMAT.format(cal.getTime())));
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                case DATA_AWAITING_FILING:
                    warningCodeDisplay = "Data Awaiting Filing";
                    // #266
                    annotation.setText(DATA_AWAITING_FILING_NOTE);
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                default:
                    break;
            }
            // #182
            Extension warningExt = new Extension(SystemURL.WARNING_CODE, new CodeType(warningCode));
            list.addExtension(warningExt);
        }
    });
    // cardinality of note 0..1 #266
    if (sb.length() > 0) {
        Annotation annotation = null;
        if (list.getNote().size() > 0) {
            annotation = list.getNote().get(0);
            annotation.setText(annotation.getText());
            annotation.setText(annotation.getText() + sb.toString());
        } else {
            annotation = new Annotation();
            list.addNote(annotation);
            annotation.setText(sb.toString().replaceFirst("^\r\n", ""));
        }
    }
}
Also used : StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Annotation(org.hl7.fhir.dstu3.model.Annotation) Date(java.util.Date) PatientEntity(uk.gov.hscic.patient.details.PatientEntity) MedicationStatementEntity(uk.gov.hscic.medication.statement.MedicationStatementEntity) Extension(org.hl7.fhir.dstu3.model.Extension) CodeType(org.hl7.fhir.dstu3.model.CodeType)

Example 19 with Patient

use of org.hl7.fhir.dstu3.model.Patient in project bunsen by cerner.

the class ValueSetUdfsTest method setUp.

/**
 * Sets up Spark and loads test value sets.
 */
@BeforeClass
public static void setUp() throws IOException {
    // Create a local spark session using an in-memory metastore.
    // We must also use Hive and set the partition mode to non-strict to
    // support dynamic partitions.
    spark = SparkSession.builder().master("local[2]").appName("UdfsTest").enableHiveSupport().config("javax.jdo.option.ConnectionURL", "jdbc:derby:memory:metastore_db;create=true").config("hive.exec.dynamic.partition.mode", "nonstrict").config("spark.sql.warehouse.dir", Files.createTempDirectory("spark_warehouse").toString()).getOrCreate();
    spark.sql("create database " + ConceptMaps.MAPPING_DATABASE);
    Hierarchies withLoinc = Loinc.withLoincHierarchy(spark, Hierarchies.getEmpty(spark), "src/test/resources/LOINC_HIERARCHY_SAMPLE.CSV", "2.56");
    Hierarchies withLoincAndSnomed = Snomed.withRelationships(spark, withLoinc, "src/test/resources/SNOMED_RELATIONSHIP_SAMPLE.TXT", "20160901");
    ValueSets withGender = ValueSets.getEmpty(spark).withValueSetsFromDirectory("src/test/resources/xml/valuesets");
    BroadcastableValueSets valueSets = BroadcastableValueSets.newBuilder().addCode("bp", Loinc.LOINC_CODE_SYSTEM_URI, "8462-4").addCode("albumin", Loinc.LOINC_CODE_SYSTEM_URI, "14959-1").addReference("married", "urn:cerner:bunsen:valueset:married_maritalstatus").addDescendantsOf("leukocytes", Loinc.LOINC_CODE_SYSTEM_URI, "LP14419-3", Loinc.LOINC_HIERARCHY_URI).addDescendantsOf("diabetes", Snomed.SNOMED_CODE_SYSTEM_URI, "73211009", Snomed.SNOMED_HIERARCHY_URI).addDescendantsOf("blood_disorder", Snomed.SNOMED_CODE_SYSTEM_URI, "266992002", Snomed.SNOMED_HIERARCHY_URI).addDescendantsOf("disorder_history", Snomed.SNOMED_CODE_SYSTEM_URI, "312850006", Snomed.SNOMED_HIERARCHY_URI).build(spark, withGender, withLoincAndSnomed);
    ValueSetUdfs.pushUdf(spark, valueSets);
    Dataset<Observation> loincObservations = spark.createDataset(ImmutableList.of(// "is a" LP14419-3
    observation("leukocytes", "5821-4"), // Blood pressure
    observation("bp", "8462-4")), encoders.of(Observation.class));
    loincObservations.createOrReplaceTempView("test_loinc_obs");
    // Conditions include history of anemia, which includes a cycling ancestor
    // in our test data. This ensures that can be loaded correctly.
    Dataset<Condition> conditions = spark.createDataset(ImmutableList.of(// "is a" 73211009 (diabetes)
    condition("diabetes", "44054006"), // 312850006 (history of disorder)
    condition("history_of_anemia", "275538002")), encoders.of(Condition.class));
    conditions.createOrReplaceTempView("test_snomed_cond");
    Dataset<Patient> patients = spark.createDataset(ImmutableList.of(patient("married", "M"), patient("unmarried", "U")), encoders.of(Patient.class));
    patients.createOrReplaceTempView("test_valueset_patient");
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) Hierarchies(com.cerner.bunsen.codes.Hierarchies) Observation(org.hl7.fhir.dstu3.model.Observation) BroadcastableValueSets(com.cerner.bunsen.codes.broadcast.BroadcastableValueSets) Patient(org.hl7.fhir.dstu3.model.Patient) BroadcastableValueSets(com.cerner.bunsen.codes.broadcast.BroadcastableValueSets) ValueSets(com.cerner.bunsen.codes.ValueSets) BeforeClass(org.junit.BeforeClass)

Example 20 with Patient

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

the class ObservationDownloader method retrievePatient.

static List<Patient> retrievePatient(String given, String family) {
    List<Patient> patients = new ArrayList<>();
    Bundle bundle = client.search().forResource(Patient.class).where(new StringClientParam("given").matches().value(given)).where(new StringClientParam("family").matches().value(family)).prettyPrint().returnBundle(Bundle.class).execute();
    while (true) {
        for (Bundle.BundleEntryComponent bundleEntryComponent : bundle.getEntry()) {
            Patient patient = (Patient) bundleEntryComponent.getResource();
            patients.add(patient);
        }
        if (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
            bundle = client.loadPage().next(bundle).execute();
        } else {
            break;
        }
    }
    return patients;
}
Also used : StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)8 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)5 Extension (org.hl7.fhir.dstu3.model.Extension)5 IdDt (ca.uhn.fhir.model.primitive.IdDt)4 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 Date (java.util.Date)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 AdministrativeGender (org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender)4 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)3 Search (ca.uhn.fhir.rest.annotation.Search)3 Calendar (java.util.Calendar)3 Collectors (java.util.stream.Collectors)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)3 PatientDetails (uk.gov.hscic.model.patient.PatientDetails)3