/** * The "@Read" annotation indicates that this method supports the * read operation. It takes one argument, the Resource type being returned. * * @param theId * The read operation takes one parameter, which must be of type * IdDt and must be annotated with the "@Read.IdParam" annotation. * @return * Returns a resource matching this identifier, or null if none exists. */ @Read() public Patient getResourceById(@IdParam IdDt theId) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00002"); patient.addName().addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.FEMALE); return patient; }
String patientId = patient.getIdentifier().get(0).getValue(); String familyName = patient.getName().get(0).getFamily().get(0).getValue(); String gender = patient.getGender();
@SuppressWarnings("unused") public static void codes() { // START SNIPPET: codes Patient patient = new Patient(); // You can set this code using a String if you want. Note that // for "closed" valuesets (such as the one used for Patient.gender) // you must use one of the strings defined by the FHIR specification. // You must not define your own. patient.getGenderElement().setValue("male"); // HAPI also provides Java enumerated types which make it easier to // deal with coded values. This code achieves the exact same result // as the code above. patient.setGender(AdministrativeGenderEnum.MALE); // You can also retrieve coded values the same way String genderString = patient.getGenderElement().getValueAsString(); AdministrativeGenderEnum genderEnum = patient.getGenderElement().getValueAsEnum(); // The following is a shortcut to create patient.setMaritalStatus(MaritalStatusCodesEnum.M); // END SNIPPET: codes }
for (Patient patient : patients) { if (patient.getId().equals(search)) { return patient; } } return null;
Patient patient = new Patient(); patient.addIdentifier() .setSystem("http://acme.org/mrns") .setValue("12345"); patient.addName() .addFamily("Jameson") .addGiven("J") .addGiven("Jonah"); patient.setGender(AdministrativeGenderEnum.MALE); patient.setId(IdDt.newRandomUuid()); observation.setSubject(new ResourceReferenceDt(patient.getId().getValue())); .setFullUrl(patient.getId().getValue()) .setResource(patient) .getRequest()
public void testFindPatientWherePatientExists() { Patient thePatient = surgery.findPatient("Teddy"); assertEquals("Teddy", thePatient.getName()); } public void testFindPatientWherePatientDoesntExist() { assertNull(surgery.findPatient("I dont exist")); }
public static int total(List<Patient> firstList, List<Patient> secondList, int search) { int total = 0; for(Patient p:firstList) { if(p.getId() == search) { total = p.getServiceCost(); for(Patient p2 : secondList) { if(p2.getId()== search) { total += p2.gettotaltestcost() + p2.gettotaltreatmentcost(); break; } } } } return total; }
/** * Creates a CCOW context from the specified patient object. */ @Override public ContextItems toCCOWContext(Patient patient) { IdentifierDt mrn = FhirUtil.getIdentifier(patient.getIdentifier(), IdentifierTypeCodesEnum.MR); contextItems.setItem(CCOW_MRN, mrn == null ? null : mrn.getValue(), "MRN"); contextItems.setItem(CCOW_NAM, patient.getName()); contextItems.setItem(CCOW_SEX, patient.getGender()); contextItems.setItem(CCOW_DOB, patient.getBirthDate()); return contextItems; }
HumanNameParser hnp = new HumanNameParser(); changeUserContext(); Patient patient1 = new Patient(); patient1.setId("321"); patient1.getName().add(hnp.fromString(null, "Smith, Joe")); IdentifierDt ssn = new IdentifierDt(); ssn.setType(IdentifierTypeCodesEnum.SS); ssn.setValue("999-99-9999"); patient1.getIdentifier().add(ssn); patient1.setBirthDate(new DateDt("1958-07-27")); Patient patient2 = new Patient(); patient2.setId("123"); patient2.getName().add(hnp.fromString(null, "Doe, Jane")); IdentifierDt ssn2 = new IdentifierDt(); ssn2.setType(IdentifierTypeCodesEnum.SS); ssn2.setValue("123-45-6789"); patient2.getIdentifier().add(ssn2); patient2.setBirthDate(new DateDt("1963-05-01")); Object subscriber = new ContextChangeSubscriber(); // Create a patient context change subscriber
} else { text = FhirUtil.formatName(patient.getName()); String gender = patient.getGender(); Date deceased = patient.getDeceased() instanceof DateDt ? ((DateDt) patient.getDeceased()).getValue() : null; String age = DateUtil.formatAge(patient.getBirthDate(), true, deceased); text += " Age: " + age;
Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135"); patient.addUndeclaredExtension(ext); HumanNameDt name = patient.addName(); name.addFamily().setValue("Shmoe"); StringDt given = name.addGiven(); List<ExtensionDt> resourceExts = patient.getUndeclaredExtensionsByUrl("http://fooextensions.com#exts"); List<ExtensionDt> nonModExts = patient.getUndeclaredExtensions(); List<ExtensionDt> modExts = patient.getUndeclaredModifierExtensions();
public void UpdateTable() { DefaultTableModel tableModel = (DefaultTableModel)TableName.getModel(); for(Patient k: PatientList) { int TableID = k.getAccountNumber(); String TableName = k.getName(); int TableAge = k.getAge(); String TableAddress = k.getAddress(); String TableSex = k.getSex(); String TablePhone = k.getPhone(); //Add row here. tableModel.addRow(new String[]{TableID,TableName,TableAge,TableAddress,TableSex,TablePhone }); } }
@Search private List<IBaseResource> searchForPatients() { // Create an organization Organization org = new Organization(); org.setId("Organization/65546"); org.setName("Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); patient.getManagingOrganization().setResource(org); // Here we return only the patient object, which has links to other resources List<IBaseResource> retVal = new ArrayList<IBaseResource>(); retVal.add(patient); return retVal; } // END SNIPPET: addIncludes
/** * The main method here will directly call an open FHIR server and retrieve a * list of resources matching a given criteria, then load a linked resource. */ public static void main(String[] args) throws IOException { // Create a client factory FhirContext ctx = FhirContext.forDstu2(); // Create the client String serverBase = "http://fhir.healthintersections.com.au/open"; ClientInterface client = ctx.newRestfulClient(ClientInterface.class, serverBase); // Invoke the client to search for patient List<Patient> patients = client.findPatientsForMrn(new IdentifierDt("urn:oid:1.2.36.146.595.217.0.1", "12345")); System.out.println("Found " + patients.size() + " patients"); // Print a value from the loaded resource Patient patient = patients.get(0); System.out.println("Patient Last Name: " + patient.getName().get(0).getFamily().get(0).getValue()); // Load a referenced resource ResourceReferenceDt managingRef = patient.getManagingOrganization(); Organization org = (Organization) managingRef.loadResource(client); // Print organization name System.out.println(org.getName()); }
@Search public List<Patient> getAllPatients() { ArrayList<Patient> retVal = new ArrayList<Patient>(); // Create a patient to return Patient patient = new Patient(); patient.setId("Patient/123"); patient.addName().addFamily("Smith").addGiven("John"); // Create a tag list and add it to the resource TagList tags = new TagList(); ResourceMetadataKeyEnum.TAG_LIST.put(patient, tags); // Add some tags to the list tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag1.html", "Some tag"); tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag2.html", "Another tag"); return retVal; } // END SNIPPET: serverMethod
@SuppressWarnings("unused") public static void main(String[] args) throws DataFormatException, IOException { Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135"); patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior"); patient.setGender(AdministrativeGenderEnum.MALE); FhirContext ctx = FhirContext.forDstu2(); String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient); String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient); MyClientInterface client = ctx.newRestfulClient(MyClientInterface.class, "http://foo/fhir"); IdentifierDt searchParam = new IdentifierDt("urn:someidentifiers", "7000135"); List<Patient> clients = client.findPatientsByIdentifier(searchParam); }
for (Patient p : patients) { System.out.println(String.format(DATA_FORMAT, p.getMediacareNumber(), p.getName(), p.getDob(), p.getVisits())); }