use of org.hl7.fhir.r4.model.ContactPoint in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.
/**
* fhir resource Appointment to AppointmentDetail
*
* @param appointment Resource
* @return populated AppointmentDetail
*/
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " characters");
}
AppointmentDetail appointmentDetail = new AppointmentDetail();
Long id = appointment.getIdElement().getIdPartAsLong();
appointmentDetail.setId(id);
appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
if (cnlExtension != null && !cnlExtension.isEmpty()) {
IBaseDatatype value = cnlExtension.get(0).getValue();
if (null == value) {
throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
}
appointmentDetail.setCancellationReason(value.toString());
}
appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
appointmentDetail.setPriority(appointment.getPriority());
appointmentDetail.setStartDateTime(appointment.getStart());
appointmentDetail.setEndDateTime(appointment.getEnd());
List<Long> slotIds = new ArrayList<>();
for (Reference slotReference : appointment.getSlot()) {
// #200 check slots for absolute references
checkReferenceIsRelative(slotReference.getReference());
try {
String here = slotReference.getReference().substring("Slot/".length());
Long slotId = new Long(here);
slotIds.add(slotId);
} catch (NumberFormatException ex) {
throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
}
}
appointmentDetail.setSlotIds(slotIds);
if (appointmentValidation.appointmentCommentTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
}
appointmentDetail.setComment(appointment.getComment());
appointmentDetail.setDescription(appointment.getDescription());
for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
if (participant.getActor() != null) {
String participantReference = participant.getActor().getReference();
String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
Long actorId;
if (actorIdString.equals("null")) {
actorId = null;
} else {
actorId = Long.valueOf(actorIdString);
}
if (participantReference.contains("Patient/")) {
appointmentDetail.setPatientId(actorId);
} else if (participantReference.contains("Practitioner/")) {
appointmentDetail.setPractitionerId(actorId);
} else if (participantReference.contains("Location/")) {
appointmentDetail.setLocationId(actorId);
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
}
}
if (appointment.getCreated() != null) {
Date created = appointment.getCreated();
appointmentDetail.setCreated(created);
}
// #200 check extensions for absolute references
List<Extension> extensions = appointment.getExtension();
for (Extension extension : extensions) {
try {
Reference reference = (Reference) extension.getValue();
if (reference != null) {
checkReferenceIsRelative(reference.getReference());
}
} catch (ClassCastException ex) {
}
}
List<Resource> contained = appointment.getContained();
if (contained != null && !contained.isEmpty()) {
Resource org = contained.get(0);
Organization bookingOrgRes = (Organization) org;
BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
bookingOrgDetail.setName(bookingOrgRes.getName());
// #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
while (iter.hasNext()) {
ContactPoint thisTelecom = iter.next();
if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
telecom = thisTelecom;
break;
}
}
bookingOrgDetail.setTelephone(telecom.getValue());
bookingOrgDetail.setSystem(telecom.getSystem().toString());
if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
bookingOrgDetail.setUsetype(telecom.getUse().toString());
}
if (!bookingOrgRes.getIdentifier().isEmpty()) {
bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
// check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
if (system != null && !system.trim().isEmpty()) {
if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
}
}
bookingOrgDetail.setAppointmentDetail(appointmentDetail);
appointmentDetail.setBookingOrganization(bookingOrgDetail);
// 1.2.7
appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
}
return appointmentDetail;
}
use of org.hl7.fhir.r4.model.ContactPoint 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.r4.model.ContactPoint 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.r4.model.ContactPoint in project kindling by HL7.
the class Publisher method generateCodeSystemRegistry.
private void generateCodeSystemRegistry() throws FileNotFoundException, IOException, Exception {
XmlParser xml = new XmlParser();
xml.setOutputStyle(OutputStyle.PRETTY);
Bundle bnd = (Bundle) xml.parse(new CSFileInputStream(Utilities.path(page.getFolders().srcDir, "namingsystem", "namingsystem-terminologies.xml")));
for (BundleEntryComponent entry : bnd.getEntry()) {
NamingSystem ns = (NamingSystem) entry.getResource();
entry.setFullUrl("http://hl7.org/fhir/NamingSystem/" + ns.getId());
String url = null;
for (NamingSystemUniqueIdComponent t : ns.getUniqueId()) {
if (t.getType() == NamingSystemIdentifierType.URI)
url = t.getValue();
}
if (url != null) {
if (url.startsWith("http://hl7.org/fhir"))
page.getDefinitions().addNs(url, "System " + ns.getName(), "terminologies-systems.html#" + url);
page.getDefinitions().addNs(entry.getFullUrl(), ns.getId(), "terminologies-systems.html#" + url);
}
}
List<String> names = new ArrayList<String>();
Set<String> urls = new HashSet<>();
names.addAll(page.getCodeSystems().keys());
Collections.sort(names);
for (String n : names) {
CodeSystem cs = page.getCodeSystems().get(n);
if (cs != null && !urls.contains(cs.getUrl()) && cs.hasUrl() && !cs.getUrl().startsWith("http://terminology.hl7.org")) {
urls.add(cs.getUrl());
if (cs.hasName()) {
NamingSystem ns = new NamingSystem();
ns.setId(cs.getId());
ns.setName(cs.getName());
ns.setStatus(cs.getStatus());
if (!ns.hasStatus())
ns.setStatus(PublicationStatus.DRAFT);
ns.setKind(NamingSystemType.CODESYSTEM);
ns.setPublisher(cs.getPublisher());
for (ContactDetail c : cs.getContact()) {
ContactDetail nc = ns.addContact();
nc.setName(c.getName());
for (ContactPoint cc : c.getTelecom()) {
nc.getTelecom().add(cc);
}
}
ns.setDate(cs.getDate());
if (!ns.hasDate())
ns.setDate(page.getGenDate().getTime());
ns.setDescription(cs.getDescription());
ns.addUniqueId().setType(NamingSystemIdentifierType.URI).setValue(cs.getUrl()).setPreferred(true);
String oid = CodeSystemUtilities.getOID(cs);
if (oid != null) {
if (oid.startsWith("urn:oid:"))
oid = oid.substring(8);
ns.addUniqueId().setType(NamingSystemIdentifierType.OID).setValue(oid).setPreferred(false);
}
ns.setUserData("path", cs.getUserData("path"));
bnd.addEntry().setResource(ns).setFullUrl("http://hl7.org/fhir/" + ns.fhirType() + "/" + ns.getId());
}
}
}
xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.xml")), bnd);
cloneToXhtml("namingsystem-terminologies", "Terminology Registry", false, "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
xml.setOutputStyle(OutputStyle.CANONICAL);
xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.xml")), bnd);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), bnd);
jsonToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
json.setOutputStyle(OutputStyle.CANONICAL);
json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.json")), bnd);
RdfParser rdf = new RdfParser();
rdf.setOutputStyle(OutputStyle.PRETTY);
rdf.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), bnd);
ttlToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
StringBuilder b = new StringBuilder();
b.append("<table class=\"grid\">\r\n");
b.append(" <tr>");
b.append("<td><b>Name</b></td>");
b.append("<td><b>Uri</b></td>");
b.append("<td><b>OID</b></td>");
b.append("</tr>\r\n");
for (BundleEntryComponent entry : bnd.getEntry()) {
NamingSystem ns = (NamingSystem) entry.getResource();
String uri = "";
String oid = "";
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
if (id.getType() == NamingSystemIdentifierType.URI)
uri = id.getValue();
if (id.getType() == NamingSystemIdentifierType.OID)
oid = id.getValue();
}
String link = "terminologies-systems.html#" + uri;
if (ns.getUserData("path") != null)
link = ns.getUserString("path");
b.append(" <tr>");
b.append("<td><a href=\"" + link + "\">" + Utilities.escapeXml(ns.getName()) + "</a></td>");
b.append("<td>" + Utilities.escapeXml(uri) + "</td>");
b.append("<td>" + Utilities.escapeXml(oid) + "</td>");
b.append("</tr>\r\n");
}
b.append("</table>\r\n");
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", b.toString()).replace("<%example-usage%>", "");
html = page.processPageIncludes("namingsystem-terminologies.html", html, "resource-instance:NamingSystem", null, bnd, null, "Example", null, null, page.getDefinitions().getWorkgroups().get("fhir"));
TextFile.stringToFile(html, page.getFolders().dstDir + "namingsystem-terminologies.html");
cachePage("namingsystem-terminologies.html", html, "Registered Code Systems", false);
}
use of org.hl7.fhir.r4.model.ContactPoint in project kindling by HL7.
the class CodeListToValueSetParser method generateConceptMapV2.
private void generateConceptMapV2(String v2map, ValueSet vs, CodeSystem cs) throws Exception {
ConceptMap cm = new ConceptMap();
cm.setId("cm-" + vs.getId() + "-v2");
cm.setVersion(version);
cm.setUserData("path", cm.getId() + ".html");
cm.setUserData("generate", true);
cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
cm.setName("v2." + vs.getName());
cm.setTitle("v2 map for " + vs.present());
cm.setPublisher("HL7 (FHIR Project)");
for (ContactDetail cc : vs.getContact()) {
ContactDetail cd = cm.addContact();
cd.setName(cc.getName());
for (ContactPoint ccs : cc.getTelecom()) cd.addTelecom(ccs.copy());
}
cm.setCopyright(vs.getCopyright());
// until we publish DSTU, then .review
cm.setStatus(vs.getStatus());
cm.setDate(vs.getDate());
cm.setSource(Factory.newCanonical(vs.getUrl()));
cm.setTarget(Factory.newCanonical(v2map));
if (cs != null)
processV2ConceptDefs(cm, cs.getUrl(), cs.getConcept());
for (ConceptSetComponent cc : vs.getCompose().getInclude()) for (ConceptReferenceComponent c : cc.getConcept()) {
processV2Map(cm, cc.getSystem(), c.getCode(), c.getUserString("v2"));
}
maps.see(cm, packageInfo);
}
Aggregations