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;
}
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;
}
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", ""));
}
}
}
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");
}
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;
}
Aggregations