use of org.hl7.fhir.dstu3.model.StringType in project gpconnect-demonstrator by nhsconnect.
the class LocationResourceProvider method createAddress.
/**
* Some of the assignments look rather odd but they are deliberate.
* They result from a change to spec to remove the state attribute from the address
* See the commit cd26528 by James Cox 6/3/18 see also OrganizationResourceProvider.getValidAddress
* @param locationDetails
* @return Address Resource
*/
private Address createAddress(LocationDetails locationDetails) {
Address address = new Address();
List<StringType> list = new LinkedList<>();
list.add(new StringType(locationDetails.getAddressLine()));
list.add(new StringType(locationDetails.getAddressCity()));
address.setLine(list);
address.setCity(locationDetails.getAddressDistrict());
address.setDistrict(locationDetails.getAddressState());
address.setPostalCode(locationDetails.getAddressPostalCode());
address.setCountry(locationDetails.getAddressCountry());
return address;
}
use of org.hl7.fhir.dstu3.model.StringType in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method createContact.
// patientDetailsToMinimalPatient
/**
* add a set of contact details into the patient record NB these are
* Contacts (related people etc) not contactpoints (telecoms)
*
* @param patient fhirResource object
*/
private void createContact(Patient patient) {
// relationships
Patient.ContactComponent contact = new ContactComponent();
for (String relationship : new String[] { "Emergency contact", "Next of kin", "Daughter" }) {
CodeableConcept crelationship = new CodeableConcept();
crelationship.setText(relationship);
contact.addRelationship(crelationship);
}
// contact address
Address address = new Address();
address.addLine("Trevelyan Square");
address.addLine("Boar Ln");
address.setPostalCode("LS1 6AE");
address.setType(AddressType.PHYSICAL);
address.setUse(AddressUse.HOME);
contact.setAddress(address);
// gender
contact.setGender(AdministrativeGender.FEMALE);
// telecom
ContactPoint telecom = new ContactPoint();
telecom.setSystem(ContactPointSystem.PHONE);
telecom.setUse(ContactPointUse.MOBILE);
telecom.setValue("07777123123");
contact.addTelecom(telecom);
// Name
HumanName name = new HumanName();
name.addGiven("Jane");
name.setFamily("Jackson");
List<StringType> prefixList = new ArrayList<>();
prefixList.add(new StringType("Miss"));
name.setPrefix(prefixList);
name.setText("JACKSON Jane (Miss)");
name.setUse(NameUse.OFFICIAL);
contact.setName(name);
patient.addContact(contact);
}
use of org.hl7.fhir.dstu3.model.StringType in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentDetailToAppointmentResourceConverter.
/**
* AppointmentDetail to fhir resource Appointment
*
* @param appointmentDetail
* @return Appointment Resource
*/
private Appointment appointmentDetailToAppointmentResourceConverter(AppointmentDetail appointmentDetail) {
Appointment appointment = new Appointment();
String appointmentId = String.valueOf(appointmentDetail.getId());
String versionId = String.valueOf(appointmentDetail.getLastUpdated().getTime());
String resourceType = appointment.getResourceType().toString();
IdType id = new IdType(resourceType, appointmentId, versionId);
appointment.setId(id);
appointment.getMeta().setVersionId(versionId);
appointment.getMeta().setLastUpdated(appointmentDetail.getLastUpdated());
appointment.getMeta().addProfile(SystemURL.SD_GPC_APPOINTMENT);
Extension extension = new Extension(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON, new StringType(appointmentDetail.getCancellationReason()));
appointment.addExtension(extension);
// #157 derive delivery channel from slot
List<Long> sids = appointmentDetail.getSlotIds();
ScheduleDetail scheduleDetail = null;
if (sids.size() > 0) {
// get the first slot but it should not matter because for multi slot appts the deliveryChannel is always the same
SlotDetail slotDetail = slotSearch.findSlotByID(sids.get(0));
String deliveryChannel = slotDetail.getDeliveryChannelCode();
if (deliveryChannel != null && !deliveryChannel.trim().isEmpty()) {
Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeType(deliveryChannel));
appointment.addExtension(deliveryChannelExtension);
}
scheduleDetail = scheduleSearch.findScheduleByID(slotDetail.getScheduleReference());
}
// practitioner role extension here
// lookup the practitioner
Long practitionerID = appointmentDetail.getPractitionerId();
if (practitionerID != null) {
// #195 we need to get this detail from the schedule not the practitioner table
if (scheduleDetail != null) {
Coding roleCoding = new Coding(SystemURL.VS_GPC_PRACTITIONER_ROLE, scheduleDetail.getPractitionerRoleCode(), scheduleDetail.getPractitionerRoleDisplay());
Extension practitionerRoleExtension = new Extension(SystemURL.SD_EXTENSION_GPC_PRACTITIONER_ROLE, new CodeableConcept().addCoding(roleCoding));
appointment.addExtension(practitionerRoleExtension);
}
}
switch(appointmentDetail.getStatus().toLowerCase(Locale.UK)) {
case "pending":
appointment.setStatus(AppointmentStatus.PENDING);
break;
case "booked":
appointment.setStatus(AppointmentStatus.BOOKED);
break;
case "arrived":
appointment.setStatus(AppointmentStatus.ARRIVED);
break;
case "fulfilled":
appointment.setStatus(AppointmentStatus.FULFILLED);
break;
case "cancelled":
appointment.setStatus(AppointmentStatus.CANCELLED);
break;
case "noshow":
appointment.setStatus(AppointmentStatus.NOSHOW);
break;
default:
appointment.setStatus(AppointmentStatus.PENDING);
break;
}
appointment.setStart(appointmentDetail.getStartDateTime());
appointment.setEnd(appointmentDetail.getEndDateTime());
// #218 Date time formats
appointment.getStartElement().setPrecision(TemporalPrecisionEnum.SECOND);
appointment.getEndElement().setPrecision(TemporalPrecisionEnum.SECOND);
List<Reference> slotResources = new ArrayList<>();
for (Long slotId : appointmentDetail.getSlotIds()) {
slotResources.add(new Reference("Slot/" + slotId));
}
appointment.setSlot(slotResources);
if (appointmentDetail.getPriority() != null) {
appointment.setPriority(appointmentDetail.getPriority());
}
appointment.setComment(appointmentDetail.getComment());
appointment.setDescription(appointmentDetail.getDescription());
appointment.addParticipant().setActor(new Reference("Patient/" + appointmentDetail.getPatientId())).setStatus(ParticipationStatus.ACCEPTED);
appointment.addParticipant().setActor(new Reference("Location/" + appointmentDetail.getLocationId())).setStatus(ParticipationStatus.ACCEPTED);
if (null != appointmentDetail.getPractitionerId()) {
appointment.addParticipant().setActor(new Reference("Practitioner/" + appointmentDetail.getPractitionerId())).setStatus(ParticipationStatus.ACCEPTED);
}
if (null != appointmentDetail.getCreated()) {
appointment.setCreated(appointmentDetail.getCreated());
}
if (null != appointmentDetail.getBookingOrganization()) {
// add extension with reference to contained item
String reference = "#1";
Reference orgRef = new Reference(reference);
Extension bookingOrgExt = new Extension(SystemURL.SD_CC_APPOINTMENT_BOOKINGORG, orgRef);
appointment.addExtension(bookingOrgExt);
BookingOrgDetail bookingOrgDetail = appointmentDetail.getBookingOrganization();
Organization bookingOrg = new Organization();
bookingOrg.setId(reference);
bookingOrg.getNameElement().setValue(bookingOrgDetail.getName());
// #198 org phone now persists usetype and system
ContactPoint orgTelecom = bookingOrg.getTelecomFirstRep();
orgTelecom.setValue(bookingOrgDetail.getTelephone());
try {
orgTelecom.setSystem(ContactPointSystem.fromCode(bookingOrgDetail.getSystem().toLowerCase()));
if (bookingOrgDetail.getUsetype() != null && !bookingOrgDetail.getUsetype().trim().isEmpty()) {
orgTelecom.setUse(ContactPointUse.fromCode(bookingOrgDetail.getUsetype().toLowerCase()));
}
} catch (FHIRException ex) {
// Logger.getLogger(AppointmentResourceProvider.class.getName()).log(Level.SEVERE, null, ex);
}
bookingOrg.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
if (null != bookingOrgDetail.getOrgCode()) {
bookingOrg.getIdentifierFirstRep().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(bookingOrgDetail.getOrgCode());
}
// add contained booking organization resource
appointment.getContained().add(bookingOrg);
}
// if bookingOrganization
appointment.setMinutesDuration(appointmentDetail.getMinutesDuration());
// 1.2.7 set service category from schedule type description
appointment.setServiceCategory(new CodeableConcept().setText(scheduleDetail.getTypeDescription()));
// 1.2.7 set service type from slot type description
appointment.addServiceType(new CodeableConcept().setText(slotSearch.findSlotByID(sids.get(0)).getTypeDisply()));
return appointment;
}
use of org.hl7.fhir.dstu3.model.StringType in project gpconnect-demonstrator by nhsconnect.
the class StructuredAllergyIntoleranceBuilder method buildStructuredAllergyIntolerence.
public Bundle buildStructuredAllergyIntolerence(String NHS, Set<String> practitionerIds, Bundle bundle, Boolean includedResolved) {
List<StructuredAllergyIntoleranceEntity> allergyData = structuredAllergySearch.getAllergyIntollerence(NHS);
ListResource activeList = initiateListResource(NHS, ACTIVE_ALLERGIES_DISPLAY, allergyData);
ListResource resolvedList = initiateListResource(NHS, RESOLVED_ALLERGIES_DISPLAY, allergyData);
// This is patient 5 example 2 only
if (allergyData.size() == 1 && allergyData.get(0).getClinicalStatus().equals(SystemConstants.NO_KNOWN)) {
StructuredAllergyIntoleranceEntity noKnownAllergy = allergyData.get(0);
// #214 had incorrect code and value for no known allergies
CodeableConcept noKnownAllergies = createCoding(SystemURL.VS_LIST_EMPTY_REASON_CODE, NO_CONTENT_RECORDED, NO_CONTENT_RECORDED_DISPLAY);
noKnownAllergies.setText("No Known Allergies");
// activeList.setEmptyReason(noKnownAllergies);
// see spec example 2 no known allergies positively asserted
Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyData.get(0).getPatientRef());
String noKnownAllergyId = noKnownAllergy.getGuid();
Reference allergyIntolerance = new Reference("AllergyIntolerance/" + noKnownAllergyId);
Resource noKnownAllergyResource = createNoKnownAllergy(noKnownAllergy);
activeList.setSubject(patient);
// reference to AllergyIntolerance item
activeList.addEntry().setItem(allergyIntolerance);
activeList.setOrderedBy(createCoding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date"));
bundle.addEntry().setResource(activeList);
bundle.addEntry().setResource(noKnownAllergyResource);
if (includedResolved) {
resolvedList.setSubject(patient);
resolvedList.setEmptyReason(noKnownAllergies);
bundle.addEntry().setResource(resolvedList);
}
return bundle;
}
for (StructuredAllergyIntoleranceEntity allergyIntoleranceEntity : allergyData) {
AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
allergyIntolerance.setOnset(new DateTimeType(allergyIntoleranceEntity.getOnSetDateTime()));
allergyIntolerance.setMeta(createMeta(SystemURL.SD_CC_ALLERGY_INTOLERANCE));
allergyIntolerance.setId(allergyIntoleranceEntity.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier1 = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(allergyIntoleranceEntity.getGuid());
identifiers.add(identifier1);
allergyIntolerance.setIdentifier(identifiers);
if (allergyIntoleranceEntity.getClinicalStatus().equals(SystemConstants.ACTIVE)) {
allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
} else {
allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
}
if (allergyIntoleranceEntity.getCategory().equals(SystemConstants.MEDICATION)) {
allergyIntolerance.addCategory(AllergyIntoleranceCategory.MEDICATION);
} else {
allergyIntolerance.addCategory(AllergyIntoleranceCategory.ENVIRONMENT);
}
allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.UNCONFIRMED);
// CODE
codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getConceptCode(), allergyIntoleranceEntity.getConceptDisplay()).addDescription(allergyIntoleranceEntity.getDescCode(), allergyIntoleranceEntity.getDescDisplay()).addTranslation(allergyIntoleranceEntity.getCodeTranslationRef());
allergyIntolerance.setCode(codeableConceptBuilder.build());
codeableConceptBuilder.clear();
allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
allergyIntolerance.setPatient(patient);
Annotation noteAnnotation = new Annotation(new StringType(allergyIntoleranceEntity.getNote()));
allergyIntolerance.setNote(Collections.singletonList(noteAnnotation));
AllergyIntoleranceReactionComponent reaction = new AllergyIntoleranceReactionComponent();
// MANIFESTATION
List<CodeableConcept> theManifestation = new ArrayList<>();
codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getManifestationCoding(), allergyIntoleranceEntity.getManifestationDisplay()).addDescription(allergyIntoleranceEntity.getManifestationDescCoding(), allergyIntoleranceEntity.getManifestationDescDisplay()).addTranslation(allergyIntoleranceEntity.getManTranslationRef());
theManifestation.add(codeableConceptBuilder.build());
codeableConceptBuilder.clear();
reaction.setManifestation(theManifestation);
reaction.setDescription(allergyIntoleranceEntity.getNote());
// SEVERITY
try {
reaction.setSeverity(AllergyIntoleranceSeverity.fromCode(allergyIntoleranceEntity.getSeverity()));
} catch (FHIRException e) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Unknown severity: " + allergyIntoleranceEntity.getSeverity()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
// EXPOSURE
CodeableConcept exposureRoute = new CodeableConcept();
reaction.setExposureRoute(exposureRoute);
allergyIntolerance.addReaction(reaction);
// RECORDER
final Reference refValue = new Reference();
final Identifier identifier = new Identifier();
final String recorder = allergyIntoleranceEntity.getRecorder();
// This is just an example to demonstrate using Reference element instead of Identifier element
if (recorder.equals(patient2NhsNo.trim())) {
Reference rec = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
allergyIntolerance.setRecorder(rec);
} else if (patientRepository.findByNhsNumber(recorder) != null) {
identifier.setSystem(SystemURL.ID_NHS_NUMBER);
identifier.setValue(recorder);
refValue.setIdentifier(identifier);
allergyIntolerance.setRecorder(refValue);
} else if (practitionerSearch.findPractitionerByUserId(recorder) != null) {
refValue.setReference("Practitioner/" + recorder);
allergyIntolerance.setRecorder(refValue);
practitionerIds.add(recorder);
}
// CLINICAL STATUS
List<Extension> extensions = new ArrayList<>();
if (allergyIntolerance.getClinicalStatus().getDisplay().contains("Active")) {
listResourceBuilder(activeList, allergyIntolerance, false);
bundle.addEntry().setResource(allergyIntolerance);
} else if (allergyIntolerance.getClinicalStatus().getDisplay().equals("Resolved") && includedResolved.equals(true)) {
listResourceBuilder(resolvedList, allergyIntolerance, true);
allergyIntolerance.setLastOccurrence(allergyIntoleranceEntity.getEndDate());
final Extension allergyEndExtension = createAllergyEndExtension(allergyIntoleranceEntity);
extensions.add(allergyEndExtension);
}
if (!extensions.isEmpty()) {
allergyIntolerance.setExtension(extensions);
}
// ASSERTER
Reference asserter = allergyIntolerance.getAsserter();
if (asserter != null && asserter.getReference() != null && asserter.getReference().startsWith("Practitioner")) {
String[] split = asserter.getReference().split("/");
practitionerIds.add(split[1]);
}
}
if (!activeList.hasEntry()) {
addEmptyListNote(activeList);
addEmptyReasonCode(activeList);
}
bundle.addEntry().setResource(activeList);
if (includedResolved && !resolvedList.hasEntry()) {
addEmptyListNote(resolvedList);
addEmptyReasonCode(resolvedList);
}
if (includedResolved) {
bundle.addEntry().setResource(resolvedList);
}
return bundle;
}
use of org.hl7.fhir.dstu3.model.StringType in project gpconnect-demonstrator by nhsconnect.
the class StructuredAllergyIntoleranceBuilder method createNoKnownAllergy.
/**
* This relates to the positively asserted this patient has no know
* allergies as opposed to the the negatively asserted no allergies recorded
* patient 5 example 2 from the spec
*
* @param allergyIntoleranceEntity object from the db
* @return the allergy intolerance resource
*/
private AllergyIntolerance createNoKnownAllergy(StructuredAllergyIntoleranceEntity allergyIntoleranceEntity) {
AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
allergyIntolerance.setId(allergyIntoleranceEntity.getGuid());
allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
// db has clinical status of "no known" which is not a valid value
allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.valueOf(allergyIntoleranceEntity.getVerificationStatus().toUpperCase()));
allergyIntolerance.setType(AllergyIntoleranceType.ALLERGY);
CodeableConcept codeableConcept = new CodeableConcept();
Coding coding = new Coding();
coding.setDisplay(allergyIntoleranceEntity.getConceptDisplay());
// That's as in db under concept code 716186003
coding.setCode(allergyIntoleranceEntity.getConceptCode());
coding.setSystem(SystemConstants.SNOMED_URL);
Extension extension = new Extension(SystemURL.SD_EXT_SCT_DESC_ID);
// 3305010017
extension.addExtension("descriptionId", new StringType(allergyIntoleranceEntity.getDescCode()));
// NKA - No known allergy
extension.addExtension("descriptionDisplay", new StringType(allergyIntoleranceEntity.getDescDisplay()));
coding.addExtension(extension);
codeableConcept.addCoding(coding);
allergyIntolerance.setCode(codeableConcept);
return allergyIntolerance;
}
Aggregations