use of org.hl7.fhir.dstu3.model.Patient 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");
}
}
use of org.hl7.fhir.dstu3.model.Patient in project loinc2hpo by monarch-initiative.
the class FhirResourceRetriever method retrieveObservationFromServer.
/**
* @TODO: implement it
* retrieve a patient's observations from FHIR server
* @param patient
* @return
*/
public static List<Observation> retrieveObservationFromServer(Patient patient) {
List<Observation> observationList = new ArrayList<>();
String id = patient.getId();
if (id != null) {
Bundle observationBundle = client.search().forResource(Observation.class).where(new ReferenceClientParam("subject").hasId(id)).prettyPrint().returnBundle(Bundle.class).execute();
while (true) {
observationBundle.getEntry().forEach(p -> observationList.add((Observation) p.getResource()));
if (observationBundle.getLink(IBaseBundle.LINK_NEXT) != null) {
observationBundle = client.loadPage().next(observationBundle).execute();
} else {
break;
}
}
}
return observationList;
}
use of org.hl7.fhir.dstu3.model.Patient in project syndesis-qe by syndesisio.
the class FhirUtils method insertPatientToFhir.
// entity PATIENT:
public String insertPatientToFhir(MyPatientSpecification ps) {
Patient patient = new Patient();
patient.addName().setFamily(ps.getFamilyName()).addGiven(ps.getGivenName());
checkConnection();
MethodOutcome outcome = fhirClient.createPatient(patient);
lastPatientId = this.extractSimpleId(outcome.getId().getValue(), FhirEntity.PATIENT.getName());
log.info("Patient *{}* has been inserted with id:*{}*", ps.toString(), lastPatientId);
return lastPatientId;
}
use of org.hl7.fhir.dstu3.model.Patient 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;
}
use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method registerPatientResourceConverterToPatientDetail.
private PatientDetails registerPatientResourceConverterToPatientDetail(Patient patientResource) {
PatientDetails patientDetails = new PatientDetails();
HumanName name = patientResource.getNameFirstRep();
String givenNames = name.getGiven().stream().map(n -> n.getValue()).collect(Collectors.joining(","));
patientDetails.setForename(givenNames);
patientDetails.setSurname(name.getFamily());
patientDetails.setDateOfBirth(patientResource.getBirthDate());
if (patientResource.getGender() != null) {
patientDetails.setGender(patientResource.getGender().toString());
}
patientDetails.setNhsNumber(patientResource.getIdentifierFirstRep().getValue());
DateTimeType deceased = (DateTimeType) patientResource.getDeceased();
if (deceased != null) {
try {
patientDetails.setDeceased((deceased.getValue()));
} catch (ClassCastException cce) {
throwUnprocessableEntity422_InvalidResourceException("The multiple deceased property is expected to be a datetime");
}
}
// activate patient as temporary
patientDetails.setRegistrationStartDateTime(new Date());
// patientDetails.setRegistrationEndDateTime(getRegistrationEndDate(patientResource));
patientDetails.setRegistrationStatus(ACTIVE_REGISTRATION_STATUS);
patientDetails.setRegistrationType(TEMPORARY_RESIDENT_REGISTRATION_TYPE);
updateAddressAndTelecom(patientResource, patientDetails);
// set some standard values for defaults, ensure managing org is always returned
// added at 1.2.2 7 is A20047 the default GP Practice
patientDetails.setManagingOrganization("7");
return patientDetails;
}
Aggregations